From: markt The password to access the trust store. The default is the value of the
+ * keytool -genkey -alias tomcat -keyalg RSA
+ * Use "changeit" as password (this is the default we use).
+ *
* @author Harish Prabandham
* @author Costin Manolache
* @author Stefan Freyr Stefansson
@@ -342,8 +337,23 @@ public class JSSESocketFactory
}
if (truststoreFile != null){
- trustStore = getStore(truststoreType, truststoreProvider,
- truststoreFile, truststorePassword);
+ try {
+ trustStore = getStore(truststoreType, truststoreProvider,
+ truststoreFile, truststorePassword);
+ } catch (IOException ioe) {
+ Throwable cause = ioe.getCause();
+ if (cause instanceof UnrecoverableKeyException) {
+ // Log a warning we had a password issue
+ log.warn(sm.getString("jsse.invalid_truststore_password"),
+ cause);
+ // Re-try
+ trustStore = getStore(truststoreType, truststoreProvider,
+ truststoreFile, null);
+ } else {
+ // Something else went wrong - re-throw
+ throw ioe;
+ }
+ }
}
return trustStore;
@@ -374,7 +384,7 @@ public class JSSESocketFactory
}
char[] storePass = null;
- if (pass != null) {
+ if (pass != null && !"".equals(pass)) {
storePass = pass.toCharArray();
}
ks.load(istream, storePass);
@@ -383,9 +393,9 @@ public class JSSESocketFactory
fnfe.getMessage()), fnfe);
throw fnfe;
} catch (IOException ioe) {
- log.error(sm.getString("jsse.keystore_load_failed", type, path,
- ioe.getMessage()), ioe);
- throw ioe;
+ // May be expected when working with a trust store
+ // Re-throw. Caller will catch and log as required
+ throw ioe;
} catch(Exception ex) {
String msg = sm.getString("jsse.keystore_load_failed", type, path,
ex.getMessage());
diff --git a/java/org/apache/tomcat/util/net/jsse/res/LocalStrings.properties b/java/org/apache/tomcat/util/net/jsse/res/LocalStrings.properties
index 20a4d0188..69302278b 100644
--- a/java/org/apache/tomcat/util/net/jsse/res/LocalStrings.properties
+++ b/java/org/apache/tomcat/util/net/jsse/res/LocalStrings.properties
@@ -15,4 +15,5 @@
jsse.alias_no_key_entry=Alias name {0} does not identify a key entry
jsse.keystore_load_failed=Failed to load keystore type {0} with path {1} due to {2}
-jsse.invalid_ssl_conf=SSL configuration is invalid due to {0}
+jsse.invalid_ssl_conf=SSL configuration is invalid due to {0}
+jsse.invalid_truststore_password=The provided trust store password could not be used to unlock and/or validate the trust store. Retrying to access the trust store with a null password which will skip validation.
\ No newline at end of file
diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml
index 5b713f653..c91dc2601 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -44,6 +44,14 @@
+ javax.net.ssl.trustStorePassword system property. If that
- property is null, no trust store password will be configured.