@@ -80,21 +80,8 @@ public SslContext createNettySslContextForClient(ZKConfig config)
80
80
sslContextBuilder .trustManager (tm );
81
81
}
82
82
83
- SslProvider sslProvider = getSslProvider (config );
84
- sslContextBuilder .sslProvider (sslProvider );
85
- if (sslProvider == SslProvider .OPENSSL || sslProvider == SslProvider .OPENSSL_REFCNT ) {
86
- boolean ocspEnabled = config .getBoolean (getSslOcspEnabledProperty ());
87
- logTcnativeOcsp (ocspEnabled );
88
- // Set it even in unsupported, tcnative will just ignore it
89
- sslContextBuilder .enableOcsp (ocspEnabled );
90
- }
91
- // Explicit option takes precedence if set
92
- if (config .getTristate (getSslTcnativeOcspStaplingEnabledProperty ()).isTrue ()) {
93
- logTcnativeOcsp (true );
94
- sslContextBuilder .enableOcsp (true );
95
- } else if (config .getTristate (getSslTcnativeOcspStaplingEnabledProperty ()).isFalse ()) {
96
- sslContextBuilder .enableOcsp (false );
97
- }
83
+ sslContextBuilder .sslProvider (getSslProvider (config ));
84
+ handleTcnativeOcspStapling (sslContextBuilder , config );
98
85
String [] enabledProtocols = getEnabledProtocols (config );
99
86
if (enabledProtocols != null ) {
100
87
sslContextBuilder .protocols (enabledProtocols );
@@ -113,12 +100,29 @@ public SslContext createNettySslContextForClient(ZKConfig config)
113
100
}
114
101
}
115
102
116
- private void logTcnativeOcsp (boolean enable ) {
117
- if (enable && !OpenSsl .isOcspSupported ()) {
118
- // SslContextBuilder.enableOcsp() doesn't do anything, unless the default BoringSSL
119
- // tcnative dependency is replaced with an OpenSsl one.
120
- LOG .warn ("Trying to enable OCSP for tcnative OpenSSL provider, but it is not supported. The setting will be ignored" , OpenSsl .versionString ());
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 );
121
124
}
125
+ return builder ;
122
126
}
123
127
124
128
public SslContext createNettySslContextForServer (ZKConfig config )
@@ -144,17 +148,8 @@ public SslContext createNettySslContextForServer(ZKConfig config, KeyManager key
144
148
if (trustManager != null ) {
145
149
sslContextBuilder .trustManager (trustManager );
146
150
}
147
-
148
- SslProvider sslProvider = getSslProvider (config );
149
- sslContextBuilder .sslProvider (sslProvider );
150
- if (sslProvider == SslProvider .OPENSSL || sslProvider == SslProvider .OPENSSL_REFCNT ) {
151
- sslContextBuilder .enableOcsp (config .getBoolean (getSslOcspEnabledProperty ()));
152
- }
153
- if (config .getTristate (getSslTcnativeOcspStaplingEnabledProperty ()).isTrue ()) {
154
- sslContextBuilder .enableOcsp (true );
155
- } else if (config .getTristate (getSslTcnativeOcspStaplingEnabledProperty ()).isFalse ()) {
156
- sslContextBuilder .enableOcsp (false );
157
- }
151
+ sslContextBuilder .sslProvider (getSslProvider (config ));
152
+ handleTcnativeOcspStapling (sslContextBuilder , config );
158
153
String [] enabledProtocols = getEnabledProtocols (config );
159
154
if (enabledProtocols != null ) {
160
155
sslContextBuilder .protocols (enabledProtocols );
0 commit comments