in ch-commons-ssl/src/main/java/com/cloudhopper/commons/ssl/SslContextFactory.java [341:372]
public void checkKeyStore() {
if (sslContext != null)
return; //nothing to check if using preconfigured context
if (keyStoreInputStream == null &&
sslConfig.getKeyStorePath() == null) {
throw new IllegalStateException("SSL doesn't have a valid keystore");
}
// if the keystore has been configured but there is no
// truststore configured, use the keystore as the truststore
if (trustStoreInputStream == null && sslConfig.getTrustStorePath() == null) {
trustStoreInputStream = keyStoreInputStream;
sslConfig.setTrustStorePath(sslConfig.getKeyStorePath());
sslConfig.setTrustStoreType(sslConfig.getKeyStoreType());
sslConfig.setTrustStoreProvider(sslConfig.getKeyStoreProvider());
sslConfig.setTrustStorePassword(sslConfig.getKeyStorePassword());
sslConfig.setTrustManagerFactoryAlgorithm(sslConfig.getKeyManagerFactoryAlgorithm());
}
// It's the same stream we cannot read it twice, so read it once in memory
if (keyStoreInputStream != null && keyStoreInputStream == trustStoreInputStream) {
try {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
streamCopy(keyStoreInputStream, baos, null, false);
keyStoreInputStream.close();
keyStoreInputStream = new ByteArrayInputStream(baos.toByteArray());
trustStoreInputStream = new ByteArrayInputStream(baos.toByteArray());
} catch (Exception ex) {
throw new IllegalStateException(ex);
}
}
}