Talk to your Credit Card part 2: identify applications on the card

AndroidCrypto
3 min readApr 12, 2023

--

In part 1 of our Credit Card journey we made the first contact to our Credit Card, in this part we will analyze the card’s response and identify the applications available on the card.

App after reading a Credit Card

Beside some “nice to know” data we saw one important field in the response — that is tag 0x47 or “Application Identifier (AID)”:

4F 07 -- Application Identifier (AID) - card
A0 00 00 00 04 10 10 (BINARY)

This card have (only) one application available on the card, when reading a (German) GiroCard (a payment card) we do find 3 or more entries:

4F 09 -- Application Identifier (AID) - card
A0 00 00 00 59 45 43 01 00 (BINARY)
...
4F 0A -- Application Identifier (AID) - card
A0 00 00 03 59 10 10 02 80 01 (BINARY)
...
4F 09 -- Application Identifier (AID) - card
D2 76 00 00 25 47 41 01 00 (BINARY)
...

This information — the AID — is the key to our next step but how do we get this information programmatically ?

We do use an BER-TLV parser that gives us an easy access to every tag in the response:

BerTlvParser parser = new BerTlvParser();
BerTlvs tlv4Fs = parser.parse(selectPpseResponseOk);
// find all entries for tag 0x4f
List<BerTlv> tag4fList = tlv4Fs.findAll(new BerTag(0x4F));
...
writeToUiAppend("Found tag 0x4F " + tag4fList.size() + (tag4fList.size() == 1 ? " time:" : " times:"));

That we get a list of all “BerTlv” that are in the response.

The next step is to iterate over the list and extract the tag values for the next article:

ArrayList<byte[]> aidList = new ArrayList<>();
for (int i4f = 0; i4f < tag4fList.size(); i4f++) {
BerTlv tlv4f = tag4fList.get(i4f);
byte[] tlv4fBytes = tlv4f.getBytesValue();
aidList.add(tlv4fBytes);
writeToUiAppend("application Id (AID): " + bytesToHexNpe(tlv4fBytes));
}

The result for our MasterCard with one entry is:

02 analyze select PPSE response and search for tag 0x4F (applications on card)
Found tag 0x4F 1 time:
application Id (AID): a0000000041010

This is the code added in MainActivity.java-class:

public void onTagDiscovered(Tag tag) {
...
//writeToUiAppend("");
printStepHeader(2, "search applications on card");
writeToUiAppend("02 analyze select PPSE response and search for tag 0x4F (applications on card)");

BerTlvParser parser = new BerTlvParser();
BerTlvs tlv4Fs = parser.parse(selectPpseResponseOk);
// find all entries for tag 0x4f
List<BerTlv> tag4fList = tlv4Fs.findAll(new BerTag(0x4F));
if (tag4fList.size() < 1) {
writeToUiAppend("there is no tag 0x4F available, stopping here");
startEndSequence(nfc);
}
writeToUiAppend("Found tag 0x4F " + tag4fList.size() + (tag4fList.size() == 1 ? " time:" : " times:"));
ArrayList<byte[]> aidList = new ArrayList<>();
for (int i4f = 0; i4f < tag4fList.size(); i4f++) {
BerTlv tlv4f = tag4fList.get(i4f);
byte[] tlv4fBytes = tlv4f.getBytesValue();
aidList.add(tlv4fBytes);
writeToUiAppend("application Id (AID): " + bytesToHexNpe(tlv4fBytes));
}
writeToUiAppend(etData, "02 analyze select PPSE response completed");
...
Log file of step 2

Find the full code of the app in my GitHub repository TalkToYourCreditCardPart2: TalkToYourCreditCardPart2

Now we are ready to move to step 3: select one application on the card to work with (“select AID”):

--

--