use of com.quorum.tessera.encryption.EncryptorException in project tessera by ConsenSys.
the class EllipticalCurveEncryptor method openAfterPrecomputation.
@Override
public byte[] openAfterPrecomputation(byte[] cipherText, Nonce nonce, SharedKey sharedKey) {
try {
Cipher cipher = Cipher.getInstance(symmetricCipher);
cipher.init(Cipher.DECRYPT_MODE, new SecretKeySpec(sharedKey.getKeyBytes(), "AES"), new GCMParameterSpec(128, nonce.getNonceBytes()));
return cipher.doFinal(cipherText);
} catch (GeneralSecurityException e) {
LOGGER.error("unable to perform symmetric decryption", e);
throw new EncryptorException("unable to perform symmetric decryption");
}
}
use of com.quorum.tessera.encryption.EncryptorException in project tessera by ConsenSys.
the class InlineKeypair method getPrivateKey.
@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;
}
use of com.quorum.tessera.encryption.EncryptorException in project tessera by ConsenSys.
the class InlineKeypairTest method updatingPasswordsAttemptsToDecryptAgain.
@Test
public void updatingPasswordsAttemptsToDecryptAgain() {
PrivateKeyData privateKeyData = mock(PrivateKeyData.class);
final KeyDataConfig privKeyDataConfig = mock(KeyDataConfig.class);
when(privKeyDataConfig.getPrivateKeyData()).thenReturn(privateKeyData);
when(privKeyDataConfig.getType()).thenReturn(PrivateKeyType.LOCKED);
when(keyEncryptor.decryptPrivateKey(privateKeyData, "wrong-password".toCharArray())).thenThrow(new EncryptorException("WHAT YOU TALKING ABOUT WILLIS"));
final InlineKeypair inlineKeypair = new InlineKeypair("public", privKeyDataConfig, keyEncryptor);
inlineKeypair.withPassword("wrong-password".toCharArray());
String result = inlineKeypair.getPrivateKey();
assertThat(result).isEqualTo("NACL_FAILURE");
// change password and attempt again
inlineKeypair.withPassword("testpassword".toCharArray());
PrivateKey privateKey = mock(PrivateKey.class);
when(privateKey.encodeToBase64()).thenReturn("SUCCESS");
when(keyEncryptor.decryptPrivateKey(privateKeyData, "testpassword".toCharArray())).thenReturn(privateKey);
assertThat(inlineKeypair.getPrivateKey()).isEqualTo("SUCCESS");
verify(keyEncryptor).decryptPrivateKey(privateKeyData, "wrong-password".toCharArray());
verify(keyEncryptor).decryptPrivateKey(privateKeyData, "testpassword".toCharArray());
}
use of com.quorum.tessera.encryption.EncryptorException in project tessera by ConsenSys.
the class InlineKeypairTest method incorrectPasswordGetsCorrectFailureToken.
@Test
public void incorrectPasswordGetsCorrectFailureToken() {
PrivateKeyData privateKeyData = mock(PrivateKeyData.class);
final KeyDataConfig privKeyDataConfig = mock(KeyDataConfig.class);
when(privKeyDataConfig.getPrivateKeyData()).thenReturn(privateKeyData);
when(privKeyDataConfig.getType()).thenReturn(PrivateKeyType.LOCKED);
when(keyEncryptor.decryptPrivateKey(privateKeyData, "wrong-password".toCharArray())).thenThrow(new EncryptorException("WHAT YOU TALKING ABOUT WILLIS"));
final InlineKeypair inlineKeypair = new InlineKeypair("public", privKeyDataConfig, keyEncryptor);
inlineKeypair.withPassword("wrong-password".toCharArray());
String result = inlineKeypair.getPrivateKey();
assertThat(String.valueOf(inlineKeypair.getPassword())).isEqualTo("wrong-password");
assertThat(result).isEqualTo("NACL_FAILURE");
}
Aggregations