github.com/pvitto98/fabric@v2.1.1+incompatible/msp/revocation_test.go (about) 1 /* 2 Copyright IBM Corp. 2017 All Rights Reserved. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package msp 18 19 import ( 20 "path/filepath" 21 "testing" 22 23 "github.com/hyperledger/fabric-protos-go/msp" 24 "github.com/hyperledger/fabric/bccsp/sw" 25 "github.com/stretchr/testify/assert" 26 ) 27 28 func TestRevocation(t *testing.T) { 29 // testdata/revocation 30 // 1) a key and a signcert (used to populate the default signing identity); 31 // 2) cacert is the CA that signed the intermediate; 32 // 3) a revocation list that revokes signcert 33 thisMSP := getLocalMSP(t, "testdata/revocation") 34 35 id, err := thisMSP.GetDefaultSigningIdentity() 36 assert.NoError(t, err) 37 38 // the certificate associated to this id is revoked and so validation should fail! 39 err = id.Validate() 40 assert.Error(t, err) 41 42 // This MSP is identical to the previous one, with only 1 difference: 43 // the signature on the CRL is invalid 44 thisMSP = getLocalMSP(t, "testdata/revocation2") 45 46 id, err = thisMSP.GetDefaultSigningIdentity() 47 assert.NoError(t, err) 48 49 // the certificate associated to this id is revoked but the signature on the CRL is invalid 50 // so validation should succeed 51 err = id.Validate() 52 assert.NoError(t, err, "Identity found revoked although the signature over the CRL is invalid") 53 } 54 55 func TestIdentityPolicyPrincipalAgainstRevokedIdentity(t *testing.T) { 56 // testdata/revocation 57 // 1) a key and a signcert (used to populate the default signing identity); 58 // 2) cacert is the CA that signed the intermediate; 59 // 3) a revocation list that revokes signcert 60 thisMSP := getLocalMSP(t, "testdata/revocation") 61 62 id, err := thisMSP.GetDefaultSigningIdentity() 63 assert.NoError(t, err) 64 65 idSerialized, err := id.Serialize() 66 assert.NoError(t, err) 67 68 principal := &msp.MSPPrincipal{ 69 PrincipalClassification: msp.MSPPrincipal_IDENTITY, 70 Principal: idSerialized} 71 72 err = id.SatisfiesPrincipal(principal) 73 assert.Error(t, err) 74 } 75 76 func TestRevokedIntermediateCA(t *testing.T) { 77 // testdata/revokedica 78 // 1) a key and a signcert (used to populate the default signing identity); 79 // 2) cacert is the CA that signed the intermediate; 80 // 3) a revocation list that revokes the intermediate CA cert 81 dir := "testdata/revokedica" 82 conf, err := GetLocalMspConfig(dir, nil, "SampleOrg") 83 assert.NoError(t, err) 84 85 cryptoProvider, err := sw.NewDefaultSecurityLevelWithKeystore(sw.NewDummyKeyStore()) 86 assert.NoError(t, err) 87 thisMSP, err := newBccspMsp(MSPv1_0, cryptoProvider) 88 assert.NoError(t, err) 89 ks, err := sw.NewFileBasedKeyStore(nil, filepath.Join(dir, "keystore"), true) 90 assert.NoError(t, err) 91 csp, err := sw.NewWithParams(256, "SHA2", ks) 92 assert.NoError(t, err) 93 thisMSP.(*bccspmsp).bccsp = csp 94 95 err = thisMSP.Setup(conf) 96 assert.Error(t, err) 97 assert.Contains(t, err.Error(), "CA Certificate is not valid, ") 98 }