Search in sources :

Example 1 with ReusableBodySigningFactory

use of com.hedera.services.sigs.factories.ReusableBodySigningFactory in project hedera-services by hashgraph.

the class HederaKeyActivationTest method canMatchCompressedEcdsaSecp256k1Key.

@Test
void canMatchCompressedEcdsaSecp256k1Key() throws Exception {
    final var mockTxnBytes = "012345789012345789012345789012345789012345789012345789012345789012345789012345789012345789".getBytes();
    final var explicitList = keyList.getKeyList().getKeysList();
    final var secp256k1Key = explicitList.get(0);
    final var ed25519Key = explicitList.get(1);
    final var keyFactory = KeyFactory.getDefaultInstance();
    final var mockSigs = mock(PubKeyToSigBytes.class);
    given(mockSigs.sigBytesFor(explicitList.get(0).getECDSASecp256k1Key())).willReturn(signBytes(keccak256DigestOf(mockTxnBytes), keyFactory.lookupPrivateKey(hex(secp256k1Key.getECDSASecp256k1Key()))));
    given(mockSigs.sigBytesFor(explicitList.get(1).getEd25519())).willReturn(signBytes(mockTxnBytes, keyFactory.lookupPrivateKey(hex(ed25519Key.getEd25519()))));
    final var accessor = mock(TxnAccessor.class);
    given(accessor.getTxnBytes()).willReturn(mockTxnBytes);
    final var cryptoSigs = createCryptoSigsFrom(explicitList, mockSigs, new ReusableBodySigningFactory(accessor)).getPlatformSigs();
    new CryptoEngine().verifySync(cryptoSigs);
    final var subject = pkToSigMapFrom(cryptoSigs);
    final var ed25519Sig = subject.apply(ed25519Key.getEd25519());
    assertEquals(SignatureType.ED25519, ed25519Sig.getSignatureType());
    assertEquals(VerificationStatus.VALID, ed25519Sig.getSignatureStatus());
    final var secp256k1Sig = subject.apply(secp256k1Key.getECDSASecp256k1Key());
    assertEquals(SignatureType.ECDSA_SECP256K1, secp256k1Sig.getSignatureType());
}
Also used : CryptoEngine(com.swirlds.common.crypto.engine.CryptoEngine) ReusableBodySigningFactory(com.hedera.services.sigs.factories.ReusableBodySigningFactory) Test(org.junit.jupiter.api.Test)

Example 2 with ReusableBodySigningFactory

use of com.hedera.services.sigs.factories.ReusableBodySigningFactory in project hedera-services by hashgraph.

the class HederaToPlatformSigOpsTest method stopImmediatelyOnOtherPartiesSigCreationFailure.

@Test
void stopImmediatelyOnOtherPartiesSigCreationFailure() throws Exception {
    final var mockAccessor = mock(PlatformTxnAccessor.class);
    given(keyOrdering.keysForPayer(platformTxn.getTxn(), CODE_ORDER_RESULT_FACTORY)).willReturn(new SigningOrderResult<>(payerKey));
    given(keyOrdering.keysForOtherParties(platformTxn.getTxn(), CODE_ORDER_RESULT_FACTORY)).willReturn(new SigningOrderResult<>(otherKeys));
    given(allSigBytes.sigBytesFor(any())).willReturn("1".getBytes()).willReturn("2".getBytes()).willThrow(KeyPrefixMismatchException.class);
    givenMirrorMock(mockAccessor, platformTxn);
    final var rationalization = new Rationalization(ALWAYS_VALID, keyOrdering, new ReusableBodySigningFactory());
    rationalization.performFor(mockAccessor);
    assertEquals(KEY_PREFIX_MISMATCH, rationalization.finalStatus());
}
Also used : ReusableBodySigningFactory(com.hedera.services.sigs.factories.ReusableBodySigningFactory) Test(org.junit.jupiter.api.Test)

Example 3 with ReusableBodySigningFactory

use of com.hedera.services.sigs.factories.ReusableBodySigningFactory in project hedera-services by hashgraph.

the class HederaToPlatformSigOpsTest method stopImmediatelyOnPayerKeyOrderFailure.

@Test
void stopImmediatelyOnPayerKeyOrderFailure() {
    given(keyOrdering.keysForPayer(platformTxn.getTxn(), CODE_ORDER_RESULT_FACTORY)).willReturn(new SigningOrderResult<>(INVALID_ACCOUNT_ID));
    final var rationalization = new Rationalization(ALWAYS_VALID, keyOrdering, new ReusableBodySigningFactory());
    rationalization.performFor(platformTxn);
    assertEquals(INVALID_ACCOUNT_ID, rationalization.finalStatus());
}
Also used : ReusableBodySigningFactory(com.hedera.services.sigs.factories.ReusableBodySigningFactory) Test(org.junit.jupiter.api.Test)

Example 4 with ReusableBodySigningFactory

use of com.hedera.services.sigs.factories.ReusableBodySigningFactory in project hedera-services by hashgraph.

the class HederaToPlatformSigOpsTest method stopImmediatelyOnOtherPartiesKeyOrderFailure.

@Test
void stopImmediatelyOnOtherPartiesKeyOrderFailure() throws Exception {
    wellBehavedOrdersAndSigSources();
    given(keyOrdering.keysForOtherParties(platformTxn.getTxn(), CODE_ORDER_RESULT_FACTORY)).willReturn(new SigningOrderResult<>(INVALID_ACCOUNT_ID));
    final var rationalization = new Rationalization(ALWAYS_VALID, keyOrdering, new ReusableBodySigningFactory());
    rationalization.performFor(platformTxn);
    assertEquals(INVALID_ACCOUNT_ID, rationalization.finalStatus());
}
Also used : ReusableBodySigningFactory(com.hedera.services.sigs.factories.ReusableBodySigningFactory) Test(org.junit.jupiter.api.Test)

Example 5 with ReusableBodySigningFactory

use of com.hedera.services.sigs.factories.ReusableBodySigningFactory in project hedera-services by hashgraph.

the class HederaToPlatformSigOpsTest method rationalizesMissingSigs.

@Test
void rationalizesMissingSigs() throws Exception {
    final var rationalization = new Rationalization(ALWAYS_VALID, keyOrdering, new ReusableBodySigningFactory());
    final var captor = ArgumentCaptor.forClass(RationalizedSigMeta.class);
    final var mockAccessor = mock(PlatformTxnAccessor.class);
    wellBehavedOrdersAndSigSources();
    givenMirrorMock(mockAccessor, platformTxn);
    rationalization.performFor(mockAccessor);
    assertEquals(OK, rationalization.finalStatus());
    assertTrue(rationalization.usedSyncVerification());
    verify(mockAccessor).setSigMeta(captor.capture());
    final var sigMeta = captor.getValue();
    assertEquals(expectedSigsWithNoErrors(), sigMeta.verifiedSigs());
    platformTxn.setSigMeta(sigMeta);
    assertTrue(allVerificationStatusesAre(VerificationStatus.VALID::equals));
}
Also used : VerificationStatus(com.swirlds.common.crypto.VerificationStatus) ReusableBodySigningFactory(com.hedera.services.sigs.factories.ReusableBodySigningFactory) Test(org.junit.jupiter.api.Test)

Aggregations

ReusableBodySigningFactory (com.hedera.services.sigs.factories.ReusableBodySigningFactory)11 Test (org.junit.jupiter.api.Test)7 SigRequirements (com.hedera.services.sigs.order.SigRequirements)4 SyncVerifier (com.hedera.services.sigs.verification.SyncVerifier)3 VerificationStatus (com.swirlds.common.crypto.VerificationStatus)3 BeforeAll (org.junit.jupiter.api.BeforeAll)3 JKey (com.hedera.services.legacy.core.jproto.JKey)2 KeyPrefixMismatchException (com.hedera.services.legacy.exception.KeyPrefixMismatchException)2 HederaToPlatformSigOps.expandIn (com.hedera.services.sigs.HederaToPlatformSigOps.expandIn)2 PlatformSigFactory (com.hedera.services.sigs.factories.PlatformSigFactory)2 HfsSigMetaLookup (com.hedera.services.sigs.metadata.lookups.HfsSigMetaLookup)2 CODE_ORDER_RESULT_FACTORY (com.hedera.services.sigs.order.CodeOrderResultFactory.CODE_ORDER_RESULT_FACTORY)2 SigningOrderResult (com.hedera.services.sigs.order.SigningOrderResult)2 KeyType (com.hedera.services.sigs.sourcing.KeyType)2 PubKeyToSigBytes (com.hedera.services.sigs.sourcing.PubKeyToSigBytes)2 SigObserver (com.hedera.services.sigs.sourcing.SigObserver)2 PlatformTxnAccessor (com.hedera.services.utils.PlatformTxnAccessor)2 RationalizedSigMeta (com.hedera.services.utils.RationalizedSigMeta)2 KeyTree (com.hedera.test.factories.keys.KeyTree)2 NodeFactory.ed25519 (com.hedera.test.factories.keys.NodeFactory.ed25519)2