Skip to content

Commit

Permalink
updated
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelfehr committed Aug 29, 2024
1 parent 6f964f3 commit a1dc71d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,13 @@ Minimum SDK is 21 (Android 5)

The Ultralight C tag uses a Triple DES authentication scheme with a 2 DES keys model, so in the end it uses a 16 bytes long TDES key.

I'm using 2 predefined keys in the app:

```plaintext
byte[] defaultAuthKey = hexStringToByteArray("49454D4B41455242214E4143554F5946"); // "IEMKAERB!NACUOYF" => "BREAKMEIFYOUCAN!", 16 bytes long
byte[] customAuthKey = "1234567890123456".getBytes(StandardCharsets.UTF_8);
```

### Counter on Mifare Ultralight-C:
```plaintext
7.5.11 Counter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ public class MIFARE_Ultralight_C {

public static final byte[] defaultAuthKey = hexStringToByteArray("49454D4B41455242214E4143554F5946"); // "IEMKAERB!NACUOYF" => "BREAKMEIFYOUCAN!", 16 bytes long
public static final byte[] customAuthKey = "1234567890123456".getBytes(StandardCharsets.UTF_8);
public static final byte[] default2AuthKey = "BREAKMEIFYOUCAN!".getBytes(StandardCharsets.UTF_8);

public static boolean identifyUltralightFamily(NfcA nfcA) {
// get card details
Expand Down Expand Up @@ -92,15 +91,12 @@ public static boolean authenticateUltralightC(NfcA nfcA, byte[] key) {
byte[] rndA = new byte[8];
generateRandom(rndA);
Log.d(TAG, " - RndA: " + bytesToHexNpe(rndA));
//byte[] encRndArotPrime = transmitRaw(ArrayUtils.addAll(new byte[] {(byte) 0xAF}, desEncrypt(key, ArrayUtils.addAll(rndA, rndBrot))));
//byte[] rndARndBrot = ArrayUtils.addAll(rndA, rndBrot);
byte[] rndARndBrot = combineByteArrays(rndA, rndBrot);
Log.d(TAG, printData("rndARndBrot", rndARndBrot));
Log.d(TAG, " - rndARndBrot: " + bytesToHexNpe(rndARndBrot));
byte[] encRndARndBrot = desEncrypt(key, rndARndBrot);
Log.d(TAG, printData("encRndARndBrot", encRndARndBrot));
Log.d(TAG, " - encRndARndBrot: " + bytesToHexNpe(encRndARndBrot));
byte[] dataToSend = combineByteArrays(new byte[]{(byte) 0xAF}, encRndARndBrot);
Log.d(TAG, printData("dataToSend", dataToSend));
// AF0A638559FC7737F9F15D7862EBBE967A
Log.d(TAG, " - dataToSend: " + bytesToHexNpe(dataToSend));
byte[] encRndArotPrime;
try {
encRndArotPrime = nfcA.transceive(dataToSend);
Expand All @@ -110,15 +106,15 @@ public static boolean authenticateUltralightC(NfcA nfcA, byte[] key) {
}
Log.d(TAG, "encRndArotPrime: " + bytesToHexNpe(encRndArotPrime));
if ((encRndArotPrime.length != 9) || (encRndArotPrime[0] != 0x00)) {
Log.d(TAG, "RuntimeException (Invalid response!)");
Log.e(TAG, "RuntimeException (Invalid response!)");
return false;
}
encRndArotPrime = Arrays.copyOfRange(encRndArotPrime, 1, 9);
Log.d(TAG, " - EncRndArot': " + bytesToHexNpe(encRndArotPrime));
byte[] rndArotPrime = desDecrypt(key, encRndArotPrime);
Log.d(TAG, " - RndArot': " + bytesToHexNpe(rndArotPrime));
if (!Arrays.equals(rotateLeft(rndA), rndArotPrime)) {
Log.d(TAG, "RuntimeException (Card authentication failed)");
Log.e(TAG, "RuntimeException (Card authentication failed)");
return false;
} else {
Log.d(TAG, "Card authentication success");
Expand Down

0 comments on commit a1dc71d

Please sign in to comment.