@@ -523,24 +523,7 @@ protected static SplitHttpClient buildSplitHttpClient(String apiToken, SplitClie
523523 SDKMetadata sdkMetadata , RequestDecorator requestDecorator )
524524 throws URISyntaxException {
525525
526- SSLContext sslContext ;
527- if (config .proxyMTLSAuth () != null ) {
528- _log .debug ("Proxy setup using mTLS" );
529- try {
530- KeyStore keyStore = KeyStore .getInstance ("PKCS12" );
531- InputStream keystoreStream = java .nio .file .Files .newInputStream (Paths .get (config .proxyMTLSAuth ().getP12File ()));
532- keyStore .load (keystoreStream , config .proxyMTLSAuth ().getP12FilePassKey ().toCharArray ());
533- sslContext = SSLContexts .custom ()
534- .loadKeyMaterial (keyStore , config .proxyMTLSAuth ().getP12FilePassKey ().toCharArray ())
535- .build ();
536- } catch (Exception e ) {
537- _log .error ("Exception caught while processing p12 file for Proxy mTLS auth: " , e );
538- _log .warn ("Ignoring p12 mTLS config and switching to default context" );
539- sslContext = SSLContexts .createSystemDefault ();
540- }
541- } else {
542- sslContext = SSLContexts .createSystemDefault ();
543- }
526+ SSLContext sslContext = buildSSLContext (config );
544527
545528 SSLConnectionSocketFactory sslSocketFactory = SSLConnectionSocketFactoryBuilder .create ()
546529 .setSslContext (sslContext )
@@ -585,8 +568,10 @@ private static CloseableHttpClient buildSSEdHttpClient(String apiToken, SplitCli
585568 .setConnectTimeout (Timeout .ofMilliseconds (SSE_CONNECT_TIMEOUT ))
586569 .build ();
587570
571+ SSLContext sslContext = buildSSLContext (config );
572+
588573 SSLConnectionSocketFactory sslSocketFactory = SSLConnectionSocketFactoryBuilder .create ()
589- .setSslContext (SSLContexts . createSystemDefault () )
574+ .setSslContext (sslContext )
590575 .setTlsVersions (TLS .V_1_1 , TLS .V_1_2 )
591576 .build ();
592577
@@ -613,6 +598,28 @@ private static CloseableHttpClient buildSSEdHttpClient(String apiToken, SplitCli
613598 return httpClientbuilder .build ();
614599 }
615600
601+ private static SSLContext buildSSLContext (SplitClientConfig config ) {
602+ SSLContext sslContext ;
603+ if (config .proxyMTLSAuth () != null ) {
604+ _log .debug ("Proxy setup using mTLS" );
605+ try {
606+ KeyStore keyStore = KeyStore .getInstance ("PKCS12" );
607+ InputStream keystoreStream = java .nio .file .Files .newInputStream (Paths .get (config .proxyMTLSAuth ().getP12File ()));
608+ keyStore .load (keystoreStream , config .proxyMTLSAuth ().getP12FilePassKey ().toCharArray ());
609+ sslContext = SSLContexts .custom ()
610+ .loadKeyMaterial (keyStore , config .proxyMTLSAuth ().getP12FilePassKey ().toCharArray ())
611+ .build ();
612+ } catch (Exception e ) {
613+ _log .error ("Exception caught while processing p12 file for Proxy mTLS auth: " , e );
614+ _log .warn ("Ignoring p12 mTLS config and switching to default context" );
615+ sslContext = SSLContexts .createSystemDefault ();
616+ }
617+ } else {
618+ sslContext = SSLContexts .createSystemDefault ();
619+ }
620+ return sslContext ;
621+ }
622+
616623 private static HttpClientBuilder setupProxy (HttpClientBuilder httpClientbuilder , SplitClientConfig config ) {
617624 _log .info ("Initializing Split SDK with proxy settings" );
618625 DefaultProxyRoutePlanner routePlanner = new DefaultProxyRoutePlanner (config .proxy ());
0 commit comments