Skip to content

Commit

Permalink
[FAB-18298] Default cluster cert and key
Browse files Browse the repository at this point in the history
Signed-off-by: Tiffany Harris <tiffany.harris@ibm.com>
Signed-off-by: Will Lahti <wtlahti@us.ibm.com>
  • Loading branch information
stephyee authored and wlahti committed Nov 6, 2020
1 parent 4db7e4c commit b024fc8
Show file tree
Hide file tree
Showing 3 changed files with 109 additions and 13 deletions.
2 changes: 2 additions & 0 deletions integration/raft/cft_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,8 @@ var _ = Describe("EndToEnd Crash Fault Tolerance", func() {
ordererConfig.General.Cluster.ListenAddress = ""
ordererConfig.General.Cluster.ServerCertificate = ""
ordererConfig.General.Cluster.ServerPrivateKey = ""
ordererConfig.General.Cluster.ClientCertificate = ""
ordererConfig.General.Cluster.ClientPrivateKey = ""
network.WriteOrdererConfig(orderer, ordererConfig)
}

Expand Down
16 changes: 11 additions & 5 deletions orderer/common/server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -539,17 +539,23 @@ func initializeClusterClientConfig(conf *localconfig.TopLevel) comm.ClientConfig
SecOpts: comm.SecureOptions{},
}

if conf.General.Cluster.ClientCertificate == "" {
return cc
}
reuseGrpcListener := reuseListener(conf)

certFile := conf.General.Cluster.ClientCertificate
keyFile := conf.General.Cluster.ClientPrivateKey
if certFile == "" && keyFile == "" {
if !reuseGrpcListener {
return cc
}
certFile = conf.General.TLS.Certificate
keyFile = conf.General.TLS.PrivateKey
}

certBytes, err := ioutil.ReadFile(certFile)
if err != nil {
logger.Fatalf("Failed to load client TLS certificate file '%s' (%s)", certFile, err)
}

keyFile := conf.General.Cluster.ClientPrivateKey
keyBytes, err := ioutil.ReadFile(keyFile)
if err != nil {
logger.Fatalf("Failed to load client TLS key file '%s' (%s)", keyFile, err)
Expand All @@ -565,7 +571,7 @@ func initializeClusterClientConfig(conf *localconfig.TopLevel) comm.ClientConfig
}

timeShift := conf.General.TLS.TLSHandshakeTimeShift
if reuseGrpcListener := reuseListener(conf); !reuseGrpcListener {
if !reuseGrpcListener {
timeShift = conf.General.Cluster.TLSHandshakeTimeShift
}

Expand Down
104 changes: 96 additions & 8 deletions orderer/common/server/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,14 +195,102 @@ func TestInitializeServerConfig(t *testing.T) {
clusterCert string
clusterKey string
clusterCA string
isCluster bool
}{
{"BadCertificate", badFile, goodFile, goodFile, goodFile, "", "", ""},
{"BadPrivateKey", goodFile, badFile, goodFile, goodFile, "", "", ""},
{"BadRootCA", goodFile, goodFile, badFile, goodFile, "", "", ""},
{"BadClientRootCertificate", goodFile, goodFile, goodFile, badFile, "", "", ""},
{"ClusterBadCertificate", goodFile, goodFile, goodFile, goodFile, badFile, goodFile, goodFile},
{"ClusterBadPrivateKey", goodFile, goodFile, goodFile, goodFile, goodFile, badFile, goodFile},
{"ClusterBadRootCA", goodFile, goodFile, goodFile, goodFile, goodFile, goodFile, badFile},
{
name: "BadCertificate",
certificate: badFile,
privateKey: goodFile,
rootCA: goodFile,
clientRootCert: goodFile,
},
{
name: "BadPrivateKey",
certificate: goodFile,
privateKey: badFile,
rootCA: goodFile,
clientRootCert: goodFile,
},
{
name: "BadRootCA",
certificate: goodFile,
privateKey: goodFile,
rootCA: badFile,
clientRootCert: goodFile,
},
{
name: "BadClientRootCertificate",
certificate: goodFile,
privateKey: goodFile,
rootCA: goodFile,
clientRootCert: badFile,
},
{
name: "BadCertificate - cluster reuses server config",
certificate: badFile,
privateKey: goodFile,
rootCA: goodFile,
clientRootCert: goodFile,
clusterCert: "",
clusterKey: "",
clusterCA: "",
isCluster: true,
},
{
name: "BadPrivateKey - cluster reuses server config",
certificate: goodFile,
privateKey: badFile,
rootCA: goodFile,
clientRootCert: goodFile,
clusterCert: "",
clusterKey: "",
clusterCA: "",
isCluster: true,
},
{
name: "BadRootCA - cluster reuses server config",
certificate: goodFile,
privateKey: goodFile,
rootCA: badFile,
clientRootCert: goodFile,
clusterCert: "",
clusterKey: "",
clusterCA: "",
isCluster: true,
},
{
name: "ClusterBadCertificate",
certificate: goodFile,
privateKey: goodFile,
rootCA: goodFile,
clientRootCert: goodFile,
clusterCert: badFile,
clusterKey: goodFile,
clusterCA: goodFile,
isCluster: true,
},
{
name: "ClusterBadPrivateKey",
certificate: goodFile,
privateKey: goodFile,
rootCA: goodFile,
clientRootCert: goodFile,
clusterCert: goodFile,
clusterKey: badFile,
clusterCA: goodFile,
isCluster: true,
},
{
name: "ClusterBadRootCA",
certificate: goodFile,
privateKey: goodFile,
rootCA: goodFile,
clientRootCert: goodFile,
clusterCert: goodFile,
clusterKey: goodFile,
clusterCA: badFile,
isCluster: true,
},
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
Expand All @@ -224,7 +312,7 @@ func TestInitializeServerConfig(t *testing.T) {
},
}
require.Panics(t, func() {
if tc.clusterCert == "" {
if !tc.isCluster {
initializeServerConfig(conf, nil)
} else {
initializeClusterClientConfig(conf)
Expand Down

0 comments on commit b024fc8

Please sign in to comment.