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

[FAB-18298] Default cluster cert and key #2078

Merged
merged 1 commit into from
Nov 6, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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