this commit refactors the signature checks. First we introduce a common pm3 generic private / public key pair in order to allow for users to self sign their own modded device. The verification checks now looks at both hard coded public keys. If a vendor wants to add their own public key thus allowing for a simple way for us to identify their devices they can now do so. The downside is that the firmware mismatch detection becomes a bit dodgy. mem info; mem info -v; mem info -s -p <filename.pem>; mem info -s -p <filename.pem> -w contains the changes. OBS! when -w be careful to not overwrite your genuine RDV4 signature. As always, with great power comes great responsibility

This commit is contained in:
iceman1001 committed 2025-09-25 19:44:36 +02:00
1 parent 1412b6882b
commit b097e10aa3
11 files changed
+340 -178

No files matched your search

+246 -149
View File
@@ -27,6 +27,7 @@
#include "rsa.h"
#include "sha1.h"
#include "pk.h" // PEM key load functions
#include "commonutil.h"
#define MCK 48000000
#define FLASH_MINFAST 24000000 //33000000
@@ -37,21 +38,36 @@
static int CmdHelp(const char *Cmd);
//-------------------------------------------------------------------------------------
#define PM3_RSA_KEY_LEN ( 128 )
#define PM3_RSA_SHA1_LEN ( 20 )
typedef struct {
const char *desc;
const char *E; // public key Exponent E
const char *N; // public key modulus N
} rsa_keypairs_t;
static const rsa_keypairs_t rsa_keypairs[] = {
// RRG Public RSA Key
#define RRG_RSA_KEY_LEN 128
{
"RDV4", "010001", "E28D809BF323171D11D1ACA4C32A5B7E0A8974FD171E75AD120D60E9B76968FF" \
"4B0A6364AE50583F9555B8EE1A725F279E949246DF0EFCE4C02B9F3ACDCC623F" \
"9337F21C0C066FFB703D8BFCB5067F309E056772096642C2B1A8F50305D5EC33" \
"DB7FB5A3C8AC42EB635AE3C148C910750ABAA280CE82DC2F180F49F30A1393B5"
},
// public key Exponent E
#define RRG_RSA_E "010001"
// public key modulus N
#define RRG_RSA_N "E28D809BF323171D11D1ACA4C32A5B7E0A8974FD171E75AD120D60E9B76968FF" \
"4B0A6364AE50583F9555B8EE1A725F279E949246DF0EFCE4C02B9F3ACDCC623F" \
"9337F21C0C066FFB703D8BFCB5067F309E056772096642C2B1A8F50305D5EC33" \
"DB7FB5A3C8AC42EB635AE3C148C910750ABAA280CE82DC2F180F49F30A1393B5"
// GENERIC Public RSA Key for modded devices. They can now be self signed
{
"GENERIC", "010001", "FAECE60ADC10934D8284E52A06121DF018786A94572CBB0F318DCE942BC8B04D" \
"DDE5488F6FB6A1007F05F5B8C06A5F837E6CFD1D2884264E8C9F35A0B2B5805C" \
"7E9AF14C9B350FF4CCCD0F132CFF74EE9A2490A844123D0622F014162D76DDEF" \
"7A5F24FEA9E34FA608AEB58B7C10B4BFC7F39C4BFC6E463503A0DDBB9B773E01"
},
};
//-------------------------------------------------------------------------------------
int rdv4_get_flash_pages64k(uint8_t *pages64k) {
int pm3_get_flash_pages64k(uint8_t *pages64k) {
if (pages64k == NULL) {
return PM3_EINVARG;
}
@@ -60,7 +76,7 @@ int rdv4_get_flash_pages64k(uint8_t *pages64k) {
SendCommandNG(CMD_FLASHMEM_PAGES64K, NULL, 0);
PacketResponseNG resp;
if (WaitForResponseTimeout(CMD_FLASHMEM_PAGES64K, &resp, 2500) == false) {
PrintAndLogEx(WARNING, "rdv4_get_flash_pages64k() timeout while waiting for reply");
PrintAndLogEx(WARNING, "pm3_get_flash_pages64k() timeout while waiting for reply");
return PM3_ETIMEOUT;
}
@@ -73,15 +89,15 @@ int rdv4_get_flash_pages64k(uint8_t *pages64k) {
return PM3_SUCCESS;
}
int rdv4_get_signature(rdv40_validation_t *out) {
int pm3_get_signature(rdv40_validation_t *out) {
if (out == NULL) {
return PM3_EINVARG;
}
clearCommandBuffer();
SendCommandNG(CMD_FLASHMEM_INFO, NULL, 0);
SendCommandNG(CMD_FLASHMEM_GET_SIGNATURE, NULL, 0);
PacketResponseNG resp;
if (WaitForResponseTimeout(CMD_FLASHMEM_INFO, &resp, 2500) == false) {
if (WaitForResponseTimeout(CMD_FLASHMEM_GET_SIGNATURE, &resp, 2500) == false) {
PrintAndLogEx(WARNING, "timeout while waiting for reply");
return PM3_ETIMEOUT;
}
@@ -96,32 +112,63 @@ int rdv4_get_signature(rdv40_validation_t *out) {
}
// validate signature
int rdv4_validate(rdv40_validation_t *mem) {
int pm3_validate(rdv40_validation_t *mem, signature_e *type) {
// Flash ID hash (sha1)
uint8_t sha_hash[20] = {0};
uint8_t sha_hash[PM3_RSA_SHA1_LEN] = {0};
mbedtls_sha1(mem->flashid, sizeof(mem->flashid), sha_hash);
// set up RSA
mbedtls_rsa_context rsa;
mbedtls_rsa_init(&rsa, MBEDTLS_RSA_PKCS_V15, 0);
rsa.len = RRG_RSA_KEY_LEN;
mbedtls_mpi_read_string(&rsa.N, 16, RRG_RSA_N);
mbedtls_mpi_read_string(&rsa.E, 16, RRG_RSA_E);
*type = SIGN_UNK;
int is_valid = 0;
// Verify (public key)
int is_verified = mbedtls_rsa_pkcs1_verify(&rsa, NULL, NULL, MBEDTLS_RSA_PUBLIC, MBEDTLS_MD_SHA1, 20, sha_hash, mem->signature);
mbedtls_rsa_free(&rsa);
for (uint8_t i = 0; i < ARRAYLEN(rsa_keypairs); i++) {
if (is_verified == 0) {
return PM3_SUCCESS;
// set up RSA
mbedtls_rsa_context rsa;
mbedtls_rsa_init(&rsa, MBEDTLS_RSA_PKCS_V15, 0);
rsa.len = PM3_RSA_KEY_LEN;
mbedtls_mpi_read_string(&rsa.N, 16, rsa_keypairs[i].N);
mbedtls_mpi_read_string(&rsa.E, 16, rsa_keypairs[i].E);
// Verify (public key)
is_valid = mbedtls_rsa_pkcs1_verify(&rsa, NULL, NULL, MBEDTLS_RSA_PUBLIC, MBEDTLS_MD_SHA1, PM3_RSA_SHA1_LEN, sha_hash, mem->signature);
mbedtls_rsa_free(&rsa);
if (is_valid == 0) {
*type = i;
return PM3_SUCCESS;
}
}
return PM3_EFAILED;
}
static int rdv4_sign_write(uint8_t *signature, uint8_t slen) {
static int pm3_get_flash_info(spi_flash_t *info) {
if (info == NULL) {
return PM3_EINVARG;
}
clearCommandBuffer();
SendCommandNG(CMD_FLASHMEM_GET_INFO, NULL, 0);
PacketResponseNG resp;
if (WaitForResponseTimeout(CMD_FLASHMEM_GET_INFO, &resp, 2500) == false) {
PrintAndLogEx(WARNING, "pm3_get_flash_info() timeout while waiting for reply");
return PM3_ETIMEOUT;
}
if (resp.status != PM3_SUCCESS) {
PrintAndLogEx(FAILED, "fail reading flash info");
return PM3_EFLASH;
}
memcpy(info, resp.data.asBytes, sizeof(spi_flash_t));
return PM3_SUCCESS;
}
static int pm3_sign_write(uint8_t *signature, uint8_t slen) {
uint8_t spi_flash_pages = 0;
int res = rdv4_get_flash_pages64k(&spi_flash_pages);
int res = pm3_get_flash_pages64k(&spi_flash_pages);
if (res != PM3_SUCCESS) {
PrintAndLogEx(ERR, "failed to get flash pages (%x)", res);
return res;
@@ -146,10 +193,84 @@ static int rdv4_sign_write(uint8_t *signature, uint8_t slen) {
return PM3_EFAILED;
}
}
PrintAndLogEx(SUCCESS, "Writing signature at offset %u ( "_GREEN_("ok") " )", FLASH_MEM_SIGNATURE_OFFSET_P(spi_flash_pages));
PrintAndLogEx(SUCCESS, "Wrote signature at offset " _YELLOW_("%u") " ( "_GREEN_("ok") " )", FLASH_MEM_SIGNATURE_OFFSET_P(spi_flash_pages));
return PM3_SUCCESS;
}
static void pm3_print_flash_memory_info(spi_flash_t *spi, rdv40_validation_t *mem, uint8_t *sha_hash, signature_e *type) {
// print header
PrintAndLogEx(NORMAL, "");
PrintAndLogEx(INFO, "--- " _CYAN_("Flash memory Information"));
PrintAndLogEx(INFO, "ID...................... %s", sprint_hex_inrow(mem->flashid, sizeof(mem->flashid)));
PrintAndLogEx(INFO, "SHA1.................... %s", sprint_hex_inrow(sha_hash, PM3_RSA_SHA1_LEN));
if (spi->device_id) {
PrintAndLogEx(INFO, "Mfr ID / Dev ID......... " _YELLOW_("%02X") " / " _YELLOW_("%02X"), spi->manufacturer_id, spi->device_id);
}
if (spi->jedec_id) {
PrintAndLogEx(INFO, "JEDEC Mfr ID / Dev ID... " _YELLOW_("%02X") " / "_YELLOW_("%04X"), spi->manufacturer_id, spi->jedec_id);
}
PrintAndLogEx(INFO, "Memory size............. " _YELLOW_("%d Kb") " ( %d * 64 Kb )", spi->pages64k * 64, spi->pages64k);
PrintAndLogEx(NORMAL, "");
// Print Signature Header
switch (*type) {
case SIGN_RDV4:
case SIGN_GENERIC:
PrintAndLogEx(INFO, "--- " _CYAN_("PM3 %s RSA signature"), rsa_keypairs[*type].desc);
break;
case SIGN_UNK:
default:
PrintAndLogEx(INFO, "--- " _CYAN_("Unknown RSA signature"));
break;
}
// Print the Signature Data
for (int i = 0; i < (sizeof(mem->signature) / 32); i++) {
PrintAndLogEx(INFO, " %s", sprint_hex_inrow(mem->signature + (i * 32), 32));
}
}
static void pm3_print_public_keys(void) {
mbedtls_rsa_context rsa;
mbedtls_rsa_init(&rsa, MBEDTLS_RSA_PKCS_V15, 0);
rsa.len = PM3_RSA_KEY_LEN;
for (uint8_t i = 0; i < ARRAYLEN(rsa_keypairs); i++) {
mbedtls_mpi_read_string(&rsa.N, 16, rsa_keypairs[i].N);
mbedtls_mpi_read_string(&rsa.E, 16, rsa_keypairs[i].E);
PrintAndLogEx(INFO, "--- " _CYAN_("%s RSA Public key"), rsa_keypairs[i].desc);
char str_exp[10];
char str_pk[261];
size_t exlen = 0, pklen = 0;
mbedtls_mpi_write_string(&rsa.E, 16, str_exp, sizeof(str_exp), &exlen);
mbedtls_mpi_write_string(&rsa.N, 16, str_pk, sizeof(str_pk), &pklen);
PrintAndLogEx(INFO, "Len........ %"PRIu64, rsa.len);
PrintAndLogEx(INFO, "Exponent... %s", str_exp);
PrintAndLogEx(INFO, "Public key modulus N");
PrintAndLogEx(INFO, " %.64s", str_pk);
PrintAndLogEx(INFO, " %.64s", str_pk + 64);
PrintAndLogEx(INFO, " %.64s", str_pk + 128);
PrintAndLogEx(INFO, " %.64s", str_pk + 192);
bool is_keyok = (mbedtls_rsa_check_pubkey(&rsa) == 0);
PrintAndLogEx(
(is_keyok) ? SUCCESS : FAILED,
"RSA public key check.... ( %s )",
(is_keyok) ? _GREEN_("ok") : _RED_("fail")
);
PrintAndLogEx(NORMAL, "");
}
}
static int CmdFlashmemSpiBaud(const char *Cmd) {
CLIParserContext *ctx;
@@ -242,7 +363,7 @@ static int CmdFlashMemLoad(const char *Cmd) {
}
uint8_t spi_flash_pages = 0;
int res = rdv4_get_flash_pages64k(&spi_flash_pages);
int res = pm3_get_flash_pages64k(&spi_flash_pages);
if (res != PM3_SUCCESS) {
PrintAndLogEx(ERR, "Failed to get flash pages count (%x)", res);
return res;
@@ -442,7 +563,7 @@ static int CmdFlashMemDump(const char *Cmd) {
CLIExecWithReturn(ctx, Cmd, argtable, false);
uint8_t spi_flash_pages = 0;
int res = rdv4_get_flash_pages64k(&spi_flash_pages);
int res = pm3_get_flash_pages64k(&spi_flash_pages);
if (res != PM3_SUCCESS) {
PrintAndLogEx(ERR, "failed to get flash pages count (%x)", res);
return res;
@@ -507,7 +628,7 @@ static int CmdFlashMemWipe(const char *Cmd) {
CLIParserFree(ctx);
uint8_t spi_flash_pages = 0;
int res = rdv4_get_flash_pages64k(&spi_flash_pages);
int res = pm3_get_flash_pages64k(&spi_flash_pages);
if (res != PM3_SUCCESS) {
PrintAndLogEx(ERR, "failed to get flash pages count (%x)", res);
return res;
@@ -541,7 +662,8 @@ static int CmdFlashMemInfo(const char *Cmd) {
CLIParserContext *ctx;
CLIParserInit(&ctx, "mem info",
"Collect signature and verify it from flash memory",
"mem info"
"mem info\n"
"mem info -s -d 0102030405060708 -p pm3_generic_private_key.pem -w --> generate and write a RSA 1024 signature "
);
void *argtable[] = {
@@ -574,16 +696,19 @@ static int CmdFlashMemInfo(const char *Cmd) {
}
if (dlen > 0 && dlen < sizeof(id)) {
PrintAndLogEx(FAILED, "Error parsing flash memory id, expect 8, got %d", dlen);
PrintAndLogEx(FAILED, "Error parsing flash memory id, expect 8, got " _RED_("%d"), dlen);
return PM3_EINVARG;
}
// set up PK key context now.
mbedtls_pk_context pkctx;
mbedtls_pk_init(&pkctx);
bool got_private = false;
// PEM
if (pemlen) {
// PEM file
char *path = NULL;
if (searchFile(&path, RESOURCES_SUBDIR, pem_fn, ".pem", true) != PM3_SUCCESS) {
@@ -597,6 +722,7 @@ static int CmdFlashMemInfo(const char *Cmd) {
// load private
res = mbedtls_pk_parse_keyfile(&pkctx, path, NULL);
free(path);
//res = mbedtls_pk_parse_public_keyfile(&pkctx, path);
if (res == 0) {
PrintAndLogEx(NORMAL, " ( " _GREEN_("ok") " )");
@@ -611,7 +737,9 @@ static int CmdFlashMemInfo(const char *Cmd) {
PrintAndLogEx(WARNING, "Failed to allocate memory");
return PM3_EMALLOC;
}
got_private = true;
} else {
// it not loaded, we need to setup the context manually
@@ -621,148 +749,117 @@ static int CmdFlashMemInfo(const char *Cmd) {
}
}
// validate devicesignature data
rdv40_validation_t mem;
res = rdv4_get_signature(&mem);
// download signature data from device
rdv40_validation_t mem = {0};
res = pm3_get_signature(&mem);
if (res != PM3_SUCCESS) {
return res;
}
res = rdv4_validate(&mem);
// download SPI chip information
spi_flash_t spi = {0};
res = pm3_get_flash_info(&spi);
if (res != PM3_SUCCESS) {
PrintAndLogEx(WARNING, "Failed to get flash information. Are you sure your device have a external flash?");
return res;
}
// Flash ID hash (sha1)
uint8_t sha_hash[20] = {0};
// try to verify the found device signature
signature_e type;
res = pm3_validate(&mem, &type);
// Calculate Flash ID hash ( SHA1 )
uint8_t sha_hash[PM3_RSA_SHA1_LEN] = {0};
mbedtls_sha1(mem.flashid, sizeof(mem.flashid), sha_hash);
// print header
PrintAndLogEx(NORMAL, "");
PrintAndLogEx(INFO, "--- " _CYAN_("Flash memory Information") " ---------");
PrintAndLogEx(INFO, "ID................... %s", sprint_hex_inrow(mem.flashid, sizeof(mem.flashid)));
PrintAndLogEx(INFO, "SHA1................. %s", sprint_hex_inrow(sha_hash, sizeof(sha_hash)));
PrintAndLogEx(NORMAL, "");
PrintAndLogEx(INFO, "--- " _CYAN_("RDV4 RSA signature") " ---------------");
for (int i = 0; i < (sizeof(mem.signature) / 32); i++) {
PrintAndLogEx(INFO, " %s", sprint_hex_inrow(mem.signature + (i * 32), 32));
}
pm3_print_flash_memory_info(&spi, &mem, sha_hash, &type);
PrintAndLogEx(
(res == PM3_SUCCESS) ? SUCCESS : FAILED,
"Signature............ ( %s )",
"Signature............... ( %s )",
(res == PM3_SUCCESS) ? _GREEN_("ok") : _RED_("fail")
);
PrintAndLogEx(NORMAL, "");
// Print the hardcoded RSA public keys
if (verbose) {
pm3_print_public_keys();
}
if (type != SIGN_UNK) {
PrintAndLogEx(SUCCESS, "Genuine Proxmark3 " _CYAN_("%s") " signature detected :white_check_mark:", rsa_keypairs[type].desc);
} else {
PrintAndLogEx(FAILED, "No genuine Proxmark3 signature detected :x:");
}
// end here if we not going to create a signature
if (shall_sign == false) {
PrintAndLogEx(NORMAL, "");
return PM3_SUCCESS;
}
// enter the Signing process
mbedtls_rsa_context *rsa = NULL;
// called with private key .pem file
if (got_private) {
rsa = mbedtls_pk_rsa(pkctx);
rsa->padding = MBEDTLS_RSA_PKCS_V15;
rsa->hash_id = 0;
rsa->len = RRG_RSA_KEY_LEN;
} else {
rsa->len = PM3_RSA_KEY_LEN;
rsa = (mbedtls_rsa_context *)calloc(1, sizeof(mbedtls_rsa_context));
if (rsa == NULL) {
PrintAndLogEx(WARNING, "Failed to allocate memory");
return PM3_EMALLOC;
}
mbedtls_rsa_init(rsa, MBEDTLS_RSA_PKCS_V15, 0);
rsa->len = RRG_RSA_KEY_LEN;
// add public key
mbedtls_mpi_read_string(&rsa->N, 16, RRG_RSA_N);
mbedtls_mpi_read_string(&rsa->E, 16, RRG_RSA_E);
}
PrintAndLogEx(INFO, "--- " _CYAN_("RDV4 RSA Public key") " --------------");
if (verbose) {
char str_exp[10];
char str_pk[261];
size_t exlen = 0, pklen = 0;
mbedtls_mpi_write_string(&rsa->E, 16, str_exp, sizeof(str_exp), &exlen);
mbedtls_mpi_write_string(&rsa->N, 16, str_pk, sizeof(str_pk), &pklen);
PrintAndLogEx(INFO, "Len.................. %"PRIu64, rsa->len);
PrintAndLogEx(INFO, "Exponent............. %s", str_exp);
PrintAndLogEx(INFO, "Public key modulus N");
PrintAndLogEx(INFO, " %.64s", str_pk);
PrintAndLogEx(INFO, " %.64s", str_pk + 64);
PrintAndLogEx(INFO, " %.64s", str_pk + 128);
PrintAndLogEx(INFO, " %.64s", str_pk + 192);
PrintAndLogEx(NORMAL, "");
}
bool is_keyok = (mbedtls_rsa_check_pubkey(rsa) == 0);
PrintAndLogEx(
(is_keyok) ? SUCCESS : FAILED,
"RDV4 RSA public key check.... ( %s )",
(is_keyok) ? _GREEN_("ok") : _RED_("fail")
);
is_keyok = (mbedtls_rsa_check_privkey(rsa) == 0);
if (verbose) {
PrintAndLogEx(
(is_keyok) ? SUCCESS : FAILED,
"RDV4 RSA private key check... ( %s )",
(is_keyok) ? _GREEN_("ok") : _YELLOW_("n/aA")
);
}
// to be verified
uint8_t from_device[RRG_RSA_KEY_LEN];
memcpy(from_device, mem.signature, RRG_RSA_KEY_LEN);
// to be signed
uint8_t sign[RRG_RSA_KEY_LEN];
memset(sign, 0, RRG_RSA_KEY_LEN);
// Signing (private key)
if (shall_sign) {
if (is_keyok) {
PrintAndLogEx(NORMAL, "");
PrintAndLogEx(INFO, "--- " _CYAN_("Enter signing") " --------------------");
if (dlen == 8) {
mbedtls_sha1(id, sizeof(id), sha_hash);
}
PrintAndLogEx(INFO, "Signing....... %s", sprint_hex_inrow(sha_hash, sizeof(sha_hash)));
int is_signed = mbedtls_rsa_pkcs1_sign(rsa, NULL, NULL, MBEDTLS_RSA_PRIVATE, MBEDTLS_MD_SHA1, 20, sha_hash, sign);
bool is_keyok = (mbedtls_rsa_check_privkey(rsa) == 0);
if (verbose) {
PrintAndLogEx(
(is_signed == 0) ? SUCCESS : FAILED,
"RSA signing... ( %s )",
(is_signed == 0) ? _GREEN_("ok") : _RED_("fail")
(is_keyok) ? SUCCESS : FAILED,
"RSA private key check... ( %s )",
(is_keyok) ? _GREEN_("ok") : _YELLOW_("n/a")
);
if (shall_write) {
rdv4_sign_write(sign, RRG_RSA_KEY_LEN);
}
PrintAndLogEx(INFO, "New signature");
for (int i = 0; i < (sizeof(sign) / 32); i++) {
PrintAndLogEx(INFO, " %s", sprint_hex_inrow(sign + (i * 32), 32));
}
} else {
PrintAndLogEx(FAILED, "no private key available to sign");
}
}
// Verify (public key)
bool is_verified = (mbedtls_rsa_pkcs1_verify(rsa, NULL, NULL, MBEDTLS_RSA_PUBLIC, MBEDTLS_MD_SHA1, 20, sha_hash, from_device) == 0);
if (is_keyok == false) {
PrintAndLogEx(FAILED, "No private key available to sign");
return PM3_ECRYPTO;
}
// to be signed
uint8_t sign[PM3_RSA_KEY_LEN] = {0};
// Signing (private key)
PrintAndLogEx(NORMAL, "");
PrintAndLogEx(INFO, "--- " _CYAN_("Enter signing"));
// use ID from CLI, otherwise we use FLash ID from device
if (dlen == 8) {
mbedtls_sha1(id, sizeof(id), sha_hash);
PrintAndLogEx(INFO, "Using ID......... %s", sprint_hex_inrow(id, dlen));
} else {
PrintAndLogEx(INFO, "Using ID......... %s", sprint_hex_inrow(mem.flashid, sizeof(mem.flashid)));
}
PrintAndLogEx(INFO, "Signing.......... %s", sprint_hex_inrow(sha_hash, sizeof(sha_hash)));
int is_signed = mbedtls_rsa_pkcs1_sign(rsa, NULL, NULL, MBEDTLS_RSA_PRIVATE, MBEDTLS_MD_SHA1, PM3_RSA_SHA1_LEN, sha_hash, sign);
PrintAndLogEx(
(is_signed == 0) ? SUCCESS : FAILED,
"RSA signing...... ( %s )",
(is_signed == 0) ? _GREEN_("ok") : _RED_("fail")
);
PrintAndLogEx(INFO, "--- " _CYAN_("New signature"));
for (int i = 0; i < (sizeof(sign) / 32); i++) {
PrintAndLogEx(INFO, " %s", sprint_hex_inrow(sign + (i * 32), 32));
}
if (shall_write) {
pm3_sign_write(sign, PM3_RSA_KEY_LEN);
}
if (got_private == false) {
mbedtls_rsa_free(rsa);
free(rsa);
mbedtls_pk_free(&pkctx);
}
mbedtls_pk_free(&pkctx);
PrintAndLogEx(NORMAL, "");
PrintAndLogEx(
(is_verified) ? SUCCESS : FAILED,
"Genuine Proxmark3 RDV4 signature detected... %s",
(is_verified) ? ":heavy_check_mark:" : ":x:"
);
PrintAndLogEx(NORMAL, "");
return PM3_SUCCESS;
}
+9 -3
View File
@@ -31,8 +31,14 @@ typedef enum {
DICTIONARY_MIFARE_ULAES,
} Dictionary_t;
typedef enum {
SIGN_RDV4 = 0,
SIGN_GENERIC,
SIGN_UNK = 99
} signature_e;
int CmdFlashMem(const char *Cmd);
int rdv4_get_signature(rdv40_validation_t *out);
int rdv4_validate(rdv40_validation_t *mem);
int rdv4_get_flash_pages64k(uint8_t *pages64k);
int pm3_get_signature(rdv40_validation_t *out);
int pm3_validate(rdv40_validation_t *mem, signature_e *type);
int pm3_get_flash_pages64k(uint8_t *pages64k);
#endif
+29 -11
View File
@@ -1575,16 +1575,25 @@ void pm3_version_short(void) {
if (IfPm3Rdv4Fw()) {
bool is_genuine_rdv4 = false;
// validate signature data
rdv40_validation_t mem;
if (rdv4_get_signature(&mem) == PM3_SUCCESS) {
if (rdv4_validate(&mem) == PM3_SUCCESS) {
is_genuine_rdv4 = true;
signature_e type;
if (pm3_get_signature(&mem) == PM3_SUCCESS) {
if (pm3_validate(&mem, &type) == PM3_SUCCESS) {
if (type == SIGN_RDV4) {
PrintAndLogEx(NORMAL, " Target.... %s", _YELLOW_("RDV4"));
} else if (type == SIGN_GENERIC) {
PrintAndLogEx(NORMAL, " Target.... %s", _YELLOW_("GENERIC"));
} else {
PrintAndLogEx(NORMAL, " Target.... %s", _RED_("device / fw mismatch"));
}
}
}
PrintAndLogEx(NORMAL, " Target.... %s", (is_genuine_rdv4) ? _YELLOW_("RDV4") : _RED_("device / fw mismatch"));
} else {
PrintAndLogEx(NORMAL, " Target.... %s", _YELLOW_("PM3 GENERIC"));
}
@@ -1702,17 +1711,26 @@ void pm3_version(bool verbose, bool oneliner) {
if (WaitForResponseTimeout(CMD_VERSION, &resp, 1000)) {
if (IfPm3Rdv4Fw()) {
bool is_genuine_rdv4 = false;
// validate signature data
rdv40_validation_t mem;
if (rdv4_get_signature(&mem) == PM3_SUCCESS) {
if (rdv4_validate(&mem) == PM3_SUCCESS) {
is_genuine_rdv4 = true;
signature_e type;
if (pm3_get_signature(&mem) == PM3_SUCCESS) {
if (pm3_validate(&mem, &type) == PM3_SUCCESS) {
if (type == SIGN_RDV4) {
PrintAndLogEx(NORMAL, " Device.................... " _GREEN_("RDV4"));
PrintAndLogEx(NORMAL, " Firmware.................. " _GREEN_("RDV4"));
} else if (type == SIGN_GENERIC) {
PrintAndLogEx(NORMAL, " Device.................... ", _GREEN_("GENERIC"));
PrintAndLogEx(NORMAL, " Firmware.................. ", _GREEN_("GENERIC"));
} else {
PrintAndLogEx(NORMAL, " Device.................... " _RED_("Bad signature detected!"));
PrintAndLogEx(NORMAL, " Firmware.................. " _YELLOW_("N/A"));
}
}
}
PrintAndLogEx(NORMAL, " Device.................... %s", (is_genuine_rdv4) ? _GREEN_("RDV4") : _RED_("device / fw mismatch"));
PrintAndLogEx(NORMAL, " Firmware.................. %s", (is_genuine_rdv4) ? _GREEN_("RDV4") : _YELLOW_("RDV4"));
PrintAndLogEx(NORMAL, " External flash............ %s", IfPm3Flash() ? _GREEN_("present") : _YELLOW_("absent"));
PrintAndLogEx(NORMAL, " Smartcard reader.......... %s", IfPm3Smartcard() ? _GREEN_("present") : _YELLOW_("absent"));
PrintAndLogEx(NORMAL, " FPC USART for BT add-on... %s", IfPm3FpcUsartHost() ? _GREEN_("present") : _YELLOW_("absent"));