@@ -82,11 +82,15 @@ enum SslImplementation {
8282 * @param sslImplementation the SSL implementation to use
8383 * @param clientAuth whether the client should authenticate
8484 * @param trustingServer whether the client should trust the server's certificate
85+ * @param protocol SSLContext protocol to use, e.g. TLSv1.2
8586 * @return {@link com.datastax.driver.core.SSLOptions} with the given configuration for server
8687 * certificate validation and client certificate authentication.
8788 */
8889 public SSLOptions getSSLOptions (
89- SslImplementation sslImplementation , boolean clientAuth , boolean trustingServer )
90+ SslImplementation sslImplementation ,
91+ boolean clientAuth ,
92+ boolean trustingServer ,
93+ String protocol )
9094 throws Exception {
9195
9296 TrustManagerFactory tmf = null ;
@@ -113,7 +117,7 @@ public SSLOptions getSSLOptions(
113117 kmf .init (ks , CCMBridge .DEFAULT_CLIENT_KEYSTORE_PASSWORD .toCharArray ());
114118 }
115119
116- SSLContext sslContext = SSLContext .getInstance ("TLS" );
120+ SSLContext sslContext = SSLContext .getInstance (protocol );
117121 sslContext .init (
118122 kmf != null ? kmf .getKeyManagers () : null ,
119123 tmf != null ? tmf .getTrustManagers () : null ,
@@ -125,6 +129,14 @@ public SSLOptions getSSLOptions(
125129 SslContextBuilder builder =
126130 SslContextBuilder .forClient ().sslProvider (OPENSSL ).trustManager (tmf );
127131
132+ if (protocol .equals ("TLS" ) || protocol .isEmpty ()) {
133+ // There is no netty constant for "TLS". Use defaults.
134+ // see
135+ // https://netty.io/4.1/api/constant-values.html#io.netty.handler.ssl.SslProtocols.SSL_v2
136+ } else {
137+ builder .protocols (protocol );
138+ }
139+
128140 if (clientAuth ) {
129141 builder .keyManager (
130142 CCMBridge .DEFAULT_CLIENT_CERT_CHAIN_FILE , CCMBridge .DEFAULT_CLIENT_PRIVATE_KEY_FILE );
@@ -136,4 +148,15 @@ public SSLOptions getSSLOptions(
136148 return null ;
137149 }
138150 }
151+
152+ /**
153+ * Legacy method using "TLS" as the protocol.
154+ *
155+ * @see SSLTestBase#getSSLOptions(SslImplementation, boolean, boolean, String)
156+ */
157+ public SSLOptions getSSLOptions (
158+ SslImplementation sslImplementation , boolean clientAuth , boolean trustingServer )
159+ throws Exception {
160+ return getSSLOptions (sslImplementation , clientAuth , trustingServer , "TLS" );
161+ }
139162}
0 commit comments