Skip to content

Commit ea3528e

Browse files
committed
[FAB-4904] Modify peer to use MSP tls structure
With FAB-4626, the X509 MSP impl now separates the root/intermediate certs for signing from the root/intermediates used for TLS. This change modifies the peer to use the updated TLS certs rather than the signing certs. The following changes were made: - Use GetTLSRootCerts and GetTLSIntermediateCerts functions provided by the msp impl - remove the GetRootCerts and GetIntermediateCerts methods from the msp impl - modify examples/cluster (includes adding a separate TLS CA) Change-Id: I820b658aac9ca43f766a728f0f9b37194d8c7a7a Signed-off-by: Gari Singh <[email protected]>
1 parent ced20e8 commit ea3528e

File tree

12 files changed

+312
-116
lines changed

12 files changed

+312
-116
lines changed

common/tools/cryptogen/main.go

+2-4
Original file line numberDiff line numberDiff line change
@@ -401,8 +401,7 @@ func generatePeerOrg(baseDir string, orgSpec OrgSpec) {
401401
fmt.Printf("Error generating tlsCA for org %s:\n%v\n", orgName, err)
402402
os.Exit(1)
403403
}
404-
// TODO remove the following line once MSP and peer changes are done
405-
tlsCA = signCA
404+
406405
err = msp.GenerateVerifyingMSP(mspDir, signCA, tlsCA)
407406
if err != nil {
408407
fmt.Printf("Error generating MSP for org %s:\n%v\n", orgName, err)
@@ -505,8 +504,7 @@ func generateOrdererOrg(baseDir string, orgSpec OrgSpec) {
505504
fmt.Printf("Error generating tlsCA for org %s:\n%v\n", orgName, err)
506505
os.Exit(1)
507506
}
508-
// TODO remove the following line once MSP and peer changes are done
509-
tlsCA = signCA
507+
510508
err = msp.GenerateVerifyingMSP(mspDir, signCA, tlsCA)
511509
if err != nil {
512510
fmt.Printf("Error generating MSP for org %s:\n%v\n", orgName, err)

core/peer/peer.go

+18-45
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,7 @@
11
/*
2-
Copyright IBM Corp. 2016 All Rights Reserved.
2+
Copyright IBM Corp. All Rights Reserved.
33
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.
4+
SPDX-License-Identifier: Apache-2.0
155
*/
166

177
package peer
@@ -22,7 +12,6 @@ import (
2212
"net"
2313
"sync"
2414

25-
"github.com/golang/protobuf/proto"
2615
"github.com/hyperledger/fabric/common/config"
2716
"github.com/hyperledger/fabric/common/configtx"
2817
configtxapi "github.com/hyperledger/fabric/common/configtx/api"
@@ -41,7 +30,6 @@ import (
4130
"github.com/hyperledger/fabric/msp"
4231
mspmgmt "github.com/hyperledger/fabric/msp/mgmt"
4332
"github.com/hyperledger/fabric/protos/common"
44-
mspprotos "github.com/hyperledger/fabric/protos/msp"
4533
pb "github.com/hyperledger/fabric/protos/peer"
4634
"github.com/hyperledger/fabric/protos/utils"
4735
"github.com/spf13/viper"
@@ -394,7 +382,6 @@ func buildTrustedRootsForChain(cm configtxapi.Manager) {
394382
appRootCAs := [][]byte{}
395383
ordererRootCAs := [][]byte{}
396384
appOrgMSPs := make(map[string]struct{})
397-
398385
ac, ok := cm.ApplicationConfig()
399386
if ok {
400387
//loop through app orgs and build map of MSPIDs
@@ -413,38 +400,24 @@ func buildTrustedRootsForChain(cm configtxapi.Manager) {
413400
for k, v := range msps {
414401
// check to see if this is a FABRIC MSP
415402
if v.GetType() == msp.FABRIC {
416-
for _, root := range v.GetRootCerts() {
417-
sid, err := root.Serialize()
418-
if err == nil {
419-
id := &mspprotos.SerializedIdentity{}
420-
err = proto.Unmarshal(sid, id)
421-
if err == nil {
422-
// check to see of this is an app org MSP
423-
if _, ok := appOrgMSPs[k]; ok {
424-
peerLogger.Debugf("adding app root CAs for MSP [%s]", k)
425-
appRootCAs = append(appRootCAs, id.IdBytes)
426-
} else {
427-
peerLogger.Debugf("adding orderer root CAs for MSP [%s]", k)
428-
ordererRootCAs = append(ordererRootCAs, id.IdBytes)
429-
}
430-
}
403+
for _, root := range v.GetTLSRootCerts() {
404+
// check to see of this is an app org MSP
405+
if _, ok := appOrgMSPs[k]; ok {
406+
peerLogger.Debugf("adding app root CAs for MSP [%s]", k)
407+
appRootCAs = append(appRootCAs, root)
408+
} else {
409+
peerLogger.Debugf("adding orderer root CAs for MSP [%s]", k)
410+
ordererRootCAs = append(ordererRootCAs, root)
431411
}
432412
}
433-
for _, intermediate := range v.GetIntermediateCerts() {
434-
sid, err := intermediate.Serialize()
435-
if err == nil {
436-
id := &mspprotos.SerializedIdentity{}
437-
err = proto.Unmarshal(sid, id)
438-
if err == nil {
439-
// check to see of this is an app org MSP
440-
if _, ok := appOrgMSPs[k]; ok {
441-
peerLogger.Debugf("adding app root CAs for MSP [%s]", k)
442-
appRootCAs = append(appRootCAs, id.IdBytes)
443-
} else {
444-
peerLogger.Debugf("adding orderer root CAs for MSP [%s]", k)
445-
ordererRootCAs = append(ordererRootCAs, id.IdBytes)
446-
}
447-
}
413+
for _, intermediate := range v.GetTLSIntermediateCerts() {
414+
// check to see of this is an app org MSP
415+
if _, ok := appOrgMSPs[k]; ok {
416+
peerLogger.Debugf("adding app root CAs for MSP [%s]", k)
417+
appRootCAs = append(appRootCAs, intermediate)
418+
} else {
419+
peerLogger.Debugf("adding orderer root CAs for MSP [%s]", k)
420+
ordererRootCAs = append(ordererRootCAs, intermediate)
448421
}
449422
}
450423
}

core/peer/pkg_test.go

+15-22
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,7 @@
11
/*
2-
Copyright IBM Corp. 2017 All Rights Reserved.
2+
Copyright IBM Corp. All Rights Reserved.
33
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.
4+
SPDX-License-Identifier: Apache-2.0
155
*/
166

177
package peer_test
@@ -96,13 +86,14 @@ func invokeEmptyCall(address string, dialOptions []grpc.DialOption) (*testpb.Emp
9686
}
9787

9888
// helper function to build an MSPConfig given root certs
99-
func createMSPConfig(rootCerts, intermediateCerts [][]byte,
89+
func createMSPConfig(rootCerts, tlsRootCerts, tlsIntermediateCerts [][]byte,
10090
mspID string) (*mspproto.MSPConfig, error) {
10191

10292
fmspconf := &mspproto.FabricMSPConfig{
103-
RootCerts: rootCerts,
104-
IntermediateCerts: intermediateCerts,
105-
Name: mspID}
93+
RootCerts: rootCerts,
94+
TlsRootCerts: tlsRootCerts,
95+
TlsIntermediateCerts: tlsIntermediateCerts,
96+
Name: mspID}
10697

10798
fmpsjs, err := proto.Marshal(fmspconf)
10899
if err != nil {
@@ -147,12 +138,14 @@ func TestUpdateRootsFromConfigBlock(t *testing.T) {
147138
}
148139

149140
// create test MSPConfigs
150-
org1MSPConf, err := createMSPConfig([][]byte{org1CA}, [][]byte{}, "Org1MSP")
151-
org2MSPConf, err := createMSPConfig([][]byte{org2CA}, [][]byte{}, "Org2MSP")
152-
org2IntermediateMSPConf, err := createMSPConfig([][]byte{org2CA},
153-
[][]byte{org2IntermediateCA}, "Org2IntermediateMSP")
154-
ordererOrgMSPConf, err := createMSPConfig([][]byte{ordererOrgCA},
155-
[][]byte{}, "OrdererOrgMSP")
141+
org1MSPConf, err := createMSPConfig([][]byte{org2CA}, [][]byte{org1CA},
142+
[][]byte{}, "Org1MSP")
143+
org2MSPConf, err := createMSPConfig([][]byte{org1CA}, [][]byte{org2CA},
144+
[][]byte{}, "Org2MSP")
145+
org2IntermediateMSPConf, err := createMSPConfig([][]byte{org1CA},
146+
[][]byte{org2CA}, [][]byte{org2IntermediateCA}, "Org2IntermediateMSP")
147+
ordererOrgMSPConf, err := createMSPConfig([][]byte{org1CA},
148+
[][]byte{ordererOrgCA}, [][]byte{}, "OrdererOrgMSP")
156149
if err != nil {
157150
t.Fatalf("Failed to create MSPConfigs (%s)", err)
158151
}

examples/cluster/Makefile

+9
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ NODES += $(PEERS)
77
NODES += orderer
88
NODES += cli
99
NODES += ca
10+
NODES += tlsca
1011

1112
DAEMONS = $(filter-out cli,$(NODES))
1213

@@ -17,6 +18,7 @@ ORDERER_ORG = $(CRYPTOOUTPUT)/ordererOrganizations/orderer.net
1718
PEER_ORG= $(CRYPTOOUTPUT)/peerOrganizations/org1.net
1819

1920
CA_PATH = $(PEER_ORG)/ca
21+
TLSCA_PATH= $(PEER_ORG)/tlsca
2022
ORDERER_PATH = $(ORDERER_ORG)/orderers
2123
PEER_PATH = $(PEER_ORG)/peers
2224
USERS_PATH = $(PEER_ORG)/users
@@ -106,8 +108,15 @@ build/nodes/ca: build/nodes/ca/fabric-ca-server-config.yaml
106108
cp $(CA_PATH)/*_sk $@/ca.key
107109
cp $(CA_PATH)/*.pem $@/ca.crt
108110

111+
build/nodes/tlsca: build/nodes/tlsca/fabric-tlsca-server-config.yaml
112+
@mkdir -p $@
113+
cp $(TLSCA_PATH)/*_sk $@/ca.key
114+
cp $(TLSCA_PATH)/*.pem $@/ca.crt
115+
mv $@/fabric-tlsca-server-config.yaml $@/fabric-ca-server-config.yaml
116+
109117
build/nodes/%: build/nodes/%/msp build/nodes/%/configtx.yaml build/nodes/%/core.yaml
110118
@echo "Built $@"
111119

112120
clean: compose-down
113121
rm -rf build
122+
rm $(CHANNEL_NAME).block

examples/cluster/compose/docker-compose.yaml

+11
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,17 @@ services:
2121
volumes:
2222
- ../build/nodes/ca:/etc/hyperledger/fabric-ca-server
2323

24+
tlsca:
25+
container_name: tlsca
26+
image: hyperledger/fabric-ca
27+
dns_search: .
28+
environment:
29+
- FABRIC_CA_SERVER_TLS_ENABLED=${TLS_ENABLED}
30+
logging:
31+
<<: *logging
32+
volumes:
33+
- ../build/nodes/tlsca:/etc/hyperledger/fabric-ca-server
34+
2435
orderer:
2536
container_name: orderer
2637
image: hyperledger/fabric-orderer

examples/cluster/compose/report-env.sh

+6-2
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ includefile() {
5959
prefix=$2
6060

6161
echo "|"
62-
62+
6363
while IFS= read -r line; do
6464
printf '%s%s\n' "$prefix" "$line"
6565
done < "$file"
@@ -77,7 +77,11 @@ cat <<EOF > $CONFIG
7777
#
7878
ca:
7979
url: $(http "ca" "7054")
80-
certificate: $(includefile build/nodes/cli/tls/ca.crt " ")
80+
certificate: $(includefile build/nodes/ca/ca.crt " ")
81+
82+
tlsca:
83+
url: $(http "tlsca" "7054")
84+
certificate: $(includefile build/nodes/tlsca/ca.crt " ")
8185
8286
orderer:
8387
url: $(grpc "orderer" "7050")

examples/cluster/config/fabric-ca-server-config.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ ca:
101101
registry:
102102
# Maximum number of times a password/secret can be reused for enrollment
103103
# (default: 0, which means there is no limit)
104-
maxEnrollments: 0
104+
maxEnrollments: -1
105105

106106
# Contains identity information which is used when LDAP is disabled
107107
identities:

0 commit comments

Comments
 (0)