11/*
2- Copyright IBM Corp. 2017 All Rights Reserved.
2+ Copyright IBM Corp. All Rights Reserved.
33
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
155*/
6+
167package pkcs11
178
189import (
@@ -270,9 +261,10 @@ func (csp *impl) generateECKey(curve asn1.ObjectIdentifier, ephemeral bool) (ski
270261 hash := sha256 .Sum256 (ecpt )
271262 ski = hash [:]
272263
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
274265 setski_t := []* pkcs11.Attribute {
275266 pkcs11 .NewAttribute (pkcs11 .CKA_ID , ski ),
267+ pkcs11 .NewAttribute (pkcs11 .CKA_LABEL , hex .EncodeToString (ski )),
276268 }
277269
278270 logger .Infof ("Generated new P11 key, SKI %x\n " , ski )
@@ -376,8 +368,6 @@ func (csp *impl) importECKey(curve asn1.ObjectIdentifier, privKey, ecPt []byte,
376368 session := csp .getSession ()
377369 defer csp .returnSession (session )
378370
379- id := nextIDCtr ()
380-
381371 marshaledOID , err := asn1 .Marshal (curve )
382372 if err != nil {
383373 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,
386376 var keyTemplate []* pkcs11.Attribute
387377 if keyType == publicKeyFlag {
388378 logger .Debug ("Importing Public EC Key" )
389- publabel := fmt .Sprintf ("BCPUB%s" , id .Text (16 ))
390379
391380 hash := sha256 .Sum256 (ecPt )
392381 ski = hash [:]
393382
383+ publabel := hex .EncodeToString (ski )
384+
394385 // Add DER encoding for the CKA_EC_POINT
395386 ecPt = append ([]byte {0x04 , byte (len (ecPt ))}, ecPt ... )
396387
@@ -413,7 +404,7 @@ func (csp *impl) importECKey(curve asn1.ObjectIdentifier, privKey, ecPt []byte,
413404 }
414405
415406 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 )
417408 keyTemplate = []* pkcs11.Attribute {
418409 pkcs11 .NewAttribute (pkcs11 .CKA_KEY_TYPE , pkcs11 .CKK_EC ),
419410 pkcs11 .NewAttribute (pkcs11 .CKA_CLASS , pkcs11 .CKO_PRIVATE_KEY ),
0 commit comments