mirror of
https://github.com/floci-io/floci.git
synced 2026-12-04 02:28:08 -05:00
fix(paymentcryptography): the account number may be the account field (#10076)
TranslatePinData binds a format 0 or 3 PIN block to the twelve-digit account field, the twelve right-most digits of the account number without its check digit, and a caller holding the block sends that field as PrimaryAccountNumber. A twelve-digit value was read as a PAN whose check digit was dropped, so the derived field was one digit short and the block did not decipher. For the formats 0 and 3 a twelve-digit value is now the field itself, while format 4, which binds the PIN to the whole PAN, reads it as a PAN as before; the Visa verification value follows the same reading. A request whose translation attributes name no account number is refused with ValidationException instead of throwing. Closes #10077
This commit is contained in:
1 parent
e92a9736be
commit
c95aecbb92
5 files changed
+196
-43
No files matched your search
+62
@@ -32,6 +32,10 @@ class PaymentCryptographyPinTest {
|
||||
/** The account number the PIN belongs to. */
|
||||
private static final String PAN = "5081470082639564";
|
||||
|
||||
/** The account field of the account number: its twelve right-most digits without the
|
||||
* check digit. It is what a caller that holds the PIN block holds. */
|
||||
private static final String ACCOUNT_FIELD = "147008263956";
|
||||
|
||||
/** The index of the verification key the PVV is computed under. */
|
||||
private static final int VERIFICATION_KEY_INDEX = 1;
|
||||
|
||||
@@ -226,6 +230,64 @@ class PaymentCryptographyPinTest {
|
||||
assertThat(block0).hasSize(16);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("a PIN block bound to the account field translates")
|
||||
void aPinBlockBoundToTheAccountFieldTranslates() {
|
||||
// The account field is the twelve right-most digits of the account number without
|
||||
// its check digit, and a caller that holds the PIN block holds the field: the
|
||||
// translation attributes carry it, and the service reads it as the field.
|
||||
String outgoingKeyArn = createKeyArn(KeyAlgorithm.TDES_2_KEY,
|
||||
KeyUsage.TR31_P0_PIN_ENCRYPTION_KEY, m -> m.encrypt(true).decrypt(true));
|
||||
|
||||
// The block the acquirer sends is bound to the account field of the account number.
|
||||
GeneratePinDataResponse generated = client.generatePinData(r -> r
|
||||
.encryptionKeyIdentifier(pinEncryptionKeyArn)
|
||||
.generationKeyIdentifier(visaVerificationKeyArn)
|
||||
.pinBlockFormat(PinBlockFormatForPinData.ISO_FORMAT_0)
|
||||
.primaryAccountNumber(PAN)
|
||||
.generationAttributes(PinGenerationAttributes.builder()
|
||||
.visaPin(VisaPin.builder()
|
||||
.pinVerificationKeyIndex(VERIFICATION_KEY_INDEX)
|
||||
.build())
|
||||
.build()));
|
||||
String block0 = generated.encryptedPinBlock();
|
||||
String value = generated.pinData().verificationValue();
|
||||
|
||||
String translated = client.translatePinData(r -> r
|
||||
.encryptedPinBlock(block0)
|
||||
.incomingKeyIdentifier(pinEncryptionKeyArn)
|
||||
.outgoingKeyIdentifier(outgoingKeyArn)
|
||||
.incomingTranslationAttributes(TranslationIsoFormats.builder()
|
||||
.isoFormat0(TranslationPinDataIsoFormat034.builder()
|
||||
.primaryAccountNumber(ACCOUNT_FIELD)
|
||||
.build())
|
||||
.build())
|
||||
.outgoingTranslationAttributes(TranslationIsoFormats.builder()
|
||||
.isoFormat0(TranslationPinDataIsoFormat034.builder()
|
||||
.primaryAccountNumber(ACCOUNT_FIELD)
|
||||
.build())
|
||||
.build()))
|
||||
.pinBlock();
|
||||
|
||||
assertThat(translated).isNotBlank();
|
||||
assertThat(translated).hasSize(16);
|
||||
|
||||
// The translated block still verifies against the verification value that goes
|
||||
// with it: the PIN survived the translation, bound to the same account.
|
||||
client.verifyPinData(r -> r
|
||||
.encryptionKeyIdentifier(outgoingKeyArn)
|
||||
.verificationKeyIdentifier(visaVerificationKeyArn)
|
||||
.pinBlockFormat(PinBlockFormatForPinData.ISO_FORMAT_0)
|
||||
.primaryAccountNumber(PAN)
|
||||
.encryptedPinBlock(translated)
|
||||
.verificationAttributes(PinVerificationAttributes.builder()
|
||||
.visaPin(VisaPinVerification.builder()
|
||||
.pinVerificationKeyIndex(VERIFICATION_KEY_INDEX)
|
||||
.verificationValue(value)
|
||||
.build())
|
||||
.build()));
|
||||
}
|
||||
|
||||
@Test
|
||||
void aKeyThatMayNotEncryptIsRefused() {
|
||||
String readOnlyKeyArn = createKeyArn(KeyAlgorithm.TDES_2_KEY,
|
||||
|
||||
Reference in new issue
Block a user