@Test public void keyGetsUpdatedToNoPassword() throws Exception { final KeyDataConfig startingKey = JaxbUtil.unmarshal(getClass().getResourceAsStream("/lockedprivatekey.json"), KeyDataConfig.class); when(passwordReader.requestUserPassword()).thenReturn("".toCharArray()); final Path key = Files.createTempFile("key", ".key"); Files.write(key, JaxbUtil.marshalToString(startingKey).getBytes()); command.privateKeyPath = key; command.password = "testpassword"; addDefaultArgonConfigToCommand(); addEmptyEncryptorConfigToCommand(); byte[] privateKeyData = "SOME PRIVATE DATA".getBytes(); PrivateKey privateKey = PrivateKey.from(privateKeyData); when(keyEncryptor.decryptPrivateKey(any(PrivateKeyData.class), any())).thenReturn(privateKey); command.call(); final KeyDataConfig endingKey = JaxbUtil.unmarshal(Files.newInputStream(key), KeyDataConfig.class); assertThat(endingKey.getSbox()).isNotEqualTo(startingKey.getSbox()); assertThat(endingKey.getSnonce()).isNotEqualTo(startingKey.getSnonce()); assertThat(endingKey.getAsalt()).isNotEqualTo(startingKey.getAsalt()); assertThat(endingKey.getPrivateKeyData().getValue()) .isEqualTo(Base64.getEncoder().encodeToString(privateKeyData)); verify(keyEncryptorFactory).create(any()); verify(keyEncryptor).decryptPrivateKey(any(PrivateKeyData.class), any()); verify(keyEncryptor, never()).encryptPrivateKey(any(PrivateKey.class), any(), any(ArgonOptions.class)); verify(passwordReader).requestUserPassword(); }
@Override public CliResult call() throws Exception { final EncryptorConfig encryptorConfig; if (Optional.ofNullable(config).map(Config::getEncryptor).isPresent()) { encryptorConfig = config.getEncryptor(); } else { encryptorConfig = encryptorOptions.parseEncryptorConfig(); } this.keyEncryptor = keyEncryptorFactory.create(encryptorConfig); return execute(); }
KeyUpdateCommand implements Callable<CliResult> { @Override public CliResult call() throws Exception { final EncryptorConfig encryptorConfig; if (Optional.ofNullable(config).map(Config::getEncryptor).isPresent()) { encryptorConfig = config.getEncryptor(); } else { encryptorConfig = encryptorOptions.parseEncryptorConfig(); } this.keyEncryptor = keyEncryptorFactory.create(encryptorConfig); return execute(); } }
KeyUpdateCommand implements Callable<CliResult> { @Override public CliResult call() throws Exception { final EncryptorConfig encryptorConfig; if (Optional.ofNullable(config).map(Config::getEncryptor).isPresent()) { encryptorConfig = config.getEncryptor(); } else { encryptorConfig = encryptorOptions.parseEncryptorConfig(); } this.keyEncryptor = keyEncryptorFactory.create(encryptorConfig); return execute(); } KeyUpdateCommand(KeyEncryptorFactory keyEncryptorFactory, PasswordReader passwordReader); }
KeyUpdateCommand implements Callable<CliResult> { @Override public CliResult call() throws Exception { final EncryptorConfig encryptorConfig; if (Optional.ofNullable(config).map(Config::getEncryptor).isPresent()) { encryptorConfig = config.getEncryptor(); } else { encryptorConfig = encryptorOptions.parseEncryptorConfig(); } this.keyEncryptor = keyEncryptorFactory.create(encryptorConfig); return execute(); } KeyUpdateCommand(KeyEncryptorFactory keyEncryptorFactory, PasswordReader passwordReader); @Override CliResult call(); CliResult execute(); }
KeyUpdateCommand implements Callable<CliResult> { @Override public CliResult call() throws Exception { final EncryptorConfig encryptorConfig; if (Optional.ofNullable(config).map(Config::getEncryptor).isPresent()) { encryptorConfig = config.getEncryptor(); } else { encryptorConfig = encryptorOptions.parseEncryptorConfig(); } this.keyEncryptor = keyEncryptorFactory.create(encryptorConfig); return execute(); } KeyUpdateCommand(KeyEncryptorFactory keyEncryptorFactory, PasswordReader passwordReader); @Override CliResult call(); CliResult execute(); @CommandLine.Option(names = "--keys.keyData.privateKeyPath", required = true)
    public Path privateKeyPath; @CommandLine.Option(names = "--keys.keyData.config.data.aopts.algorithm", defaultValue = "i")
    public String algorithm; @CommandLine.Option(names = "--keys.keyData.config.data.aopts.iterations", defaultValue = "10")
    public Integer iterations; @CommandLine.Option(names = "--keys.keyData.config.data.aopts.memory", defaultValue = "1048576")
    public Integer memory; @CommandLine.Option(names = "--keys.keyData.config.data.aopts.parallelism", defaultValue = "4")
    public Integer parallelism; @CommandLine.Option(names = {"--keys.passwords"})
    public String password; @CommandLine.Option(names = {"--keys.passwordFile"})
    public Path passwordFile; @CommandLine.Option(
            names = {"--configfile", "-configfile"},
            description = "Path to node configuration file")
    public Config config; @CommandLine.Mixin public EncryptorOptions encryptorOptions; @CommandLine.Mixin public DebugOptions debugOptions; }