@@ -34,7 +34,7 @@ type validateIdentityOUsFuncType func(id *identity) error
3434// satisfiesPrincipalInternalFuncType is the prototype of the function to check if principals are satisfied
3535type satisfiesPrincipalInternalFuncType func (id Identity , principal * m.MSPPrincipal ) error
3636
37- //setupAdminInternalFuncType is a prototype of the function to setup the admins
37+ // setupAdminInternalFuncType is a prototype of the function to setup the admins
3838type setupAdminInternalFuncType func (conf * m.FabricMSPConfig ) error
3939
4040// This is an instantiation of an MSP that
@@ -778,28 +778,42 @@ func (msp *bccspmsp) getCertificationChainIdentifierFromChain(chain []*x509.Cert
778778// do have signatures in Low-S. If this is not the case, the certificate
779779// is regenerated to have a Low-S signature.
780780func (msp * bccspmsp ) sanitizeCert (cert * x509.Certificate ) (* x509.Certificate , error ) {
781+ var err error
781782 if isECDSASignedCert (cert ) {
783+ isRootCACert := false
784+ validityOpts := msp .getValidityOptsForCert (cert )
785+ if cert .IsCA && cert .CheckSignatureFrom (cert ) == nil {
786+ // this is a root CA we can already sanitize it
787+ cert , err = sanitizeECDSASignedCert (cert , cert )
788+ if err != nil {
789+ return nil , err
790+ }
791+ isRootCACert = true
792+ validityOpts .Roots = x509 .NewCertPool ()
793+ validityOpts .Roots .AddCert (cert )
794+ }
782795 // Lookup for a parent certificate to perform the sanitization
783- var parentCert * x509.Certificate
784- chain , err := msp .getUniqueValidationChain (cert , msp .getValidityOptsForCert (cert ))
796+ // run cert validation at any rate, if this is a root CA
797+ // we will validate already sanitized cert
798+ chain , err := msp .getUniqueValidationChain (cert , validityOpts )
785799 if err != nil {
786800 return nil , err
787801 }
788802
789- // at this point, cert might be a root CA certificate
790- // or an intermediate CA certificate
791- if cert .IsCA && len (chain ) == 1 {
792- // cert is a root CA certificate
793- parentCert = cert
794- } else {
795- parentCert = chain [1 ]
803+ // once we finish validation and this is already
804+ // sanitized certificate, there is no need to
805+ // sanitize it once again hence we can just return it
806+ if isRootCACert {
807+ return cert , nil
796808 }
797809
810+ // ok, this is no a root CA cert, and now we
811+ // then we have chain of certs and can get parent
812+ // to sanitize the cert whenever it's intermediate or leaf certificate
813+ parentCert := chain [1 ]
814+
798815 // Sanitize
799- cert , err = sanitizeECDSASignedCert (cert , parentCert )
800- if err != nil {
801- return nil , err
802- }
816+ return sanitizeECDSASignedCert (cert , parentCert )
803817 }
804818 return cert , nil
805819}
0 commit comments