Search in sources :

Example 71 with Nonce

use of com.quorum.tessera.encryption.Nonce in project tessera by ConsenSys.

the class StagingTransactionUtilsTest method testFromRawPayload.

@Test
public void testFromRawPayload() {
    final TxHash affectedHash = new TxHash("TX2");
    final EncodedPayload encodedPayload = EncodedPayload.Builder.create().withSenderKey(sender).withCipherText("cipherText".getBytes()).withCipherTextNonce(new Nonce("nonce".getBytes())).withRecipientBoxes(List.of("box1".getBytes(), "box2".getBytes())).withRecipientNonce(new Nonce("recipientNonce".getBytes())).withRecipientKeys(List.of(recipient1)).withPrivacyMode(PrivacyMode.PARTY_PROTECTION).withAffectedContractTransactions(Map.of(affectedHash, "somesecurityHash".getBytes())).build();
    // FIXME: Cross module depenency!!!
    final String messageHash = Base64.getEncoder().encodeToString(payloadDigest.digest(encodedPayload.getCipherText()));
    final byte[] raw = encoder.encode(encodedPayload);
    StagingTransaction result = StagingTransactionUtils.fromRawPayload(raw, EncodedPayloadCodec.current());
    assertThat(result).isNotNull();
    assertThat(result.getHash()).isEqualTo(messageHash);
    assertThat(result.getPayload()).isEqualTo(raw);
    assertThat(result.getPrivacyMode()).isEqualTo(PrivacyMode.PARTY_PROTECTION);
    assertThat(result.getValidationStage()).isNull();
    assertThat(result.getAffectedContractTransactions()).hasSize(1);
    result.getAffectedContractTransactions().forEach(atx -> {
        assertThat(atx.getHash()).isEqualTo(affectedHash.encodeToBase64());
        assertThat(atx.getSourceTransaction()).isEqualTo(result);
    });
}
Also used : Nonce(com.quorum.tessera.encryption.Nonce) Test(org.junit.Test)

Example 72 with Nonce

use of com.quorum.tessera.encryption.Nonce in project tessera by ConsenSys.

the class KeyEncryptorTest method encryptingKeyReturnsCorrectJson.

@Test
public void encryptingKeyReturnsCorrectJson() {
    final PrivateKey key = PrivateKey.from(new byte[] { 1, 2, 3, 4, 5 });
    final char[] password = "pass".toCharArray();
    final ArgonResult result = new ArgonResult(new com.quorum.tessera.argon2.ArgonOptions("i", 1, 1, 1), new byte[] {}, new byte[] {});
    doReturn(result).when(argon2).hash(eq(password), any(byte[].class));
    doReturn(new Nonce(new byte[] {})).when(encryptor).randomNonce();
    doReturn(new byte[] {}).when(encryptor).sealAfterPrecomputation(any(byte[].class), any(Nonce.class), any(SharedKey.class));
    final PrivateKeyData privateKey = this.keyEncryptor.encryptPrivateKey(key, password, null);
    final ArgonOptions aopts = privateKey.getArgonOptions();
    assertThat(privateKey.getSbox()).isNotNull();
    assertThat(privateKey.getAsalt()).isNotNull();
    assertThat(privateKey.getSnonce()).isNotNull();
    assertThat(aopts).isNotNull();
    assertThat(aopts.getMemory()).isNotNull();
    assertThat(aopts.getParallelism()).isNotNull();
    assertThat(aopts.getIterations()).isNotNull();
    assertThat(aopts.getAlgorithm()).isNotNull();
    verify(argon2).hash(eq(password), any(byte[].class));
    verify(encryptor).randomNonce();
    verify(encryptor).sealAfterPrecomputation(any(byte[].class), any(Nonce.class), any(SharedKey.class));
}
Also used : Nonce(com.quorum.tessera.encryption.Nonce) ArgonOptions(com.quorum.tessera.config.ArgonOptions) PrivateKey(com.quorum.tessera.encryption.PrivateKey) ArgonResult(com.quorum.tessera.argon2.ArgonResult) PrivateKeyData(com.quorum.tessera.config.PrivateKeyData) SharedKey(com.quorum.tessera.encryption.SharedKey) Test(org.junit.Test)

Aggregations

Nonce (com.quorum.tessera.encryption.Nonce)72 Test (org.junit.Test)64 LegacyEncodedPayload (com.quorum.tessera.enclave.encoder.LegacyEncodedPayload)31 PublicKey (com.quorum.tessera.encryption.PublicKey)18 SharedKey (com.quorum.tessera.encryption.SharedKey)6 ArgonResult (com.quorum.tessera.argon2.ArgonResult)4 com.quorum.tessera.enclave (com.quorum.tessera.enclave)4 JerseyTest (org.glassfish.jersey.test.JerseyTest)4 ArgonOptions (com.quorum.tessera.config.ArgonOptions)3 PrivateKeyData (com.quorum.tessera.config.PrivateKeyData)3 MasterKey (com.quorum.tessera.encryption.MasterKey)3 PrivateKey (com.quorum.tessera.encryption.PrivateKey)3 Response (jakarta.ws.rs.core.Response)3 List (java.util.List)3 Optional (java.util.Optional)3 Collectors (java.util.stream.Collectors)3 Service (com.quorum.tessera.service.Service)2 RecipientKeyNotFoundException (com.quorum.tessera.transaction.exception.RecipientKeyNotFoundException)2 TransactionNotFoundException (com.quorum.tessera.transaction.exception.TransactionNotFoundException)2 Json (jakarta.json.Json)2