Skip to content

Commit 2be2d00

Browse files
author
Manu Drijvers
committed
[FAB-10370] change format for storing revocationpk
We store the revocation key as encoded PEM bytes to be consistent with how x509 certs are stored. Change-Id: Iee8373b1ceaa00095b0dcf72ecca4a92ab0bcc6f Signed-off-by: Manu Drijvers <mdr@zurich.ibm.com>
1 parent ff950e2 commit 2be2d00

32 files changed

+47
-18
lines changed

common/tools/idemixgen/idemixca/idemixca_test.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ import (
1212
"path/filepath"
1313
"testing"
1414

15-
"crypto/elliptic"
15+
"crypto/x509"
16+
17+
"encoding/pem"
1618

1719
"github.com/golang/protobuf/proto"
1820
"github.com/hyperledger/fabric/idemix"
@@ -37,7 +39,11 @@ func TestIdemixCa(t *testing.T) {
3739
err = proto.Unmarshal(ipkBytes, ipk)
3840
assert.NoError(t, err)
3941

40-
writeVerifierToFile(ipkBytes, elliptic.Marshal(elliptic.P384(), revocationkey.X, revocationkey.Y))
42+
encodedRevocationPK, err := x509.MarshalPKIXPublicKey(revocationkey.Public())
43+
assert.NoError(t, err)
44+
pemEncodedRevocationPK := pem.EncodeToMemory(&pem.Block{Type: "PUBLIC KEY", Bytes: encodedRevocationPK})
45+
46+
writeVerifierToFile(ipkBytes, pemEncodedRevocationPK)
4147

4248
key := &idemix.IssuerKey{Isk: isk, Ipk: ipk}
4349

common/tools/idemixgen/idemixgen.go

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ import (
1818
"os"
1919
"path/filepath"
2020

21-
"crypto/elliptic"
22-
2321
"crypto/ecdsa"
2422

23+
"encoding/pem"
24+
2525
"github.com/golang/protobuf/proto"
2626
"github.com/hyperledger/fabric/common/tools/idemixgen/idemixca"
2727
"github.com/hyperledger/fabric/common/tools/idemixgen/metadata"
@@ -64,9 +64,13 @@ func main() {
6464

6565
revocationKey, err := idemix.GenerateLongTermRevocationKey()
6666
handleError(err)
67-
revocationKeyBytes, err := x509.MarshalECPrivateKey(revocationKey)
67+
encodedRevocationSK, err := x509.MarshalECPrivateKey(revocationKey)
68+
handleError(err)
69+
pemEncodedRevocationSK := pem.EncodeToMemory(&pem.Block{Type: "PRIVATE KEY", Bytes: encodedRevocationSK})
6870
handleError(err)
69-
revocationPkBytes := elliptic.Marshal(elliptic.P384(), revocationKey.X, revocationKey.Y)
71+
encodedRevocationPK, err := x509.MarshalPKIXPublicKey(revocationKey.Public())
72+
handleError(err)
73+
pemEncodedRevocationPK := pem.EncodeToMemory(&pem.Block{Type: "PUBLIC KEY", Bytes: encodedRevocationPK})
7074

7175
// Prevent overwriting the existing key
7276
path := filepath.Join(*outputDir, IdemixDirIssuer)
@@ -79,9 +83,9 @@ func main() {
7983
handleError(os.MkdirAll(filepath.Join(*outputDir, IdemixDirIssuer), 0770))
8084
handleError(os.MkdirAll(filepath.Join(*outputDir, msp.IdemixConfigDirMsp), 0770))
8185
writeFile(filepath.Join(*outputDir, IdemixDirIssuer, IdemixConfigIssuerSecretKey), isk)
82-
writeFile(filepath.Join(*outputDir, IdemixDirIssuer, IdemixConfigRevocationKey), revocationKeyBytes)
86+
writeFile(filepath.Join(*outputDir, IdemixDirIssuer, IdemixConfigRevocationKey), pemEncodedRevocationSK)
8387
writeFile(filepath.Join(*outputDir, IdemixDirIssuer, msp.IdemixConfigFileIssuerPublicKey), ipk)
84-
writeFile(filepath.Join(*outputDir, msp.IdemixConfigDirMsp, msp.IdemixConfigFileRevocationPublicKey), revocationPkBytes)
88+
writeFile(filepath.Join(*outputDir, msp.IdemixConfigDirMsp, msp.IdemixConfigFileRevocationPublicKey), pemEncodedRevocationPK)
8589
writeFile(filepath.Join(*outputDir, msp.IdemixConfigDirMsp, msp.IdemixConfigFileIssuerPublicKey), ipk)
8690

8791
case genSignerConfig.FullCommand():
@@ -134,7 +138,12 @@ func readRevocationKey() *ecdsa.PrivateKey {
134138
if err != nil {
135139
handleError(errors.Wrapf(err, "failed to open revocation secret key file: %s", path))
136140
}
137-
key, err := x509.ParseECPrivateKey(keyBytes)
141+
142+
block, _ := pem.Decode(keyBytes)
143+
if block == nil {
144+
handleError(errors.Errorf("failed to decode ECDSA private key"))
145+
}
146+
key, err := x509.ParseECPrivateKey(block.Bytes)
138147
handleError(err)
139148

140149
return key

msp/idemixmsp.go

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,11 @@ import (
1313

1414
"crypto/ecdsa"
1515

16-
"crypto/elliptic"
16+
"crypto/x509"
17+
18+
"encoding/pem"
19+
20+
"reflect"
1721

1822
"github.com/golang/protobuf/proto"
1923
"github.com/hyperledger/fabric-amcl/amcl"
@@ -129,12 +133,19 @@ func (msp *idemixmsp) Setup(conf1 *m.MSPConfig) error {
129133
msp.rng = rng
130134

131135
// get the revocation public key from the config
132-
revPkX, revPkY := elliptic.Unmarshal(elliptic.P384(), conf.RevocationPk)
133-
msp.revocationPK = &ecdsa.PublicKey{
134-
Curve: elliptic.P384(),
135-
X: revPkX,
136-
Y: revPkY,
136+
blockPub, _ := pem.Decode(conf.RevocationPk)
137+
if blockPub == nil {
138+
return errors.New("Failed to decode revocation ECDSA public key")
139+
}
140+
revocationPk, err := x509.ParsePKIXPublicKey(blockPub.Bytes)
141+
if err != nil {
142+
return errors.Wrap(err, "Failed to parse revocation ECDSA public key bytes")
143+
}
144+
ecdsaPublicKey, isECDSA := revocationPk.(*ecdsa.PublicKey)
145+
if !isECDSA {
146+
return errors.Errorf("key is of type %v, not of type ECDSA", reflect.TypeOf(revocationPk))
137147
}
148+
msp.revocationPK = ecdsaPublicKey
138149

139150
if conf.Signer == nil {
140151
// No credential in config, so we don't setup a default signer
0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.
115 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.
118 Bytes
Binary file not shown.
4 Bytes
Binary file not shown.
Binary file not shown.

0 commit comments

Comments
 (0)