Skip to content

Commit 538f33e

Browse files
committedDec 16, 2017
[FAB-7884] InitTLSForPeer fail on missing caCert config
Prior to the change set, the method InitTLSForPeer falls back on an empty root CA cert pool if the config option isn't specified. It doesn't make sense to do that, since we don't have any way of trusting a remote node in such a case and thus establishing a TLS connection. Change-Id: I7b0595995d879f3d44b1fd616e80f44aefb473d4 Signed-off-by: yacovm <yacovm@il.ibm.com>
1 parent 341159b commit 538f33e

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed
 

‎core/comm/connection.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ func InitTLSForPeer() credentials.TransportCredentials {
231231
grpclog.Fatalf("Failed to create TLS credentials %v", err)
232232
}
233233
} else {
234-
creds = credentials.NewClientTLSFromCert(nil, sn)
234+
logger.Panic("peer.tls.rootcert.file isn't configured")
235235
}
236236
return creds
237237
}

‎core/comm/connection_test.go

+17
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
"time"
1919

2020
testpb "github.com/hyperledger/fabric/core/comm/testdata/grpc"
21+
"github.com/spf13/viper"
2122
"github.com/stretchr/testify/assert"
2223
"golang.org/x/net/context"
2324
"google.golang.org/grpc"
@@ -352,3 +353,19 @@ func testInvoke(t *testing.T, channelID string, s *srv, shouldSucceed bool) {
352353
assert.NoError(t, err)
353354
s.assertServiced(t)
354355
}
356+
357+
func TestInitTLSForPeerNoCACerts(t *testing.T) {
358+
prevCACerts := viper.Get("peer.tls.rootcert.file")
359+
defer func() {
360+
viper.Set("peer.tls.rootcert.file", prevCACerts)
361+
}()
362+
viper.Set("peer.tls.rootcert.file", nil)
363+
defer func() {
364+
r := recover()
365+
if r == nil {
366+
assert.Fail(t, "should have panicked")
367+
}
368+
assert.Equal(t, "peer.tls.rootcert.file isn't configured", r)
369+
}()
370+
InitTLSForPeer()
371+
}

0 commit comments

Comments
 (0)
Please sign in to comment.