Skip to content

Commit

Permalink
added Common Payment Application Cryptogram Specs and Builder + tests.
Browse files Browse the repository at this point in the history
note: verify CVNCPADataBuilder getDefaultARPCRequest ARC Values.
  • Loading branch information
T-eli committed Dec 21, 2023
1 parent 0a9f0a4 commit 36c19ed
Show file tree
Hide file tree
Showing 4 changed files with 125 additions and 0 deletions.
35 changes: 35 additions & 0 deletions jpos/src/main/java/org/jpos/emv/cryptogram/CPACryptogram.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package org.jpos.emv.cryptogram;

import org.jpos.security.ARPCMethod;
import org.jpos.security.MKDMethod;
import org.jpos.security.SKDMethod;

import org.jpos.emv.cryptogram.CryptogramDataBuilder.PaddingMethod;

/**
* Common Payment Application (CPA) Cryptogram Specification
*/
public class CPACryptogram implements CryptogramSpec {

final PaddingMethod paddingMethod = CryptogramDataBuilder.ISO9797Method2;

@Override
public MKDMethod getMKDMethod() {
return MKDMethod.OPTION_A;
}

@Override
public SKDMethod getSKDMethod() {
return SKDMethod.EMV_CSKD;
}

@Override
public ARPCMethod getARPCMethod() {
return ARPCMethod.METHOD_2;
}

@Override
public CryptogramDataBuilder getDataBuilder() {
return new CVNCPADataBuilder();
}
}
26 changes: 26 additions & 0 deletions jpos/src/main/java/org/jpos/emv/cryptogram/CVNCPADataBuilder.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package org.jpos.emv.cryptogram;

import org.jpos.emv.IssuerApplicationData;
import org.jpos.tlv.TLVList;
import static org.jpos.emv.cryptogram.CryptogramDataBuilder.minimumSetOfDataElement;

public class CVNCPADataBuilder implements CryptogramDataBuilder {

@Override
public String getDefaultARPCRequest(boolean approved) {
return approved ? "3030" : "3031";
}

@Override
public String buildARQCRequest(TLVList data, IssuerApplicationData iad) {
StringBuilder sb = new StringBuilder();
minimumSetOfDataElement(data).stream().forEach(sb::append);
sb.append(iad.toString());
return sb.toString();
}

@Override
public String buildARQCRequest_padded(TLVList data, IssuerApplicationData iad, PaddingMethod paddingMethod) {
return paddingMethod.apply(buildARQCRequest(data, iad));
}
}
21 changes: 21 additions & 0 deletions jpos/src/test/java/org/jpos/emv/cryptogram/CPACryptogramTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package org.jpos.emv.cryptogram;

import org.jpos.security.ARPCMethod;
import org.jpos.security.MKDMethod;
import org.jpos.security.SKDMethod;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;

public class CPACryptogramTest {
@Test
void test(){
CPACryptogram spec = new CPACryptogram();
assertEquals(spec.paddingMethod, CryptogramDataBuilder.ISO9797Method2);
assertEquals(spec.getMKDMethod(), MKDMethod.OPTION_A);
assertEquals(spec.getSKDMethod(), SKDMethod.EMV_CSKD);
assertEquals(spec.getARPCMethod(), ARPCMethod.METHOD_2);
assertTrue(spec.getDataBuilder() instanceof CVNCPADataBuilder);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package org.jpos.emv.cryptogram;

import org.jpos.emv.IssuerApplicationData;
import org.jpos.tlv.TLVList;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;

public class CVNCPADataBuilderTest {
private final CVNCPADataBuilder builder = new CVNCPADataBuilder();

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

TLVList data = new TLVList();
data.append(0x9F02, "000000010000");
data.append(0x9F03, "000000001000");
data.append(0x9F1A, "0840");
data.append(0x95, "0000001080");
data.append(0x5F2A, "0840");
data.append(0x9A, "980704");
data.append(0x9C, "00");
data.append(0x9F37, "11111111");
data.append(0x82, "5800");
data.append(0x9F36, "3456");
data.append(0x9f10, "0FA500A03800000000000000000000000F010000000000000000000000000000");

IssuerApplicationData iad = new IssuerApplicationData(data.getString(0x9f10));

assertEquals(
"0000000100000000000010000840000000108008409807040011111111580034560FA500A03800000000000000000000000F010000000000000000000000000000",
builder.buildARQCRequest(data, iad)
);

assertEquals(
"0000000100000000000010000840000000108008409807040011111111580034560FA500A03800000000000000000000000F01000000000000000000000000000080000000000000",
builder.buildARQCRequest_padded(data, iad, builder.ISO9797Method2)
);
}
}

0 comments on commit 36c19ed

Please sign in to comment.