From 5bc9457364c66f64e636dcac5fe2708600853ae7 Mon Sep 17 00:00:00 2001 From: Jonathan Shook Date: Mon, 21 Mar 2022 17:03:19 -0500 Subject: [PATCH] make SSL errors more clear by showing the details of the caught exception --- .../engine/api/util/SSLKsFactoryTest.java | 4 ++-- .../nosqlbench/engine/api/util/SSLKsFactory.java | 14 +++++++------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/engine-api/src/test/java/io/nosqlbench/engine/api/util/SSLKsFactoryTest.java b/engine-api/src/test/java/io/nosqlbench/engine/api/util/SSLKsFactoryTest.java index 11211aef5..8e4892fc9 100644 --- a/engine-api/src/test/java/io/nosqlbench/engine/api/util/SSLKsFactoryTest.java +++ b/engine-api/src/test/java/io/nosqlbench/engine/api/util/SSLKsFactoryTest.java @@ -162,7 +162,7 @@ public class SSLKsFactoryTest { NBConfiguration sslCfg = SSLKsFactory.get().getConfigModel().extractConfig(activityDef.getParams()); assertThatExceptionOfType(RuntimeException.class) .isThrownBy(() -> SSLKsFactory.get().getContext(sslCfg)) - .withMessageMatching("Unable to load the keystore. Please check."); + .withMessageMatching("Unable to load the keystore: .*"); } @Test @@ -192,7 +192,7 @@ public class SSLKsFactoryTest { NBConfiguration sslCfg = SSLKsFactory.get().getConfigModel().extractConfig(activityDef.getParams()); assertThatExceptionOfType(RuntimeException.class) .isThrownBy(() -> SSLKsFactory.get().getContext(sslCfg)) - .withMessageMatching("Unable to load the truststore. Please check."); + .withMessageMatching("Unable to load the truststore: .*"); } @Test diff --git a/nb-api/src/main/java/io/nosqlbench/engine/api/util/SSLKsFactory.java b/nb-api/src/main/java/io/nosqlbench/engine/api/util/SSLKsFactory.java index e8c227069..de90ea843 100644 --- a/nb-api/src/main/java/io/nosqlbench/engine/api/util/SSLKsFactory.java +++ b/nb-api/src/main/java/io/nosqlbench/engine/api/util/SSLKsFactory.java @@ -98,7 +98,7 @@ public class SSLKsFactory implements NBMapConfigurable { try { return KeyStore.getInstance(new File(ksPath), keyStorePassword); } catch (Exception e) { - throw new RuntimeException("Unable to load the keystore. Please check.", e); + throw new RuntimeException("Unable to load the keystore: " + e, e); } }).orElse(null); @@ -109,7 +109,7 @@ public class SSLKsFactory implements NBMapConfigurable { .map(String::toCharArray) .orElse(null)); } catch (Exception e) { - throw new RuntimeException("Unable to load the truststore. Please check.", e); + throw new RuntimeException("Unable to load the truststore: " + e, e); } }).orElse(null); @@ -125,7 +125,7 @@ public class SSLKsFactory implements NBMapConfigurable { return cf.generateCertificate(is); } catch (Exception e) { throw new RuntimeException( - String.format("Unable to load cert from %s. Please check.", certFilePath), + String.format("Unable to load cert from %s: " + e, certFilePath), e ); } @@ -148,7 +148,7 @@ public class SSLKsFactory implements NBMapConfigurable { keyStore.setKeyEntry("key", key, keyPassword, cert != null ? new Certificate[]{cert} : null); } catch (Exception e) { - throw new RuntimeException(String.format("Unable to load key from %s. Please check.", + throw new RuntimeException(String.format("Unable to load key from %s: " + e, keyFile), e); } @@ -163,7 +163,7 @@ public class SSLKsFactory implements NBMapConfigurable { ts.setCertificateEntry("caCertFile", caCert); return ts; } catch (Exception e) { - throw new RuntimeException(String.format("Unable to load caCert from %s. Please check.", + throw new RuntimeException(String.format("Unable to load caCert from %s: " + e, caCertFilePath), e); } @@ -183,7 +183,7 @@ public class SSLKsFactory implements NBMapConfigurable { kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm()); kmf.init(keyStore, keyPassword); } catch (Exception e) { - throw new RuntimeException("Unable to init KeyManagerFactory. Please check password and location.", e); + throw new RuntimeException("Unable to init KeyManagerFactory. Please check password and location: " + e, e); } TrustManagerFactory tmf; @@ -191,7 +191,7 @@ public class SSLKsFactory implements NBMapConfigurable { tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm()); tmf.init(trustStore != null ? trustStore : keyStore); } catch (Exception e) { - throw new RuntimeException("Unable to init TrustManagerFactory. Please check.", e); + throw new RuntimeException("Unable to init TrustManagerFactory: " + e, e); } try {