Skip to content

Commit

Permalink
Merge "[FAB-10370] change format for storing revocationpk"
Browse files Browse the repository at this point in the history
  • Loading branch information
hacera-jonathan authored and Gerrit Code Review committed May 31, 2018
2 parents efbe29f + 2be2d00 commit 67b537d
Show file tree
Hide file tree
Showing 32 changed files with 47 additions and 18 deletions.
10 changes: 8 additions & 2 deletions common/tools/idemixgen/idemixca/idemixca_test.go
Expand Up @@ -12,7 +12,9 @@ import (
"path/filepath"
"testing"

"crypto/elliptic"
"crypto/x509"

"encoding/pem"

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

writeVerifierToFile(ipkBytes, elliptic.Marshal(elliptic.P384(), revocationkey.X, revocationkey.Y))
encodedRevocationPK, err := x509.MarshalPKIXPublicKey(revocationkey.Public())
assert.NoError(t, err)
pemEncodedRevocationPK := pem.EncodeToMemory(&pem.Block{Type: "PUBLIC KEY", Bytes: encodedRevocationPK})

writeVerifierToFile(ipkBytes, pemEncodedRevocationPK)

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

Expand Down
23 changes: 16 additions & 7 deletions common/tools/idemixgen/idemixgen.go
Expand Up @@ -18,10 +18,10 @@ import (
"os"
"path/filepath"

"crypto/elliptic"

"crypto/ecdsa"

"encoding/pem"

"github.com/golang/protobuf/proto"
"github.com/hyperledger/fabric/common/tools/idemixgen/idemixca"
"github.com/hyperledger/fabric/common/tools/idemixgen/metadata"
Expand Down Expand Up @@ -64,9 +64,13 @@ func main() {

revocationKey, err := idemix.GenerateLongTermRevocationKey()
handleError(err)
revocationKeyBytes, err := x509.MarshalECPrivateKey(revocationKey)
encodedRevocationSK, err := x509.MarshalECPrivateKey(revocationKey)
handleError(err)
pemEncodedRevocationSK := pem.EncodeToMemory(&pem.Block{Type: "PRIVATE KEY", Bytes: encodedRevocationSK})
handleError(err)
revocationPkBytes := elliptic.Marshal(elliptic.P384(), revocationKey.X, revocationKey.Y)
encodedRevocationPK, err := x509.MarshalPKIXPublicKey(revocationKey.Public())
handleError(err)
pemEncodedRevocationPK := pem.EncodeToMemory(&pem.Block{Type: "PUBLIC KEY", Bytes: encodedRevocationPK})

// Prevent overwriting the existing key
path := filepath.Join(*outputDir, IdemixDirIssuer)
Expand All @@ -79,9 +83,9 @@ func main() {
handleError(os.MkdirAll(filepath.Join(*outputDir, IdemixDirIssuer), 0770))
handleError(os.MkdirAll(filepath.Join(*outputDir, msp.IdemixConfigDirMsp), 0770))
writeFile(filepath.Join(*outputDir, IdemixDirIssuer, IdemixConfigIssuerSecretKey), isk)
writeFile(filepath.Join(*outputDir, IdemixDirIssuer, IdemixConfigRevocationKey), revocationKeyBytes)
writeFile(filepath.Join(*outputDir, IdemixDirIssuer, IdemixConfigRevocationKey), pemEncodedRevocationSK)
writeFile(filepath.Join(*outputDir, IdemixDirIssuer, msp.IdemixConfigFileIssuerPublicKey), ipk)
writeFile(filepath.Join(*outputDir, msp.IdemixConfigDirMsp, msp.IdemixConfigFileRevocationPublicKey), revocationPkBytes)
writeFile(filepath.Join(*outputDir, msp.IdemixConfigDirMsp, msp.IdemixConfigFileRevocationPublicKey), pemEncodedRevocationPK)
writeFile(filepath.Join(*outputDir, msp.IdemixConfigDirMsp, msp.IdemixConfigFileIssuerPublicKey), ipk)

case genSignerConfig.FullCommand():
Expand Down Expand Up @@ -134,7 +138,12 @@ func readRevocationKey() *ecdsa.PrivateKey {
if err != nil {
handleError(errors.Wrapf(err, "failed to open revocation secret key file: %s", path))
}
key, err := x509.ParseECPrivateKey(keyBytes)

block, _ := pem.Decode(keyBytes)
if block == nil {
handleError(errors.Errorf("failed to decode ECDSA private key"))
}
key, err := x509.ParseECPrivateKey(block.Bytes)
handleError(err)

return key
Expand Down
23 changes: 17 additions & 6 deletions msp/idemixmsp.go
Expand Up @@ -13,7 +13,11 @@ import (

"crypto/ecdsa"

"crypto/elliptic"
"crypto/x509"

"encoding/pem"

"reflect"

"github.com/golang/protobuf/proto"
"github.com/hyperledger/fabric-amcl/amcl"
Expand Down Expand Up @@ -131,12 +135,19 @@ func (msp *idemixmsp) Setup(conf1 *m.MSPConfig) error {
msp.rng = rng

// get the revocation public key from the config
revPkX, revPkY := elliptic.Unmarshal(elliptic.P384(), conf.RevocationPk)
msp.revocationPK = &ecdsa.PublicKey{
Curve: elliptic.P384(),
X: revPkX,
Y: revPkY,
blockPub, _ := pem.Decode(conf.RevocationPk)
if blockPub == nil {
return errors.New("Failed to decode revocation ECDSA public key")
}
revocationPk, err := x509.ParsePKIXPublicKey(blockPub.Bytes)
if err != nil {
return errors.Wrap(err, "Failed to parse revocation ECDSA public key bytes")
}
ecdsaPublicKey, isECDSA := revocationPk.(*ecdsa.PublicKey)
if !isECDSA {
return errors.Errorf("key is of type %v, not of type ECDSA", reflect.TypeOf(revocationPk))
}
msp.revocationPK = ecdsaPublicKey

if conf.Signer == nil {
// No credential in config, so we don't setup a default signer
Expand Down
Binary file modified msp/testdata/idemix/MSP1OU1/ca/IssuerPublicKey
Binary file not shown.
Binary file modified msp/testdata/idemix/MSP1OU1/ca/IssuerSecretKey
Binary file not shown.
Binary file modified msp/testdata/idemix/MSP1OU1/ca/RevocationKey
Binary file not shown.
Binary file modified msp/testdata/idemix/MSP1OU1/msp/IssuerPublicKey
Binary file not shown.
Binary file modified msp/testdata/idemix/MSP1OU1/msp/RevocationPublicKey
Binary file not shown.
Binary file modified msp/testdata/idemix/MSP1OU1/user/SignerConfig
Binary file not shown.
Binary file modified msp/testdata/idemix/MSP1OU1Admin/ca/IssuerPublicKey
Binary file not shown.
Binary file modified msp/testdata/idemix/MSP1OU1Admin/ca/IssuerSecretKey
Binary file not shown.
Binary file modified msp/testdata/idemix/MSP1OU1Admin/ca/RevocationKey
Binary file not shown.
Binary file modified msp/testdata/idemix/MSP1OU1Admin/msp/IssuerPublicKey
Binary file not shown.
Binary file modified msp/testdata/idemix/MSP1OU1Admin/msp/RevocationPublicKey
Binary file not shown.
Binary file modified msp/testdata/idemix/MSP1OU1Admin/user/SignerConfig
Binary file not shown.
Binary file modified msp/testdata/idemix/MSP1OU2/ca/IssuerPublicKey
Binary file not shown.
Binary file modified msp/testdata/idemix/MSP1OU2/ca/IssuerSecretKey
Binary file not shown.
Binary file modified msp/testdata/idemix/MSP1OU2/ca/RevocationKey
Binary file not shown.
Binary file modified msp/testdata/idemix/MSP1OU2/msp/IssuerPublicKey
Binary file not shown.
Binary file modified msp/testdata/idemix/MSP1OU2/msp/RevocationPublicKey
Binary file not shown.
Binary file modified msp/testdata/idemix/MSP1OU2/user/SignerConfig
Binary file not shown.
Binary file modified msp/testdata/idemix/MSP1Verifier/ca/IssuerPublicKey
Binary file not shown.
Binary file modified msp/testdata/idemix/MSP1Verifier/ca/IssuerSecretKey
Binary file not shown.
Binary file modified msp/testdata/idemix/MSP1Verifier/ca/RevocationKey
Binary file not shown.
Binary file modified msp/testdata/idemix/MSP1Verifier/msp/IssuerPublicKey
Binary file not shown.
Binary file modified msp/testdata/idemix/MSP1Verifier/msp/RevocationPublicKey
Binary file not shown.
Binary file modified msp/testdata/idemix/MSP2OU1/ca/IssuerPublicKey
Binary file not shown.
2 changes: 1 addition & 1 deletion msp/testdata/idemix/MSP2OU1/ca/IssuerSecretKey
@@ -1 +1 @@
"�B�ݢxʱL���\tybõC<d.��!
�P}j�!�gI/n�{H��]G� �h�L��
Binary file modified msp/testdata/idemix/MSP2OU1/ca/RevocationKey
Binary file not shown.
Binary file modified msp/testdata/idemix/MSP2OU1/msp/IssuerPublicKey
Binary file not shown.
7 changes: 5 additions & 2 deletions msp/testdata/idemix/MSP2OU1/msp/RevocationPublicKey
@@ -1,2 +1,5 @@
~��g ��,Ȗ����ӽ��ݚv(]�M�@�~6����:~�,k��p����9''�8��vDx�>U�?Z�(
�%� 5�������V*������
-----BEGIN PUBLIC KEY-----
MHYwEAYHKoZIzj0CAQYFK4EEACIDYgAEPxN4FO+VZCjn9BQ1zhSurncwXRtGXjsF
TB4gZYYy5Wds0UHv3B8hiVMt6QfV38pmc5DAAy2IH6bu9cg3WtiDGbSyL8cPzMm4
Z0mOasXUQHocwO95ssXOnmRr1n/LAOpi
-----END PUBLIC KEY-----
Binary file modified msp/testdata/idemix/MSP2OU1/user/SignerConfig
Binary file not shown.

0 comments on commit 67b537d

Please sign in to comment.