Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deduplicate orderer server TLS root CAs #2029

Merged
merged 1 commit into from
Oct 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 16 additions & 5 deletions orderer/common/server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -1007,15 +1007,26 @@ func (mgr *caManager) updateClusterDialer(

// Iterate over all orderer root CAs for all chains and add them
// to the root CAs
var clusterRootCAs [][]byte
for _, roots := range mgr.ordererRootCAsByChain {
clusterRootCAs = append(clusterRootCAs, roots...)
clusterRootCAs := make(cluster.StringSet)
for _, orgRootCAs := range mgr.ordererRootCAsByChain {
for _, rootCA := range orgRootCAs {
clusterRootCAs[string(rootCA)] = struct{}{}
}
}

// Add the local root CAs too
clusterRootCAs = append(clusterRootCAs, localClusterRootCAs...)
for _, localRootCA := range localClusterRootCAs {
clusterRootCAs[string(localRootCA)] = struct{}{}
}

// Convert StringSet to byte slice
var clusterRootCAsBytes [][]byte
for root := range clusterRootCAs {
clusterRootCAsBytes = append(clusterRootCAsBytes, []byte(root))
}

// Update the cluster config with the new root CAs
clusterDialer.UpdateRootCAs(clusterRootCAs)
clusterDialer.UpdateRootCAs(clusterRootCAsBytes)
}

func prettyPrintStruct(i interface{}) {
Expand Down
30 changes: 28 additions & 2 deletions orderer/common/server/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ package server

import (
"fmt"
"github.com/hyperledger/fabric/bccsp"
"github.com/hyperledger/fabric/orderer/common/filerepo"
"io/ioutil"
"net"
"net/http"
Expand All @@ -20,6 +18,7 @@ import (

"github.com/golang/protobuf/proto"
"github.com/hyperledger/fabric-protos-go/common"
"github.com/hyperledger/fabric/bccsp"
"github.com/hyperledger/fabric/bccsp/factory"
"github.com/hyperledger/fabric/bccsp/sw"
"github.com/hyperledger/fabric/common/channelconfig"
Expand All @@ -37,6 +36,7 @@ import (
"github.com/hyperledger/fabric/internal/pkg/identity"
"github.com/hyperledger/fabric/orderer/common/bootstrap/file"
"github.com/hyperledger/fabric/orderer/common/cluster"
"github.com/hyperledger/fabric/orderer/common/filerepo"
"github.com/hyperledger/fabric/orderer/common/localconfig"
"github.com/hyperledger/fabric/orderer/common/multichannel"
"github.com/hyperledger/fabric/orderer/common/onboarding"
Expand Down Expand Up @@ -752,6 +752,32 @@ func TestUpdateTrustedRoots(t *testing.T) {
grpcServer.Listener().Close()
}

func TestRootServerCertAggregation(t *testing.T) {
caMgr := &caManager{
appRootCAsByChain: make(map[string][][]byte),
ordererRootCAsByChain: make(map[string][][]byte),
}

predDialer := &cluster.PredicateDialer{
Config: comm.ClientConfig{},
}

ca1, err := tlsgen.NewCA()
require.NoError(t, err)

ca2, err := tlsgen.NewCA()
require.NoError(t, err)

caMgr.ordererRootCAsByChain["foo"] = [][]byte{ca1.CertBytes()}
caMgr.ordererRootCAsByChain["bar"] = [][]byte{ca1.CertBytes()}

caMgr.updateClusterDialer(predDialer, [][]byte{ca2.CertBytes(), ca2.CertBytes(), ca2.CertBytes()})

require.Len(t, predDialer.Config.SecOpts.ServerRootCAs, 2)
require.Contains(t, predDialer.Config.SecOpts.ServerRootCAs, ca1.CertBytes())
require.Contains(t, predDialer.Config.SecOpts.ServerRootCAs, ca2.CertBytes())
}

func TestConfigureClusterListener(t *testing.T) {
logEntries := make(chan string, 100)

Expand Down