@@ -51,14 +51,6 @@ public static PoolingHttpClientConnectionManager getBaseConnectionManager(
5151 SocketFactoryUtil .getTrustAllSocketFactoryRegistry ());
5252 }
5353
54- // If self-signed certificates are allowed, use a trust-all socket factory
55- if (connectionContext .allowSelfSignedCerts ()) {
56- LOGGER .warn (
57- "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." );
58- return new PoolingHttpClientConnectionManager (
59- SocketFactoryUtil .getTrustAllSocketFactoryRegistry ());
60- }
61-
6254 // For standard SSL configuration, create a custom socket factory registry
6355 Registry <ConnectionSocketFactory > socketFactoryRegistry =
6456 createConnectionSocketFactoryRegistry (connectionContext );
@@ -75,59 +67,7 @@ public static PoolingHttpClientConnectionManager getBaseConnectionManager(
7567 public static Registry <ConnectionSocketFactory > createConnectionSocketFactoryRegistry (
7668 IDatabricksConnectionContext connectionContext ) throws DatabricksHttpException {
7769
78- // First check if a custom trust store is specified
79- if (connectionContext .getSSLTrustStore () != null ) {
80- return createRegistryWithCustomTrustStore (connectionContext );
81- } else {
82- return createRegistryWithSystemOrDefaultTrustStore (connectionContext );
83- }
84- }
85-
86- /**
87- * Creates a socket factory registry using a custom trust store.
88- *
89- * @param connectionContext The connection context containing the trust store information.
90- * @return A registry of connection socket factories.
91- * @throws DatabricksHttpException If there is an error setting up the trust store.
92- */
93- private static Registry <ConnectionSocketFactory > createRegistryWithCustomTrustStore (
94- IDatabricksConnectionContext connectionContext ) throws DatabricksHttpException {
95-
96- try {
97- KeyStore trustStore = loadTruststoreOrNull (connectionContext );
98- if (trustStore == null ) {
99- String errorMessage =
100- "Specified trust store could not be loaded: " + connectionContext .getSSLTrustStore ();
101- handleError (errorMessage , new IOException (errorMessage ));
102- }
103-
104- // Get trust anchors from custom store
105- Set <TrustAnchor > trustAnchors = getTrustAnchorsFromTrustStore (trustStore );
106- if (trustAnchors .isEmpty ()) {
107- String errorMessage =
108- "Custom trust store contains no trust anchors. Certificate validation will fail." ;
109- handleError (errorMessage , new KeyStoreException (errorMessage ));
110- }
111-
112- LOGGER .info ("Using custom trust store: " + connectionContext .getSSLTrustStore ());
113-
114- // Create trust managers from trust store
115- TrustManager [] trustManagers =
116- createTrustManagers (
117- trustAnchors ,
118- connectionContext .checkCertificateRevocation (),
119- connectionContext .acceptUndeterminedCertificateRevocation ());
120-
121- // Create socket factory registry
122- return createSocketFactoryRegistry (trustManagers );
123- } catch (DatabricksHttpException
124- | NoSuchAlgorithmException
125- | InvalidAlgorithmParameterException
126- | KeyManagementException e ) {
127- handleError (
128- "Error while setting up custom trust store: " + connectionContext .getSSLTrustStore (), e );
129- }
130- return null ; // This will never be reached, but is required for method signature.
70+ return createRegistryWithSystemOrDefaultTrustStore (connectionContext );
13171 }
13272
13373 /**
@@ -357,57 +297,6 @@ private static X509TrustManager findX509TrustManager(TrustManager[] trustManager
357297 return null ;
358298 }
359299
360- /**
361- * Loads a trust store from the path specified in the connection context.
362- *
363- * @param connectionContext The connection context containing trust store configuration.
364- * @return The loaded KeyStore or null if it could not be loaded.
365- * @throws DatabricksHttpException If there is an error during loading.
366- */
367- public static KeyStore loadTruststoreOrNull (IDatabricksConnectionContext connectionContext )
368- throws DatabricksHttpException {
369- String trustStorePath = connectionContext .getSSLTrustStore ();
370- if (trustStorePath == null ) {
371- return null ;
372- }
373-
374- // If the specified file doesn't exist, throw a specific error
375- File trustStoreFile = new File (trustStorePath );
376- if (!trustStoreFile .exists ()) {
377- String errorMessage = "Specified trust store file does not exist: " + trustStorePath ;
378- handleError (errorMessage , new IOException (errorMessage ));
379- }
380-
381- char [] password = null ;
382- if (connectionContext .getSSLTrustStorePassword () != null ) {
383- password = connectionContext .getSSLTrustStorePassword ().toCharArray ();
384- }
385-
386- // Get the specified type, defaulting to JKS if not specified
387- String trustStoreType = connectionContext .getSSLTrustStoreType ();
388- if (trustStoreType == null || trustStoreType .isEmpty ()) {
389- trustStoreType = "JKS" ; // Default to JKS if not specified
390- }
391-
392- try (FileInputStream trustStoreStream = new FileInputStream (trustStorePath )) {
393- LOGGER .info ("Loading trust store as type: " + trustStoreType );
394- KeyStore trustStore = KeyStore .getInstance (trustStoreType );
395- trustStore .load (trustStoreStream , password );
396- LOGGER .info ("Successfully loaded trust store: " + trustStorePath );
397- return trustStore ;
398- } catch (KeyStoreException | NoSuchAlgorithmException | CertificateException | IOException e ) {
399- String errorMessage =
400- "Failed to load trust store: "
401- + trustStorePath
402- + " with type "
403- + trustStoreType
404- + ": "
405- + e .getMessage ();
406- handleError (errorMessage , e );
407- }
408- return null ; // This will never be reached, but is required for method signature.
409- }
410-
411300 /**
412301 * Extracts trust anchors from a KeyStore.
413302 *
0 commit comments