Skip to content

Commit ab1065a

Browse files
committed
rearrange code to make patch smaller
1 parent 3af6fda commit ab1065a

File tree

1 file changed

+28
-27
lines changed

1 file changed

+28
-27
lines changed

zookeeper-server/src/main/java/org/apache/zookeeper/common/ClientX509Util.java

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ public SslContext createNettySslContextForClient(ZKConfig config)
8080
sslContextBuilder.trustManager(tm);
8181
}
8282

83-
sslContextBuilder.sslProvider(getSslProvider(config));
8483
handleTcnativeOcspStapling(sslContextBuilder, config);
8584
String[] enabledProtocols = getEnabledProtocols(config);
8685
if (enabledProtocols != null) {
@@ -90,6 +89,7 @@ public SslContext createNettySslContextForClient(ZKConfig config)
9089
if (enabledCiphers != null) {
9190
sslContextBuilder.ciphers(enabledCiphers);
9291
}
92+
sslContextBuilder.sslProvider(getSslProvider(config));
9393

9494
SslContext sslContext1 = sslContextBuilder.build();
9595

@@ -100,31 +100,6 @@ public SslContext createNettySslContextForClient(ZKConfig config)
100100
}
101101
}
102102

103-
private SslContextBuilder handleTcnativeOcspStapling(SslContextBuilder builder, ZKConfig config) {
104-
SslProvider sslProvider = getSslProvider(config);
105-
boolean tcnative = sslProvider == SslProvider.OPENSSL || sslProvider == SslProvider.OPENSSL_REFCNT;
106-
boolean ocspEnabled = config.getBoolean(getSslOcspEnabledProperty());
107-
TriState tcnativeOcspStapling = config.getTristate(getSslTcnativeOcspStaplingEnabledProperty());
108-
109-
if (tcnative && ocspEnabled && tcnativeOcspStapling.isDefault() && OpenSsl.isOcspSupported()) {
110-
// Maintain old behaviour (mostly, we also check for OpenSsl.isOcspSupported())
111-
builder.enableOcsp(ocspEnabled);
112-
} else if (tcnativeOcspStapling.isTrue()) {
113-
if (!tcnative) {
114-
// Don't override the explicit setting, let it error out
115-
LOG.error("Trying to enable OpenSSL OCSP stapling for non-OpenSSL TLS provider. "
116-
+ "This is going to fail. Please fix the TLS configuration");
117-
} else if (!OpenSsl.isOcspSupported()) {
118-
LOG.warn("Trying to enable OpenSSL OCSP stapling for OpenSSL provider {} which does not support it. "
119-
+ "This is either going to be ignored or fail.", OpenSsl.versionString());
120-
}
121-
builder.enableOcsp(true);
122-
} else if (tcnativeOcspStapling.isFalse()) {
123-
builder.enableOcsp(false);
124-
}
125-
return builder;
126-
}
127-
128103
public SslContext createNettySslContextForServer(ZKConfig config)
129104
throws X509Exception.SSLContextException, X509Exception.KeyManagerException, X509Exception.TrustManagerException, SSLException {
130105
String keyStoreLocation = config.getProperty(getSslKeystoreLocationProperty(), "");
@@ -148,7 +123,7 @@ public SslContext createNettySslContextForServer(ZKConfig config, KeyManager key
148123
if (trustManager != null) {
149124
sslContextBuilder.trustManager(trustManager);
150125
}
151-
sslContextBuilder.sslProvider(getSslProvider(config));
126+
152127
handleTcnativeOcspStapling(sslContextBuilder, config);
153128
String[] enabledProtocols = getEnabledProtocols(config);
154129
if (enabledProtocols != null) {
@@ -159,6 +134,7 @@ public SslContext createNettySslContextForServer(ZKConfig config, KeyManager key
159134
if (enabledCiphers != null) {
160135
sslContextBuilder.ciphers(enabledCiphers);
161136
}
137+
sslContextBuilder.sslProvider(getSslProvider(config));
162138

163139
SslContext sslContext1 = sslContextBuilder.build();
164140

@@ -169,6 +145,31 @@ public SslContext createNettySslContextForServer(ZKConfig config, KeyManager key
169145
}
170146
}
171147

148+
private SslContextBuilder handleTcnativeOcspStapling(SslContextBuilder builder, ZKConfig config) {
149+
SslProvider sslProvider = getSslProvider(config);
150+
boolean tcnative = sslProvider == SslProvider.OPENSSL || sslProvider == SslProvider.OPENSSL_REFCNT;
151+
boolean ocspEnabled = config.getBoolean(getSslOcspEnabledProperty());
152+
TriState tcnativeOcspStapling = config.getTristate(getSslTcnativeOcspStaplingEnabledProperty());
153+
154+
if (tcnative && ocspEnabled && tcnativeOcspStapling.isDefault() && OpenSsl.isOcspSupported()) {
155+
// Maintain old behaviour (mostly, we also check for OpenSsl.isOcspSupported())
156+
builder.enableOcsp(ocspEnabled);
157+
} else if (tcnativeOcspStapling.isTrue()) {
158+
if (!tcnative) {
159+
// Don't override the explicit setting, let it error out
160+
LOG.error("Trying to enable OpenSSL OCSP stapling for non-OpenSSL TLS provider. "
161+
+ "This is going to fail. Please fix the TLS configuration");
162+
} else if (!OpenSsl.isOcspSupported()) {
163+
LOG.warn("Trying to enable OpenSSL OCSP stapling for OpenSSL provider {} which does not support it. "
164+
+ "This is either going to be ignored or fail.", OpenSsl.versionString());
165+
}
166+
builder.enableOcsp(true);
167+
} else if (tcnativeOcspStapling.isFalse()) {
168+
builder.enableOcsp(false);
169+
}
170+
return builder;
171+
}
172+
172173
private SslContext addHostnameVerification(SslContext sslContext, String clientOrServer) {
173174
return new DelegatingSslContext(sslContext) {
174175
@Override

0 commit comments

Comments
 (0)