Skip to content

Commit

Permalink
Switch to PEM encoding for serialized identities
Browse files Browse the repository at this point in the history
This change-set switches to PEM encoding for serialized identities in protocol
messages to facilitate the integration with nodejs clients.

Change-Id: I2d91f6977e0965cbf88d549c29d4fb68e70ae1be
Signed-off-by: Alessandro Sorniotti <ale.linux@sopit.net>
  • Loading branch information
ale-linux committed Nov 22, 2016
1 parent 56fb71d commit ecc3eea
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
6 changes: 5 additions & 1 deletion msp/bccspmsp.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,11 @@ func (msp *bccspmsp) DeserializeIdentity(serializedID []byte) (Identity, error)
mspLogger.Infof("Obtaining identity")

// This MSP will always deserialize certs this way
cert, err := x509.ParseCertificate(serializedID)
bl, _ := pem.Decode(serializedID)
if bl == nil {
return nil, fmt.Errorf("Could not decode the PEM structure")
}
cert, err := x509.ParseCertificate(bl.Bytes)
if err != nil {
return nil, fmt.Errorf("ParseCertificate failed %s", err)
}
Expand Down
25 changes: 16 additions & 9 deletions msp/identities.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import (
"crypto/x509"
"fmt"

"encoding/pem"

"github.com/hyperledger/fabric/core/crypto/bccsp"
"github.com/hyperledger/fabric/core/crypto/bccsp/factory"
"github.com/hyperledger/fabric/core/crypto/bccsp/signer"
Expand Down Expand Up @@ -79,18 +81,23 @@ func (id *identity) VerifyAttributes(proof [][]byte, spec *AttributeProofSpec) (

func (id *identity) Serialize() ([]byte, error) {
/*
mspLogger.Infof("Serializing identity %s", id.id)
mspLogger.Infof("Serializing identity %s", id.id)
// We serialize identities by prepending the MSPID and appending the ASN.1 DER content of the cert
sId := SerializedIdentity{Mspid: id.id.Mspid, IdBytes: id.cert.Raw}
idBytes, err := asn1.Marshal(sId)
if err != nil {
return nil, fmt.Errorf("Could not marshal a SerializedIdentity structure for identity %s, err %s", id.id, err)
}
// We serialize identities by prepending the MSPID and appending the ASN.1 DER content of the cert
sId := SerializedIdentity{Mspid: id.id.Mspid, IdBytes: id.cert.Raw}
idBytes, err := asn1.Marshal(sId)
if err != nil {
return nil, fmt.Errorf("Could not marshal a SerializedIdentity structure for identity %s, err %s", id.id, err)
}
return idBytes, nil
return idBytes, nil
*/
return id.cert.Raw, nil
pb := &pem.Block{Bytes: id.cert.Raw}
pemBytes := pem.EncodeToMemory(pb)
if pemBytes == nil {
return nil, fmt.Errorf("Encoding of identitiy failed")
}
return pemBytes, nil
}

type signingidentity struct {
Expand Down

0 comments on commit ecc3eea

Please sign in to comment.