Search in sources :

Example 1 with SyncVerifier

use of com.hedera.services.sigs.verification.SyncVerifier in project hedera-services by hashgraph.

the class SigOpsRegressionTest method invokeRationalizationScenario.

private Rationalization invokeRationalizationScenario() {
    // setup:
    SyncVerifier syncVerifier = new CryptoEngine()::verifySync;
    final var hfsSigMetaLookup = new HfsSigMetaLookup(hfs, fileNumbers);
    SigMetadataLookup sigMetaLookups = defaultLookupsFor(aliasManager, hfsSigMetaLookup, () -> accounts, () -> null, ref -> null, ref -> null);
    SigRequirements keyOrder = new SigRequirements(sigMetaLookups, mockSignatureWaivers);
    // given:
    final var rationalization = new Rationalization(syncVerifier, keyOrder, new ReusableBodySigningFactory());
    rationalization.performFor(platformTxn);
    return rationalization;
}
Also used : SyncVerifier(com.hedera.services.sigs.verification.SyncVerifier) SigRequirements(com.hedera.services.sigs.order.SigRequirements) CryptoEngine(com.swirlds.common.crypto.engine.CryptoEngine) HfsSigMetaLookup(com.hedera.services.sigs.metadata.lookups.HfsSigMetaLookup) SigMetadataLookup(com.hedera.services.sigs.metadata.SigMetadataLookup) ReusableBodySigningFactory(com.hedera.services.sigs.factories.ReusableBodySigningFactory)

Example 2 with SyncVerifier

use of com.hedera.services.sigs.verification.SyncVerifier in project hedera-services by hashgraph.

the class SigVerifierRegressionTest method setupFor.

private void setupFor(TxnHandlingScenario scenario) throws Throwable {
    accounts = scenario.accounts();
    platformTxn = scenario.platformTxn();
    aliasManager = mock(AliasManager.class);
    keyOrder = new SigRequirements(defaultLookupsFor(aliasManager, null, () -> accounts, () -> null, ref -> null, ref -> null), mockSignatureWaivers);
    final var nodeInfo = mock(NodeInfo.class);
    given(nodeInfo.selfAccount()).willReturn(DEFAULT_NODE);
    isQueryPayment = PrecheckUtils.queryPaymentTestFor(nodeInfo);
    SyncVerifier syncVerifier = new CryptoEngine()::verifySync;
    precheckKeyReqs = new PrecheckKeyReqs(keyOrder, isQueryPayment);
    precheckVerifier = new PrecheckVerifier(syncVerifier, precheckKeyReqs);
}
Also used : SyncVerifier(com.hedera.services.sigs.verification.SyncVerifier) AliasManager(com.hedera.services.ledger.accounts.AliasManager) SigRequirements(com.hedera.services.sigs.order.SigRequirements) PrecheckKeyReqs(com.hedera.services.sigs.verification.PrecheckKeyReqs) PrecheckVerifier(com.hedera.services.sigs.verification.PrecheckVerifier) CryptoEngine(com.swirlds.common.crypto.engine.CryptoEngine)

Example 3 with SyncVerifier

use of com.hedera.services.sigs.verification.SyncVerifier in project hedera-services by hashgraph.

the class HederaToPlatformSigOpsTest method rationalizesOnlyMissingSigs.

@Test
void rationalizesOnlyMissingSigs() throws Exception {
    wellBehavedOrdersAndSigSources();
    platformTxn.getPlatformTxn().addAll(asValid(expectedSigsWithOtherPartiesCreationError()).toArray(new TransactionSignature[0]));
    final SyncVerifier syncVerifier = l -> {
        if (l.equals(expectedSigsWithOtherPartiesCreationError())) {
            throw new AssertionError("Payer sigs were verified async!");
        } else {
            ALWAYS_VALID.verifySync(l);
        }
    };
    final var mockAccessor = mock(PlatformTxnAccessor.class);
    final var captor = ArgumentCaptor.forClass(RationalizedSigMeta.class);
    givenMirrorMock(mockAccessor, platformTxn);
    final var rationalization = new Rationalization(syncVerifier, keyOrdering, new ReusableBodySigningFactory());
    rationalization.performFor(mockAccessor);
    assertTrue(rationalization.usedSyncVerification());
    assertEquals(OK, rationalization.finalStatus());
    verify(mockAccessor).setSigMeta(captor.capture());
    final var sigMeta = captor.getValue();
    platformTxn.setSigMeta(sigMeta);
    assertEquals(expectedSigsWithNoErrors(), platformTxn.getSigMeta().verifiedSigs());
    assertTrue(allVerificationStatusesAre(VerificationStatus.VALID::equals));
}
Also used : SyncVerifier(com.hedera.services.sigs.verification.SyncVerifier) PubKeyToSigBytes(com.hedera.services.sigs.sourcing.PubKeyToSigBytes) BeforeEach(org.junit.jupiter.api.BeforeEach) OK(com.hederahashgraph.api.proto.java.ResponseCodeEnum.OK) KeyPrefixMismatchException(com.hedera.services.legacy.exception.KeyPrefixMismatchException) NodeFactory.ed25519(com.hedera.test.factories.keys.NodeFactory.ed25519) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) KEY_PREFIX_MISMATCH(com.hederahashgraph.api.proto.java.ResponseCodeEnum.KEY_PREFIX_MISMATCH) SigRequirements(com.hedera.services.sigs.order.SigRequirements) SigWrappers.asValid(com.hedera.test.factories.sigs.SigWrappers.asValid) PlatformTxnFactory(com.hedera.test.factories.txns.PlatformTxnFactory) ArrayList(java.util.ArrayList) CODE_ORDER_RESULT_FACTORY(com.hedera.services.sigs.order.CodeOrderResultFactory.CODE_ORDER_RESULT_FACTORY) BDDMockito.any(org.mockito.BDDMockito.any) ArgumentCaptor(org.mockito.ArgumentCaptor) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) BeforeAll(org.junit.jupiter.api.BeforeAll) BDDMockito.given(org.mockito.BDDMockito.given) BiConsumer(java.util.function.BiConsumer) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) PlatformTxnAccessor(com.hedera.services.utils.PlatformTxnAccessor) SigningOrderResult(com.hedera.services.sigs.order.SigningOrderResult) HederaToPlatformSigOps.expandIn(com.hedera.services.sigs.HederaToPlatformSigOps.expandIn) KeyType(com.hedera.services.sigs.sourcing.KeyType) SystemDeleteFactory.newSignedSystemDelete(com.hedera.test.factories.txns.SystemDeleteFactory.newSignedSystemDelete) ALWAYS_VALID(com.hedera.test.factories.sigs.SyncVerifiers.ALWAYS_VALID) ReusableBodySigningFactory(com.hedera.services.sigs.factories.ReusableBodySigningFactory) Predicate(java.util.function.Predicate) SigObserver(com.hedera.services.sigs.sourcing.SigObserver) PlatformSigFactory(com.hedera.services.sigs.factories.PlatformSigFactory) VerificationStatus(com.swirlds.common.crypto.VerificationStatus) BDDMockito.willAnswer(org.mockito.BDDMockito.willAnswer) Mockito.verify(org.mockito.Mockito.verify) RationalizedSigMeta(com.hedera.services.utils.RationalizedSigMeta) Test(org.junit.jupiter.api.Test) TransactionSignature(com.swirlds.common.crypto.TransactionSignature) INVALID_ACCOUNT_ID(com.hederahashgraph.api.proto.java.ResponseCodeEnum.INVALID_ACCOUNT_ID) List(java.util.List) JKey(com.hedera.services.legacy.core.jproto.JKey) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) SyncVerifier(com.hedera.services.sigs.verification.SyncVerifier) BDDMockito.mock(org.mockito.BDDMockito.mock) KeyTree(com.hedera.test.factories.keys.KeyTree) VerificationStatus(com.swirlds.common.crypto.VerificationStatus) TransactionSignature(com.swirlds.common.crypto.TransactionSignature) ReusableBodySigningFactory(com.hedera.services.sigs.factories.ReusableBodySigningFactory) Test(org.junit.jupiter.api.Test)

Example 4 with SyncVerifier

use of com.hedera.services.sigs.verification.SyncVerifier in project hedera-services by hashgraph.

the class HederaToPlatformSigOpsTest method doesNothingToTxnIfAllSigsAreRational.

@Test
void doesNothingToTxnIfAllSigsAreRational() throws Exception {
    wellBehavedOrdersAndSigSources();
    platformTxn = new PlatformTxnAccessor(PlatformTxnFactory.withClearFlag(platformTxn.getPlatformTxn()));
    platformTxn.getPlatformTxn().addAll(asValid(expectedSigsWithNoErrors()).toArray(new TransactionSignature[0]));
    final SyncVerifier syncVerifier = l -> {
        throw new AssertionError("All sigs were verified async!");
    };
    final var rationalization = new Rationalization(syncVerifier, keyOrdering, new ReusableBodySigningFactory());
    rationalization.performFor(platformTxn);
    assertFalse(rationalization.usedSyncVerification());
    assertEquals(OK, rationalization.finalStatus());
    assertEquals(expectedSigsWithNoErrors(), platformTxn.getPlatformTxn().getSignatures());
    assertTrue(allVerificationStatusesAre(VerificationStatus.VALID::equals));
    assertFalse(((PlatformTxnFactory.TransactionWithClearFlag) platformTxn.getPlatformTxn()).hasClearBeenCalled());
}
Also used : SyncVerifier(com.hedera.services.sigs.verification.SyncVerifier) PubKeyToSigBytes(com.hedera.services.sigs.sourcing.PubKeyToSigBytes) BeforeEach(org.junit.jupiter.api.BeforeEach) OK(com.hederahashgraph.api.proto.java.ResponseCodeEnum.OK) KeyPrefixMismatchException(com.hedera.services.legacy.exception.KeyPrefixMismatchException) NodeFactory.ed25519(com.hedera.test.factories.keys.NodeFactory.ed25519) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) KEY_PREFIX_MISMATCH(com.hederahashgraph.api.proto.java.ResponseCodeEnum.KEY_PREFIX_MISMATCH) SigRequirements(com.hedera.services.sigs.order.SigRequirements) SigWrappers.asValid(com.hedera.test.factories.sigs.SigWrappers.asValid) PlatformTxnFactory(com.hedera.test.factories.txns.PlatformTxnFactory) ArrayList(java.util.ArrayList) CODE_ORDER_RESULT_FACTORY(com.hedera.services.sigs.order.CodeOrderResultFactory.CODE_ORDER_RESULT_FACTORY) BDDMockito.any(org.mockito.BDDMockito.any) ArgumentCaptor(org.mockito.ArgumentCaptor) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) BeforeAll(org.junit.jupiter.api.BeforeAll) BDDMockito.given(org.mockito.BDDMockito.given) BiConsumer(java.util.function.BiConsumer) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) PlatformTxnAccessor(com.hedera.services.utils.PlatformTxnAccessor) SigningOrderResult(com.hedera.services.sigs.order.SigningOrderResult) HederaToPlatformSigOps.expandIn(com.hedera.services.sigs.HederaToPlatformSigOps.expandIn) KeyType(com.hedera.services.sigs.sourcing.KeyType) SystemDeleteFactory.newSignedSystemDelete(com.hedera.test.factories.txns.SystemDeleteFactory.newSignedSystemDelete) ALWAYS_VALID(com.hedera.test.factories.sigs.SyncVerifiers.ALWAYS_VALID) ReusableBodySigningFactory(com.hedera.services.sigs.factories.ReusableBodySigningFactory) Predicate(java.util.function.Predicate) SigObserver(com.hedera.services.sigs.sourcing.SigObserver) PlatformSigFactory(com.hedera.services.sigs.factories.PlatformSigFactory) VerificationStatus(com.swirlds.common.crypto.VerificationStatus) BDDMockito.willAnswer(org.mockito.BDDMockito.willAnswer) Mockito.verify(org.mockito.Mockito.verify) RationalizedSigMeta(com.hedera.services.utils.RationalizedSigMeta) Test(org.junit.jupiter.api.Test) TransactionSignature(com.swirlds.common.crypto.TransactionSignature) INVALID_ACCOUNT_ID(com.hederahashgraph.api.proto.java.ResponseCodeEnum.INVALID_ACCOUNT_ID) List(java.util.List) JKey(com.hedera.services.legacy.core.jproto.JKey) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) SyncVerifier(com.hedera.services.sigs.verification.SyncVerifier) BDDMockito.mock(org.mockito.BDDMockito.mock) KeyTree(com.hedera.test.factories.keys.KeyTree) VerificationStatus(com.swirlds.common.crypto.VerificationStatus) PlatformTxnAccessor(com.hedera.services.utils.PlatformTxnAccessor) TransactionSignature(com.swirlds.common.crypto.TransactionSignature) PlatformTxnFactory(com.hedera.test.factories.txns.PlatformTxnFactory) ReusableBodySigningFactory(com.hedera.services.sigs.factories.ReusableBodySigningFactory) Test(org.junit.jupiter.api.Test)

Aggregations

SigRequirements (com.hedera.services.sigs.order.SigRequirements)4 SyncVerifier (com.hedera.services.sigs.verification.SyncVerifier)4 ReusableBodySigningFactory (com.hedera.services.sigs.factories.ReusableBodySigningFactory)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 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 SigWrappers.asValid (com.hedera.test.factories.sigs.SigWrappers.asValid)2 ALWAYS_VALID (com.hedera.test.factories.sigs.SyncVerifiers.ALWAYS_VALID)2 PlatformTxnFactory (com.hedera.test.factories.txns.PlatformTxnFactory)2 SystemDeleteFactory.newSignedSystemDelete (com.hedera.test.factories.txns.SystemDeleteFactory.newSignedSystemDelete)2