@@ -56,14 +56,6 @@ public static PoolingHttpClientConnectionManager getBaseConnectionManager(
5656 SocketFactoryUtil .getTrustAllSocketFactoryRegistry ());
5757 }
5858
59- // If self-signed certificates are allowed, use a trust-all socket factory
60- if (connectionContext .allowSelfSignedCerts ()) {
61- LOGGER .warn (
62- "Self-signed certificates are allowed. Please only use this parameter (AllowSelfSignedCerts) when you're sure of what you're doing. This is not recommended for production use." );
63- return new PoolingHttpClientConnectionManager (
64- SocketFactoryUtil .getTrustAllSocketFactoryRegistry ());
65- }
66-
6759 // For standard SSL configuration, create a custom socket factory registry
6860 Registry <ConnectionSocketFactory > socketFactoryRegistry =
6961 createConnectionSocketFactoryRegistry (connectionContext );
@@ -80,59 +72,7 @@ public static PoolingHttpClientConnectionManager getBaseConnectionManager(
8072 public static Registry <ConnectionSocketFactory > createConnectionSocketFactoryRegistry (
8173 IDatabricksConnectionContext connectionContext ) throws DatabricksHttpException {
8274
83- // First check if a custom trust store is specified
84- if (connectionContext .getSSLTrustStore () != null ) {
85- return createRegistryWithCustomTrustStore (connectionContext );
86- } else {
87- return createRegistryWithSystemOrDefaultTrustStore (connectionContext );
88- }
89- }
90-
91- /**
92- * Creates a socket factory registry using a custom trust store.
93- *
94- * @param connectionContext The connection context containing the trust store information.
95- * @return A registry of connection socket factories.
96- * @throws DatabricksHttpException If there is an error setting up the trust store.
97- */
98- private static Registry <ConnectionSocketFactory > createRegistryWithCustomTrustStore (
99- IDatabricksConnectionContext connectionContext ) throws DatabricksHttpException {
100-
101- try {
102- KeyStore trustStore = loadTruststoreOrNull (connectionContext );
103- if (trustStore == null ) {
104- String errorMessage =
105- "Specified trust store could not be loaded: " + connectionContext .getSSLTrustStore ();
106- handleError (errorMessage , new IOException (errorMessage ));
107- }
108-
109- // Get trust anchors from custom store
110- Set <TrustAnchor > trustAnchors = getTrustAnchorsFromTrustStore (trustStore );
111- if (trustAnchors .isEmpty ()) {
112- String errorMessage =
113- "Custom trust store contains no trust anchors. Certificate validation will fail." ;
114- handleError (errorMessage , new KeyStoreException (errorMessage ));
115- }
116-
117- LOGGER .info ("Using custom trust store: " + connectionContext .getSSLTrustStore ());
118-
119- // Create trust managers from trust store
120- TrustManager [] trustManagers =
121- createTrustManagers (
122- trustAnchors ,
123- connectionContext .checkCertificateRevocation (),
124- connectionContext .acceptUndeterminedCertificateRevocation ());
125-
126- // Create socket factory registry
127- return createSocketFactoryRegistry (trustManagers );
128- } catch (DatabricksHttpException
129- | NoSuchAlgorithmException
130- | InvalidAlgorithmParameterException
131- | KeyManagementException e ) {
132- handleError (
133- "Error while setting up custom trust store: " + connectionContext .getSSLTrustStore (), e );
134- }
135- return null ; // This will never be reached, but is required for method signature.
75+ return createRegistryWithSystemOrDefaultTrustStore (connectionContext );
13676 }
13777
13878 /**
@@ -337,57 +277,6 @@ private static X509TrustManager findX509TrustManager(TrustManager[] trustManager
337277 return null ;
338278 }
339279
340- /**
341- * Loads a trust store from the path specified in the connection context.
342- *
343- * @param connectionContext The connection context containing trust store configuration.
344- * @return The loaded KeyStore or null if it could not be loaded.
345- * @throws DatabricksHttpException If there is an error during loading.
346- */
347- public static KeyStore loadTruststoreOrNull (IDatabricksConnectionContext connectionContext )
348- throws DatabricksHttpException {
349- String trustStorePath = connectionContext .getSSLTrustStore ();
350- if (trustStorePath == null ) {
351- return null ;
352- }
353-
354- // If the specified file doesn't exist, throw a specific error
355- File trustStoreFile = new File (trustStorePath );
356- if (!trustStoreFile .exists ()) {
357- String errorMessage = "Specified trust store file does not exist: " + trustStorePath ;
358- handleError (errorMessage , new IOException (errorMessage ));
359- }
360-
361- char [] password = null ;
362- if (connectionContext .getSSLTrustStorePassword () != null ) {
363- password = connectionContext .getSSLTrustStorePassword ().toCharArray ();
364- }
365-
366- // Get the specified type, defaulting to JKS if not specified
367- String trustStoreType = connectionContext .getSSLTrustStoreType ();
368- if (trustStoreType == null || trustStoreType .isEmpty ()) {
369- trustStoreType = "JKS" ; // Default to JKS if not specified
370- }
371-
372- try (FileInputStream trustStoreStream = new FileInputStream (trustStorePath )) {
373- LOGGER .info ("Loading trust store as type: " + trustStoreType );
374- KeyStore trustStore = KeyStore .getInstance (trustStoreType );
375- trustStore .load (trustStoreStream , password );
376- LOGGER .info ("Successfully loaded trust store: " + trustStorePath );
377- return trustStore ;
378- } catch (KeyStoreException | NoSuchAlgorithmException | CertificateException | IOException e ) {
379- String errorMessage =
380- "Failed to load trust store: "
381- + trustStorePath
382- + " with type "
383- + trustStoreType
384- + ": "
385- + e .getMessage ();
386- handleError (errorMessage , e );
387- }
388- return null ; // This will never be reached, but is required for method signature.
389- }
390-
391280 /**
392281 * Extracts trust anchors from a KeyStore.
393282 *
@@ -443,8 +332,9 @@ public static CertPathTrustManagerParameters buildTrustManagerParameters(
443332 PKIXRevocationChecker .Option .NO_FALLBACK ,
444333 PKIXRevocationChecker .Option .PREFER_CRLS ));
445334 }
446- LOGGER .info ("Certificate revocation enabled. Undetermined revocation accepted: "
447- + acceptUndeterminedCertificateRevocation );
335+ LOGGER .info (
336+ "Certificate revocation enabled. Undetermined revocation accepted: "
337+ + acceptUndeterminedCertificateRevocation );
448338
449339 pkixBuilderParameters .addCertPathChecker (revocationChecker );
450340 }
0 commit comments