@@ -72,8 +72,34 @@ private void enableSSL(final Hashtable<String, String> environment, Long domainI
7272 if (sslStatus ) {
7373 s_logger .info ("LDAP SSL enabled." );
7474 environment .put (Context .SECURITY_PROTOCOL , "ssl" );
75- System .setProperty ("javax.net.ssl.trustStore" , _ldapConfiguration .getTrustStore (domainId ));
76- System .setProperty ("javax.net.ssl.trustStorePassword" , _ldapConfiguration .getTrustStorePassword (domainId ));
75+ String trustStore = _ldapConfiguration .getTrustStore (domainId );
76+ String trustStorePassword = _ldapConfiguration .getTrustStorePassword (domainId );
77+
78+ // Validate truststore and password before setting system properties
79+ if (!validateTrustStore (trustStore , trustStorePassword )) {
80+ throw new RuntimeException ("Invalid truststore or truststore password" );
81+ }
82+
83+ System .setProperty ("javax.net.ssl.trustStore" , trustStore );
84+ System .setProperty ("javax.net.ssl.trustStorePassword" , trustStorePassword );
85+ }
86+ }
87+
88+ private boolean validateTrustStore (String trustStore , String trustStorePassword ) {
89+ if (trustStore == null || trustStorePassword == null ) {
90+ return false ;
91+ }
92+
93+ try {
94+ // Try to load the truststore with the provided password
95+ java .security .KeyStore .getInstance ("JKS" ).load (
96+ new java .io .FileInputStream (trustStore ),
97+ trustStorePassword .toCharArray ()
98+ );
99+ return true ;
100+ } catch (Exception e ) {
101+ s_logger .warn ("Failed to validate truststore: " + e .getMessage ());
102+ return false ;
77103 }
78104 }
79105
0 commit comments