Skip to content

Commit

Permalink
updated
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelfehr committed Mar 26, 2023
1 parent 4f87157 commit bef882f
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 40 deletions.
2 changes: 1 addition & 1 deletion .idea/deploymentTargetDropDown.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,13 @@
*
* Source: https://github.com/sasc999/javaemvreader/blob/master/src/main/java/sasc/emv/DOL.java
*/

/**
* This is a modified version of the original DOL.java, it now returns TagAndLength TlvUtil from
* import com.github.devnied.emvnfccard.iso7816emv.TagAndLength;
* import com.github.devnied.emvnfccard.utils.TlvUtil;
*/

public class DOL {

public enum Type{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,14 +191,7 @@ public void onTagDiscovered(Tag tag) {
List<BerTlv> tag4fList = tlv4Fs.findAll(new BerTag(0x4F));
if (tag4fList.size() < 1) {
writeToUiAppend("there is no tag 0x4F available, stopping here");
setLoadingLayoutVisibility(false);
vibrate();
try {
nfc.close();
} catch (IOException e) {
throw new RuntimeException(e);
}
return;
startEndSequence(nfc);
}
writeToUiAppend("Found tag 0x4F " + tag4fList.size() + (tag4fList.size() == 1 ? " time:" : " times:"));
ArrayList<byte[]> aidList = new ArrayList<>();
Expand Down Expand Up @@ -246,6 +239,9 @@ public void onTagDiscovered(Tag tag) {
writeToUiAppend(dumpSingleData(applicationTransactionCounter, pinTryCounter, lastOnlineATCRegister, logFormat));
writeToUiAppend("");

byte[] challenge8Byte = getChallenge(nfc);
writeToUiAppend("challenge length: " + challenge8Byte.length + " data: " + bytesToHexNpe(challenge8Byte));


/**
* step 4 code start
Expand Down Expand Up @@ -274,26 +270,6 @@ public void onTagDiscovered(Tag tag) {
byte[] pdolValue = tag9f38.getBytesValue();
writeToUiAppend("found tag 0x9F38 in the selectAid with this length: " + pdolValue.length + " data: " + bytesToHexNpe(pdolValue));

/*
// using code from DOL.java sasc999
DOL pdol = new DOL(DOL.Type.PDOL, pdolValue);
writeToUiAppend("");
writeToUiAppend(pdol.toString());
// using TagAndLength
List<TagAndLength> pdolList = pdol.getTagAndLengthList();
int pdolListSize = pdolList.size();
writeToUiAppend("The card is requesting " + pdolListSize + (pdolListSize == 1 ? " tag" : " tags") + " with length:");
for (int i = 0; i < pdolListSize; i++) {
TagAndLength pdolEntry = pdolList.get(i);
//writeToUiAppend("tag " + (i + 1) + " : " + pdolEntry.getTag().getName() + " [" +
writeToUiAppend("tag " + String.format("%02d", i + 1) + ": " + pdolEntry.getTag().getName() + " [" +
bytesToHexNpe(pdolEntry.getTag().getTagBytes()) +
"] length " + String.valueOf(pdolEntry.getLength()));
}
*/

// using modified code from DOL.java sasc999
DOL pdol = new DOL(DOL.Type.PDOL, pdolValue);
writeToUiAppend("");
Expand All @@ -311,7 +287,6 @@ public void onTagDiscovered(Tag tag) {
"] length " + String.valueOf(pdolEntry.getLength()));
}


gpoRequestCommand = getGpoFromPdol(pdolValue);
//gpoRequestCommand = getGetProcessingOptionsFromPdol(pdolValue); // not working for DKB Visa

Expand Down Expand Up @@ -524,7 +499,8 @@ public void onTagDiscovered(Tag tag) {
writeToUiAppend("");
}
} catch (RuntimeException e) {
System.out.println("Runtime Exception: " + e.getMessage());
//System.out.println("Runtime Exception: " + e.getMessage());
startEndSequence(nfc);
}
} else {
writeToUiAppend("readRecord response was NULL");
Expand Down Expand Up @@ -587,11 +563,8 @@ public void onTagDiscovered(Tag tag) {
} catch (IOException e) {
writeToUiAppend("connection with card failure");
writeToUiAppend(e.getMessage());
// playPing();
vibrate();
writeToUiFinal(etLog);
setLoadingLayoutVisibility(false);
// throw new RuntimeException(e);
startEndSequence(nfc);
return;
}
}
Expand All @@ -609,6 +582,7 @@ private void startEndSequence(IsoDep nfc) {
playPing();
writeToUiFinal(etLog);
setLoadingLayoutVisibility(false);
vibrate();
try {
nfc.close();
} catch (IOException e) {
Expand Down Expand Up @@ -714,17 +688,42 @@ private String removeTrailingF(String input) {
* overview: https://github.com/sasc999/javaemvreader/blob/master/src/main/java/sasc/emv/EMVAPDUCommands.java
*/

// Get the data of ATC(Application Transaction Counter, tag '9F36')), template 77 or 80
private byte[] getChallenge(IsoDep nfc) {
byte[] cmd = new byte[]{(byte) 0x80, (byte) 0x84, (byte) 0x00, (byte) 0x00, (byte) 0x00};
byte[] result = new byte[0];
try {
result = nfc.transceive(cmd);
} catch (IOException e) {
Log.e(TAG, "* getApplicationTransactionCounter failed");
return null;
}
return result;
/*
//System.out.println("*** getATC: " + bytesToHexNpe(result));
// e.g. visa returns 9f360200459000
// e.g. visa returns 9f36020045 9000
byte[] resultOk = checkResponse(result);
if (resultOk == null) {
return null;
} else {
return getTagValueFromResult(resultOk, (byte) 0x9f, (byte) 0x36);
}
*/
}

// Get the data of ATC(Application Transaction Counter, tag '9F36')), template 77 or 80
private byte[] getApplicationTransactionCounter(IsoDep nfc) {
byte[] cmd = new byte[]{(byte) 0x80, (byte) 0xCA, (byte) 0x9F, (byte) 0x36, (byte) 0x00};
byte[] result = new byte[0];
try {
result = nfc.transceive(cmd);
} catch (IOException e) {
System.out.println("* getApplicationTransactionCounter failed");
Log.e(TAG, "* getApplicationTransactionCounter failed");
return null;
}
System.out.println("*** getATC: " + bytesToHexNpe(result));
//System.out.println("*** getATC: " + bytesToHexNpe(result));
// e.g. visa returns 9f360200459000
// e.g. visa returns 9f36020045 9000
byte[] resultOk = checkResponse(result);
Expand All @@ -741,7 +740,7 @@ private byte[] getPinTryCounter(IsoDep nfc) {
try {
result = nfc.transceive(cmd);
} catch (IOException e) {
System.out.println("* getPinTryCounterCounter failed");
Log.e(TAG, "* getPinTryCounterCounter failed");
return null;
}
byte[] resultOk = checkResponse(result);
Expand All @@ -758,7 +757,7 @@ private byte[] getLastOnlineATCRegister(IsoDep nfc) {
try {
result = nfc.transceive(cmd);
} catch (IOException e) {
System.out.println("* getLastOnlineATCRegister failed");
Log.e(TAG, "* getLastOnlineATCRegister failed");
return null;
}
byte[] resultOk = checkResponse(result);
Expand All @@ -775,7 +774,7 @@ private byte[] getLogFormat(IsoDep nfc) {
try {
result = nfc.transceive(cmd);
} catch (IOException e) {
System.out.println("* getLastOnlineATCRegister failed");
Log.e(TAG, "* getLastOnlineATCRegister failed");
return null;
}
byte[] resultOk = checkResponse(result);
Expand Down

0 comments on commit bef882f

Please sign in to comment.