@Test void createKeystore_errorPropertiesFile() throws IOException { final KeystoreHelper keystoreHelper = new KeystoreHelper(); if (FileUtils.POSIX_ENABLED) { Files.setPosixFilePermissions(systemProperties.toPath(), PosixFilePermissions.fromString("---------")); } else { systemProperties.setWritable(false); } assertThrows(KeyStoreCreationException.class, () -> KeystoreCreator.updateSystemPropertiesFile(keystoreHelper, keystoreFile, systemProperties.getPath())); if (FileUtils.POSIX_ENABLED) { Files.setPosixFilePermissions(systemProperties.toPath(), PosixFilePermissions.fromString("rwxrwxrwx")); } else { systemProperties.setWritable(true); } Files.delete(systemProperties.toPath()); }
static void updateSystemPropertiesFile(KeystoreHelper keystoreHelper, File keyStoreFile, String systemPropertiesPath) { File systemPropertiesFile = new File(systemPropertiesPath); try (FileWriter fileWriter = new FileWriter(systemPropertiesFile, true); BufferedWriter br = new BufferedWriter(fileWriter) ) { br.newLine(); br.write("# Properties to configure a file based Keystore"); br.newLine(); br.write("com.l7tech.common.security.jceProviderEngineName=generic"); br.newLine(); br.write("com.l7tech.keystore.type=" + keystoreHelper.getKeyStoreType()); br.newLine(); br.write("com.l7tech.keystore.path=" + PathUtils.unixPath(keyStoreFile.getAbsolutePath())); br.newLine(); br.write("com.l7tech.keystore.savePath=EMPTY"); br.newLine(); br.write("com.l7tech.keystore.password=" + new String(keystoreHelper.getKeystorePassword())); br.newLine(); br.write("com.l7tech.common.security.jceProviderEngine=com.l7tech.security.prov.generic.GenericJceProviderEngine"); } catch (IOException e) { throw new KeyStoreCreationException("Unexpected error adding to system properties", e); } }
KeystoreCreator { static void updateSystemPropertiesFile(KeystoreHelper keystoreHelper, File keyStoreFile, String systemPropertiesPath) { File systemPropertiesFile = new File(systemPropertiesPath); try (FileWriter fileWriter = new FileWriter(systemPropertiesFile, true); BufferedWriter br = new BufferedWriter(fileWriter) ) { br.newLine(); br.write("# Properties to configure a file based Keystore"); br.newLine(); br.write("com.l7tech.common.security.jceProviderEngineName=generic"); br.newLine(); br.write("com.l7tech.keystore.type=" + keystoreHelper.getKeyStoreType()); br.newLine(); br.write("com.l7tech.keystore.path=" + PathUtils.unixPath(keyStoreFile.getAbsolutePath())); br.newLine(); br.write("com.l7tech.keystore.savePath=EMPTY"); br.newLine(); br.write("com.l7tech.keystore.password=" + new String(keystoreHelper.getKeystorePassword())); br.newLine(); br.write("com.l7tech.common.security.jceProviderEngine=com.l7tech.security.prov.generic.GenericJceProviderEngine"); } catch (IOException e) { throw new KeyStoreCreationException("Unexpected error adding to system properties", e); } } }
KeystoreCreator { static void updateSystemPropertiesFile(KeystoreHelper keystoreHelper, File keyStoreFile, String systemPropertiesPath) { File systemPropertiesFile = new File(systemPropertiesPath); try (FileWriter fileWriter = new FileWriter(systemPropertiesFile, true); BufferedWriter br = new BufferedWriter(fileWriter) ) { br.newLine(); br.write("# Properties to configure a file based Keystore"); br.newLine(); br.write("com.l7tech.common.security.jceProviderEngineName=generic"); br.newLine(); br.write("com.l7tech.keystore.type=" + keystoreHelper.getKeyStoreType()); br.newLine(); br.write("com.l7tech.keystore.path=" + PathUtils.unixPath(keyStoreFile.getAbsolutePath())); br.newLine(); br.write("com.l7tech.keystore.savePath=EMPTY"); br.newLine(); br.write("com.l7tech.keystore.password=" + new String(keystoreHelper.getKeystorePassword())); br.newLine(); br.write("com.l7tech.common.security.jceProviderEngine=com.l7tech.security.prov.generic.GenericJceProviderEngine"); } catch (IOException e) { throw new KeyStoreCreationException("Unexpected error adding to system properties", e); } } private  KeystoreCreator(); }
KeystoreCreator { static void updateSystemPropertiesFile(KeystoreHelper keystoreHelper, File keyStoreFile, String systemPropertiesPath) { File systemPropertiesFile = new File(systemPropertiesPath); try (FileWriter fileWriter = new FileWriter(systemPropertiesFile, true); BufferedWriter br = new BufferedWriter(fileWriter) ) { br.newLine(); br.write("# Properties to configure a file based Keystore"); br.newLine(); br.write("com.l7tech.common.security.jceProviderEngineName=generic"); br.newLine(); br.write("com.l7tech.keystore.type=" + keystoreHelper.getKeyStoreType()); br.newLine(); br.write("com.l7tech.keystore.path=" + PathUtils.unixPath(keyStoreFile.getAbsolutePath())); br.newLine(); br.write("com.l7tech.keystore.savePath=EMPTY"); br.newLine(); br.write("com.l7tech.keystore.password=" + new String(keystoreHelper.getKeystorePassword())); br.newLine(); br.write("com.l7tech.common.security.jceProviderEngine=com.l7tech.security.prov.generic.GenericJceProviderEngine"); } catch (IOException e) { throw new KeyStoreCreationException("Unexpected error adding to system properties", e); } } private  KeystoreCreator();  }
KeystoreCreator { static void updateSystemPropertiesFile(KeystoreHelper keystoreHelper, File keyStoreFile, String systemPropertiesPath) { File systemPropertiesFile = new File(systemPropertiesPath); try (FileWriter fileWriter = new FileWriter(systemPropertiesFile, true); BufferedWriter br = new BufferedWriter(fileWriter) ) { br.newLine(); br.write("# Properties to configure a file based Keystore"); br.newLine(); br.write("com.l7tech.common.security.jceProviderEngineName=generic"); br.newLine(); br.write("com.l7tech.keystore.type=" + keystoreHelper.getKeyStoreType()); br.newLine(); br.write("com.l7tech.keystore.path=" + PathUtils.unixPath(keyStoreFile.getAbsolutePath())); br.newLine(); br.write("com.l7tech.keystore.savePath=EMPTY"); br.newLine(); br.write("com.l7tech.keystore.password=" + new String(keystoreHelper.getKeystorePassword())); br.newLine(); br.write("com.l7tech.common.security.jceProviderEngine=com.l7tech.security.prov.generic.GenericJceProviderEngine"); } catch (IOException e) { throw new KeyStoreCreationException("Unexpected error adding to system properties", e); } } private  KeystoreCreator();   }