private Optional<ArgonOptions> argonOptions(final CommandLine commandLine) throws IOException { if (commandLine.hasOption("keygenconfig")) { final String pathName = commandLine.getOptionValue("keygenconfig"); final InputStream configStream = Files.newInputStream(Paths.get(pathName)); final ArgonOptions argonOptions = JaxbUtil.unmarshal(configStream, ArgonOptions.class); return Optional.of(argonOptions); } return Optional.empty(); }
private Optional<ArgonOptions> argonOptions(final CommandLine commandLine) throws IOException { if (commandLine.hasOption("keygenconfig")) { final String pathName = commandLine.getOptionValue("keygenconfig"); final InputStream configStream = Files.newInputStream(Paths.get(pathName)); final ArgonOptions argonOptions = JaxbUtil.unmarshal(configStream, ArgonOptions.class); return Optional.of(argonOptions); } return Optional.empty(); }
private void loadKeys() { this.inlineKeypair = new InlineKeypair( IOCallback.execute(() -> new String(Files.readAllBytes(this.publicKeyPath), UTF_8)), JaxbUtil.unmarshal( IOCallback.execute(() -> Files.newInputStream(privateKeyPath)), KeyDataConfig.class ) ); }
private void loadKeys() { this.inlineKeypair = new InlineKeypair( IOCallback.execute(() -> new String(Files.readAllBytes(this.publicKeyPath), UTF_8)), JaxbUtil.unmarshal( IOCallback.execute(() -> Files.newInputStream(privateKeyPath)), KeyDataConfig.class ) ); }
@Override public Optional parse(final CommandLine commandLine) throws IOException { if (commandLine.hasOption("updatepassword")) { final ArgonOptions argonOptions = argonOptions(commandLine); final List<String> passwords = passwords(commandLine); final Path keypath = privateKeyPath(commandLine); final KeyDataConfig keyDataConfig = JaxbUtil.unmarshal(Files.newInputStream(keypath), KeyDataConfig.class); final PrivateKey privateKey = this.getExistingKey(keyDataConfig, passwords); final String newPassword = passwordReader.requestUserPassword(); final KeyDataConfig updatedKey; if(newPassword.isEmpty()) { final PrivateKeyData privateKeyData = new PrivateKeyData(privateKey.encodeToBase64(), null, null, null, null); updatedKey = new KeyDataConfig(privateKeyData, PrivateKeyType.UNLOCKED); } else { final PrivateKeyData privateKeyData = keyEncryptor.encryptPrivateKey(privateKey, newPassword, argonOptions); updatedKey = new KeyDataConfig(privateKeyData, PrivateKeyType.LOCKED); } //write the key to file Files.write(keypath, JaxbUtil.marshalToString(updatedKey).getBytes(UTF_8)); System.out.println("Private key at " + keypath.toString() + " updated."); } return Optional.empty(); }
@Override public Optional parse(final CommandLine commandLine) throws IOException { if (commandLine.hasOption("updatepassword")) { final ArgonOptions argonOptions = argonOptions(commandLine); final List<String> passwords = passwords(commandLine); final Path keypath = privateKeyPath(commandLine); final KeyDataConfig keyDataConfig = JaxbUtil.unmarshal(Files.newInputStream(keypath), KeyDataConfig.class); final PrivateKey privateKey = this.getExistingKey(keyDataConfig, passwords); final String newPassword = passwordReader.requestUserPassword(); final KeyDataConfig updatedKey; if(newPassword.isEmpty()) { final PrivateKeyData privateKeyData = new PrivateKeyData(privateKey.encodeToBase64(), null, null, null, null); updatedKey = new KeyDataConfig(privateKeyData, PrivateKeyType.UNLOCKED); } else { final PrivateKeyData privateKeyData = keyEncryptor.encryptPrivateKey(privateKey, newPassword, argonOptions); updatedKey = new KeyDataConfig(privateKeyData, PrivateKeyType.LOCKED); } //write the key to file Files.write(keypath, JaxbUtil.marshalToString(updatedKey).getBytes(UTF_8)); System.out.println("Private key at " + keypath.toString() + " updated."); } return Optional.empty(); }
@Override public Config create(final InputStream configData, final List<ConfigKeyPair> newKeys) { final Config config = JaxbUtil.unmarshal(configData, Config.class);
@Override public Config create(final InputStream configData, final List<ConfigKeyPair> newKeys) { final Config config = JaxbUtil.unmarshal(configData, Config.class);