1
1
/*
2
- Copyright IBM Corp. 2017 All Rights Reserved.
2
+ Copyright IBM Corp. All Rights Reserved.
3
3
4
- Licensed under the Apache License, Version 2.0 (the "License");
5
- you may not use this file except in compliance with the License.
6
- You may obtain a copy of the License at
7
-
8
- http://www.apache.org/licenses/LICENSE-2.0
9
-
10
- Unless required by applicable law or agreed to in writing, software
11
- distributed under the License is distributed on an "AS IS" BASIS,
12
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- See the License for the specific language governing permissions and
14
- limitations under the License.
4
+ SPDX-License-Identifier: Apache-2.0
15
5
*/
6
+
16
7
package pkcs11
17
8
18
9
import (
@@ -270,9 +261,10 @@ func (csp *impl) generateECKey(curve asn1.ObjectIdentifier, ephemeral bool) (ski
270
261
hash := sha256 .Sum256 (ecpt )
271
262
ski = hash [:]
272
263
273
- // set CKA_ID of the both keys to SKI(public key)
264
+ // set CKA_ID of the both keys to SKI(public key) and CKA_LABEL to hex string of SKI
274
265
setski_t := []* pkcs11.Attribute {
275
266
pkcs11 .NewAttribute (pkcs11 .CKA_ID , ski ),
267
+ pkcs11 .NewAttribute (pkcs11 .CKA_LABEL , hex .EncodeToString (ski )),
276
268
}
277
269
278
270
logger .Infof ("Generated new P11 key, SKI %x\n " , ski )
@@ -376,8 +368,6 @@ func (csp *impl) importECKey(curve asn1.ObjectIdentifier, privKey, ecPt []byte,
376
368
session := csp .getSession ()
377
369
defer csp .returnSession (session )
378
370
379
- id := nextIDCtr ()
380
-
381
371
marshaledOID , err := asn1 .Marshal (curve )
382
372
if err != nil {
383
373
return nil , fmt .Errorf ("Could not marshal OID [%s]" , err .Error ())
@@ -386,11 +376,12 @@ func (csp *impl) importECKey(curve asn1.ObjectIdentifier, privKey, ecPt []byte,
386
376
var keyTemplate []* pkcs11.Attribute
387
377
if keyType == publicKeyFlag {
388
378
logger .Debug ("Importing Public EC Key" )
389
- publabel := fmt .Sprintf ("BCPUB%s" , id .Text (16 ))
390
379
391
380
hash := sha256 .Sum256 (ecPt )
392
381
ski = hash [:]
393
382
383
+ publabel := hex .EncodeToString (ski )
384
+
394
385
// Add DER encoding for the CKA_EC_POINT
395
386
ecPt = append ([]byte {0x04 , byte (len (ecPt ))}, ecPt ... )
396
387
@@ -413,7 +404,7 @@ func (csp *impl) importECKey(curve asn1.ObjectIdentifier, privKey, ecPt []byte,
413
404
}
414
405
415
406
logger .Debugf ("Importing Private EC Key [%d]\n %s\n " , len (privKey )* 8 , hex .Dump (privKey ))
416
- prvlabel := fmt . Sprintf ( "BCPRV%s" , id . Text ( 16 ) )
407
+ prvlabel := hex . EncodeToString ( ski )
417
408
keyTemplate = []* pkcs11.Attribute {
418
409
pkcs11 .NewAttribute (pkcs11 .CKA_KEY_TYPE , pkcs11 .CKK_EC ),
419
410
pkcs11 .NewAttribute (pkcs11 .CKA_CLASS , pkcs11 .CKO_PRIVATE_KEY ),
0 commit comments