Skip to content

Commit

Permalink
Removing calls to NewEcdsaPublicKey
Browse files Browse the repository at this point in the history
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 <adc@zurich.ibm.com>
  • Loading branch information
adecaro committed Nov 25, 2016
1 parent f046f3c commit d016edb
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 16 deletions.
5 changes: 0 additions & 5 deletions core/crypto/bccsp/sw/ecdsakey.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,6 @@ type ecdsaPublicKey struct {
pubKey *ecdsa.PublicKey
}

// FIXME: remove as soon as there's a way to import the key more properly
func NewEcdsaPublicKey(k *ecdsa.PublicKey) bccsp.Key {
return &ecdsaPublicKey{pubKey: k}
}

// Bytes converts this key to its byte representation,
// if this operation is allowed.
func (k *ecdsaPublicKey) Bytes() (raw []byte, err error) {
Expand Down
31 changes: 20 additions & 11 deletions msp/bccspmsp.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ limitations under the License.
package msp

import (
"crypto/ecdsa"
"crypto/x509"
"fmt"
"time"
Expand All @@ -30,7 +29,6 @@ import (
"github.com/hyperledger/fabric/core/crypto/bccsp"
"github.com/hyperledger/fabric/core/crypto/bccsp/factory"
"github.com/hyperledger/fabric/core/crypto/bccsp/signer"
"github.com/hyperledger/fabric/core/crypto/bccsp/sw"
)

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

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

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

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

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

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

return newIdentity(id, cert, sw.NewEcdsaPublicKey(cert.PublicKey.(*ecdsa.PublicKey))), nil
pub, err := msp.bccsp.KeyImport(cert, &bccsp.X509PublicKeyImportOpts{Temporary: true})
if err != nil {
return nil, fmt.Errorf("Failed to import certitifacateś public key [%s]", err)
}

return newIdentity(id, cert, pub), nil
}

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

0 comments on commit d016edb

Please sign in to comment.