combine all auth data to single struct and fill it
authorOleg Moiseenko <olegmsn@gmail.com>
Sat, 10 Feb 2018 17:03:29 +0000 (19:03 +0200)
committerOleg Moiseenko <olegmsn@gmail.com>
Sat, 10 Feb 2018 17:03:29 +0000 (19:03 +0200)
client/cmdhf.c
client/cmdhflist.c
client/cmdhflist.h

index ae1b12a67f216b92d8d7140ddcf1ae3072270fba..2557607b35e320217c0a0afde98d679cb671862a 100644 (file)
@@ -543,6 +543,7 @@ int CmdHFList(const char *Cmd)
        PrintAndLog("      Start |        End | Src | Data (! denotes parity error)                                   | CRC | Annotation         |");
        PrintAndLog("------------|------------|-----|-----------------------------------------------------------------|-----|--------------------|");
 
+       ClearAuthData();
        while(tracepos < traceLen)
        {
                tracepos = printTraceLine(tracepos, traceLen, trace, protocol, showWaitCycles, markCRCBytes);
index 065cbde2b861f84fb36138397a51b273a1bfe934..ec710b2c24d55d0a220d01809a7247b09c3832d0 100644 (file)
@@ -28,11 +28,19 @@ enum MifareAuthSeq {
        masNt,
        masNrAr,
        masAt,
+       masFirstData,
        masData,
        masDataNested,
        masError,
 };
 static enum MifareAuthSeq MifareAuthState;
+static TAuthData AuthData;
+
+void ClearAuthData() {
+       AuthData.uid = 0;
+       AuthData.nt = 0;
+       AuthData.first_auth = false;
+}
 
 /**
  * @brief iso14443A_CRC_check Checks CRC in command or response
@@ -63,6 +71,7 @@ uint8_t mifare_CRC_check(bool isResponse, uint8_t* data, uint8_t len)
 {
        switch(MifareAuthState) {
                case masNone:
+               case masFirstData:
                case masData:
                case masDataNested:
                case masError:
@@ -172,22 +181,27 @@ void annotateIso14443a(char *exp, size_t size, uint8_t* cmd, uint8_t cmdsize)
 }
 
 void annotateMifare(char *exp, size_t size, uint8_t* cmd, uint8_t cmdsize, bool isResponse) {
-//     uint32_t uid;       // UID
-       static uint32_t nt;        // tag challenge
-//     uint32_t nt_enc;    // encrypted tag challenge
-//     uint8_t nt_enc_par; // encrypted tag challenge parity
-       static uint32_t nr_enc;    // encrypted reader challenge
-       static uint32_t ar_enc;    // encrypted reader response
-//     uint8_t ar_enc_par; // encrypted reader response parity
-       static uint32_t at_enc;    // encrypted tag response
-//     uint8_t at_enc_par; // encrypted tag response parity
-
+       // get UID
+       if (MifareAuthState == masNone) {
+               if (cmdsize == 7 && cmd[0] == ISO14443A_CMD_ANTICOLL_OR_SELECT && cmd[1] == 0x70) {
+                       ClearAuthData();
+                       AuthData.uid = bytes_to_num(&cmd[2], 4);
+               }
+               if (cmdsize == 7 && cmd[0] == ISO14443A_CMD_ANTICOLL_OR_SELECT_2 && cmd[1] == 0x70) {
+                       ClearAuthData();
+                       AuthData.uid = bytes_to_num(&cmd[2], 4);
+               }
+       }
+       
        switch(MifareAuthState) {
                case masNt:
                        if (cmdsize == 4 && isResponse) {
-                               snprintf(exp,size,"AUTH: nt %s", (nt) ? "(enc)" : "");
+                               snprintf(exp,size,"AUTH: nt %s", (AuthData.first_auth) ? "" : "(enc)");
                                MifareAuthState = masNrAr;
-                               nt = bytes_to_num(cmd, cmdsize);
+                               if (AuthData.first_auth)
+                                       AuthData.nt = bytes_to_num(cmd, cmdsize);
+                               else
+                                       AuthData.nt_enc = bytes_to_num(cmd, cmdsize);
                                return;
                        } else {
                                MifareAuthState = masError;
@@ -197,8 +211,8 @@ void annotateMifare(char *exp, size_t size, uint8_t* cmd, uint8_t cmdsize, bool
                        if (cmdsize == 8 && !isResponse) {
                                snprintf(exp,size,"AUTH: nr ar (enc)");
                                MifareAuthState = masAt;
-                               nr_enc = bytes_to_num(cmd, cmdsize);
-                               ar_enc = bytes_to_num(&cmd[3], cmdsize);
+                               AuthData.nr_enc = bytes_to_num(cmd, cmdsize);
+                               AuthData.ar_enc = bytes_to_num(&cmd[3], cmdsize);
                                return;
                        } else {
                                MifareAuthState = masError;
@@ -207,8 +221,8 @@ void annotateMifare(char *exp, size_t size, uint8_t* cmd, uint8_t cmdsize, bool
                case masAt:
                        if (cmdsize == 4 && isResponse) {
                                snprintf(exp,size,"AUTH: at (enc)");
-                               MifareAuthState = masData;
-                               at_enc = bytes_to_num(cmd, cmdsize);
+                               MifareAuthState = masFirstData;
+                               AuthData.at_enc = bytes_to_num(cmd, cmdsize);
                                return;
                        } else {
                                MifareAuthState = masError;
index 9bed08abfcd758bc08a4d198ae5285c8d7ff9c00..6ec2f6fc273e85bacdad0bf6a29bba013e62cfdf 100644 (file)
 #include <stdint.h>
 #include <stdbool.h>
 
+typedef struct {
+       uint32_t uid;       // UID
+       uint32_t nt;        // tag challenge
+       uint32_t nt_enc;    // encrypted tag challenge
+       uint8_t nt_enc_par; // encrypted tag challenge parity
+       uint32_t nr_enc;    // encrypted reader challenge
+       uint32_t ar_enc;    // encrypted reader response
+       uint8_t ar_enc_par; // encrypted reader response parity
+       uint32_t at_enc;    // encrypted tag response
+       uint8_t at_enc_par; // encrypted tag response parity
+       bool first_auth;    // is first authentication
+} TAuthData;
+extern void ClearAuthData();
+
 extern uint8_t iso14443A_CRC_check(bool isResponse, uint8_t* data, uint8_t len);
 extern uint8_t mifare_CRC_check(bool isResponse, uint8_t* data, uint8_t len);
 extern void annotateIso14443a(char *exp, size_t size, uint8_t* cmd, uint8_t cmdsize);
Impressum, Datenschutz