Skip to content
This repository was archived by the owner on Apr 22, 2025. It is now read-only.

Commit 8b976c7

Browse files
committed
FAB-9418 Default for SSL neg/provider
Change-Id: Ic0f909e656584972e15051dc2415a34d5be362fc Signed-off-by: rickr <cr22rc@gmail.com>
1 parent b8aa183 commit 8b976c7

File tree

6 files changed

+66
-23
lines changed

6 files changed

+66
-23
lines changed

config.properties

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@
3333
## If true the SDK will perform a check on the endorsed proposals to guarantee they are consistent. This will be checked by the endorsing peers
3434
## prior to committing the block and will fail regardless.
3535
#org.hyperledger.fabric.sdk.proposal.consistency_validation=true
36+
## Default ssl provider on grpc connections (openSSL, JDK)
37+
#org.hyperledger.fabric.sdk.connections.ssl.sslProvider=openSSL
38+
## Default negotiation type for grpc ssl connections. (TLS, plainText)
39+
#org.hyperledger.fabric.sdk.connections.ssl.negotiationType=TLS
3640

3741
# System wide defaults for CryptoPrimitives objects. You can customize further by using the
3842
# CryptoPrimitives.setProperties() method.

src/main/java/org/hyperledger/fabric/sdk/Endpoint.java

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,19 @@
5353
import org.bouncycastle.crypto.Digest;
5454
import org.bouncycastle.crypto.digests.SHA256Digest;
5555
import org.hyperledger.fabric.sdk.exception.CryptoException;
56+
import org.hyperledger.fabric.sdk.helper.Config;
5657
import org.hyperledger.fabric.sdk.security.CryptoPrimitives;
5758

59+
import static java.lang.String.format;
5860
import static java.nio.charset.StandardCharsets.UTF_8;
5961
import static org.hyperledger.fabric.sdk.helper.Utils.parseGrpcUrl;
6062

6163
class Endpoint {
6264
private static final Log logger = LogFactory.getLog(Endpoint.class);
6365

66+
private static final String SSLPROVIDER = Config.getConfig().getDefaultSSLProvider();
67+
private static final String SSLNEGOTIATION = Config.getConfig().getDefaultSSLNegotiationType();
68+
6469
private final String addr;
6570
private final int port;
6671
private final String url;
@@ -71,7 +76,7 @@ class Endpoint {
7176
private static final Map<String, String> CN_CACHE = Collections.synchronizedMap(new HashMap<>());
7277

7378
Endpoint(String url, Properties properties) {
74-
logger.trace(String.format("Creating endpoint for url %s", url));
79+
logger.trace(format("Creating endpoint for url %s", url));
7580
this.url = url;
7681
String cn = null;
7782
String sslp = null;
@@ -168,19 +173,23 @@ class Endpoint {
168173
}
169174

170175
sslp = properties.getProperty("sslProvider");
171-
if (sslp == null) {
172-
throw new RuntimeException("Property of sslProvider expected");
176+
177+
if (null == sslp) {
178+
sslp = SSLPROVIDER;
179+
logger.trace(format("Endpoint %s specific SSL provider not found use global value: %s ", url, SSLPROVIDER));
173180
}
174-
if (!sslp.equals("openSSL") && !sslp.equals("JDK")) {
175-
throw new RuntimeException("Property of sslProvider has to be either openSSL or JDK");
181+
if (!"openSSL".equals(sslp) && !"JDK".equals(sslp)) {
182+
throw new RuntimeException(format("Endpoint %s property of sslProvider has to be either openSSL or JDK. value: '%s'", url, sslp));
176183
}
177184

178185
nt = properties.getProperty("negotiationType");
179-
if (nt == null) {
180-
throw new RuntimeException("Property of negotiationType expected");
186+
if (null == nt) {
187+
nt = SSLNEGOTIATION;
188+
logger.trace(format("Endpoint %s specific Negotiation type not found use global value: %s ", url, SSLNEGOTIATION));
181189
}
182-
if (!nt.equals("TLS") && !nt.equals("plainText")) {
183-
throw new RuntimeException("Property of negotiationType has to be either TLS or plainText");
190+
191+
if (!"TLS".equals(nt) && !"plainText".equals(nt)) {
192+
throw new RuntimeException(format("Endpoint %s property of negotiationType has to be either TLS or plainText. value: '%s'", url, nt));
184193
}
185194
}
186195
}
@@ -197,6 +206,7 @@ class Endpoint {
197206
} else {
198207
try {
199208

209+
logger.trace(format("Endpoint %s Negotiation type: '%s', SSLprovider: '%s'", url, nt, sslp));
200210
SslProvider sslprovider = sslp.equals("openSSL") ? SslProvider.OPENSSL : SslProvider.JDK;
201211
NegotiationType ntype = nt.equals("TLS") ? NegotiationType.TLS : NegotiationType.PLAINTEXT;
202212

@@ -331,7 +341,7 @@ private void addNettyBuilderProps(NettyChannelBuilder channelBuilder, Properties
331341
sep = ", ";
332342

333343
}
334-
logger.trace(String.format("Endpoint with url: %s set managed channel builder method %s (%s) ", url,
344+
logger.trace(format("Endpoint with url: %s set managed channel builder method %s (%s) ", url,
335345
method, sb.toString()));
336346

337347
}

src/main/java/org/hyperledger/fabric/sdk/NetworkConfig.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,6 @@ public class NetworkConfig {
7777
// Organizations, keyed on org name (and not on mspid!)
7878
private Map<String, OrgInfo> organizations;
7979

80-
// CAs keyed on name
81-
private Map<String, CAInfo> certificateAuthorities;
82-
private Map<String, CAInfo> certificateAuthoritiesJSON;
83-
8480
private static final Log logger = LogFactory.getLog(NetworkConfig.class);
8581

8682
private NetworkConfig(JsonObject jsonConfig) throws InvalidArgumentException, NetworkConfigurationException {

src/main/java/org/hyperledger/fabric/sdk/helper/Config.java

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,14 @@ public class Config {
7676
public static final String LOGGERLEVEL = "org.hyperledger.fabric.sdk.loglevel"; // ORG_HYPERLEDGER_FABRIC_SDK_LOGLEVEL=TRACE,DEBUG
7777
public static final String DIAGNOTISTIC_FILE_DIRECTORY = "org.hyperledger.fabric.sdk.diagnosticFileDir"; //ORG_HYPERLEDGER_FABRIC_SDK_DIAGNOSTICFILEDIR
7878

79+
/**
80+
* Connections settings
81+
*/
82+
83+
public static final String CONN_SSL_PROVIDER = "org.hyperledger.fabric.sdk.connections.ssl.sslProvider";
84+
public static final String CONN_SSL_NEGTYPE = "org.hyperledger.fabric.sdk.connections.ssl.negotiationType";
85+
86+
7987
/**
8088
* Miscellaneous settings
8189
**/
@@ -133,6 +141,13 @@ private Config() {
133141
defaultProperty(CERTIFICATE_FORMAT, "X.509");
134142
defaultProperty(SIGNATURE_ALGORITHM, "SHA256withECDSA");
135143

144+
/**
145+
* Connection defaults
146+
*/
147+
148+
defaultProperty(CONN_SSL_PROVIDER, "openSSL");
149+
defaultProperty(CONN_SSL_NEGTYPE, "TLS");
150+
136151
/**
137152
* Logging settings
138153
**/
@@ -271,6 +286,28 @@ public String getHashAlgorithm() {
271286

272287
}
273288

289+
/**
290+
* The default ssl provider for grpc connection
291+
*
292+
* @return The default ssl provider for grpc connection
293+
*/
294+
public String getDefaultSSLProvider() {
295+
return getProperty(CONN_SSL_PROVIDER);
296+
297+
}
298+
299+
/**
300+
* The default ssl negotiation type
301+
*
302+
* @return The default ssl negotiation type
303+
*/
304+
305+
public String getDefaultSSLNegotiationType() {
306+
return getProperty(CONN_SSL_NEGTYPE);
307+
308+
}
309+
310+
274311
private Map<Integer, String> curveMapping = null;
275312

276313
/**

src/test/fixture/sdkintegration/network_configs/network-config-tls.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -256,8 +256,8 @@ peers:
256256
grpcOptions:
257257
ssl-target-name-override: peer0.org1.example.com
258258
grpc.http2.keepalive_time: 15
259-
negotiationType: TLS
260-
sslProvider: openSSL
259+
# negotiationType: TLS ### purposely commented out to verify these are the defaults
260+
# sslProvider: openSSL
261261
hostnameOverride: peer1.org1.example.com
262262

263263
tlsCACerts:

src/test/java/org/hyperledger/fabric/sdk/EndpointTest.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,6 @@ public void testEndpointNonPEM() {
6868

6969
@Test
7070
public void testNullPropertySslProvider() {
71-
thrown.expect(RuntimeException.class);
72-
thrown.expectMessage("Property of sslProvider expected");
7371

7472
Properties testprops = new Properties();
7573
testprops.setProperty("hostnameOverride", "override");
@@ -80,19 +78,17 @@ public void testNullPropertySslProvider() {
8078
@Test
8179
public void testEmptyPropertySslProvider() {
8280
thrown.expect(RuntimeException.class);
83-
thrown.expectMessage("Property of sslProvider has to be either openSSL or JDK");
81+
thrown.expectMessage("property of sslProvider has to be either openSSL or JDK");
8482

8583
Properties testprops = new Properties();
86-
testprops.setProperty("sslProvider", "");
84+
testprops.setProperty("sslProvider", "closedSSL");
8785
testprops.setProperty("hostnameOverride", "override");
8886

8987
new Endpoint("grpcs://localhost:594", testprops);
9088
}
9189

9290
@Test
9391
public void testNullPropertyNegotiationType() {
94-
thrown.expect(RuntimeException.class);
95-
thrown.expectMessage("Property of negotiationType expected");
9692

9793
Properties testprops = new Properties();
9894
testprops.setProperty("sslProvider", "openSSL");
@@ -104,7 +100,7 @@ public void testNullPropertyNegotiationType() {
104100
@Test
105101
public void testEmptyPropertyNegotiationType() {
106102
thrown.expect(RuntimeException.class);
107-
thrown.expectMessage("Property of negotiationType has to be either TLS or plainText");
103+
thrown.expectMessage("property of negotiationType has to be either TLS or plainText");
108104

109105
Properties testprops = new Properties();
110106
testprops.setProperty("sslProvider", "openSSL");

0 commit comments

Comments
 (0)