@@ -680,11 +680,14 @@ func (msp *bccspmsp) getCertificationChainForBCCSPIdentity(id *identity) ([]*x50
680680 return nil , errors .New ("A CA certificate cannot be used directly by this MSP" )
681681 }
682682
683- return msp .getValidationChain (id .cert )
683+ return msp .getValidationChain (id .cert , false )
684684}
685685
686686func (msp * bccspmsp ) getUniqueValidationChain (cert * x509.Certificate ) ([]* x509.Certificate , error ) {
687687 // ask golang to validate the cert for us based on the options that we've built at setup time
688+ if msp .opts == nil {
689+ return nil , fmt .Errorf ("The supplied identity has no verify options" )
690+ }
688691 validationChains , err := cert .Verify (* (msp .opts ))
689692 if err != nil {
690693 return nil , fmt .Errorf ("The supplied identity is not valid, Verify() returned %s" , err )
@@ -700,7 +703,7 @@ func (msp *bccspmsp) getUniqueValidationChain(cert *x509.Certificate) ([]*x509.C
700703 return validationChains [0 ], nil
701704}
702705
703- func (msp * bccspmsp ) getValidationChain (cert * x509.Certificate ) ([]* x509.Certificate , error ) {
706+ func (msp * bccspmsp ) getValidationChain (cert * x509.Certificate , isIntermediateChain bool ) ([]* x509.Certificate , error ) {
704707 validationChain , err := msp .getUniqueValidationChain (cert )
705708 if err != nil {
706709 return nil , fmt .Errorf ("Failed getting validation chain %s" , err )
@@ -712,10 +715,14 @@ func (msp *bccspmsp) getValidationChain(cert *x509.Certificate) ([]*x509.Certifi
712715 }
713716
714717 // check that the parent is a leaf of the certification tree
715- if msp .certificationTreeInternalNodesMap [string (validationChain [1 ].Raw )] {
718+ // if validating an intermediate chain, the first certificate will the parent
719+ parentPosition := 1
720+ if isIntermediateChain {
721+ parentPosition = 0
722+ }
723+ if msp .certificationTreeInternalNodesMap [string (validationChain [parentPosition ].Raw )] {
716724 return nil , fmt .Errorf ("Invalid validation chain. Parent certificate should be a leaf of the certification tree [%v]." , cert .Raw )
717725 }
718-
719726 return validationChain , nil
720727}
721728
@@ -753,14 +760,21 @@ func (msp *bccspmsp) getCertificationChainIdentifierFromChain(chain []*x509.Cert
753760func (msp * bccspmsp ) setupOUs (conf m.FabricMSPConfig ) error {
754761 msp .ouIdentifiers = make (map [string ][][]byte )
755762 for _ , ou := range conf .OrganizationalUnitIdentifiers {
756- // 1. check that it registered in msp.rootCerts or msp.intermediateCerts
763+
764+ // 1. check that certificate is registered in msp.rootCerts or msp.intermediateCerts
757765 cert , err := msp .getCertFromPem (ou .Certificate )
758766 if err != nil {
759767 return fmt .Errorf ("Failed getting certificate for [%v]: [%s]" , ou , err )
760768 }
761769
770+ // 2. Sanitize it to ensure like for like comparison
771+ cert , err = msp .sanitizeCert (cert )
772+ if err != nil {
773+ return fmt .Errorf ("sanitizeCert failed %s" , err )
774+ }
775+
762776 found := false
763- root := true
777+ root := false
764778 // Search among root certificates
765779 for _ , v := range msp .rootCerts {
766780 if v .(* identity ).cert .Equal (cert ) {
@@ -783,19 +797,19 @@ func (msp *bccspmsp) setupOUs(conf m.FabricMSPConfig) error {
783797 return fmt .Errorf ("Failed adding OU. Certificate [%v] not in root or intermediate certs." , ou .Certificate )
784798 }
785799
786- // 2 . get the certification path for it
800+ // 3 . get the certification path for it
787801 var certifiersIdentitifer []byte
788802 var chain []* x509.Certificate
789803 if root {
790804 chain = []* x509.Certificate {cert }
791805 } else {
792- chain , err = msp .getValidationChain (cert )
806+ chain , err = msp .getValidationChain (cert , true )
793807 if err != nil {
794808 return fmt .Errorf ("Failed computing validation chain for [%v]. [%s]" , cert , err )
795809 }
796810 }
797811
798- // 3 . compute the hash of the certification path
812+ // 4 . compute the hash of the certification path
799813 certifiersIdentitifer , err = msp .getCertificationChainIdentifierFromChain (chain )
800814 if err != nil {
801815 return fmt .Errorf ("Failed computing Certifiers Identifier for [%v]. [%s]" , ou .Certificate , err )
@@ -969,6 +983,9 @@ func (msp *bccspmsp) validateIdentityOUs(id *identity) error {
969983 }
970984
971985 if ! found {
986+ if len (id .GetOrganizationalUnits ()) == 0 {
987+ return fmt .Errorf ("The identity certificate does not contain an Organizational Unit (OU)" )
988+ }
972989 return fmt .Errorf ("None of the identity's organizational units [%v] are in MSP %s" , id .GetOrganizationalUnits (), msp .name )
973990 }
974991 }
0 commit comments