Skip to content

Create truststore without keystore #1394

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,16 @@

import javax.net.ssl.SSLContext;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.hc.core5.ssl.SSLContextBuilder;

import org.springframework.core.io.Resource;

public class SSLContextFactory {

private static Log logger = LogFactory.getLog(SSLContextFactory.class);

private TlsProperties properties;

public SSLContextFactory(TlsProperties properties) {
Expand All @@ -39,26 +43,32 @@ public SSLContextFactory(TlsProperties properties) {

public SSLContext createSSLContext() throws GeneralSecurityException, IOException {
SSLContextBuilder builder = new SSLContextBuilder();
char[] keyPassword = properties.keyPassword();
KeyStore keyStore = createKeyStore();

try {
builder.loadKeyMaterial(keyStore, keyPassword);
KeyStore trust = createTrustStore();
if (trust != null) {
builder.loadTrustMaterial(trust, null);
}
catch (UnrecoverableKeyException e) {
if (keyPassword.length == 0) {
// Retry if empty password, see
// https://rt.openssl.org/Ticket/Display.html?id=1497&user=guest&pass=guest
builder.loadKeyMaterial(keyStore, new char[] { '\0' });

char[] keyPassword = properties.keyPassword();
try {
KeyStore keyStore = createKeyStore();

try {
builder.loadKeyMaterial(keyStore, keyPassword);
}
else {
throw e;
catch (UnrecoverableKeyException e) {
if (keyPassword.length == 0) {
// Retry if empty password, see
// https://rt.openssl.org/Ticket/Display.html?id=1497&user=guest&pass=guest
builder.loadKeyMaterial(keyStore, new char[] { '\0' });
}
else {
logger.warn("Could not create keystore.", e);
}
}
}

KeyStore trust = createTrustStore();
if (trust != null) {
builder.loadTrustMaterial(trust, null);
catch (KeyStoreException e) {
logger.warn("Could not create keystore.", e);
}

return builder.build();
Expand Down