Search in sources :

Example 6 with ReusableBodySigningFactory

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

the class SigOpsRegressionTest method setupFor.

private void setupFor(TxnHandlingScenario scenario) throws Throwable {
    hfs = scenario.hfs();
    aliasManager = mock(AliasManager.class);
    runningAvgs = mock(MiscRunningAvgs.class);
    speedometers = mock(MiscSpeedometers.class);
    accounts = scenario.accounts();
    platformTxn = scenario.platformTxn();
    expectedErrorStatus = null;
    final var hfsSigMetaLookup = new HfsSigMetaLookup(hfs, fileNumbers);
    signingOrder = new SigRequirements(defaultLookupsFor(aliasManager, hfsSigMetaLookup, () -> accounts, () -> null, ref -> null, ref -> null), mockSignatureWaivers);
    final var payerKeys = signingOrder.keysForPayer(platformTxn.getTxn(), CODE_ORDER_RESULT_FACTORY);
    expectedSigs = new ArrayList<>();
    if (payerKeys.hasErrorReport()) {
        expectedErrorStatus = payerKeys.getErrorReport();
    } else {
        PlatformSigsCreationResult payerResult = PlatformSigOps.createCryptoSigsFrom(payerKeys.getOrderedKeys(), new PojoSigMapPubKeyToSigBytes(platformTxn.getSigMap()), new ReusableBodySigningFactory(platformTxn));
        expectedSigs.addAll(payerResult.getPlatformSigs());
        SigningOrderResult<ResponseCodeEnum> otherKeys = signingOrder.keysForOtherParties(platformTxn.getTxn(), CODE_ORDER_RESULT_FACTORY);
        if (otherKeys.hasErrorReport()) {
            expectedErrorStatus = otherKeys.getErrorReport();
        } else {
            PlatformSigsCreationResult otherResult = PlatformSigOps.createCryptoSigsFrom(otherKeys.getOrderedKeys(), new PojoSigMapPubKeyToSigBytes(platformTxn.getSigMap()), new ReusableBodySigningFactory(platformTxn));
            if (!otherResult.hasFailed()) {
                expectedSigs.addAll(otherResult.getPlatformSigs());
            }
        }
    }
}
Also used : AliasManager(com.hedera.services.ledger.accounts.AliasManager) SigRequirements(com.hedera.services.sigs.order.SigRequirements) PojoSigMapPubKeyToSigBytes(com.hedera.services.sigs.sourcing.PojoSigMapPubKeyToSigBytes) ResponseCodeEnum(com.hederahashgraph.api.proto.java.ResponseCodeEnum) MiscSpeedometers(com.hedera.services.stats.MiscSpeedometers) HfsSigMetaLookup(com.hedera.services.sigs.metadata.lookups.HfsSigMetaLookup) MiscRunningAvgs(com.hedera.services.stats.MiscRunningAvgs) ReusableBodySigningFactory(com.hedera.services.sigs.factories.ReusableBodySigningFactory)

Example 7 with ReusableBodySigningFactory

use of com.hedera.services.sigs.factories.ReusableBodySigningFactory 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 8 with ReusableBodySigningFactory

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

the class PrecheckVerifierTest method setupAll.

@BeforeAll
static void setupAll() throws Throwable {
    reqKeys = List.of(KeyTree.withRoot(list(ed25519(), list(ed25519(), ed25519()))).asJKey(), KeyTree.withRoot(ed25519()).asJKey());
    expectedSigs = PlatformSigOps.createCryptoSigsFrom(reqKeys, VALID_PROVIDER_FACTORY.get(), new ReusableBodySigningFactory(realAccessor)).getPlatformSigs();
}
Also used : ReusableBodySigningFactory(com.hedera.services.sigs.factories.ReusableBodySigningFactory) BeforeAll(org.junit.jupiter.api.BeforeAll)

Example 9 with ReusableBodySigningFactory

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

the class PrecheckVerifier method getAvailSigs.

private List<TransactionSignature> getAvailSigs(List<JKey> reqKeys, SignedTxnAccessor accessor) throws Exception {
    final var pkToSigFn = accessor.getPkToSigsFn();
    final var sigFactory = new ReusableBodySigningFactory(accessor);
    PlatformSigsCreationResult creationResult = createCryptoSigsFrom(reqKeys, pkToSigFn, sigFactory);
    if (creationResult.hasFailed()) {
        throw creationResult.getTerminatingEx();
    } else {
        return creationResult.getPlatformSigs();
    }
}
Also used : PlatformSigsCreationResult(com.hedera.services.sigs.PlatformSigsCreationResult) ReusableBodySigningFactory(com.hedera.services.sigs.factories.ReusableBodySigningFactory)

Example 10 with ReusableBodySigningFactory

use of com.hedera.services.sigs.factories.ReusableBodySigningFactory 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)

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