@Test void createKeystore_noKeys() { KeystoreCreator.createKeyStoreIfNecessary(temporaryFolder.getRoot().getPath(), getClass().getClassLoader().getResource("privateKeys").getPath(), emptyList(), fileUtils, systemProperties.getPath()); assertFalse(new File(temporaryFolder.getRoot(), KEYSTORE_FILE_NAME).exists()); }
static void createKeyStoreIfNecessary(String keyStoreDirPath, String privateKeyFolderPath, Collection<PrivateKey> privateKeys, FileUtils fileUtils, String systemPropertiesPath) { PrivateKey.loadFromDirectory(privateKeys, new File(privateKeyFolderPath), true); KeystoreHelper keystoreHelper = InjectionRegistry.getInjector().getInstance(KeystoreHelper.class); final byte[] keyStore = keystoreHelper.createKeyStore(privateKeys); if (keyStore.length == 0) { return; } final File keyStoreDirectory = new File(keyStoreDirPath); if (!keyStoreDirectory.exists() && !keyStoreDirectory.mkdirs()) { throw new KeyStoreCreationException("Could not create directory '" + keyStoreDirPath + "' for KeyStore"); } File keyStoreFile = new File(keyStoreDirectory, KEYSTORE_FILE_NAME); OutputStream stream = fileUtils.getOutputStream(keyStoreFile); try { IOUtils.write(keyStore, stream); } catch (IOException e) { throw new KeyStoreCreationException("Unexpected error writing key store", e); } finally { closeQuietly(stream); } updateSystemPropertiesFile(keystoreHelper, keyStoreFile, systemPropertiesPath); }
KeystoreCreator { static void createKeyStoreIfNecessary(String keyStoreDirPath, String privateKeyFolderPath, Collection<PrivateKey> privateKeys, FileUtils fileUtils, String systemPropertiesPath) { PrivateKey.loadFromDirectory(privateKeys, new File(privateKeyFolderPath), true); KeystoreHelper keystoreHelper = InjectionRegistry.getInjector().getInstance(KeystoreHelper.class); final byte[] keyStore = keystoreHelper.createKeyStore(privateKeys); if (keyStore.length == 0) { return; } final File keyStoreDirectory = new File(keyStoreDirPath); if (!keyStoreDirectory.exists() && !keyStoreDirectory.mkdirs()) { throw new KeyStoreCreationException("Could not create directory '" + keyStoreDirPath + "' for KeyStore"); } File keyStoreFile = new File(keyStoreDirectory, KEYSTORE_FILE_NAME); OutputStream stream = fileUtils.getOutputStream(keyStoreFile); try { IOUtils.write(keyStore, stream); } catch (IOException e) { throw new KeyStoreCreationException("Unexpected error writing key store", e); } finally { closeQuietly(stream); } updateSystemPropertiesFile(keystoreHelper, keyStoreFile, systemPropertiesPath); } }
KeystoreCreator { static void createKeyStoreIfNecessary(String keyStoreDirPath, String privateKeyFolderPath, Collection<PrivateKey> privateKeys, FileUtils fileUtils, String systemPropertiesPath) { PrivateKey.loadFromDirectory(privateKeys, new File(privateKeyFolderPath), true); KeystoreHelper keystoreHelper = InjectionRegistry.getInjector().getInstance(KeystoreHelper.class); final byte[] keyStore = keystoreHelper.createKeyStore(privateKeys); if (keyStore.length == 0) { return; } final File keyStoreDirectory = new File(keyStoreDirPath); if (!keyStoreDirectory.exists() && !keyStoreDirectory.mkdirs()) { throw new KeyStoreCreationException("Could not create directory '" + keyStoreDirPath + "' for KeyStore"); } File keyStoreFile = new File(keyStoreDirectory, KEYSTORE_FILE_NAME); OutputStream stream = fileUtils.getOutputStream(keyStoreFile); try { IOUtils.write(keyStore, stream); } catch (IOException e) { throw new KeyStoreCreationException("Unexpected error writing key store", e); } finally { closeQuietly(stream); } updateSystemPropertiesFile(keystoreHelper, keyStoreFile, systemPropertiesPath); } private  KeystoreCreator(); }
KeystoreCreator { static void createKeyStoreIfNecessary(String keyStoreDirPath, String privateKeyFolderPath, Collection<PrivateKey> privateKeys, FileUtils fileUtils, String systemPropertiesPath) { PrivateKey.loadFromDirectory(privateKeys, new File(privateKeyFolderPath), true); KeystoreHelper keystoreHelper = InjectionRegistry.getInjector().getInstance(KeystoreHelper.class); final byte[] keyStore = keystoreHelper.createKeyStore(privateKeys); if (keyStore.length == 0) { return; } final File keyStoreDirectory = new File(keyStoreDirPath); if (!keyStoreDirectory.exists() && !keyStoreDirectory.mkdirs()) { throw new KeyStoreCreationException("Could not create directory '" + keyStoreDirPath + "' for KeyStore"); } File keyStoreFile = new File(keyStoreDirectory, KEYSTORE_FILE_NAME); OutputStream stream = fileUtils.getOutputStream(keyStoreFile); try { IOUtils.write(keyStore, stream); } catch (IOException e) { throw new KeyStoreCreationException("Unexpected error writing key store", e); } finally { closeQuietly(stream); } updateSystemPropertiesFile(keystoreHelper, keyStoreFile, systemPropertiesPath); } private  KeystoreCreator();  }
KeystoreCreator { static void createKeyStoreIfNecessary(String keyStoreDirPath, String privateKeyFolderPath, Collection<PrivateKey> privateKeys, FileUtils fileUtils, String systemPropertiesPath) { PrivateKey.loadFromDirectory(privateKeys, new File(privateKeyFolderPath), true); KeystoreHelper keystoreHelper = InjectionRegistry.getInjector().getInstance(KeystoreHelper.class); final byte[] keyStore = keystoreHelper.createKeyStore(privateKeys); if (keyStore.length == 0) { return; } final File keyStoreDirectory = new File(keyStoreDirPath); if (!keyStoreDirectory.exists() && !keyStoreDirectory.mkdirs()) { throw new KeyStoreCreationException("Could not create directory '" + keyStoreDirPath + "' for KeyStore"); } File keyStoreFile = new File(keyStoreDirectory, KEYSTORE_FILE_NAME); OutputStream stream = fileUtils.getOutputStream(keyStoreFile); try { IOUtils.write(keyStore, stream); } catch (IOException e) { throw new KeyStoreCreationException("Unexpected error writing key store", e); } finally { closeQuietly(stream); } updateSystemPropertiesFile(keystoreHelper, keyStoreFile, systemPropertiesPath); } private  KeystoreCreator();   }