Skip to content

Commit 52e78b5

Browse files
committed
NettyGrpcServer -- support mutual TLS
Signed-off-by: Fedor Tokarev <[email protected]>
1 parent 1663b4f commit 52e78b5

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

fabric-chaincode-shim/src/main/java/org/hyperledger/fabric/shim/ChaincodeServerProperties.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ public final class ChaincodeServerProperties {
2020
private String keyPassword;
2121
private String keyCertChainFile;
2222
private String keyFile;
23+
private String trustCertCollectionFile;
2324
private boolean tlsEnabled = false;
2425

2526
public ChaincodeServerProperties() {
@@ -133,6 +134,14 @@ public void setKeyFile(String keyFile) {
133134
this.keyFile = keyFile;
134135
}
135136

137+
public String getTrustCertCollectionFile() {
138+
return trustCertCollectionFile;
139+
}
140+
141+
public void setTrustCertCollectionFile(String trustCertCollectionFile) {
142+
this.trustCertCollectionFile = trustCertCollectionFile;
143+
}
144+
136145
public boolean isTlsEnabled() {
137146
return tlsEnabled;
138147
}

fabric-chaincode-shim/src/main/java/org/hyperledger/fabric/shim/NettyGrpcServer.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import io.grpc.netty.shaded.io.netty.handler.ssl.SslContextBuilder;
1313
import io.grpc.netty.shaded.io.netty.handler.ssl.ApplicationProtocolConfig;
1414
import io.grpc.netty.shaded.io.netty.handler.ssl.ApplicationProtocolNames;
15+
import io.grpc.netty.shaded.io.netty.handler.ssl.ClientAuth;
1516
import org.apache.commons.logging.Log;
1617
import org.apache.commons.logging.LogFactory;
1718

@@ -72,6 +73,12 @@ public NettyGrpcServer(final ChaincodeBase chaincodeBase, final ChaincodeServerP
7273
ApplicationProtocolNames.HTTP_2);
7374
sslContextBuilder.applicationProtocolConfig(apn);
7475

76+
if (chaincodeServerProperties.getTrustCertCollectionFile() != null) {
77+
final File trustCertCollectionFile = Paths.get(chaincodeServerProperties.getTrustCertCollectionFile()).toFile();
78+
sslContextBuilder.clientAuth(ClientAuth.REQUIRE);
79+
sslContextBuilder.trustManager(trustCertCollectionFile);
80+
}
81+
7582
serverBuilder.sslContext(sslContextBuilder.build());
7683
}
7784

0 commit comments

Comments
 (0)