@Test void testCreateHelper_keyStore_trustStore_same_file_throwsException() throws SocketEndpointAddressException { val keyStorefileName = RandomStringUtils.randomAlphabetic(10); keyStoreFilePath = Paths.get(keyStorefileName); val trustStorePass = "truststore123"; val keyStorePass = "keystore123"; val keyPass = "keypass123"; val alias = "other_alias"; final KeyStoreHelper.KeyStoreOptions options = KeyStoreHelper.KeyStoreOptions .builder() .keyStorePath(keyStoreFilePath) .keyStorePass(keyStorePass) .trustStorePath(keyStoreFilePath) .trustStorePass(trustStorePass) .keyPass(keyPass) .keyAlias(alias) .workloadApiClient(workloadApiClient) .build(); try { KeyStoreHelper.create(options); fail("expected exception: KeyStore and TrustStore should use different files"); } catch (KeyStoreHelperException e) { assertEquals("KeyStore and TrustStore should use different files", e.getMessage()); } catch (KeyStoreException e) { fail(e); } }
public static KeyStoreHelper create(@NonNull final KeyStoreOptions options) throws SocketEndpointAddressException, KeyStoreHelperException, KeyStoreException { if (options.keyStorePath.equals(options.trustStorePath)) { throw new KeyStoreHelperException("KeyStore and TrustStore should use different files"); } if (options.keyStoreType == null) { options.keyStoreType = KeyStoreType.getDefaultType(); } if (StringUtils.isBlank(options.keyAlias)) { options.keyAlias = DEFAULT_ALIAS; } val keyStore = createKeyStore(options, options.keyStorePath, options.keyStorePass); val trustStore = createKeyStore(options, options.trustStorePath, options.trustStorePass); if (options.workloadApiClient == null) { options.workloadApiClient = createNewClient(options.spiffeSocketPath); } return new KeyStoreHelper(keyStore, trustStore, options.keyPass, options.keyAlias, options.workloadApiClient); }
KeyStoreHelper implements Closeable { public static KeyStoreHelper create(@NonNull final KeyStoreOptions options) throws SocketEndpointAddressException, KeyStoreHelperException, KeyStoreException { if (options.keyStorePath.equals(options.trustStorePath)) { throw new KeyStoreHelperException("KeyStore and TrustStore should use different files"); } if (options.keyStoreType == null) { options.keyStoreType = KeyStoreType.getDefaultType(); } if (StringUtils.isBlank(options.keyAlias)) { options.keyAlias = DEFAULT_ALIAS; } val keyStore = createKeyStore(options, options.keyStorePath, options.keyStorePass); val trustStore = createKeyStore(options, options.trustStorePath, options.trustStorePass); if (options.workloadApiClient == null) { options.workloadApiClient = createNewClient(options.spiffeSocketPath); } return new KeyStoreHelper(keyStore, trustStore, options.keyPass, options.keyAlias, options.workloadApiClient); } }
KeyStoreHelper implements Closeable { public static KeyStoreHelper create(@NonNull final KeyStoreOptions options) throws SocketEndpointAddressException, KeyStoreHelperException, KeyStoreException { if (options.keyStorePath.equals(options.trustStorePath)) { throw new KeyStoreHelperException("KeyStore and TrustStore should use different files"); } if (options.keyStoreType == null) { options.keyStoreType = KeyStoreType.getDefaultType(); } if (StringUtils.isBlank(options.keyAlias)) { options.keyAlias = DEFAULT_ALIAS; } val keyStore = createKeyStore(options, options.keyStorePath, options.keyStorePass); val trustStore = createKeyStore(options, options.trustStorePath, options.trustStorePass); if (options.workloadApiClient == null) { options.workloadApiClient = createNewClient(options.spiffeSocketPath); } return new KeyStoreHelper(keyStore, trustStore, options.keyPass, options.keyAlias, options.workloadApiClient); } private  KeyStoreHelper(KeyStore keyStore, KeyStore trustStore, String keyPass, String keyAlias, WorkloadApiClient workloadApiClient); }
KeyStoreHelper implements Closeable { public static KeyStoreHelper create(@NonNull final KeyStoreOptions options) throws SocketEndpointAddressException, KeyStoreHelperException, KeyStoreException { if (options.keyStorePath.equals(options.trustStorePath)) { throw new KeyStoreHelperException("KeyStore and TrustStore should use different files"); } if (options.keyStoreType == null) { options.keyStoreType = KeyStoreType.getDefaultType(); } if (StringUtils.isBlank(options.keyAlias)) { options.keyAlias = DEFAULT_ALIAS; } val keyStore = createKeyStore(options, options.keyStorePath, options.keyStorePass); val trustStore = createKeyStore(options, options.trustStorePath, options.trustStorePass); if (options.workloadApiClient == null) { options.workloadApiClient = createNewClient(options.spiffeSocketPath); } return new KeyStoreHelper(keyStore, trustStore, options.keyPass, options.keyAlias, options.workloadApiClient); } private  KeyStoreHelper(KeyStore keyStore, KeyStore trustStore, String keyPass, String keyAlias, WorkloadApiClient workloadApiClient); static KeyStoreHelper create(@NonNull final KeyStoreOptions options); void run(boolean keepRunning); @SneakyThrows @Override void close(); }
KeyStoreHelper implements Closeable { public static KeyStoreHelper create(@NonNull final KeyStoreOptions options) throws SocketEndpointAddressException, KeyStoreHelperException, KeyStoreException { if (options.keyStorePath.equals(options.trustStorePath)) { throw new KeyStoreHelperException("KeyStore and TrustStore should use different files"); } if (options.keyStoreType == null) { options.keyStoreType = KeyStoreType.getDefaultType(); } if (StringUtils.isBlank(options.keyAlias)) { options.keyAlias = DEFAULT_ALIAS; } val keyStore = createKeyStore(options, options.keyStorePath, options.keyStorePass); val trustStore = createKeyStore(options, options.trustStorePath, options.trustStorePass); if (options.workloadApiClient == null) { options.workloadApiClient = createNewClient(options.spiffeSocketPath); } return new KeyStoreHelper(keyStore, trustStore, options.keyPass, options.keyAlias, options.workloadApiClient); } private  KeyStoreHelper(KeyStore keyStore, KeyStore trustStore, String keyPass, String keyAlias, WorkloadApiClient workloadApiClient); static KeyStoreHelper create(@NonNull final KeyStoreOptions options); void run(boolean keepRunning); @SneakyThrows @Override void close();  }