Skip to content

Commit

Permalink
added Test for A Common Payment application ARQC verification
Browse files Browse the repository at this point in the history
  • Loading branch information
T-eli committed Dec 14, 2023
1 parent 8f82791 commit b14e893
Showing 1 changed file with 51 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,7 @@
import org.jpos.core.SimpleConfiguration;
import org.jpos.core.SubConfiguration;
import org.jpos.iso.ISOUtil;
import org.jpos.security.ARPCMethod;
import org.jpos.security.CipherMode;
import org.jpos.security.EncryptedPIN;
import org.jpos.security.KeyScheme;
import org.jpos.security.MKDMethod;
import org.jpos.security.PaddingMethod;
import org.jpos.security.SKDMethod;
import org.jpos.security.SMAdapter;
import org.jpos.security.SMException;
import org.jpos.security.SecureDESKey;
import org.jpos.security.*;
import org.jpos.util.Logger;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -163,7 +154,7 @@ public class JCESecurityModuleTest {
* Card Sequence Number
*/
static final String accountNoA_CSN = "00";

/**
* 19 digits account number
*/
Expand Down Expand Up @@ -205,9 +196,9 @@ public static void setUpClass() throws Exception {
}

static class EMVTxnData {

Map<String, byte[]> dm;

EMVTxnData() {
dm = new HashMap<String, byte[]>();
dm.put("AMMOUNT", ISOUtil.hex2byte("000000010000"));
Expand Down Expand Up @@ -1837,4 +1828,51 @@ public void testFormKeyFromClearComponent() throws Throwable {
assertArrayEquals(ISOUtil.hex2byte("40D522"), sdk.getKeyCheckValue(), "3: KeyCheck was " + ISOUtil.hexString(sdk.getKeyCheckValue()));
}


/**
* Test Data is based of EMV Issuer and Application Security Guidelines v3.0 Annex A.3.3 - Example of ARQC Generation
*/
@Test
public void TestARQCGeneration() throws Throwable {

String PAN = "5413339000006165";
String PANSeqNo = "00";
String amount = "000000010000";
String amount_other = "000000001000";
String terminalCountryCode = "0840";
String terminalVerificationResult = "0000001080";
String transactionCurrencyCode = "0840";
String transactionDate = "980704";
String transactionType = "00";
String unpredictableNumber = "11111111";
String applicationInterchangeProfile = "5800";
String applicationTransactionCounter = "3456";
String IssuerApplicationData = "0FA500A03800000000000000000000000F010000000000000000000000000000";

byte[] k = ISOUtil.hex2byte("9E15204313F7318ACB79B90BD986AD29");

SecureDESKey kek = jcesecmod.generateKey(SMAdapter.LENGTH_DES, SMAdapter.TYPE_RSA_PK);
byte[] encKey = jcesecmod.encryptData(CipherMode.ECB, kek, k , new byte[8]);
SecureDESKey mkac = jcesecmod.importKey((short) 128, SMAdapter.TYPE_MK_AC, encKey, kek, false);

byte[] d = ISOUtil.hex2byte(
amount
+ amount_other
+ terminalCountryCode
+ terminalVerificationResult
+ transactionCurrencyCode
+ transactionDate
+ transactionType
+ unpredictableNumber
+ applicationInterchangeProfile
+ applicationTransactionCounter
+ IssuerApplicationData
);

boolean result = jcesecmod.verifyARQC(MKDMethod.OPTION_A, SKDMethod.EMV_CSKD, mkac, PAN, PANSeqNo,ISOUtil.hex2byte("C20039270FE384D5") ,ISOUtil.hex2byte(applicationTransactionCounter), ISOUtil.hex2byte(unpredictableNumber), d);

assertTrue( result);

}

}

0 comments on commit b14e893

Please sign in to comment.