2525
2626import javax .net .ssl .SSLContext ;
2727
28+ import org .apache .commons .logging .Log ;
29+ import org .apache .commons .logging .LogFactory ;
2830import org .apache .hc .core5 .ssl .SSLContextBuilder ;
2931
3032import org .springframework .core .io .Resource ;
3133
3234public class SSLContextFactory {
3335
36+ private static Log logger = LogFactory .getLog (SSLContextFactory .class );
37+
3438 private TlsProperties properties ;
3539
3640 public SSLContextFactory (TlsProperties properties ) {
@@ -39,26 +43,32 @@ public SSLContextFactory(TlsProperties properties) {
3943
4044 public SSLContext createSSLContext () throws GeneralSecurityException , IOException {
4145 SSLContextBuilder builder = new SSLContextBuilder ();
42- char [] keyPassword = properties .keyPassword ();
43- KeyStore keyStore = createKeyStore ();
4446
45- try {
46- builder .loadKeyMaterial (keyStore , keyPassword );
47+ KeyStore trust = createTrustStore ();
48+ if (trust != null ) {
49+ builder .loadTrustMaterial (trust , null );
4750 }
48- catch (UnrecoverableKeyException e ) {
49- if (keyPassword .length == 0 ) {
50- // Retry if empty password, see
51- // https://rt.openssl.org/Ticket/Display.html?id=1497&user=guest&pass=guest
52- builder .loadKeyMaterial (keyStore , new char [] { '\0' });
51+
52+ char [] keyPassword = properties .keyPassword ();
53+ try {
54+ KeyStore keyStore = createKeyStore ();
55+
56+ try {
57+ builder .loadKeyMaterial (keyStore , keyPassword );
5358 }
54- else {
55- throw e ;
59+ catch (UnrecoverableKeyException e ) {
60+ if (keyPassword .length == 0 ) {
61+ // Retry if empty password, see
62+ // https://rt.openssl.org/Ticket/Display.html?id=1497&user=guest&pass=guest
63+ builder .loadKeyMaterial (keyStore , new char [] { '\0' });
64+ }
65+ else {
66+ logger .warn ("Could not create keystore." , e );
67+ }
5668 }
5769 }
58-
59- KeyStore trust = createTrustStore ();
60- if (trust != null ) {
61- builder .loadTrustMaterial (trust , null );
70+ catch (KeyStoreException e ) {
71+ logger .warn ("Could not create keystore." , e );
6272 }
6373
6474 return builder .build ();
0 commit comments