mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-08-21 13:53:55 -07:00
remove spurious spaces & tabs at end of lines
This commit is contained in:
parent
edc19f202a
commit
60f292b18e
249 changed files with 8481 additions and 8481 deletions
|
@ -29,7 +29,7 @@ static int CmdHelp(const char *Cmd);
|
|||
int usage_flashmem_spibaud(void){
|
||||
PrintAndLogEx(NORMAL, "Usage: mem spibaud [h] <baudrate>");
|
||||
PrintAndLogEx(NORMAL, "Options:");
|
||||
PrintAndLogEx(NORMAL, " h this help");
|
||||
PrintAndLogEx(NORMAL, " h this help");
|
||||
PrintAndLogEx(NORMAL, " <baudrate> SPI baudrate in MHz [24|48]");
|
||||
PrintAndLogEx(NORMAL, " ");
|
||||
PrintAndLogEx(NORMAL, " If >= 24Mhz, FASTREADS instead of READS instruction will be used.");
|
||||
|
@ -48,7 +48,7 @@ int usage_flashmem_read(void){
|
|||
PrintAndLogEx(NORMAL, "");
|
||||
PrintAndLogEx(NORMAL, "Examples:");
|
||||
PrintAndLogEx(NORMAL, " mem read o 0 l 32"); // read 32 bytes starting at offset 0
|
||||
PrintAndLogEx(NORMAL, " mem read o 1024 l 10"); // read 10 bytes starting at offset 1024
|
||||
PrintAndLogEx(NORMAL, " mem read o 1024 l 10"); // read 10 bytes starting at offset 1024
|
||||
return 0;
|
||||
}
|
||||
int usage_flashmem_load(void){
|
||||
|
@ -82,7 +82,7 @@ int usage_flashmem_save(void){
|
|||
return 0;
|
||||
}
|
||||
int usage_flashmem_wipe(void){
|
||||
|
||||
|
||||
PrintAndLogEx(WARNING, "[OBS] use with caution.");
|
||||
PrintAndLogEx(NORMAL, "Wipe flash memory on device, which fills memory with 0xFF\n");
|
||||
|
||||
|
@ -104,7 +104,7 @@ int usage_flashmem_info(void){
|
|||
PrintAndLogEx(NORMAL, "Examples:");
|
||||
PrintAndLogEx(NORMAL, " mem info");
|
||||
PrintAndLogEx(NORMAL, " mem info s");
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int CmdFlashMemRead(const char *Cmd) {
|
||||
|
@ -112,7 +112,7 @@ int CmdFlashMemRead(const char *Cmd) {
|
|||
uint8_t cmdp = 0;
|
||||
bool errors = false;
|
||||
uint32_t start_index = 0, len = 0;
|
||||
|
||||
|
||||
while (param_getchar(Cmd, cmdp) != 0x00 && !errors) {
|
||||
switch (tolower(param_getchar(Cmd, cmdp))) {
|
||||
case 'o':
|
||||
|
@ -121,7 +121,7 @@ int CmdFlashMemRead(const char *Cmd) {
|
|||
break;
|
||||
case 'l':
|
||||
len = param_get32ex(Cmd, cmdp+1, 0, 10);
|
||||
cmdp += 2;
|
||||
cmdp += 2;
|
||||
break;
|
||||
case 'h':
|
||||
return usage_flashmem_read();
|
||||
|
@ -131,16 +131,16 @@ int CmdFlashMemRead(const char *Cmd) {
|
|||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//Validations
|
||||
if (errors || cmdp == 0 ) return usage_flashmem_read();
|
||||
|
||||
if (errors || cmdp == 0 ) return usage_flashmem_read();
|
||||
|
||||
if (start_index + len > FLASH_MEM_MAX_SIZE) {
|
||||
PrintAndLogDevice(WARNING, "error, start_index + length is larger than available memory");
|
||||
return 1;
|
||||
}
|
||||
|
||||
UsbCommand c = {CMD_FLASHMEM_READ, {start_index, len, 0}};
|
||||
UsbCommand c = {CMD_FLASHMEM_READ, {start_index, len, 0}};
|
||||
clearCommandBuffer();
|
||||
SendCommand(&c);
|
||||
return 0;
|
||||
|
@ -161,11 +161,11 @@ int CmdFlashmemSpiBaudrate(const char *Cmd) {
|
|||
int CmdFlashMemLoad(const char *Cmd){
|
||||
|
||||
uint32_t start_index = 0;
|
||||
char filename[FILE_PATH_SIZE] = {0};
|
||||
char filename[FILE_PATH_SIZE] = {0};
|
||||
bool errors = false;
|
||||
uint8_t cmdp = 0;
|
||||
uint8_t cmdp = 0;
|
||||
Dictionary_t d = DICTIONARY_NONE;
|
||||
|
||||
|
||||
while (param_getchar(Cmd, cmdp) != 0x00 && !errors) {
|
||||
switch (tolower(param_getchar(Cmd, cmdp))) {
|
||||
case 'h':
|
||||
|
@ -175,8 +175,8 @@ int CmdFlashMemLoad(const char *Cmd){
|
|||
PrintAndLogEx(FAILED, "Filename too long");
|
||||
errors = true;
|
||||
break;
|
||||
}
|
||||
cmdp += 2;
|
||||
}
|
||||
cmdp += 2;
|
||||
break;
|
||||
case 'o':
|
||||
start_index = param_get32ex(Cmd, cmdp+1, 0, 10);
|
||||
|
@ -200,15 +200,15 @@ int CmdFlashMemLoad(const char *Cmd){
|
|||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//Validations
|
||||
if (errors || cmdp == 0 ) return usage_flashmem_load();
|
||||
if (errors || cmdp == 0 ) return usage_flashmem_load();
|
||||
|
||||
size_t datalen = 0;
|
||||
uint16_t keycount = 0;
|
||||
int res = 0;
|
||||
uint8_t *data = calloc(FLASH_MEM_MAX_SIZE, sizeof(uint8_t));
|
||||
|
||||
|
||||
switch (d) {
|
||||
case DICTIONARY_MIFARE:
|
||||
start_index = DEFAULT_MF_KEYS_OFFSET;
|
||||
|
@ -218,8 +218,8 @@ int CmdFlashMemLoad(const char *Cmd){
|
|||
return 1;
|
||||
}
|
||||
data[0] = (keycount >> 0) & 0xFF;
|
||||
data[1] = (keycount >> 8) & 0xFF;
|
||||
datalen += 2;
|
||||
data[1] = (keycount >> 8) & 0xFF;
|
||||
datalen += 2;
|
||||
break;
|
||||
case DICTIONARY_T55XX:
|
||||
start_index = DEFAULT_T55XX_KEYS_OFFSET;
|
||||
|
@ -229,7 +229,7 @@ int CmdFlashMemLoad(const char *Cmd){
|
|||
return 1;
|
||||
}
|
||||
data[0] = (keycount >> 0) & 0xFF;
|
||||
data[1] = (keycount >> 8) & 0xFF;
|
||||
data[1] = (keycount >> 8) & 0xFF;
|
||||
datalen += 2;
|
||||
break;
|
||||
case DICTIONARY_ICLASS:
|
||||
|
@ -240,26 +240,26 @@ int CmdFlashMemLoad(const char *Cmd){
|
|||
return 1;
|
||||
}
|
||||
data[0] = (keycount >> 0) & 0xFF;
|
||||
data[1] = (keycount >> 8) & 0xFF;
|
||||
datalen += 2;
|
||||
data[1] = (keycount >> 8) & 0xFF;
|
||||
datalen += 2;
|
||||
break;
|
||||
default:
|
||||
|
||||
|
||||
res = loadFile(filename, "bin", data, &datalen);
|
||||
//int res = loadFileEML( filename, "eml", data, &datalen);
|
||||
if ( res ) {
|
||||
free(data);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
if (datalen > FLASH_MEM_MAX_SIZE) {
|
||||
PrintAndLogDevice(WARNING, "error, filesize is larger than available memory");
|
||||
free(data);
|
||||
return 1;
|
||||
}
|
||||
break;
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
data = realloc(data, datalen);
|
||||
|
||||
//Send to device
|
||||
|
@ -268,40 +268,40 @@ int CmdFlashMemLoad(const char *Cmd){
|
|||
|
||||
while (bytes_remaining > 0){
|
||||
uint32_t bytes_in_packet = MIN(FLASH_MEM_BLOCK_SIZE, bytes_remaining);
|
||||
|
||||
|
||||
UsbCommand c = {CMD_FLASHMEM_WRITE, {start_index + bytes_sent, bytes_in_packet, 0}};
|
||||
|
||||
|
||||
memcpy(c.d.asBytes, data + bytes_sent, bytes_in_packet);
|
||||
clearCommandBuffer();
|
||||
SendCommand(&c);
|
||||
|
||||
bytes_remaining -= bytes_in_packet;
|
||||
bytes_sent += bytes_in_packet;
|
||||
|
||||
|
||||
UsbCommand resp;
|
||||
if ( !WaitForResponseTimeout(CMD_ACK, &resp, 2000) ) {
|
||||
PrintAndLogEx(WARNING, "timeout while waiting for reply.");
|
||||
free(data);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
uint8_t isok = resp.arg[0] & 0xFF;
|
||||
if (!isok)
|
||||
PrintAndLogEx(FAILED, "Flash write fail [offset %u]", bytes_sent);
|
||||
|
||||
|
||||
}
|
||||
free(data);
|
||||
|
||||
|
||||
PrintAndLogEx(SUCCESS, "Wrote %u bytes to offset %u", datalen, start_index);
|
||||
return 0;
|
||||
}
|
||||
int CmdFlashMemSave(const char *Cmd){
|
||||
|
||||
char filename[FILE_PATH_SIZE] = {0};
|
||||
char filename[FILE_PATH_SIZE] = {0};
|
||||
uint8_t cmdp = 0;
|
||||
bool errors = false;
|
||||
uint32_t start_index = 0, len = FLASH_MEM_MAX_SIZE;
|
||||
|
||||
|
||||
while (param_getchar(Cmd, cmdp) != 0x00 && !errors) {
|
||||
switch (tolower(param_getchar(Cmd, cmdp))) {
|
||||
case 'h': return usage_flashmem_save();
|
||||
|
@ -319,8 +319,8 @@ int CmdFlashMemSave(const char *Cmd){
|
|||
PrintAndLogEx(FAILED, "Filename too long");
|
||||
errors = true;
|
||||
break;
|
||||
}
|
||||
cmdp += 2;
|
||||
}
|
||||
cmdp += 2;
|
||||
break;
|
||||
default:
|
||||
PrintAndLogEx(WARNING, "Unknown parameter '%c'", param_getchar(Cmd, cmdp));
|
||||
|
@ -328,7 +328,7 @@ int CmdFlashMemSave(const char *Cmd){
|
|||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//Validations
|
||||
if (errors || cmdp == 0 ) return usage_flashmem_save();
|
||||
|
||||
|
@ -337,7 +337,7 @@ int CmdFlashMemSave(const char *Cmd){
|
|||
PrintAndLogDevice(WARNING, "error, cannot allocate memory ");
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
PrintAndLogEx(NORMAL, "downloading %u bytes from flashmem", len);
|
||||
if ( !GetFromDevice(FLASH_MEM, dump, len, start_index, NULL, -1, true) ) {
|
||||
PrintAndLogEx(FAILED, "ERROR; downloading flashmem");
|
||||
|
@ -355,10 +355,10 @@ int CmdFlashMemWipe(const char *Cmd){
|
|||
uint8_t cmdp = 0;
|
||||
bool errors = false;
|
||||
bool initalwipe = false;
|
||||
uint8_t page = 0;
|
||||
uint8_t page = 0;
|
||||
while (param_getchar(Cmd, cmdp) != 0x00 && !errors) {
|
||||
switch (tolower(param_getchar(Cmd, cmdp))) {
|
||||
case 'h': return usage_flashmem_wipe();
|
||||
case 'h': return usage_flashmem_wipe();
|
||||
case 'p':
|
||||
page = param_get8ex(Cmd, cmdp+1, 0, 10);
|
||||
if ( page > 2 ) {
|
||||
|
@ -378,10 +378,10 @@ int CmdFlashMemWipe(const char *Cmd){
|
|||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//Validations
|
||||
if (errors || cmdp == 0 ) return usage_flashmem_wipe();
|
||||
|
||||
if (errors || cmdp == 0 ) return usage_flashmem_wipe();
|
||||
|
||||
UsbCommand c = {CMD_FLASHMEM_WIPE, {page, initalwipe, 0}};
|
||||
clearCommandBuffer();
|
||||
SendCommand(&c);
|
||||
|
@ -393,7 +393,7 @@ int CmdFlashMemWipe(const char *Cmd){
|
|||
uint8_t isok = resp.arg[0] & 0xFF;
|
||||
if (isok)
|
||||
PrintAndLogEx(SUCCESS, "Flash WIPE ok");
|
||||
else
|
||||
else
|
||||
PrintAndLogEx(FAILED, "Flash WIPE failed");
|
||||
|
||||
return 0;
|
||||
|
@ -402,18 +402,18 @@ int CmdFlashMemInfo(const char *Cmd){
|
|||
|
||||
uint8_t sha_hash[20] = {0};
|
||||
mbedtls_rsa_context rsa;
|
||||
|
||||
|
||||
uint8_t cmdp = 0;
|
||||
bool errors = false, shall_write = false, shall_sign = false;
|
||||
while (param_getchar(Cmd, cmdp) != 0x00 && !errors) {
|
||||
switch (tolower(param_getchar(Cmd, cmdp))) {
|
||||
case 'h': return usage_flashmem_info();
|
||||
case 'h': return usage_flashmem_info();
|
||||
case 's': {
|
||||
shall_sign = true;
|
||||
cmdp++;
|
||||
break;
|
||||
}
|
||||
case 'w':
|
||||
case 'w':
|
||||
shall_write = true;
|
||||
cmdp++;
|
||||
break;
|
||||
|
@ -423,10 +423,10 @@ int CmdFlashMemInfo(const char *Cmd){
|
|||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//Validations
|
||||
if (errors ) return usage_flashmem_info();
|
||||
|
||||
|
||||
UsbCommand c = {CMD_FLASHMEM_INFO, {0, 0, 0}};
|
||||
clearCommandBuffer();
|
||||
SendCommand(&c);
|
||||
|
@ -435,12 +435,12 @@ int CmdFlashMemInfo(const char *Cmd){
|
|||
PrintAndLogEx(WARNING, "timeout while waiting for reply.");
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
uint8_t isok = resp.arg[0] & 0xFF;
|
||||
if (!isok) {
|
||||
PrintAndLogEx(FAILED, "failed");
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
// validate signature here
|
||||
rdv40_validation_t mem;
|
||||
|
@ -448,18 +448,18 @@ int CmdFlashMemInfo(const char *Cmd){
|
|||
|
||||
// Flash ID hash (sha1)
|
||||
mbedtls_sha1( mem.flashid, sizeof(mem.flashid), sha_hash );
|
||||
|
||||
|
||||
// print header
|
||||
PrintAndLogEx(INFO, "\n--- Flash memory Information ---------");
|
||||
PrintAndLogEx(INFO, "-------------------------------------------------------------");
|
||||
PrintAndLogEx(INFO, "-------------------------------------------------------------");
|
||||
PrintAndLogEx(INFO, "ID | %s", sprint_hex(mem.flashid, sizeof(mem.flashid) ));
|
||||
PrintAndLogEx(INFO, "SHA1 | %s", sprint_hex(sha_hash, sizeof(sha_hash)));
|
||||
PrintAndLogEx(INFO, "RSA SIGNATURE |");
|
||||
print_hex_break( mem.signature, sizeof(mem.signature), 32);
|
||||
|
||||
//-------------------------------------------------------------------------------
|
||||
//-------------------------------------------------------------------------------
|
||||
// Example RSA-1024 keypair, for test purposes (from common/polarssl/rsa.c)
|
||||
//
|
||||
//
|
||||
|
||||
// public key modulus N
|
||||
#define RSA_N "9292758453063D803DD603D5E777D788" \
|
||||
|
@ -484,7 +484,7 @@ int CmdFlashMemInfo(const char *Cmd){
|
|||
"AF1FEDFDDE2BEB674CA15F3E81A1521E" \
|
||||
"071513A1E85B5DFA031F21ECAE91A34D"
|
||||
|
||||
// prime P
|
||||
// prime P
|
||||
#define RSA_P "C36D0EB7FCD285223CFB5AABA5BDA3D8" \
|
||||
"2C01CAD19EA484A87EA4377637E75500" \
|
||||
"FCB2005C5C7DD6EC4AC023CDA285D796" \
|
||||
|
@ -511,7 +511,7 @@ int CmdFlashMemInfo(const char *Cmd){
|
|||
"F5A3B2A5D33605AEBBCCBA7FEB9F2D2F" \
|
||||
"A74206CEC169D74BF5A8C50D6F48EA08"
|
||||
|
||||
|
||||
|
||||
#define KEY_LEN 128
|
||||
|
||||
mbedtls_rsa_init(&rsa, MBEDTLS_RSA_PKCS_V15, 0);
|
||||
|
@ -528,53 +528,53 @@ int CmdFlashMemInfo(const char *Cmd){
|
|||
mbedtls_mpi_read_string( &rsa.QP, 16, RSA_QP );
|
||||
|
||||
PrintAndLogEx(INFO, "KEY length | %d", KEY_LEN);
|
||||
|
||||
|
||||
bool is_keyok = ( mbedtls_rsa_check_pubkey( &rsa ) == 0 || mbedtls_rsa_check_privkey( &rsa ) == 0 );
|
||||
if (is_keyok)
|
||||
PrintAndLogEx(SUCCESS, "RSA key validation ok");
|
||||
else
|
||||
PrintAndLogEx(FAILED, "RSA key validation failed");
|
||||
|
||||
//
|
||||
|
||||
//
|
||||
uint8_t from_device[KEY_LEN];
|
||||
uint8_t sign[KEY_LEN];
|
||||
|
||||
// to be verified
|
||||
memcpy(from_device, mem.signature, KEY_LEN);
|
||||
|
||||
|
||||
// to be signed (all zeros
|
||||
memset(sign, 0, KEY_LEN);
|
||||
|
||||
|
||||
// Signing (private key)
|
||||
if (shall_sign) {
|
||||
|
||||
|
||||
int is_signed = mbedtls_rsa_pkcs1_sign( &rsa, NULL, NULL, MBEDTLS_RSA_PRIVATE, MBEDTLS_MD_SHA1, 20, sha_hash, sign );
|
||||
if (is_signed == 0)
|
||||
if (is_signed == 0)
|
||||
PrintAndLogEx(SUCCESS, "RSA Signing ok");
|
||||
else
|
||||
PrintAndLogEx(FAILED, "RSA Signing failed");
|
||||
|
||||
if (shall_write) {
|
||||
// save to mem
|
||||
c = (UsbCommand){CMD_FLASHMEM_WRITE, {FLASH_MEM_SIGNATURE_OFFSET, FLASH_MEM_SIGNATURE_LEN, 0}};
|
||||
memcpy(c.d.asBytes, sign, sizeof(sign));
|
||||
c = (UsbCommand){CMD_FLASHMEM_WRITE, {FLASH_MEM_SIGNATURE_OFFSET, FLASH_MEM_SIGNATURE_LEN, 0}};
|
||||
memcpy(c.d.asBytes, sign, sizeof(sign));
|
||||
clearCommandBuffer();
|
||||
SendCommand(&c);
|
||||
if ( !WaitForResponseTimeout(CMD_ACK, &resp, 2000) ) {
|
||||
PrintAndLogEx(WARNING, "timeout while waiting for reply.");
|
||||
} else {
|
||||
|
||||
|
||||
if (!resp.arg[0])
|
||||
PrintAndLogEx(FAILED, "Writing signature failed");
|
||||
else
|
||||
PrintAndLogEx(SUCCESS, "Writing signature ok [offset: %u]", FLASH_MEM_SIGNATURE_OFFSET);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
PrintAndLogEx(INFO, "Signed | ");
|
||||
print_hex_break( sign, sizeof(sign), 32);
|
||||
}
|
||||
|
||||
|
||||
// Verify (public key)
|
||||
int is_verified = mbedtls_rsa_pkcs1_verify( &rsa, NULL, NULL, MBEDTLS_RSA_PUBLIC, MBEDTLS_MD_SHA1, 20, sha_hash, from_device );
|
||||
if (is_verified == 0)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue