@Test public void unlockedKeyGetsValue() { PrivateKeyData privateKeyData = mock(PrivateKeyData.class); final KeyDataConfig privKeyDataConfig = mock(KeyDataConfig.class); when(privKeyDataConfig.getPrivateKeyData()).thenReturn(privateKeyData); when(privKeyDataConfig.getType()).thenReturn(PrivateKeyType.UNLOCKED); String value = "I love sparrows"; when(privKeyDataConfig.getValue()).thenReturn(value); final InlineKeypair result = new InlineKeypair("public", privKeyDataConfig, keyEncryptor); assertThat(result.getPrivateKey()).isEqualTo(value); verifyZeroInteractions(keyEncryptor); }
@Override @NotNull @Size(min = 1) @ValidBase64(message = "Invalid Base64 key provided") @Pattern(regexp = "^((?!NACL_FAILURE).)*$", message = "Could not decrypt the private key with the provided password, please double check the passwords provided") public String getPrivateKey() { final PrivateKeyData pkd = privateKeyConfig.getPrivateKeyData(); if (privateKeyConfig.getType() == UNLOCKED) { return privateKeyConfig.getValue(); } if (this.cachedValue == null || !Objects.equals(this.cachedPassword, this.password)) { if (password != null) { try { this.cachedValue = keyEncryptor.decryptPrivateKey(pkd, password).encodeToBase64(); } catch (final EncryptorException ex) { this.cachedValue = "NACL_FAILURE"; } } } this.cachedPassword = this.password; return this.cachedValue; }
InlineKeypair implements ConfigKeyPair { @Override @NotNull @Size(min = 1) @ValidBase64(message = "Invalid Base64 key provided") @Pattern(regexp = "^((?!NACL_FAILURE).)*$", message = "Could not decrypt the private key with the provided password, please double check the passwords provided") public String getPrivateKey() { final PrivateKeyData pkd = privateKeyConfig.getPrivateKeyData(); if (privateKeyConfig.getType() == UNLOCKED) { return privateKeyConfig.getValue(); } if (this.cachedValue == null || !Objects.equals(this.cachedPassword, this.password)) { if (password != null) { try { this.cachedValue = keyEncryptor.decryptPrivateKey(pkd, password).encodeToBase64(); } catch (final EncryptorException ex) { this.cachedValue = "NACL_FAILURE"; } } } this.cachedPassword = this.password; return this.cachedValue; } }
InlineKeypair implements ConfigKeyPair { @Override @NotNull @Size(min = 1) @ValidBase64(message = "Invalid Base64 key provided") @Pattern(regexp = "^((?!NACL_FAILURE).)*$", message = "Could not decrypt the private key with the provided password, please double check the passwords provided") public String getPrivateKey() { final PrivateKeyData pkd = privateKeyConfig.getPrivateKeyData(); if (privateKeyConfig.getType() == UNLOCKED) { return privateKeyConfig.getValue(); } if (this.cachedValue == null || !Objects.equals(this.cachedPassword, this.password)) { if (password != null) { try { this.cachedValue = keyEncryptor.decryptPrivateKey(pkd, password).encodeToBase64(); } catch (final EncryptorException ex) { this.cachedValue = "NACL_FAILURE"; } } } this.cachedPassword = this.password; return this.cachedValue; } InlineKeypair(final String publicKey, final KeyDataConfig privateKeyConfig, KeyEncryptor keyEncryptor); }
InlineKeypair implements ConfigKeyPair { @Override @NotNull @Size(min = 1) @ValidBase64(message = "Invalid Base64 key provided") @Pattern(regexp = "^((?!NACL_FAILURE).)*$", message = "Could not decrypt the private key with the provided password, please double check the passwords provided") public String getPrivateKey() { final PrivateKeyData pkd = privateKeyConfig.getPrivateKeyData(); if (privateKeyConfig.getType() == UNLOCKED) { return privateKeyConfig.getValue(); } if (this.cachedValue == null || !Objects.equals(this.cachedPassword, this.password)) { if (password != null) { try { this.cachedValue = keyEncryptor.decryptPrivateKey(pkd, password).encodeToBase64(); } catch (final EncryptorException ex) { this.cachedValue = "NACL_FAILURE"; } } } this.cachedPassword = this.password; return this.cachedValue; } InlineKeypair(final String publicKey, final KeyDataConfig privateKeyConfig, KeyEncryptor keyEncryptor); KeyDataConfig getPrivateKeyConfig(); @Override @Size(min = 1) @NotNull @ValidBase64(message = "Invalid Base64 key provided") String getPublicKey(); @Override @NotNull @Size(min = 1) @ValidBase64(message = "Invalid Base64 key provided") @Pattern(regexp = "^((?!NACL_FAILURE).)*$", message = "Could not decrypt the private key with the provided password, please double check the passwords provided") String getPrivateKey(); @Override void withPassword(final char[] password); @Override char[] getPassword(); }
InlineKeypair implements ConfigKeyPair { @Override @NotNull @Size(min = 1) @ValidBase64(message = "Invalid Base64 key provided") @Pattern(regexp = "^((?!NACL_FAILURE).)*$", message = "Could not decrypt the private key with the provided password, please double check the passwords provided") public String getPrivateKey() { final PrivateKeyData pkd = privateKeyConfig.getPrivateKeyData(); if (privateKeyConfig.getType() == UNLOCKED) { return privateKeyConfig.getValue(); } if (this.cachedValue == null || !Objects.equals(this.cachedPassword, this.password)) { if (password != null) { try { this.cachedValue = keyEncryptor.decryptPrivateKey(pkd, password).encodeToBase64(); } catch (final EncryptorException ex) { this.cachedValue = "NACL_FAILURE"; } } } this.cachedPassword = this.password; return this.cachedValue; } InlineKeypair(final String publicKey, final KeyDataConfig privateKeyConfig, KeyEncryptor keyEncryptor); KeyDataConfig getPrivateKeyConfig(); @Override @Size(min = 1) @NotNull @ValidBase64(message = "Invalid Base64 key provided") String getPublicKey(); @Override @NotNull @Size(min = 1) @ValidBase64(message = "Invalid Base64 key provided") @Pattern(regexp = "^((?!NACL_FAILURE).)*$", message = "Could not decrypt the private key with the provided password, please double check the passwords provided") String getPrivateKey(); @Override void withPassword(final char[] password); @Override char[] getPassword();  }