Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save JohnMcLear/2d74f49849dd1c3382663cb3edf7217d to your computer and use it in GitHub Desktop.
Save JohnMcLear/2d74f49849dd1c3382663cb3edf7217d to your computer and use it in GitHub Desktop.
NFC-PCSC APDU based logic to get ID from various ISO14443 tags. Multos, Gemalto, Oberthur, ITSO, Oyster, Mifare, NTAG etc.
reader.on('card', async card => {
var uid = false;
// Smart card / payment ring / credit card / debit card
// Also Oyster etc.
if(card.type === "TAG_ISO_14443_4"){
// Trying GTO Credit / Debit card
var apdu = '80ca9f7f2c'; // Credit / Debit Card APDU
var data = Buffer.from(apdu, 'hex');
try {
var tagUid = await reader.transmit(data, 47);
if(tagUid.length >= 20) uid = tagUid.toString('hex');
// TODO: Remove trailing 9000 from request
} catch (err) {
console.log(err);
}
// Trying OT Credit / Debit card
var apdu = '80ca9f7f2d'; // Credit / Debit Card APDU
var data = Buffer.from(apdu, 'hex');
try {
var tagUid = await reader.transmit(data, 47);
if(tagUid.length >= 20) uid = tagUid.toString('hex');
// TODO: Remove trailing 9000 from request
} catch (err) {
console.log(err);
}
// Trying MULTOS Credit / Debit card
var apdu = '8002000016'; // Credit / Debit Card APDU
var data = Buffer.from(apdu, 'hex');
try {
var tagUid = await reader.transmit(data, 47);
if(tagUid.length >= 20) uid = tagUid.toString('hex');
// TODO: Remove trailing 9000 from request
// console.log(`UID`, uid.toString('hex'));
} catch (err) {
console.log(err);
}
// ITSO / Oyster
var apdu = '00a4000002'; // Credit / Debit Card APDU
var data = Buffer.from(apdu, 'hex');
try {
var a = await reader.transmit(Buffer.from('9060000000', 'hex'), 35);
var b = await reader.transmit(Buffer.from('90AF000000', 'hex'), 35);
var c = await reader.transmit(Buffer.from('90AF000000', 'hex'), 35);
if(c.toString('hex').length >= 14){
uid = c.toString('hex').substr(0,14);
}
} catch (err) {
console.log(err);
}
}
// NTAG and Mifare
if(card.type === "TAG_ISO_14443_3"){
// console.log("Trying NTAG and Mifare");
// var apdu = "FFCA000007";
var apdu = "FFCA000000";
var data = Buffer.from(apdu, 'hex');
try {
var tagUid = await reader.transmit(data, 20);
if(tagUid.length >= 5) uid = tagUid.toString('hex');
// console.log(`Mifare! UID`, uid.toString('hex'));
} catch (err) {
console.log(err);
}
}
if(uid){
console.log("UID IS ", uid);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment