Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add code that fails to parse the Proxmark APDU EMVs #1

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions test_emv_proxmark.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// Decrypted SDAD:
const assert = require('assert');
const crypto = require('crypto');
var decryptedSDAD = new Uint8Array([0x6A, 0x05, 0x01, 0x26, 0x08, 0xAD, 0xB1, 0xE0, 0x39, 0x64, 0x21, 0xBF, 0xB4, 0x80, 0x42, 0x2B, 0x7D, 0xB2, 0xC5, 0xB3, 0x52, 0xBE, 0x3F, 0x86, 0xBA, 0xA5, 0xD8, 0xA9, 0x4C, 0xE2, 0x0D, 0x94, 0x87, 0x79, 0xB9, 0x3F, 0x4B, 0xD4, 0xCE, 0x17, 0x53, 0x5E]);

//Step 1: SDAD and ICC Public Key Modulus have the same length
// assert(SDAD.length == iccPublicKeyModulus.length);

//Step 2: The Recovered Data Trailer is equal to 'BC'
// assert(decryptedSDAD[decryptedSDAD.length - 1] == 0xBC);

//Step 3: The Recovered Data Header is equal to '6A'
assert(decryptedSDAD[0] == 0x6A);

//Step 4: The Signed Data Format is equal to '05'
assert(decryptedSDAD[1] == 0x05);

//Step 5: Concatenation of Signed Data Format, Hash Algorithm Indicator,
// ICC Dynamic Data Length, ICC Dynamic Data, Pad Pattern, random number
var LDD = decryptedSDAD[3];
var list = decryptedSDAD.slice(1, 3 + LDD + decryptedSDAD.length - LDD - 25);
while(list.length < 123) {
list = [...list, 0xBB];
}
list = [...list, 0x29, 0x21, 0x8F, 0xCE, 0xB5, 0x48, 0xBE, 0x5F];

// list = list.concat(Data);

//Step 6: Generate hash from concatenation
// Hash the bytes directly
var hash = crypto.createHash('sha1');
hash.update(Buffer.from(list));
var hashConcat = hash.digest();

//Step 7: Compare recovered hash with generated hash
console.log(decryptedSDAD);
var hashSDAD = decryptedSDAD.slice(decryptedSDAD.length - 20, decryptedSDAD.length);
console.log(hashSDAD);
console.log(Array.from(hashConcat));
assert(hashConcat.equals(Buffer.from(hashSDAD)));
console.log("DDA was successful");