Skip to content

Commit d016edb

Browse files
committed
Removing calls to NewEcdsaPublicKey
This changes-set removes the temporary fix used to import ecdsa publick keys. The fix has been replaced by a proper invocation of the BCCSP's KeyImport method. Change-Id: I21f279df2591d7c92a1936a5cd6c5d5fc40fd621 Signed-off-by: Angelo De Caro <[email protected]>
1 parent f046f3c commit d016edb

File tree

2 files changed

+20
-16
lines changed

2 files changed

+20
-16
lines changed

core/crypto/bccsp/sw/ecdsakey.go

-5
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,6 @@ type ecdsaPublicKey struct {
7575
pubKey *ecdsa.PublicKey
7676
}
7777

78-
// FIXME: remove as soon as there's a way to import the key more properly
79-
func NewEcdsaPublicKey(k *ecdsa.PublicKey) bccsp.Key {
80-
return &ecdsaPublicKey{pubKey: k}
81-
}
82-
8378
// Bytes converts this key to its byte representation,
8479
// if this operation is allowed.
8580
func (k *ecdsaPublicKey) Bytes() (raw []byte, err error) {

msp/bccspmsp.go

+20-11
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ limitations under the License.
1717
package msp
1818

1919
import (
20-
"crypto/ecdsa"
2120
"crypto/x509"
2221
"fmt"
2322
"time"
@@ -30,7 +29,6 @@ import (
3029
"github.com/hyperledger/fabric/core/crypto/bccsp"
3130
"github.com/hyperledger/fabric/core/crypto/bccsp/factory"
3231
"github.com/hyperledger/fabric/core/crypto/bccsp/signer"
33-
"github.com/hyperledger/fabric/core/crypto/bccsp/sw"
3432
)
3533

3634
// This is an instantiation of an MSP that
@@ -127,19 +125,22 @@ func (msp *bccspmsp) Setup(configFile string) error {
127125
return fmt.Errorf("Failed to parse x509 cert, err %s", err)
128126
}
129127

130-
// Extract the keypair
131-
pemKey, _ := pem.Decode(id.PublicSigner.Key)
132-
key, err := x509.ParseECPrivateKey(pemKey.Bytes)
128+
// Get public key
129+
pub, err := msp.bccsp.KeyImport(cert, &bccsp.X509PublicKeyImportOpts{Temporary: true})
133130
if err != nil {
134-
return fmt.Errorf("Failed to parse keypair, err %s", err)
131+
return fmt.Errorf("Failed to import certificate's public key, err %s", err)
135132
}
136133

137-
// get the keypair in the right format
138-
pub := sw.NewEcdsaPublicKey(cert.PublicKey.(*ecdsa.PublicKey))
134+
// Get secret key
135+
pemKey, _ := pem.Decode(id.PublicSigner.Key)
136+
key, err := msp.bccsp.KeyImport(pemKey.Bytes, &bccsp.ECDSAPrivateKeyImportOpts{Temporary: true})
137+
if err != nil {
138+
return fmt.Errorf("Failed to import EC private key, err %s", err)
139+
}
139140

140141
// get the peer signer
141142
peerSigner := &signer.CryptoSigner{}
142-
err = peerSigner.Init(msp.bccsp, sw.NewEcdsaPrivateKey(key))
143+
err = peerSigner.Init(msp.bccsp, key)
143144
if err != nil {
144145
return fmt.Errorf("Failed initializing CryptoSigner, err %s", err)
145146
}
@@ -158,7 +159,10 @@ func (msp *bccspmsp) Setup(configFile string) error {
158159
}
159160

160161
// get the CA keypair in the right format
161-
CAPub := sw.NewEcdsaPublicKey(CACert.PublicKey.(*ecdsa.PublicKey))
162+
CAPub, err := msp.bccsp.KeyImport(CACert, &bccsp.X509PublicKeyImportOpts{Temporary: true})
163+
if err != nil {
164+
return fmt.Errorf("Failed to import certitifacate's public key [%s]", err)
165+
}
162166

163167
// Set the trusted identity related to the ROOT CA
164168
rootCaIdentity := newIdentity(&IdentityIdentifier{Mspid: MSPID, Value: "ROOTCA"}, CACert, CAPub)
@@ -256,7 +260,12 @@ func (msp *bccspmsp) DeserializeIdentity(serializedID []byte) (Identity, error)
256260
id := &IdentityIdentifier{Mspid: ProviderIdentifier{Value: msp.id.Value},
257261
Value: "PEER"} // TODO: where should this identifier be obtained from?
258262

259-
return newIdentity(id, cert, sw.NewEcdsaPublicKey(cert.PublicKey.(*ecdsa.PublicKey))), nil
263+
pub, err := msp.bccsp.KeyImport(cert, &bccsp.X509PublicKeyImportOpts{Temporary: true})
264+
if err != nil {
265+
return nil, fmt.Errorf("Failed to import certitifacateś public key [%s]", err)
266+
}
267+
268+
return newIdentity(id, cert, pub), nil
260269
}
261270

262271
func (msp *bccspmsp) DeleteSigningIdentity(identifier string) (bool, error) {

0 commit comments

Comments
 (0)