]> git.zerfleddert.de Git - proxmark3-svn/blobdiff - client/cmdhfmfu.c
Add smartcard protocol T=0 (RRG repository PRs 71,72,74,75 by @merlokk) (#757)
[proxmark3-svn] / client / cmdhfmfu.c
index c95fa20b9eb1e8fb5ff404a3f98bd33e4350a814..c3442ee3b26de848c3dc17d6a353f4a2cf494714 100644 (file)
 
 #include <stdint.h>
 #include <stdio.h>
 
 #include <stdint.h>
 #include <stdio.h>
-#include "proxmark3.h"
+#include "comms.h"
 #include "usb_cmd.h"
 #include "cmdmain.h"
 #include "ui.h"
 #include "usb_cmd.h"
 #include "cmdmain.h"
 #include "ui.h"
-#include "polarssl/des.h"
+#include "mbedtls/des.h"
 #include "cmdhfmf.h"
 #include "cmdhf14a.h"
 #include "mifare.h"
 #include "util.h"
 #include "protocols.h"
 #include "cmdhfmf.h"
 #include "cmdhf14a.h"
 #include "mifare.h"
 #include "util.h"
 #include "protocols.h"
-#include "data.h"
 
 #define MAX_UL_BLOCKS      0x0f
 #define MAX_ULC_BLOCKS     0x2b
 
 #define MAX_UL_BLOCKS      0x0f
 #define MAX_ULC_BLOCKS     0x2b
@@ -153,7 +152,7 @@ static int ul_select( iso14a_card_select_t *card ){
        ans = WaitForResponseTimeout(CMD_ACK, &resp, 1500);
        if (!ans || resp.arg[0] < 1) {
                PrintAndLog("iso14443a card select failed");
        ans = WaitForResponseTimeout(CMD_ACK, &resp, 1500);
        if (!ans || resp.arg[0] < 1) {
                PrintAndLog("iso14443a card select failed");
-               ul_switch_off_field();
+               DropField();
                return 0;
        }
 
                return 0;
        }
 
@@ -226,7 +225,7 @@ static int ul_auth_select( iso14a_card_select_t *card, TagTypeUL_t tagtype, bool
 
                if (hasAuthKey) {
                        if (ulev1_requestAuthentication(authenticationkey, pack, packSize) < 1) {
 
                if (hasAuthKey) {
                        if (ulev1_requestAuthentication(authenticationkey, pack, packSize) < 1) {
-                               ul_switch_off_field();
+                               DropField();
                                PrintAndLog("Error: Authentication Failed UL-EV1/NTAG");
                                return 0;
                        }
                                PrintAndLog("Error: Authentication Failed UL-EV1/NTAG");
                                return 0;
                        }
@@ -550,7 +549,7 @@ static int ulc_magic_test(){
        } else {
                returnValue = UL;
        }       
        } else {
                returnValue = UL;
        }       
-       ul_switch_off_field();
+       DropField();
        return returnValue;
 }
 */
        return returnValue;
 }
 */
@@ -563,7 +562,7 @@ static int ul_magic_test(){
        if ( !ul_select(&card) ) 
                return UL_ERROR;
        int status = ul_comp_write(0, NULL, 0);
        if ( !ul_select(&card) ) 
                return UL_ERROR;
        int status = ul_comp_write(0, NULL, 0);
-       ul_switch_off_field();
+       DropField();
        if ( status == 0 ) 
                return MAGIC;
        return 0;
        if ( status == 0 ) 
                return MAGIC;
        return 0;
@@ -582,14 +581,14 @@ uint32_t GetHF14AMfU_Type(void){
        // Ultralight - ATQA / SAK 
        if ( card.atqa[1] != 0x00 || card.atqa[0] != 0x44 || card.sak != 0x00 ) {
                PrintAndLog("Tag is not Ultralight | NTAG | MY-D  [ATQA: %02X %02X SAK: %02X]\n", card.atqa[1], card.atqa[0], card.sak);
        // Ultralight - ATQA / SAK 
        if ( card.atqa[1] != 0x00 || card.atqa[0] != 0x44 || card.sak != 0x00 ) {
                PrintAndLog("Tag is not Ultralight | NTAG | MY-D  [ATQA: %02X %02X SAK: %02X]\n", card.atqa[1], card.atqa[0], card.sak);
-               ul_switch_off_field();
+               DropField();
                return UL_ERROR;
        }
 
        if ( card.uid[0] != 0x05) {
 
                len  = ulev1_getVersion(version, sizeof(version));
                return UL_ERROR;
        }
 
        if ( card.uid[0] != 0x05) {
 
                len  = ulev1_getVersion(version, sizeof(version));
-               ul_switch_off_field();
+               DropField();
 
                switch (len) {
                        case 0x0A: {
 
                switch (len) {
                        case 0x0A: {
@@ -629,7 +628,7 @@ uint32_t GetHF14AMfU_Type(void){
                        // do UL_C check first...
                        uint8_t nonce[11] = {0x00};
                        status = ulc_requestAuthentication(nonce, sizeof(nonce));
                        // do UL_C check first...
                        uint8_t nonce[11] = {0x00};
                        status = ulc_requestAuthentication(nonce, sizeof(nonce));
-                       ul_switch_off_field();
+                       DropField();
                        if (status > 1) {
                                tagtype = UL_C;
                        } else { 
                        if (status > 1) {
                                tagtype = UL_C;
                        } else { 
@@ -650,15 +649,15 @@ uint32_t GetHF14AMfU_Type(void){
                                                tagtype = UNKNOWN;
                                        }
                                }
                                                tagtype = UNKNOWN;
                                        }
                                }
-                               ul_switch_off_field();
+                               DropField();
                        }
                }
                if (tagtype & UL) {
                        tagtype = ul_fudan_check(); 
                        }
                }
                if (tagtype & UL) {
                        tagtype = ul_fudan_check(); 
-                       ul_switch_off_field();
+                       DropField();
                }
        } else {
                }
        } else {
-               ul_switch_off_field();
+               DropField();
                // Infinition MY-D tests   Exam high nibble 
                uint8_t nib = (card.uid[1] & 0xf0) >> 4;
                switch ( nib ){
                // Infinition MY-D tests   Exam high nibble 
                uint8_t nib = (card.uid[1] & 0xf0) >> 4;
                switch ( nib ){
@@ -703,7 +702,7 @@ int CmdHF14AMfUInfo(const char *Cmd){
                        return usage_hf_mfu_info();
                case 'k':
                case 'K':
                        return usage_hf_mfu_info();
                case 'k':
                case 'K':
-                       dataLen = param_getstr(Cmd, cmdp+1, tempStr);
+                       dataLen = param_getstr(Cmd, cmdp+1, tempStr, sizeof(tempStr));
                        if (dataLen == 32 || dataLen == 8) { //ul-c or ev1/ntag key length
                                errors = param_gethex(tempStr, 0, authenticationkey, dataLen);
                                dataLen /= 2; // handled as bytes from now on
                        if (dataLen == 32 || dataLen == 8) { //ul-c or ev1/ntag key length
                                errors = param_gethex(tempStr, 0, authenticationkey, dataLen);
                                dataLen /= 2; // handled as bytes from now on
@@ -745,7 +744,7 @@ int CmdHF14AMfUInfo(const char *Cmd){
        // read pages 0,1,2,3 (should read 4pages)
        status = ul_read(0, data, sizeof(data));
        if ( status == -1 ) {
        // read pages 0,1,2,3 (should read 4pages)
        status = ul_read(0, data, sizeof(data));
        if ( status == -1 ) {
-               ul_switch_off_field();
+               DropField();
                PrintAndLog("Error: tag didn't answer to READ");
                return status;
        } else if (status == 16) {
                PrintAndLog("Error: tag didn't answer to READ");
                return status;
        } else if (status == 16) {
@@ -763,7 +762,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");
                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();
+                       DropField();
                        return status;
                } 
                if (status == 16) ulc_print_configuration(ulc_conf);
                        return status;
                } 
                if (status == 16) ulc_print_configuration(ulc_conf);
@@ -774,14 +773,14 @@ int CmdHF14AMfUInfo(const char *Cmd){
                        uint8_t ulc_deskey[16] = {0x00};
                        status = ul_read(0x2C, ulc_deskey, sizeof(ulc_deskey));
                        if ( status == -1 ) {
                        uint8_t ulc_deskey[16] = {0x00};
                        status = ul_read(0x2C, ulc_deskey, sizeof(ulc_deskey));
                        if ( status == -1 ) {
-                               ul_switch_off_field();
+                               DropField();
                                PrintAndLog("Error: tag didn't answer to READ magic");
                                return status;
                        }
                        if (status == 16) ulc_print_3deskey(ulc_deskey);
 
                } else {
                                PrintAndLog("Error: tag didn't answer to READ magic");
                                return status;
                        }
                        if (status == 16) ulc_print_3deskey(ulc_deskey);
 
                } else {
-                       ul_switch_off_field();
+                       DropField();
                        // if we called info with key, just return 
                        if ( hasAuthKey ) return 1;
 
                        // if we called info with key, just return 
                        if ( hasAuthKey ) return 1;
 
@@ -816,7 +815,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");
                status = ulev1_readSignature( ulev1_signature, sizeof(ulev1_signature));
                if ( status == -1 ) {
                        PrintAndLog("Error: tag didn't answer to READ SIGNATURE");
-                       ul_switch_off_field();
+                       DropField();
                        return status;
                }
                if (status == 32) ulev1_print_signature( ulev1_signature, sizeof(ulev1_signature));
                        return status;
                }
                if (status == 32) ulev1_print_signature( ulev1_signature, sizeof(ulev1_signature));
@@ -831,7 +830,7 @@ int CmdHF14AMfUInfo(const char *Cmd){
                status  = ulev1_getVersion(version, sizeof(version));
                if ( status == -1 ) {
                        PrintAndLog("Error: tag didn't answer to GETVERSION");
                status  = ulev1_getVersion(version, sizeof(version));
                if ( status == -1 ) {
                        PrintAndLog("Error: tag didn't answer to GETVERSION");
-                       ul_switch_off_field();
+                       DropField();
                        return status;
                } else if (status == 10) {
                        ulev1_print_version(version);
                        return status;
                } else if (status == 10) {
                        ulev1_print_version(version);
@@ -851,7 +850,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");
                        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();
+                               DropField();
                                return status;
                        } else if (status == 16) {
                                // save AUTHENTICATION LIMITS for later:
                                return status;
                        } else if (status == 16) {
                                // save AUTHENTICATION LIMITS for later:
@@ -881,7 +880,7 @@ int CmdHF14AMfUInfo(const char *Cmd){
                }
        }
 
                }
        }
 
-       ul_switch_off_field();
+       DropField();
        if (locked) PrintAndLog("\nTag appears to be locked, try using the key to get more info");
        PrintAndLog("");
        return 1;
        if (locked) PrintAndLog("\nTag appears to be locked, try using the key to get more info");
        PrintAndLog("");
        return 1;
@@ -1238,7 +1237,7 @@ int CmdHF14AMfUDump(const char *Cmd){
                        return usage_hf_mfu_dump();
                case 'k':
                case 'K':
                        return usage_hf_mfu_dump();
                case 'k':
                case 'K':
-                       dataLen = param_getstr(Cmd, cmdp+1, tempStr);
+                       dataLen = param_getstr(Cmd, cmdp+1, tempStr, sizeof(tempStr));
                        if (dataLen == 32 || dataLen == 8) { //ul-c or ev1/ntag key length
                                errors = param_gethex(tempStr, 0, authenticationkey, dataLen);
                                dataLen /= 2;
                        if (dataLen == 32 || dataLen == 8) { //ul-c or ev1/ntag key length
                                errors = param_gethex(tempStr, 0, authenticationkey, dataLen);
                                dataLen /= 2;
@@ -1256,7 +1255,7 @@ int CmdHF14AMfUDump(const char *Cmd){
                        break;
                case 'n':
                case 'N':
                        break;
                case 'n':
                case 'N':
-                       fileNlen = param_getstr(Cmd, cmdp+1, filename);
+                       fileNlen = param_getstr(Cmd, cmdp+1, filename, sizeof(filename));
                        if (!fileNlen) errors = true; 
                        if (fileNlen > FILE_PATH_SIZE-5) fileNlen = FILE_PATH_SIZE-5;
                        cmdp += 2;
                        if (!fileNlen) errors = true; 
                        if (fileNlen > FILE_PATH_SIZE-5) fileNlen = FILE_PATH_SIZE-5;
                        cmdp += 2;
@@ -1325,8 +1324,7 @@ int CmdHF14AMfUDump(const char *Cmd){
                PrintAndLog("Data exceeded Buffer size!");
                bufferSize = sizeof(data);
        }
                PrintAndLog("Data exceeded Buffer size!");
                bufferSize = sizeof(data);
        }
-       GetFromBigBuf(data, bufferSize, startindex);
-       WaitForResponse(CMD_ACK,NULL);
+       GetFromBigBuf(data, bufferSize, startindex, NULL, -1, false);
 
        Pages = bufferSize/4;
        // Load lock bytes.
 
        Pages = bufferSize/4;
        // Load lock bytes.
@@ -1744,11 +1742,11 @@ int CmdHF14AMfuGenDiverseKeys(const char *Cmd){
        mix[6] = block ^ uid[2];
        mix[7] = uid[3];
 
        mix[6] = block ^ uid[2];
        mix[7] = uid[3];
 
-       des3_context ctx = { 0x00 };
-       des3_set2key_enc(&ctx, masterkey);
+       mbedtls_des3_context ctx = { {0} };
+       mbedtls_des3_set2key_enc(&ctx, masterkey);
 
 
-       des3_crypt_cbc(&ctx  // des3_context
-               , DES_ENCRYPT    // int mode
+       mbedtls_des3_crypt_cbc(&ctx  // des3_context
+               , MBEDTLS_DES_ENCRYPT    // int mode
                , sizeof(mix)    // length
                , iv             // iv[8]
                , mix            // input
                , sizeof(mix)    // length
                , iv             // iv[8]
                , mix            // input
@@ -1783,10 +1781,10 @@ int CmdHF14AMfuGenDiverseKeys(const char *Cmd){
        memcpy(dmkey+16, dkeyA, 8);
        memset(iv, 0x00, 8);
 
        memcpy(dmkey+16, dkeyA, 8);
        memset(iv, 0x00, 8);
 
-       des3_set3key_enc(&ctx, dmkey);
+       mbedtls_des3_set3key_enc(&ctx, dmkey);
 
 
-       des3_crypt_cbc(&ctx  // des3_context
-               , DES_ENCRYPT    // int mode
+       mbedtls_des3_crypt_cbc(&ctx  // des3_context
+               , MBEDTLS_DES_ENCRYPT    // int mode
                , sizeof(newpwd) // length
                , iv             // iv[8]
                , zeros         // input
                , sizeof(newpwd) // length
                , iv             // iv[8]
                , zeros         // input
@@ -1836,7 +1834,7 @@ static command_t CommandTable[] =
 };
 
 int CmdHFMFUltra(const char *Cmd){
 };
 
 int CmdHFMFUltra(const char *Cmd){
-       WaitForResponseTimeout(CMD_ACK,NULL,100);
+       (void)WaitForResponseTimeout(CMD_ACK,NULL,100);
        CmdsParse(CommandTable, Cmd);
        return 0;
 }
        CmdsParse(CommandTable, Cmd);
        return 0;
 }
Impressum, Datenschutz