Skip to content

Commit

Permalink
small refactoring to prepare #865
Browse files Browse the repository at this point in the history
  • Loading branch information
rbri committed Sep 22, 2024
1 parent 9983b16 commit af50808
Showing 1 changed file with 5 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,7 @@
import java.net.Socket;
import java.net.SocketTimeoutException;
import java.security.GeneralSecurityException;
import java.security.KeyManagementException;
import java.security.KeyStore;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.security.UnrecoverableKeyException;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
import java.util.Arrays;
Expand Down Expand Up @@ -92,12 +88,13 @@ public static SSLConnectionSocketFactory buildSSLSocketFactory(final WebClientOp

if (!useInsecureSSL) {
final KeyStore keyStore = options.getSSLClientCertificateStore();
final char[] keyStorePassword = keyStore == null ? null : options.getSSLClientCertificatePassword();
final KeyStore trustStore = options.getSSLTrustStore();

return new HtmlUnitSSLConnectionSocketFactory(keyStore,
keyStore == null ? null : options.getSSLClientCertificatePassword(),
trustStore, useInsecureSSL,
sslClientProtocols, sslClientCipherSuites);
final SSLContext sslContext = SSLContexts.custom()
.loadKeyMaterial(keyStore, keyStorePassword).loadTrustMaterial(trustStore, null).build();
return new HtmlUnitSSLConnectionSocketFactory(sslContext, new DefaultHostnameVerifier(),
useInsecureSSL, sslClientProtocols, sslClientCipherSuites);
}

// we need insecure SSL + SOCKS awareness
Expand All @@ -123,17 +120,6 @@ private HtmlUnitSSLConnectionSocketFactory(final SSLContext sslContext,
useInsecureSSL_ = useInsecureSSL;
}

private HtmlUnitSSLConnectionSocketFactory(final KeyStore keystore, final char[] keystorePassword,
final KeyStore truststore, final boolean useInsecureSSL,
final String[] supportedProtocols, final String[] supportedCipherSuites)
throws NoSuchAlgorithmException, KeyManagementException, KeyStoreException, UnrecoverableKeyException {
super(SSLContexts.custom()
.loadKeyMaterial(keystore, keystorePassword).loadTrustMaterial(truststore, null).build(),
supportedProtocols, supportedCipherSuites,
new DefaultHostnameVerifier());
useInsecureSSL_ = useInsecureSSL;
}

private static void configureSocket(final SSLSocket sslSocket, final HttpContext context) {
if (isUseSSL3Only(context)) {
sslSocket.setEnabledProtocols(new String[]{"SSLv3"});
Expand Down

0 comments on commit af50808

Please sign in to comment.