@Test void generateKeystoreAndTruststoreThrowsExceptionIfKeystoreDestinationDirectoryDoesNotExist() { final String nonExistingPath = "/hbewfhjbfewhj/keystore.jks"; assertThatThrownBy(() -> underTest.createKeystoreAndTruststore(nonExistingPath, "localhost")) .hasMessageContaining(nonExistingPath); }
public void createKeystoreAndTruststore(String keystorePath, String subject) { try { final CertAndPrivateKey certAndPrivateKey = generateCertificateAndPrivateKey(subject); KeyStore ks = KeyStore.getInstance("JKS"); ks.load(null); final KeyStore.PrivateKeyEntry privateKeyEntry = new KeyStore.PrivateKeyEntry(certAndPrivateKey.privateKey, new Certificate[]{certAndPrivateKey.certificate}); ks.setEntry("jzonbie", privateKeyEntry, new KeyStore.PasswordProtection("jzonbie".toCharArray())); final FileOutputStream fileOutputStream = new FileOutputStream(keystorePath); ks.store(fileOutputStream, "jzonbie".toCharArray()); this.trustStore = createTruststore(certAndPrivateKey.certificate); } catch(Exception e) { throw new RuntimeException(format("Failed to generate jzonbie keystore: %s", keystorePath), e); } }
HttpsSupport { public void createKeystoreAndTruststore(String keystorePath, String subject) { try { final CertAndPrivateKey certAndPrivateKey = generateCertificateAndPrivateKey(subject); KeyStore ks = KeyStore.getInstance("JKS"); ks.load(null); final KeyStore.PrivateKeyEntry privateKeyEntry = new KeyStore.PrivateKeyEntry(certAndPrivateKey.privateKey, new Certificate[]{certAndPrivateKey.certificate}); ks.setEntry("jzonbie", privateKeyEntry, new KeyStore.PasswordProtection("jzonbie".toCharArray())); final FileOutputStream fileOutputStream = new FileOutputStream(keystorePath); ks.store(fileOutputStream, "jzonbie".toCharArray()); this.trustStore = createTruststore(certAndPrivateKey.certificate); } catch(Exception e) { throw new RuntimeException(format("Failed to generate jzonbie keystore: %s", keystorePath), e); } } }
HttpsSupport { public void createKeystoreAndTruststore(String keystorePath, String subject) { try { final CertAndPrivateKey certAndPrivateKey = generateCertificateAndPrivateKey(subject); KeyStore ks = KeyStore.getInstance("JKS"); ks.load(null); final KeyStore.PrivateKeyEntry privateKeyEntry = new KeyStore.PrivateKeyEntry(certAndPrivateKey.privateKey, new Certificate[]{certAndPrivateKey.certificate}); ks.setEntry("jzonbie", privateKeyEntry, new KeyStore.PasswordProtection("jzonbie".toCharArray())); final FileOutputStream fileOutputStream = new FileOutputStream(keystorePath); ks.store(fileOutputStream, "jzonbie".toCharArray()); this.trustStore = createTruststore(certAndPrivateKey.certificate); } catch(Exception e) { throw new RuntimeException(format("Failed to generate jzonbie keystore: %s", keystorePath), e); } }  }
HttpsSupport { public void createKeystoreAndTruststore(String keystorePath, String subject) { try { final CertAndPrivateKey certAndPrivateKey = generateCertificateAndPrivateKey(subject); KeyStore ks = KeyStore.getInstance("JKS"); ks.load(null); final KeyStore.PrivateKeyEntry privateKeyEntry = new KeyStore.PrivateKeyEntry(certAndPrivateKey.privateKey, new Certificate[]{certAndPrivateKey.certificate}); ks.setEntry("jzonbie", privateKeyEntry, new KeyStore.PasswordProtection("jzonbie".toCharArray())); final FileOutputStream fileOutputStream = new FileOutputStream(keystorePath); ks.store(fileOutputStream, "jzonbie".toCharArray()); this.trustStore = createTruststore(certAndPrivateKey.certificate); } catch(Exception e) { throw new RuntimeException(format("Failed to generate jzonbie keystore: %s", keystorePath), e); } }  void createKeystoreAndTruststore(String keystorePath, String subject); KeyStore getTrustStore(); byte[] getTrustStoreAsByteArray(); }
HttpsSupport { public void createKeystoreAndTruststore(String keystorePath, String subject) { try { final CertAndPrivateKey certAndPrivateKey = generateCertificateAndPrivateKey(subject); KeyStore ks = KeyStore.getInstance("JKS"); ks.load(null); final KeyStore.PrivateKeyEntry privateKeyEntry = new KeyStore.PrivateKeyEntry(certAndPrivateKey.privateKey, new Certificate[]{certAndPrivateKey.certificate}); ks.setEntry("jzonbie", privateKeyEntry, new KeyStore.PasswordProtection("jzonbie".toCharArray())); final FileOutputStream fileOutputStream = new FileOutputStream(keystorePath); ks.store(fileOutputStream, "jzonbie".toCharArray()); this.trustStore = createTruststore(certAndPrivateKey.certificate); } catch(Exception e) { throw new RuntimeException(format("Failed to generate jzonbie keystore: %s", keystorePath), e); } }  void createKeystoreAndTruststore(String keystorePath, String subject); KeyStore getTrustStore(); byte[] getTrustStoreAsByteArray();  }