From a2051d408598fb01e7bf01f14bce11be7b45ba2e Mon Sep 17 00:00:00 2001 From: mrfelek <17274927+mrfelek@users.noreply.github.com> Date: Mon, 23 Nov 2026 05:44:49 +0100 Subject: [PATCH] test(paymentcryptography): refuse a value other than the generated one, not a fixed one (#9234) The PIN refusal test of the Java SDK suite, and the card and PIN refusal tests of the AWS CLI suite, verified a fixed value, 9999 or 999, under a key created for the run. The key is new each time, so the fixed value was the key's own once in 10,000 PIN runs and once in 1,000 card runs, and the test then failed: it did on #8611's native arm64 / sdk-test-java job. Each now generates the value under its key and verifies it with another first digit, which can't be it, as the Java card test has done since #8664. The card test and the PIN test of the Java SDK suite each derived the value to refuse by changing the first digit of the one their key generated. That is now PaymentCryptographyValues.withAnotherFirstDigit, and both use it. --- .../test/payment-cryptography-card.bats | 11 ++++++++++- .../test/payment-cryptography-pin.bats | 5 ++++- .../floci/test/PaymentCryptographyCardTest.java | 3 +-- .../floci/test/PaymentCryptographyPinTest.java | 10 ++++++---- .../floci/test/PaymentCryptographyValues.java | 16 ++++++++++++++++ 5 files changed, 37 insertions(+), 8 deletions(-) create mode 100644 compatibility-tests/sdk-test-java/src/test/java/com/floci/test/PaymentCryptographyValues.java diff --git a/compatibility-tests/sdk-test-awscli/test/payment-cryptography-card.bats b/compatibility-tests/sdk-test-awscli/test/payment-cryptography-card.bats index a4569bc673..044349ca49 100644 --- a/compatibility-tests/sdk-test-awscli/test/payment-cryptography-card.bats +++ b/compatibility-tests/sdk-test-awscli/test/payment-cryptography-card.bats @@ -65,11 +65,20 @@ create_acg() { CVK_ARN=$(create_cvk) [ -n "$CVK_ARN" ] + run aws_cmd payment-cryptography-data generate-card-validation-data \ + --key-identifier "$CVK_ARN" \ + --primary-account-number "5081470082639564" \ + --generation-attributes 'CardVerificationValue1={CardExpiryDate=3003,ServiceCode=201}' + assert_success + VALUE=$(json_get "$output" '.ValidationData') + # The card's own value with another first digit, so it can't be the key's own. + INVALID="$([ "${VALUE:0:1}" = 0 ] && echo 1 || echo 0)${VALUE:1}" + # The value is not the one over the card account, so the verification fails. run aws_cmd payment-cryptography-data verify-card-validation-data \ --key-identifier "$CVK_ARN" \ --primary-account-number "5081470082639564" \ - --validation-data "999" \ + --validation-data "$INVALID" \ --verification-attributes 'CardVerificationValue1={CardExpiryDate=3003,ServiceCode=201}' assert_failure # A value that does not verify is a verification that failed, not a malformed request. diff --git a/compatibility-tests/sdk-test-awscli/test/payment-cryptography-pin.bats b/compatibility-tests/sdk-test-awscli/test/payment-cryptography-pin.bats index 206e8002fa..a9bc33ad87 100644 --- a/compatibility-tests/sdk-test-awscli/test/payment-cryptography-pin.bats +++ b/compatibility-tests/sdk-test-awscli/test/payment-cryptography-pin.bats @@ -79,6 +79,9 @@ create_pvk() { --generation-attributes 'VisaPin={PinVerificationKeyIndex=1}' assert_success BLOCK=$(json_get "$output" '.EncryptedPinBlock') + PVV=$(json_get "$output" '.PinData.VerificationValue') + # The PIN's own verification value with another first digit, so it can't be the key's own. + INVALID="$([ "${PVV:0:1}" = 0 ] && echo 1 || echo 0)${PVV:1}" # The verification value is not the one over the PIN, so the verification fails. run aws_cmd payment-cryptography-data verify-pin-data \ @@ -87,7 +90,7 @@ create_pvk() { --pin-block-format ISO_FORMAT_0 \ --primary-account-number "5081470082639564" \ --encrypted-pin-block "$BLOCK" \ - --verification-attributes 'VisaPin={PinVerificationKeyIndex=1,VerificationValue=9999}' + --verification-attributes "VisaPin={PinVerificationKeyIndex=1,VerificationValue=$INVALID}" assert_failure # A PIN that does not verify is a verification that failed, not a malformed request. [[ "$output" == *"VerificationFailedException"* ]] diff --git a/compatibility-tests/sdk-test-java/src/test/java/com/floci/test/PaymentCryptographyCardTest.java b/compatibility-tests/sdk-test-java/src/test/java/com/floci/test/PaymentCryptographyCardTest.java index 8336b1404c..d2e96fa3a6 100644 --- a/compatibility-tests/sdk-test-java/src/test/java/com/floci/test/PaymentCryptographyCardTest.java +++ b/compatibility-tests/sdk-test-java/src/test/java/com/floci/test/PaymentCryptographyCardTest.java @@ -134,8 +134,7 @@ class PaymentCryptographyCardTest { @Test void aCardVerificationValueThatDoesNotVerifyIsRefused() { String value = generateCardVerificationValue().validationData(); - String differentFirstDigit = value.startsWith("0") ? "1" : "0"; - String invalidValue = differentFirstDigit + value.substring(1); + String invalidValue = PaymentCryptographyValues.withAnotherFirstDigit(value); assertThatThrownBy(() -> client.verifyCardValidationData(r -> r .keyIdentifier(cardVerificationKeyArn) diff --git a/compatibility-tests/sdk-test-java/src/test/java/com/floci/test/PaymentCryptographyPinTest.java b/compatibility-tests/sdk-test-java/src/test/java/com/floci/test/PaymentCryptographyPinTest.java index c9eeea595e..09379c1979 100644 --- a/compatibility-tests/sdk-test-java/src/test/java/com/floci/test/PaymentCryptographyPinTest.java +++ b/compatibility-tests/sdk-test-java/src/test/java/com/floci/test/PaymentCryptographyPinTest.java @@ -122,7 +122,7 @@ class PaymentCryptographyPinTest { @Test void aPinThatDoesNotVerifyIsRefused() { - String block = client.generatePinData(r -> r + GeneratePinDataResponse generated = client.generatePinData(r -> r .encryptionKeyIdentifier(pinEncryptionKeyArn) .generationKeyIdentifier(visaVerificationKeyArn) .pinBlockFormat(PinBlockFormatForPinData.ISO_FORMAT_0) @@ -131,8 +131,10 @@ class PaymentCryptographyPinTest { .visaPin(VisaPin.builder() .pinVerificationKeyIndex(VERIFICATION_KEY_INDEX) .build()) - .build())) - .encryptedPinBlock(); + .build())); + String block = generated.encryptedPinBlock(); + String value = generated.pinData().verificationValue(); + String invalidValue = PaymentCryptographyValues.withAnotherFirstDigit(value); // The verification value is not the one over the PIN, so the verification fails. assertThatThrownBy(() -> client.verifyPinData(r -> r @@ -144,7 +146,7 @@ class PaymentCryptographyPinTest { .verificationAttributes(PinVerificationAttributes.builder() .visaPin(VisaPinVerification.builder() .pinVerificationKeyIndex(VERIFICATION_KEY_INDEX) - .verificationValue("9999") + .verificationValue(invalidValue) .build()) .build()))) .isInstanceOf(VerificationFailedException.class); diff --git a/compatibility-tests/sdk-test-java/src/test/java/com/floci/test/PaymentCryptographyValues.java b/compatibility-tests/sdk-test-java/src/test/java/com/floci/test/PaymentCryptographyValues.java new file mode 100644 index 0000000000..cee37d5a00 --- /dev/null +++ b/compatibility-tests/sdk-test-java/src/test/java/com/floci/test/PaymentCryptographyValues.java @@ -0,0 +1,16 @@ +package com.floci.test; + +/** Values the Payment Cryptography tests derive from what a key generated. */ +final class PaymentCryptographyValues { + + private PaymentCryptographyValues() { + } + + /** + * {@code value} with another first digit: a value a test generated under a key of its own, changed so that it + * can't be that key's, as a fixed value could be once in its range. + */ + static String withAnotherFirstDigit(String value) { + return (value.startsWith("0") ? "1" : "0") + value.substring(1); + } +}