/** * Requests user input for a password until two matching consecutive entries are made * * @return The password that the user has input */ default String requestUserPassword() { for(;;) { System.out.println("Enter a password if you want to lock the private key or leave blank"); final String password = this.readPasswordFromConsole(); System.out.println("Please re-enter the password (or lack of) to confirm"); final String passwordCheck = this.readPasswordFromConsole(); if(Objects.equals(password, passwordCheck)) { return password; } else { System.out.println("Passwords did not match, try again..."); } } }
@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 FilesystemKeyPair generate(final String filename, final ArgonOptions encryptionOptions, final KeyVaultOptions keyVaultOptions) { final String password = this.passwordReader.requestUserPassword();
/** * Requests user input for a password until two matching consecutive entries are made * * @return The password that the user has input */ default String requestUserPassword() { for(;;) { System.out.println("Enter a password if you want to lock the private key or leave blank"); final String password = this.readPasswordFromConsole(); System.out.println("Please re-enter the password (or lack of) to confirm"); final String passwordCheck = this.readPasswordFromConsole(); if(Objects.equals(password, passwordCheck)) { return password; } else { System.out.println("Passwords did not match, try again..."); } } }