Skip to content

Commit 5eba94f

Browse files
committed
[FAB-4626] Solution 1 implementation
This change-set implements solution 1) as described in FAB-4626. This change-set only touches the MSP part. Change-Id: Iff72a77d65472ceb7dd52b819e5c7811946a0abc Signed-off-by: Angelo De Caro <[email protected]>
1 parent 90e09ea commit 5eba94f

File tree

20 files changed

+627
-197
lines changed

20 files changed

+627
-197
lines changed

common/mocks/msp/noopmsp.go

+10
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,16 @@ func (msp *noopmsp) GetIntermediateCerts() []m.Identity {
6161
return nil
6262
}
6363

64+
// GetTLSRootCerts returns the root certificates for this MSP
65+
func (msp *noopmsp) GetTLSRootCerts() [][]byte {
66+
return nil
67+
}
68+
69+
// GetTLSIntermediateCerts returns the intermediate root certificates for this MSP
70+
func (msp *noopmsp) GetTLSIntermediateCerts() [][]byte {
71+
return nil
72+
}
73+
6474
func (msp *noopmsp) DeserializeIdentity(serializedID []byte) (m.Identity, error) {
6575
id, _ := newNoopIdentity()
6676
return id, nil

docs/source/msp.rst

+22
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,12 @@ verification. These parameters are deduced by
6161
- A list of certificate revocation lists (CRLs) each corresponding to
6262
exactly one of the listed (intermediate or root) MSP Certificate
6363
Authorities; this is an optional parameter
64+
- A list of self-signed (X.509) certificates to constitute the *TLS root of
65+
trust* for TLS certificate.
66+
- A list of X.509 certificates to represent intermediate TLS CAs this provider
67+
considers; these certificates ought to be
68+
certified by exactly one of the certificates in the TLS root of trust;
69+
intermediate CAs are optional parameters.
6470

6571
*Valid* identities for this MSP instance are required to satisfy the following conditions:
6672

@@ -82,6 +88,10 @@ specify:
8288
- The node's X.509 certificate, that is a valid identity under the
8389
verification parameters of this MSP
8490

91+
It is important to note that MSP identities never expire, they can only be revoked
92+
by adding them the appropriate CRLs. In addition, for TLS certificates,
93+
fabric does not offer support for revocation.
94+
8595
How to generate MSP certificates and their signing keys?
8696
--------------------------------------------------------
8797

@@ -120,6 +130,10 @@ and a file:
120130
6. a folder ``keystore`` to include a PEM file with the node's signing key
121131
7. a folder ``signcerts`` to include a PEM file with the node's X.509
122132
certificate
133+
8. (optional) a folder ``tlscacerts`` to include PEM files each corresponding to a TLS root
134+
CA's certificate
135+
9. (optional) a folder ``tlsintermediatecerts`` to include PEM files each
136+
corresponding to an intermediate TLS CA's certificate
123137

124138
In the configuration file of the node (core.yaml file for the peer, and
125139
orderer.yaml for the orderer), one needs to specify the path to the
@@ -286,5 +300,13 @@ considered for that MSP's identity validation:
286300
In the current MSP implementation we only support method (1) as it is simpler
287301
and does not require blacklisting the no longer considered intermediate CA.
288302

303+
**5) CAs and TLS CAs
304+
305+
MSP identities' root CAs and MSP TLS certificates' root CAs (and relative intermediate CAs)
306+
need to be declared in different folders. This is to avoid confusion between
307+
different classes of certificates. Fabric does not forbid to reuse the same
308+
CAs for both MSP identities and TLS certificates but best practices suggest
309+
to avoid this in production.
310+
289311
.. Licensed under Creative Commons Attribution 4.0 International License
290312
https://creativecommons.org/licenses/by/4.0/

msp/cert_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -104,21 +104,21 @@ func TestCertExpiration(t *testing.T) {
104104
_, cert := generateSelfSignedCert(t, time.Now().Add(24*time.Hour))
105105
msp.opts.Roots = x509.NewCertPool()
106106
msp.opts.Roots.AddCert(cert)
107-
_, err := msp.getUniqueValidationChain(cert)
107+
_, err := msp.getUniqueValidationChain(cert, msp.getValidityOptsForCert(cert))
108108
assert.NoError(t, err)
109109

110110
// Certificate is in the past
111111
_, cert = generateSelfSignedCert(t, time.Now().Add(-24*time.Hour))
112112
msp.opts.Roots = x509.NewCertPool()
113113
msp.opts.Roots.AddCert(cert)
114-
_, err = msp.getUniqueValidationChain(cert)
114+
_, err = msp.getUniqueValidationChain(cert, msp.getValidityOptsForCert(cert))
115115
assert.NoError(t, err)
116116

117117
// Certificate is in the middle
118118
_, cert = generateSelfSignedCert(t, time.Now())
119119
msp.opts.Roots = x509.NewCertPool()
120120
msp.opts.Roots.AddCert(cert)
121-
_, err = msp.getUniqueValidationChain(cert)
121+
_, err = msp.getUniqueValidationChain(cert, msp.getValidityOptsForCert(cert))
122122
assert.NoError(t, err)
123123
}
124124

msp/configbuilder.go

+37-13
Original file line numberDiff line numberDiff line change
@@ -100,13 +100,15 @@ func getPemMaterialFromDir(dir string) ([][]byte, error) {
100100
}
101101

102102
const (
103-
cacerts = "cacerts"
104-
admincerts = "admincerts"
105-
signcerts = "signcerts"
106-
keystore = "keystore"
107-
intermediatecerts = "intermediatecerts"
108-
crlsfolder = "crls"
109-
configfilename = "config.yaml"
103+
cacerts = "cacerts"
104+
admincerts = "admincerts"
105+
signcerts = "signcerts"
106+
keystore = "keystore"
107+
intermediatecerts = "intermediatecerts"
108+
crlsfolder = "crls"
109+
configfilename = "config.yaml"
110+
tlscacerts = "tlscacerts"
111+
tlsintermediatecerts = "tlsintermediatecerts"
110112
)
111113

112114
func SetupBCCSPKeystoreConfig(bccspConfig *factory.FactoryOpts, keystoreDir string) *factory.FactoryOpts {
@@ -166,6 +168,8 @@ func getMspConfig(dir string, ID string, sigid *msp.SigningIdentityInfo) (*msp.M
166168
intermediatecertsDir := filepath.Join(dir, intermediatecerts)
167169
crlsDir := filepath.Join(dir, crlsfolder)
168170
configFile := filepath.Join(dir, configfilename)
171+
tlscacertDir := filepath.Join(dir, tlscacerts)
172+
tlsintermediatecertsDir := filepath.Join(dir, tlsintermediatecerts)
169173

170174
cacerts, err := getPemMaterialFromDir(cacertDir)
171175
if err != nil || len(cacerts) == 0 {
@@ -177,18 +181,35 @@ func getMspConfig(dir string, ID string, sigid *msp.SigningIdentityInfo) (*msp.M
177181
return nil, fmt.Errorf("Could not load a valid admin certificate from directory %s, err %s", admincertDir, err)
178182
}
179183

180-
intermediatecert, err := getPemMaterialFromDir(intermediatecertsDir)
184+
intermediatecerts, err := getPemMaterialFromDir(intermediatecertsDir)
181185
if os.IsNotExist(err) {
182-
mspLogger.Infof("intermediate certs folder not found at [%s]. Skipping.: [%s]", intermediatecertsDir, err)
186+
mspLogger.Warningf("Intermediate certs folder not found at [%s]. Skipping. [%s]", intermediatecertsDir, err)
183187
} else if err != nil {
184188
return nil, fmt.Errorf("Failed loading intermediate ca certs at [%s]: [%s]", intermediatecertsDir, err)
185189
}
186190

191+
tlsCACerts, err := getPemMaterialFromDir(tlscacertDir)
192+
tlsIntermediateCerts := [][]byte{}
193+
if os.IsNotExist(err) {
194+
mspLogger.Warningf("TLS CA certs folder not found at [%s]. Skipping and ignoring TLS intermediate CA folder. [%s]", tlsintermediatecertsDir, err)
195+
} else if err != nil {
196+
return nil, fmt.Errorf("Failed loading TLS ca certs at [%s]: [%s]", tlsintermediatecertsDir, err)
197+
} else if len(tlsCACerts) != 0 {
198+
tlsIntermediateCerts, err = getPemMaterialFromDir(tlsintermediatecertsDir)
199+
if os.IsNotExist(err) {
200+
mspLogger.Warningf("TLS intermediate certs folder not found at [%s]. Skipping. [%s]", tlsintermediatecertsDir, err)
201+
} else if err != nil {
202+
return nil, fmt.Errorf("Failed loading TLS intermediate ca certs at [%s]: [%s]", tlsintermediatecertsDir, err)
203+
}
204+
} else {
205+
mspLogger.Warningf("TLS CA certs folder at [%s] is empty. Skipping.", tlsintermediatecertsDir)
206+
}
207+
187208
crls, err := getPemMaterialFromDir(crlsDir)
188209
if os.IsNotExist(err) {
189-
mspLogger.Infof("crls folder not found at [%s]. Skipping.: [%s]", intermediatecertsDir, err)
210+
mspLogger.Warningf("crls folder not found at [%s]. Skipping. [%s]", crlsDir, err)
190211
} else if err != nil {
191-
return nil, fmt.Errorf("Failed loading crls ca certs at [%s]: [%s]", intermediatecertsDir, err)
212+
return nil, fmt.Errorf("Failed loading crls at [%s]: [%s]", crlsDir, err)
192213
}
193214

194215
// Load configuration file
@@ -239,12 +260,15 @@ func getMspConfig(dir string, ID string, sigid *msp.SigningIdentityInfo) (*msp.M
239260
fmspconf := &msp.FabricMSPConfig{
240261
Admins: admincert,
241262
RootCerts: cacerts,
242-
IntermediateCerts: intermediatecert,
263+
IntermediateCerts: intermediatecerts,
243264
SigningIdentity: sigid,
244265
Name: ID,
245266
OrganizationalUnitIdentifiers: ouis,
246267
RevocationList: crls,
247-
CryptoConfig: cryptoConfig}
268+
CryptoConfig: cryptoConfig,
269+
TlsRootCerts: tlsCACerts,
270+
TlsIntermediateCerts: tlsIntermediateCerts,
271+
}
248272

249273
fmpsjs, _ := proto.Marshal(fmspconf)
250274

msp/msp.go

+6
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,12 @@ type MSP interface {
9292
// GetIntermediateCerts returns the intermediate root certificates for this MSP
9393
GetIntermediateCerts() []Identity
9494

95+
// GetTLSRootCerts returns the TLS root certificates for this MSP
96+
GetTLSRootCerts() [][]byte
97+
98+
// GetTLSIntermediateCerts returns the TLS intermediate root certificates for this MSP
99+
GetTLSIntermediateCerts() [][]byte
100+
95101
// Validate checks whether the supplied identity is valid
96102
Validate(id Identity) error
97103

msp/msp_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,8 @@ func TestMSPSetupNoCryptoConf(t *testing.T) {
122122
func TestGetters(t *testing.T) {
123123
typ := localMsp.GetType()
124124
assert.Equal(t, typ, FABRIC)
125-
assert.NotNil(t, localMsp.GetRootCerts())
126-
assert.NotNil(t, localMsp.GetIntermediateCerts())
125+
assert.NotNil(t, localMsp.GetTLSRootCerts())
126+
assert.NotNil(t, localMsp.GetTLSIntermediateCerts())
127127
}
128128

129129
func TestMSPSetupBad(t *testing.T) {

0 commit comments

Comments
 (0)