]> git.zerfleddert.de Git - proxmark3-svn/commitdiff
@Marshmellow42 's cleanup isn device-side "hf mfu" code. Looks nice. Dump uses...
authoriceman1001 <iceman@iuse.se>
Mon, 18 May 2015 18:58:33 +0000 (20:58 +0200)
committericeman1001 <iceman@iuse.se>
Mon, 18 May 2015 18:58:33 +0000 (20:58 +0200)
Consistency on the client-side code "hf mfu".  looks nice.

armsrc/appmain.c
armsrc/mifarecmd.c
armsrc/mifareutil.c
client/cmdhfmfu.c
client/cmdhfmfu.h
client/lualibs/commands.lua
include/usb_cmd.h

index be4a5f47f55d1c7d6c00130d34ab0d9ad4693846..8748f5dc0c63a49362f64d9a4f7f25a17cdece5f 100644 (file)
@@ -832,7 +832,6 @@ void UsbPacketReceived(uint8_t *packet, int len)
                        MifareUC_Auth(c->arg[0],c->d.asBytes);
                        break;
                case CMD_MIFAREU_READCARD:
-               case CMD_MIFAREUC_READCARD:
                        MifareUReadCard(c->arg[0], c->arg[1], c->arg[2], c->d.asBytes);
                        break;          
                case CMD_MIFAREUC_SETPWD: 
index fb71b17111c9a8f92490c26917be2614151a13aa..45d034380f78defa1331c2d6e9d3564ed1ef74bd 100644 (file)
@@ -101,18 +101,17 @@ void MifareUC_Auth(uint8_t arg0, uint8_t *keybytes){
                return;\r
        };\r
        \r
-       if(mifare_ultra_auth(keybytes) == 1){\r
+       if(!mifare_ultra_auth(keybytes)){\r
                if (MF_DBGLEVEL >= MF_DBG_ERROR) Dbprintf("Authentication failed");\r
                OnError(1);\r
                return;\r
        }\r
     \r
-       cmd_send(CMD_ACK,1,0,0,0,0);\r
-\r
        if (turnOffField) {\r
                FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);\r
                LEDsoff();\r
        }       \r
+       cmd_send(CMD_ACK,1,0,0,0,0);\r
 }\r
 \r
 // Arg0 = BlockNo,\r
@@ -142,7 +141,7 @@ void MifareUReadBlock(uint8_t arg0, uint8_t arg1, uint8_t *datain)
                uint8_t key[16] = {0x00};       \r
                memcpy(key, datain, sizeof(key) );\r
 \r
-               if ( mifare_ultra_auth(key)  == 1 )     {\r
+               if ( !mifare_ultra_auth(key) ) {\r
                        OnError(1);\r
                        return;                 \r
                }\r
@@ -153,8 +152,7 @@ void MifareUReadBlock(uint8_t arg0, uint8_t arg1, uint8_t *datain)
                uint8_t pwd[4] = {0x00};\r
                memcpy(pwd, datain, 4);\r
                uint8_t pack[4] = {0,0,0,0};\r
-\r
-               if (mifare_ul_ev1_auth(pwd, pack) == 1){\r
+               if (!mifare_ul_ev1_auth(pwd, pack)) {\r
                        OnError(1);\r
                        return;                 \r
                }\r
@@ -176,6 +174,7 @@ void MifareUReadBlock(uint8_t arg0, uint8_t arg1, uint8_t *datain)
        FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);\r
        LEDsoff();\r
 }\r
+\r
 //-----------------------------------------------------------------------------\r
 // Select, Authenticate, Read a MIFARE tag. \r
 // read sector (data = 4 x 16 bytes = 64 bytes, or 16 x 16 bytes = 256 bytes)\r
@@ -212,6 +211,7 @@ void MifareReadSector(uint8_t arg0, uint8_t arg1, uint8_t arg2, uint8_t *datain)
                if (MF_DBGLEVEL >= 1)   Dbprintf("Can't select card");\r
        }\r
        \r
+       \r
        if(isOK && mifare_classic_auth(pcs, cuid, FirstBlockOfSector(sectorNo), keyType, ui64Key, AUTH_FIRST)) {\r
                isOK = 0;\r
                if (MF_DBGLEVEL >= 1)   Dbprintf("Auth error");\r
@@ -254,8 +254,8 @@ void MifareUReadCard(uint8_t arg0, uint16_t arg1, uint8_t arg2, uint8_t *datain)
        uint16_t blocks = arg1;\r
        bool useKey = (arg2 == 1); //UL_C\r
        bool usePwd = (arg2 == 2); //UL_EV1/NTAG\r
-       int countblocks = 0;\r
-       uint8_t dataout[176] = {0x00};\r
+       uint32_t countblocks = 0;\r
+       uint8_t *dataout = BigBuf_get_addr();\r
 \r
        LEDsoff();\r
        LED_A_ON(); \r
@@ -274,7 +274,7 @@ void MifareUReadCard(uint8_t arg0, uint16_t arg1, uint8_t arg2, uint8_t *datain)
                uint8_t key[16] = {0x00};       \r
                memcpy(key, datain, sizeof(key) );\r
 \r
-               if ( mifare_ultra_auth(key)  == 1 )     {\r
+               if ( !mifare_ultra_auth(key) ) {\r
                        OnError(1);\r
                        return;                 \r
                }\r
@@ -286,19 +286,30 @@ void MifareUReadCard(uint8_t arg0, uint16_t arg1, uint8_t arg2, uint8_t *datain)
                memcpy(pwd, datain, sizeof(pwd));\r
                uint8_t pack[4] = {0,0,0,0};\r
 \r
-               if (mifare_ul_ev1_auth(pwd, pack) == 1){\r
+               if (!mifare_ul_ev1_auth(pwd, pack)){\r
                        OnError(1);\r
                        return;                 \r
                }\r
        }\r
        \r
        for (int i = 0; i < blocks; i++){\r
-               len = mifare_ultra_readblock(blockNo * 4 + i, dataout + 4 * i);\r
+               if ((i*4) + 4 > BigBuf_get_traceLen()) {\r
+                       Dbprintf("Data exceeds buffer!!");\r
+                       break;\r
+               }\r
+       \r
+               len = mifare_ultra_readblock(blockNo + i, dataout + 4 * i);\r
                \r
                if (len) {\r
                        if (MF_DBGLEVEL >= MF_DBG_ERROR) Dbprintf("Read block %d error",i);\r
+                       // if no blocks read - error out\r
+                       if (i==0){\r
                        OnError(2);\r
                        return;\r
+                       } else {\r
+                               //stop at last successful read block and return what we got\r
+                               break;\r
+                       }\r
                } else {\r
                        countblocks++;\r
                }\r
@@ -313,9 +324,8 @@ void MifareUReadCard(uint8_t arg0, uint16_t arg1, uint8_t arg2, uint8_t *datain)
        \r
        if (MF_DBGLEVEL >= MF_DBG_EXTENDED) Dbprintf("Blocks read %d", countblocks);\r
 \r
-       len = blocks*4;\r
-\r
-       cmd_send(CMD_ACK, 1, len, 0, dataout, len);     \r
+       countblocks *= 4;\r
+       cmd_send(CMD_ACK, 1, countblocks, countblocks, 0, 0);\r
        FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);\r
        LEDsoff();\r
 }\r
@@ -392,7 +402,6 @@ void MifareWriteBlock(uint8_t arg0, uint8_t arg1, uint8_t arg2, uint8_t *datain)
        LEDsoff();\r
 }\r
 \r
-\r
 void MifareUWriteBlock(uint8_t arg0, uint8_t *datain)\r
 {\r
     uint8_t blockNo = arg0;\r
@@ -435,7 +444,6 @@ void MifareUWriteBlock_Special(uint8_t arg0, uint8_t *datain)
 {\r
        uint8_t blockNo = arg0;\r
        byte_t blockdata[4] = {0x00};\r
-       uint8_t uid[10] = {0x00};\r
        \r
        memcpy(blockdata, datain,4);\r
        \r
@@ -444,7 +452,7 @@ void MifareUWriteBlock_Special(uint8_t arg0, uint8_t *datain)
        clear_trace();\r
        iso14443a_setup(FPGA_HF_ISO14443A_READER_LISTEN);\r
 \r
-       if(!iso14443a_select_card(uid, NULL, NULL)) {\r
+       if(!iso14443a_select_card(NULL, NULL, NULL)) {\r
                if (MF_DBGLEVEL >= 1) Dbprintf("Can't select card");\r
                OnError(0);\r
                return;\r
index 4a360170ff283894b423e792f90c0e3715e5a22f..8c44445f5c01a614cc41a0b88de01617c03d0123 100644 (file)
@@ -322,15 +322,14 @@ int mifare_ul_ev1_auth(uint8_t *keybytes, uint8_t *pack){
        len = mifare_sendcmd_short_mfuev1auth(NULL, 0, 0x1B, key, resp, respPar, NULL);\r
        if (len != 4) {\r
                if (MF_DBGLEVEL >= MF_DBG_ERROR) Dbprintf("Cmd Error: %02x %u", resp[0], len);\r
-               OnError(1);\r
-               return 1;\r
+               return 0;\r
        }\r
        \r
        if (MF_DBGLEVEL >= MF_DBG_EXTENDED)\r
                Dbprintf("Auth Resp: %02x%02x%02x%02x", resp[0],resp[1],resp[2],resp[3]);\r
        \r
        memcpy(pack, resp, 4);\r
-       return 0;\r
+       return 1;\r
 }\r
 \r
 int mifare_ultra_auth(uint8_t *keybytes){\r
@@ -352,8 +351,7 @@ int mifare_ultra_auth(uint8_t *keybytes){
        len = mifare_sendcmd_short(NULL, 1, 0x1A, 0x00, resp, respPar ,NULL);\r
        if (len != 11) {\r
                if (MF_DBGLEVEL >= MF_DBG_ERROR) Dbprintf("Cmd Error: %02x", resp[0]);\r
-               OnError(1);\r
-               return 1;\r
+               return 0;\r
        }\r
 \r
        // tag nonce.\r
@@ -385,8 +383,7 @@ int mifare_ultra_auth(uint8_t *keybytes){
        len = mifare_sendcmd_short_mfucauth(NULL, 1, 0xAF, rnd_ab, resp, respPar, NULL);\r
        if (len != 11) {\r
                if (MF_DBGLEVEL >= MF_DBG_ERROR) Dbprintf("Cmd Error: %02x", resp[0]);\r
-               OnError(1);\r
-               return 1;\r
+               return 0;\r
        }\r
 \r
        uint8_t enc_resp[8] = { 0,0,0,0,0,0,0,0 };\r
@@ -397,7 +394,7 @@ int mifare_ultra_auth(uint8_t *keybytes){
        tdes_2key_dec(resp_random_a, enc_resp, 8, key, enc_random_b);\r
        if ( memcmp(resp_random_a, random_a, 8) != 0 ) {\r
                if (MF_DBGLEVEL >= MF_DBG_ERROR) Dbprintf("failed authentication");\r
-               return 1;\r
+               return 0;\r
        }       \r
 \r
        if (MF_DBGLEVEL >= MF_DBG_EXTENDED) {\r
@@ -417,7 +414,7 @@ int mifare_ultra_auth(uint8_t *keybytes){
                                resp_random_a[0],resp_random_a[1],resp_random_a[2],resp_random_a[3],\r
                                resp_random_a[4],resp_random_a[5],resp_random_a[6],resp_random_a[7]);\r
        }\r
-       return 0;\r
+       return 1;\r
 }\r
 \r
 int mifare_ultra_readblock(uint8_t blockNo, uint8_t *blockData)\r
index d905ec82afd7a0be6741b1f6ec9cefd6346bf49e..efeda8b9d999f50398735f4e91ed7cfa8b3433e3 100644 (file)
 #include "mifare.h"
 #include "util.h"
 #include "../common/protocols.h"
+#include "data.h"
 
 #define MAX_UL_BLOCKS          0x0f
-#define MAX_ULC_BLOCKS         0x2f
+#define MAX_ULC_BLOCKS    0x2b
 #define MAX_ULEV1a_BLOCKS   0x12
 #define MAX_ULEV1b_BLOCKS      0x20
 #define MAX_NTAG_213           0x2c
@@ -157,8 +158,6 @@ static int ul_read( uint8_t page, uint8_t *response, uint16_t responseLength ){
        
        uint8_t cmd[] = {ISO14443A_CMD_READBLOCK, page};
        int len = ul_send_cmd_raw(cmd, sizeof(cmd), response, responseLength);
-       if ( len == -1 )
-               ul_switch_off_field();
        return len;
 }
 
@@ -173,9 +172,7 @@ static int ul_comp_write( uint8_t page, uint8_t *data, uint8_t datalen ){
        memcpy(cmd+2, data, datalen);
 
        uint8_t response[1] = {0xff};
-       int len = ul_send_cmd_raw(cmd, 2+datalen, response, sizeof(response));
-       if ( len == -1 )
-               ul_switch_off_field();
+       ul_send_cmd_raw(cmd, 2+datalen, response, sizeof(response));
        // ACK
        if ( response[0] == 0x0a ) return 0;
        // NACK
@@ -186,8 +183,6 @@ static int ulc_requestAuthentication( uint8_t *nonce, uint16_t nonceLength ){
        
        uint8_t cmd[] = {MIFARE_ULC_AUTH_1, 0x00};
        int len = ul_send_cmd_raw(cmd, sizeof(cmd), nonce, nonceLength);
-       if ( len == -1 ) 
-               ul_switch_off_field();
        return len;
 }
 
@@ -197,18 +192,16 @@ static int ulc_authentication( uint8_t *key, bool switch_off_field ){
        memcpy(c.d.asBytes, key, 16);   
        SendCommand(&c);
        UsbCommand resp;
-       if ( !WaitForResponseTimeout(CMD_ACK, &resp, 1500) )    return -1;
-       if ( resp.arg[0] == 1 ) return 0;
+       if ( !WaitForResponseTimeout(CMD_ACK, &resp, 1500) ) return 0;
+       if ( resp.arg[0] == 1 ) return 1;
        
-       return -2;
+       return 0;
 }
 
 static int ulev1_requestAuthentication( uint8_t *pwd, uint8_t *pack, uint16_t packLength ){
        
        uint8_t cmd[] = {MIFARE_ULEV1_AUTH, pwd[0], pwd[1], pwd[2], pwd[3]};
        int len = ul_send_cmd_raw(cmd, sizeof(cmd), pack, packLength);
-       if ( len == -1)
-               ul_switch_off_field();
        return len;
 }
 
@@ -216,8 +209,6 @@ static int ulev1_getVersion( uint8_t *response, uint16_t responseLength ){
        
        uint8_t cmd[] = {MIFARE_ULEV1_VERSION}; 
        int len = ul_send_cmd_raw(cmd, sizeof(cmd), response, responseLength);
-       if ( len == -1 )
-               ul_switch_off_field();
        return len;
 }
 
@@ -226,7 +217,6 @@ static int ulev1_getVersion( uint8_t *response, uint16_t responseLength ){
        // uint8_t cmd[] = {MIFARE_ULEV1_FASTREAD, startblock, endblock};
        
        // if ( !ul_send_cmd_raw(cmd, sizeof(cmd), response)){
-               // ul_switch_off_field();
                // return -1;
        // }
        // return 0;
@@ -236,8 +226,6 @@ static int ulev1_readCounter( uint8_t counter, uint8_t *response, uint16_t respo
 
        uint8_t cmd[] = {MIFARE_ULEV1_READ_CNT, counter};
        int len = ul_send_cmd_raw(cmd, sizeof(cmd), response, responseLength);
-       if (len == -1)
-               ul_switch_off_field();
        return len;
 }
 
@@ -245,8 +233,6 @@ static int ulev1_readTearing( uint8_t counter, uint8_t *response, uint16_t respo
 
        uint8_t cmd[] = {MIFARE_ULEV1_CHECKTEAR, counter};
        int len = ul_send_cmd_raw(cmd, sizeof(cmd), response, responseLength);
-       if (len == -1)
-               ul_switch_off_field();
        return len;
 }
 
@@ -254,8 +240,6 @@ static int ulev1_readSignature( uint8_t *response, uint16_t responseLength ){
 
        uint8_t cmd[] = {MIFARE_ULEV1_READSIG, 0x00};
        int len = ul_send_cmd_raw(cmd, sizeof(cmd), response, responseLength);
-       if (len == -1)
-               ul_switch_off_field();
        return len;
 }
 
@@ -536,7 +520,7 @@ uint16_t GetHF14AMfU_Type(void){
        if ( card.uid[0] != 0x05) {
 
                len  = ulev1_getVersion(version, sizeof(version));
-               if (len > -1) ul_switch_off_field();  //if -1 it is already off
+               ul_switch_off_field();
        
                switch (len) {
                        case 0x0A: {
@@ -558,7 +542,7 @@ uint16_t GetHF14AMfU_Type(void){
                                }
                        case 0x01: tagtype = UL_C; break;
                        case 0x00: tagtype = UL; break;
-                       case -1  : tagtype = (UL | UL_C); break;  //when does this happen? -- if getversion fails, it assumes it is either UL/ULC
+                       case -1  : tagtype = (UL | UL_C); break;  //when does this happen?
                        default  : tagtype = UNKNOWN; break;
                }
                // UL-C test
@@ -573,7 +557,7 @@ uint16_t GetHF14AMfU_Type(void){
                        status = ulc_requestAuthentication(nonce, sizeof(nonce));
                        tagtype = ( status > 0 ) ? UL_C : UL;
 
-                       if (status != -1) ul_switch_off_field();
+                       ul_switch_off_field();
                }
        } else {
                // Infinition MY-D tests   Exam high nibble 
@@ -651,26 +635,23 @@ int CmdHF14AMfUInfo(const char *Cmd){
        PrintAndLog("-------------------------------------------------------------");
        ul_print_type(tagtype, 6);
        
-       status = ul_select(&card);
-       if ( status < 1 ){
-               PrintAndLog("iso14443a card select failed");
-               ul_switch_off_field();
-               return status;
-       }
-       
-       if ( hasAuthKey ) {
-               if ((tagtype & UL_C)) {
-                       ul_switch_off_field();
-                       //will select card automatically
-                       if (ulc_authentication(authenticationkey, false) != 1) {
-                               ul_switch_off_field();
+       if ( hasAuthKey && (tagtype & UL_C)) {
+               //will select card automatically and close connection on error
+               if (!ulc_authentication(authenticationkey, false)) {
                                PrintAndLog("Error: Authentication Failed UL-C");
                                return 0;
                        }
                } else {
+               status = ul_select(&card);
+               if ( status < 1 ){
+                       PrintAndLog("iso14443a card select failed");
+                       ul_switch_off_field();
+                       return status;
+               }
+               if (hasAuthKey) {
                        len = ulev1_requestAuthentication(authenticationkey, pack, sizeof(pack));
                        if (len < 1) {
-                               if (!len) ul_switch_off_field();
+                               ul_switch_off_field();
                                PrintAndLog("Error: Authentication Failed UL-EV1/NTAG");
                                return 0;
                        }
@@ -681,7 +662,8 @@ int CmdHF14AMfUInfo(const char *Cmd){
        // read pages 0,1,2,4 (should read 4pages)
        status = ul_read(0, data, sizeof(data));
        if ( status == -1 ){
-               PrintAndLog("Error: tag didn't answer to READ A");
+               ul_switch_off_field();
+               PrintAndLog("Error: tag didn't answer to READ");
                return status;
        }
 
@@ -694,6 +676,7 @@ int CmdHF14AMfUInfo(const char *Cmd){
                status = ul_read(0x28, ulc_conf, sizeof(ulc_conf));
                if ( status == -1 ){
                        PrintAndLog("Error: tag didn't answer to READ UL-C");
+                       ul_switch_off_field();
                        return status;
                } 
                ulc_print_configuration(ulc_conf);
@@ -703,21 +686,22 @@ int CmdHF14AMfUInfo(const char *Cmd){
                        uint8_t ulc_deskey[16] = {0x00};
                        status = ul_read(0x2C, ulc_deskey, sizeof(ulc_deskey));
                        if ( status == -1 ){
+                               ul_switch_off_field();
                                PrintAndLog("Error: tag didn't answer to READ magic");
                                return status;
                        }
                        ulc_print_3deskey(ulc_deskey);
 
                } else {
+                       ul_switch_off_field();
                        // if we called info with key, just return 
                        if ( hasAuthKey ) return 1;
                        
                        // also try to diversify default keys..  look into CmdHF14AMfuGenDiverseKeys
                        PrintAndLog("Trying some default 3des keys");
-                       ul_switch_off_field(); //will select again in try3DesAuth...
                        for (uint8_t i = 0; i < KEYS_3DES_COUNT; ++i ){
                                key = default_3des_keys[i];
-                               if (ulc_authentication(key, true) == 0){
+                               if (ulc_authentication(key, true)){
                                        PrintAndLog("Found default 3des key: "); //%s", sprint_hex(key,16));
                                        uint8_t keySwap[16];
                                        memcpy(keySwap, SwapEndian64(key,16,8), 16);
@@ -737,6 +721,7 @@ int CmdHF14AMfUInfo(const char *Cmd){
                status = ulev1_readSignature( ulev1_signature, sizeof(ulev1_signature));
                if ( status == -1 ){
                        PrintAndLog("Error: tag didn't answer to READ SIGNATURE");
+                       ul_switch_off_field();
                        return status;
                }               
                ulev1_print_signature( ulev1_signature, sizeof(ulev1_signature));
@@ -746,6 +731,7 @@ int CmdHF14AMfUInfo(const char *Cmd){
                status = ul_read(startconfigblock, ulev1_conf, sizeof(ulev1_conf));
                if ( status == -1 ){
                        PrintAndLog("Error: tag didn't answer to READ EV1");
+                       ul_switch_off_field();
                        return status;
                }
                // save AUTHENTICATION LIMITS for later:
@@ -763,31 +749,39 @@ int CmdHF14AMfUInfo(const char *Cmd){
                uint8_t version[10] = {0x00};
                status  = ulev1_getVersion(version, sizeof(version));
                if ( status == -1 ){
-                       PrintAndLog("Error: tag didn't answer to GET_VERSION");
+                       PrintAndLog("Error: tag didn't answer to GETVERSION");
+                       ul_switch_off_field();
                        return status;
                }
                ulev1_print_version(version);
 
                // if we called info with key, just return 
-               if ( hasAuthKey ) return 1;
+               if ( hasAuthKey ) {
+                       ul_switch_off_field();
+                       return 1;
+               }
                
                // AUTHLIMIT, (number of failed authentications)
                // 0 = limitless.
                // 1-7 = ...  should we even try then?          
                if ( authlim == 0 ){
                        PrintAndLog("\n--- Known EV1/NTAG passwords.");
-               
-
-                       int len=0; //if len goes to -1 the connection will be turned off.
+                       len = 0;
                        for (uint8_t i = 0; i < KEYS_PWD_COUNT; ++i ){
                                key = default_pwd_pack[i];
-                               if ( len > -1 ){
                                        len = ulev1_requestAuthentication(key, pack, sizeof(pack));
+                               if (len >= 1) {
                                        PrintAndLog("Found a default password: %s || Pack: %02X %02X",sprint_hex(key, 4), pack[0], pack[1]);
                                        break;
+                               } else {
+                                       status = ul_select(&card);
+                                       if ( status < 1 ){
+                                               PrintAndLog("iso14443a card select failed - ev1 auth");
+                                               ul_switch_off_field();
+                                               return status;
                                }
                        }
-                       if (len > -1) ul_switch_off_field();
+                       }
                }
        }
        
@@ -797,6 +791,7 @@ int CmdHF14AMfUInfo(const char *Cmd){
                status = ul_read(3, cc, sizeof(cc));
                if ( status == -1 ){
                        PrintAndLog("Error: tag didn't answer to READ ntag");
+                       ul_switch_off_field();
                        return status;
                }
                ntag_print_CC(cc);      
@@ -973,7 +968,6 @@ int CmdHF14AMfUDump(const char *Cmd){
        bool bit2[16] = {0x00};
        uint8_t data[1024] = {0x00};
        bool hasPwd = false;
-       bool hasKey = false;
        int i = 0;
        int Pages = 16;
        bool tmplockbit = false;
@@ -998,18 +992,17 @@ int CmdHF14AMfUDump(const char *Cmd){
                case 'k':
                case 'K':
                        dataLen = param_getstr(Cmd, cmdp+1, tempStr);
-                       if (dataLen == 32) {
+                       if (dataLen == 32) //ul-c
                                errors = param_gethex(tempStr, 0, key, dataLen);
-                               hasKey = true;
-                       }
-                       else if (dataLen == 8) {
+                       else if (dataLen == 8) //ev1/ntag
                                errors = param_gethex(tempStr, 0, key, dataLen);
-                               hasPwd = true;
+                       else{
+                               PrintAndLog("\nERROR: Key is incorrect length\n");
+                               errors = true;
                        }
-                       else
-                               errors = true; 
                                
                        cmdp += 2;
+                               hasPwd = true;
                        break;
                case 'l':
                case 'L':
@@ -1046,8 +1039,8 @@ int CmdHF14AMfUDump(const char *Cmd){
        //Validations
        if(errors) return usage_hf_mfu_dump();
        
-       //if (swapEndian && hasKey )
-       //      keyPtr = SwapEndian64(data, 16, 8);
+       if (swapEndian && dataLen == 32)
+               keyPtr = SwapEndian64(data, 16, 8);
 
        TagTypeUL_t tagtype = GetHF14AMfU_Type();
        if (tagtype == UL_ERROR) return -1;
@@ -1059,33 +1052,35 @@ int CmdHF14AMfUDump(const char *Cmd){
 
        ul_print_type(tagtype, 0);
        PrintAndLog("Reading tag memory...");
-
-       UsbCommand c = {CMD_MIFAREUC_READCARD, {startPage, Pages}};
-       
-       if ( hasKey ) { 
-               c.arg[2] = 1; 
-               memcpy(c.d.asBytes, key, 16);
-       }
+       UsbCommand c = {CMD_MIFAREU_READCARD, {startPage,Pages}};
        if ( hasPwd ) { 
-               c.arg[2] = 2;
-               memcpy(c.d.asBytes, key, 4);
+               if (tagtype & UL_C)
+                       c.arg[2] = 1; //UL_C auth
+               else
+                       c.arg[2] = 2; //UL_EV1/NTAG auth
+
+               memcpy(c.d.asBytes, key, dataLen/2);
        }
-       
        SendCommand(&c);
        UsbCommand resp;
        if (!WaitForResponseTimeout(CMD_ACK,&resp,1500)) {
                PrintAndLog("Command execute time-out");
                return 1;
        }
-       PrintAndLog     ("%u,%u",resp.arg[0],resp.arg[1]);
-       uint8_t isOK = resp.arg[0] & 0xff;
-       if (isOK) {
-               memcpy(data, resp.d.asBytes, resp.arg[1]);
-       } else {
+       if (resp.arg[0] != 1) {
                PrintAndLog("Failed reading block: (%02x)", i);
                return 1;
        }
 
+       uint32_t bufferSize = resp.arg[1];
+       if (bufferSize > sizeof(data)) {
+               PrintAndLog("Data exceeded Buffer size!");
+               bufferSize = sizeof(data);
+       }
+       GetFromBigBuf(data, bufferSize, 0);
+       WaitForResponse(CMD_ACK,NULL);
+
+       Pages = bufferSize/4;
        // Load lock bytes.
        int j = 0;
        
@@ -1107,19 +1102,15 @@ int CmdHF14AMfUDump(const char *Cmd){
                }
        }
 
-       // add keys UL_C
-       if (hasKey ){ 
-               memcpy(data + Pages*4, key, 16);
+       // add keys to block dump
+       if (hasPwd && (tagtype & UL_C)){ //UL_C
+               memcpy(data + Pages*4, key, dataLen/2);
                Pages += 4;
-       }
-       // add keys ULEV1 / NTAG
-       if (hasPwd ){ 
-               memcpy(data + Pages*4, key, 4);
+       } else if (hasPwd) { //not sure output is in correct location.
+               memcpy(data + Pages*4, key, dataLen/2);
                Pages += 1;
        }
        
-       //TODO add key MEM location for other tags
-
        for (i = 0; i < Pages; ++i) {
                if ( i < 3 ) {
                        PrintAndLog("Block %02x:%s ", i,sprint_hex(data + i * 4, 4));
@@ -1192,15 +1183,6 @@ int CmdHF14AMfUDump(const char *Cmd){
        return 0;
 }
 
-// // Needed to Authenticate to Ultralight C tags
-// void rol (uint8_t *data, const size_t len){
-       // uint8_t first = data[0];
-       // for (size_t i = 0; i < len-1; i++) {
-               // data[i] = data[i+1];
-       // }
-       // data[len-1] = first;
-// }
-
 //-------------------------------------------------------------------------------
 // Ultralight C Methods
 //-------------------------------------------------------------------------------
@@ -1240,7 +1222,7 @@ int CmdHF14AMfucAuth(const char *Cmd){
        } 
 
        uint8_t *key = default_3des_keys[keyNo];
-       if (ulc_authentication(key, true) == 0)
+       if (ulc_authentication(key, true))
                PrintAndLog("Authentication successful. 3des key: %s",sprint_hex(key, 16));
        else
                PrintAndLog("Authentication failed");
@@ -1248,7 +1230,6 @@ int CmdHF14AMfucAuth(const char *Cmd){
        return 0;
 }
 
-
 /**
 A test function to validate that the polarssl-function works the same 
 was as the openssl-implementation. 
@@ -1704,6 +1685,9 @@ int CmdHF14AMfuGenDiverseKeys(const char *Cmd){
        // return;
 // }
 
+//------------------------------------
+// Menu Stuff
+//------------------------------------
 static command_t CommandTable[] =
 {
        {"help",        CmdHelp,                        1, "This help"},
index 2fd19d704733babcee484d6d88e3cfaf398910ed..9773b246713f44273b8bcd7a45a2cf057c207cca 100644 (file)
@@ -14,16 +14,16 @@ int CmdHF14AMfUCRdCard(const char *Cmd);
 int CmdHF14AMfucAuth(const char *Cmd);
 
 //general stuff
-int CmdHF14AMfUInfo(const char *Cmd);
 int CmdHF14AMfUDump(const char *Cmd);
+int CmdHF14AMfUInfo(const char *Cmd);
 uint16_t GetHF14AMfU_Type(void);
 
 //void rol (uint8_t *data, const size_t len);
 int ul_print_type(uint16_t tagtype, uint8_t spacer);
 void ul_switch_off_field(void);
 
-int usage_hf_mfu_info(void);
 int usage_hf_mfu_dump(void);
+int usage_hf_mfu_info(void);
 
 int CmdHFMFUltra(const char *Cmd);
 
index b0257ef0eb0d27f125b9b0a52b5b2fc994a6fbd9..bedb83678d48d562ea57e1459ba986f6fd480a8a 100644 (file)
@@ -135,9 +135,7 @@ local _commands = {
        CMD_MIFARE_SNIFFER =                                                 0x0630,
 
        --//ultralightC
-       CMD_MIFAREUC_AUTH1 =                                                                     0x0724,
-       CMD_MIFAREUC_AUTH2 =                                                                     0x0725,
-       CMD_MIFAREUC_READCARD =                                                                      0x0726,
+       CMD_MIFAREUC_AUTH =                                                  0x0724,
        CMD_MIFAREUC_SETPWD =                                                                                            0x0727,
        CMD_MIFAREU_SETUID =                                                                         0x0728,
 
index 1910312bad4a769d29b44019b9394f50a77ea823..2a6e94842e904fb106d5ea11b3c3a8948398e065 100644 (file)
@@ -165,10 +165,8 @@ typedef struct{
 
 #define CMD_MIFARE_READBL                                                 0x0620
 #define CMD_MIFAREU_READBL                                                                       0x0720
-
 #define CMD_MIFARE_READSC                                                 0x0621
 #define CMD_MIFAREU_READCARD                                                                 0x0721
-
 #define CMD_MIFARE_WRITEBL                                                0x0622
 #define CMD_MIFAREU_WRITEBL                                                                      0x0722
 #define CMD_MIFAREU_WRITEBL_COMPAT                                                           0x0723
@@ -176,12 +174,11 @@ typedef struct{
 #define CMD_MIFARE_CHKKEYS                                                0x0623
 
 #define CMD_MIFARE_SNIFFER                                                0x0630
-
 //ultralightC
 #define CMD_MIFAREUC_AUTH                                                                        0x0724
-#define CMD_MIFAREUC_READCARD                                                                0x0726
+//0x0725 and 0x0726 no longer used 
 #define CMD_MIFAREUC_SETPWD                                                                          0x0727
-#define CMD_MIFAREU_SETUID                                                                           0x0728
+
 
 // mifare desfire
 #define CMD_MIFARE_DESFIRE_READBL                                         0x0728
Impressum, Datenschutz