use of com.quorum.tessera.encryption.Nonce in project tessera by ConsenSys.
the class EllipticalCurveEncryptorTest method sealOpenAfterPrecomputation.
@Test
public void sealOpenAfterPrecomputation() {
MasterKey masterKey = encryptor.createMasterKey();
byte[] clearText = "MessageToEncrypt123".getBytes();
Nonce nonce = encryptor.randomNonce();
byte[] cipherText = encryptor.sealAfterPrecomputation(clearText, nonce, masterKey);
LOGGER.info("Encrypted outpout: {}", Base64.getEncoder().encode(cipherText));
byte[] decryptedText = encryptor.openAfterPrecomputation(cipherText, nonce, masterKey);
assertThat(decryptedText).containsExactly(clearText);
}
use of com.quorum.tessera.encryption.Nonce in project tessera by ConsenSys.
the class EllipticalCurveEncryptorTest method openAfterPrecomputationInvalidSymmetricCipher.
@Test(expected = EncryptorException.class)
public void openAfterPrecomputationInvalidSymmetricCipher() {
EllipticalCurveEncryptor facade = new EllipticalCurveEncryptor("garbage", "secp256r1");
MasterKey masterKey = encryptor.createMasterKey();
Nonce nonce = encryptor.randomNonce();
facade.openAfterPrecomputation("test".getBytes(), nonce, masterKey);
}
use of com.quorum.tessera.encryption.Nonce in project tessera by ConsenSys.
the class EllipticalCurveEncryptorTest method randomNonce.
@Test
public void randomNonce() {
Nonce nonce = encryptor.randomNonce();
assertThat(nonce).isNotNull();
assertThat(nonce.getNonceBytes()).hasSize(24);
}
use of com.quorum.tessera.encryption.Nonce in project tessera by ConsenSys.
the class TransactionManagerTest method storePayloadWithInvalidSecurityHashesIgnoreIfNotPsv.
@Test
public void storePayloadWithInvalidSecurityHashesIgnoreIfNotPsv() {
Map<TxHash, SecurityHash> affectedTx = Map.of(TxHash.from("invalidHash".getBytes()), SecurityHash.from("security".getBytes()));
final EncodedPayload payload = mock(EncodedPayload.class);
when(payload.getSenderKey()).thenReturn(PublicKey.from("sender".getBytes()));
when(payload.getCipherText()).thenReturn("CIPHERTEXT".getBytes());
when(payload.getCipherTextNonce()).thenReturn(new Nonce("nonce".getBytes()));
when(payload.getRecipientBoxes()).thenReturn(List.of(RecipientBox.from("box1".getBytes())));
when(payload.getRecipientNonce()).thenReturn(new Nonce("recipientNonce".getBytes()));
when(payload.getRecipientKeys()).thenReturn(singletonList(PublicKey.from("recipient".getBytes())));
when(payload.getPrivacyMode()).thenReturn(PrivacyMode.PARTY_PROTECTION);
when(payload.getAffectedContractTransactions()).thenReturn(affectedTx);
when(encryptedTransactionDAO.retrieveByHash(any(MessageHash.class))).thenReturn(Optional.empty());
ArgumentCaptor<EncryptedTransaction> txCaptor = ArgumentCaptor.forClass(EncryptedTransaction.class);
when(enclave.findInvalidSecurityHashes(any(), any())).thenReturn(singleton(new TxHash("invalidHash".getBytes())));
transactionManager.storePayload(payload);
verify(encryptedTransactionDAO).save(txCaptor.capture());
EncodedPayload sanitisedPayload = txCaptor.getValue().getPayload();
// Assert that the invalid ACOTH had been removed
assertThat(sanitisedPayload.getAffectedContractTransactions().get(TxHash.from("invalidHash".getBytes()))).isNull();
verify(encryptedTransactionDAO).findByHashes(any());
verify(encryptedTransactionDAO).retrieveByHash(any(MessageHash.class));
verify(enclave).getPublicKeys();
verify(enclave).findInvalidSecurityHashes(any(), any());
}
use of com.quorum.tessera.encryption.Nonce in project tessera by ConsenSys.
the class TransactionManagerTest method storeRaw.
@Test
public void storeRaw() {
PublicKey sender = PublicKey.from("SENDER".getBytes());
RawTransaction rawTransaction = mock(RawTransaction.class);
when(rawTransaction.getEncryptedPayload()).thenReturn("CIPHERTEXT".getBytes());
when(rawTransaction.getEncryptedKey()).thenReturn("SomeKey".getBytes());
when(rawTransaction.getNonce()).thenReturn(new Nonce("nonce".getBytes()));
when(rawTransaction.getFrom()).thenReturn(sender);
when(enclave.encryptRawPayload(any(), any())).thenReturn(rawTransaction);
byte[] payload = Base64.getEncoder().encode("PAYLOAD".getBytes());
StoreRawRequest sendRequest = mock(StoreRawRequest.class);
when(sendRequest.getSender()).thenReturn(sender);
when(sendRequest.getPayload()).thenReturn(payload);
MessageHash expectedHash = new MessageHash(mockDigest.digest("CIPHERTEXT".getBytes()));
StoreRawResponse result = transactionManager.store(sendRequest);
assertThat(result).isNotNull();
assertThat(result.getHash().getHashBytes()).containsExactly(expectedHash.getHashBytes());
verify(enclave).encryptRawPayload(eq(payload), eq(sender));
verify(encryptedRawTransactionDAO).save(argThat(et -> {
assertThat(et.getEncryptedKey()).containsExactly("SomeKey".getBytes());
assertThat(et.getEncryptedPayload()).containsExactly("CIPHERTEXT".getBytes());
assertThat(et.getHash()).isEqualTo(expectedHash);
assertThat(et.getNonce()).containsExactly("nonce".getBytes());
assertThat(et.getSender()).containsExactly(sender.getKeyBytes());
return true;
}));
}
Aggregations