@@ -16,6 +16,7 @@ import (
16
16
"time"
17
17
18
18
"github.com/golang/protobuf/proto"
19
+ "github.com/hyperledger/fabric/common/crypto/tlsgen"
19
20
"github.com/hyperledger/fabric/common/flogging"
20
21
pb "github.com/hyperledger/fabric/protos/peer"
21
22
"github.com/op/go-logging"
@@ -66,7 +67,20 @@ func (cs *ccSrv) stop() {
66
67
cs .l .Close ()
67
68
}
68
69
69
- func newCCServer (t * testing.T , port int , expectedCCname string , withTLS bool , ca CA ) * ccSrv {
70
+ func createTLSService (t * testing.T , ca tlsgen.CA , host string ) * grpc.Server {
71
+ keyPair , err := ca .NewServerCertKeyPair (host )
72
+ cert , err := tls .X509KeyPair (keyPair .Cert , keyPair .Key )
73
+ assert .NoError (t , err )
74
+ tlsConf := & tls.Config {
75
+ Certificates : []tls.Certificate {cert },
76
+ ClientAuth : tls .RequireAndVerifyClientCert ,
77
+ ClientCAs : x509 .NewCertPool (),
78
+ }
79
+ tlsConf .ClientCAs .AppendCertsFromPEM (ca .CertBytes ())
80
+ return grpc .NewServer (grpc .Creds (credentials .NewTLS (tlsConf )))
81
+ }
82
+
83
+ func newCCServer (t * testing.T , port int , expectedCCname string , withTLS bool , ca tlsgen.CA ) * ccSrv {
70
84
var s * grpc.Server
71
85
if withTLS {
72
86
s = createTLSService (t , ca , "localhost" )
@@ -162,7 +176,7 @@ func TestAccessControl(t *testing.T) {
162
176
Type : pb .ChaincodeMessage_PUT_STATE ,
163
177
}
164
178
165
- ca , _ := NewCA ()
179
+ ca , _ := tlsgen . NewCA ()
166
180
srv := newCCServer (t , 7052 , "example02" , true , ca )
167
181
auth := NewAuthenticator (ca )
168
182
pb .RegisterChaincodeSupportServer (srv .grpcSrv , auth .Wrap (srv ))
@@ -175,8 +189,8 @@ func TestAccessControl(t *testing.T) {
175
189
assert .Contains (t , err .Error (), "context deadline exceeded" )
176
190
177
191
// Create an attacker with its own TLS certificate
178
- maliciousCA , _ := NewCA ()
179
- keyPair , err := maliciousCA .newClientCertKeyPair ()
192
+ maliciousCA , _ := tlsgen . NewCA ()
193
+ keyPair , err := maliciousCA .NewClientCertKeyPair ()
180
194
cert , err := tls .X509KeyPair (keyPair .Cert , keyPair .Key )
181
195
assert .NoError (t , err )
182
196
_ , err = newClient (t , 7052 , & cert , ca .CertBytes ())
@@ -269,7 +283,7 @@ func TestAccessControl(t *testing.T) {
269
283
// Create a real chaincode, that its cert was generated by us
270
284
// but have it reconnect only after too much time.
271
285
// This tests a use case where the CC's cert has been expired
272
- // and the CC has been compromized . We don't want it to be able
286
+ // and the CC has been compromised . We don't want it to be able
273
287
// to reconnect to us.
274
288
kp , err = auth .Generate ("example02" )
275
289
assert .NoError (t , err )
0 commit comments