-
Notifications
You must be signed in to change notification settings - Fork 464
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added Common Payment Application Cryptogram Specs and Builder + tests.
note: verify CVNCPADataBuilder getDefaultARPCRequest ARC Values.
- Loading branch information
Showing
4 changed files
with
125 additions
and
0 deletions.
There are no files selected for viewing
35 changes: 35 additions & 0 deletions
35
jpos/src/main/java/org/jpos/emv/cryptogram/CPACryptogram.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
26
jpos/src/main/java/org/jpos/emv/cryptogram/CVNCPADataBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
21
jpos/src/test/java/org/jpos/emv/cryptogram/CPACryptogramTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
jpos/src/test/java/org/jpos/emv/cryptogram/CVNCPADataBuilderTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
); | ||
} | ||
} |