mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-08-19 21:03:48 -07:00
hf iclass encrypt - now use cliparser
This commit is contained in:
parent
4d616a1c09
commit
9ef0e07d49
2 changed files with 49 additions and 57 deletions
|
@ -71,23 +71,6 @@ static int usage_hf_iclass_sim(void) {
|
||||||
PrintAndLogEx(NORMAL, "");
|
PrintAndLogEx(NORMAL, "");
|
||||||
return PM3_SUCCESS;
|
return PM3_SUCCESS;
|
||||||
}
|
}
|
||||||
static int usage_hf_iclass_encrypt(void) {
|
|
||||||
PrintAndLogEx(NORMAL, "3DES encrypt data\n");
|
|
||||||
PrintAndLogEx(NORMAL, "OBS! In order to use this function, the file " _YELLOW_("'iclass_decryptionkey.bin'") " must reside");
|
|
||||||
PrintAndLogEx(NORMAL, "in the resources directory. The file should be 16 bytes binary data\n");
|
|
||||||
PrintAndLogEx(NORMAL, "Usage: hf iclass encrypt d <blockdata> k <transport key>\n");
|
|
||||||
PrintAndLogEx(NORMAL, "Options");
|
|
||||||
PrintAndLogEx(NORMAL, " h : Show this help");
|
|
||||||
PrintAndLogEx(NORMAL, " d <block data> : 16 bytes hex");
|
|
||||||
PrintAndLogEx(NORMAL, " k <transport key> : 16 bytes hex");
|
|
||||||
PrintAndLogEx(NORMAL, " v : verbose output");
|
|
||||||
PrintAndLogEx(NORMAL, "");
|
|
||||||
PrintAndLogEx(NORMAL, "Examples:");
|
|
||||||
PrintAndLogEx(NORMAL, _YELLOW_("\thf iclass encrypt d 0102030405060708"));
|
|
||||||
PrintAndLogEx(NORMAL, _YELLOW_("\thf iclass encrypt d 0102030405060708 k 00112233445566778899AABBCCDDEEFF"));
|
|
||||||
PrintAndLogEx(NORMAL, "");
|
|
||||||
return PM3_SUCCESS;
|
|
||||||
}
|
|
||||||
static int usage_hf_iclass_dump(void) {
|
static int usage_hf_iclass_dump(void) {
|
||||||
PrintAndLogEx(NORMAL, "Dump all memory from a iCLASS tag\n");
|
PrintAndLogEx(NORMAL, "Dump all memory from a iCLASS tag\n");
|
||||||
PrintAndLogEx(NORMAL, "Usage: hf iclass dump f <fileName> k <key> c <creditkey> [e|r|v]\n");
|
PrintAndLogEx(NORMAL, "Usage: hf iclass dump f <fileName> k <key> c <creditkey> [e|r|v]\n");
|
||||||
|
@ -1082,7 +1065,7 @@ static int CmdHFiClassDecrypt(const char *Cmd) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int key_len = 0;
|
int key_len = 0;
|
||||||
uint8_t key[32] = {0};
|
uint8_t key[16] = {0};
|
||||||
uint8_t *keyptr = NULL;
|
uint8_t *keyptr = NULL;
|
||||||
bool have_key = false;
|
bool have_key = false;
|
||||||
|
|
||||||
|
@ -1269,45 +1252,53 @@ static void iclass_encrypt_block_data(uint8_t *blk_data, uint8_t *key) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static int CmdHFiClassEncryptBlk(const char *Cmd) {
|
static int CmdHFiClassEncryptBlk(const char *Cmd) {
|
||||||
bool errors = false;
|
CLIParserContext *clictx;
|
||||||
bool have_key = false;
|
CLIParserInit(&clictx, "hf iclass encrypt",
|
||||||
bool verbose = false;
|
"3DES encrypt data\n"
|
||||||
uint8_t blk_data[8] = {0};
|
"OBS! In order to use this function, the file 'iclass_decryptionkey.bin' must reside\n"
|
||||||
uint8_t key[16] = {0};
|
"in the resources directory. The file should be 16 bytes binary data",
|
||||||
uint8_t *keyptr = NULL;
|
"hf iclass encrypt -d 0102030405060708\n"
|
||||||
uint8_t cmdp = 0;
|
"hf iclass encrypt -d 0102030405060708 --key 00112233445566778899AABBCCDDEEFF");
|
||||||
|
|
||||||
while (param_getchar(Cmd, cmdp) != 0x00 && !errors) {
|
void *argtable[] = {
|
||||||
switch (tolower(param_getchar(Cmd, cmdp))) {
|
arg_param_begin,
|
||||||
case 'h':
|
arg_str1("d", "data", "<block data>", "data to encrypt"),
|
||||||
return usage_hf_iclass_encrypt();
|
arg_str0(NULL, "key", "<transport key>", "3DES transport key"),
|
||||||
case 'd':
|
arg_lit0("v", "verbose", "verbose output"),
|
||||||
if (param_gethex(Cmd, cmdp + 1, blk_data, 16)) {
|
arg_param_end
|
||||||
PrintAndLogEx(ERR, "Block data must include 16 HEX symbols");
|
};
|
||||||
errors = true;
|
CLIExecWithReturn(clictx, Cmd, argtable, false);
|
||||||
}
|
|
||||||
cmdp += 2;
|
int blk_data_len = 0;
|
||||||
break;
|
uint8_t blk_data[8] = {0};
|
||||||
case 'k':
|
|
||||||
if (param_gethex(Cmd, cmdp + 1, key, 32)) {
|
CLIGetHexWithReturn(clictx, 1, blk_data, &blk_data_len);
|
||||||
PrintAndLogEx(ERR, "Transport key must include 32 HEX symbols");
|
|
||||||
errors = true;
|
if (blk_data_len != 8) {
|
||||||
}
|
PrintAndLogEx(ERR, "Block data must be 8 bytes (16 HEX characters)");
|
||||||
have_key = true;
|
CLIParserFree(clictx);
|
||||||
cmdp += 2;
|
return PM3_EINVARG;
|
||||||
break;
|
|
||||||
case 'v':
|
|
||||||
verbose = true;
|
|
||||||
cmdp++;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
PrintAndLogEx(WARNING, "Unknown parameter '%c'\n", param_getchar(Cmd, cmdp));
|
|
||||||
errors = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (errors || cmdp < 1) return usage_hf_iclass_encrypt();
|
int key_len = 0;
|
||||||
|
uint8_t key[16] = {0};
|
||||||
|
uint8_t *keyptr = NULL;
|
||||||
|
bool have_key = false;
|
||||||
|
|
||||||
|
CLIGetHexWithReturn(clictx, 2, key, &key_len);
|
||||||
|
|
||||||
|
if (key_len > 0) {
|
||||||
|
if (key_len != 16) {
|
||||||
|
PrintAndLogEx(ERR, "Transport key must be 16 bytes (32 HEX characters)");
|
||||||
|
CLIParserFree(clictx);
|
||||||
|
return PM3_EINVARG;
|
||||||
|
}
|
||||||
|
have_key = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool verbose = arg_get_lit(clictx, 3);
|
||||||
|
|
||||||
|
CLIParserFree(clictx);
|
||||||
|
|
||||||
bool use_sc = IsCryptoHelperPresent(verbose);
|
bool use_sc = IsCryptoHelperPresent(verbose);
|
||||||
|
|
||||||
|
|
|
@ -111,10 +111,11 @@ Encrypt iCLASS Block
|
||||||
```
|
```
|
||||||
Options
|
Options
|
||||||
---
|
---
|
||||||
d <block data> : 16 bytes hex
|
-d, --data <block data> data to encrypt
|
||||||
k <transport key> : 16 bytes hex
|
--key <transport key> 3DES transport key
|
||||||
|
-v, --verbose verbose output
|
||||||
|
|
||||||
pm3 --> hf iclass encrypt d 0000000f2aa3dba8
|
pm3 --> hf iclass encrypt -d 0000000f2aa3dba8
|
||||||
```
|
```
|
||||||
|
|
||||||
Decrypt iCLASS Block / file
|
Decrypt iCLASS Block / file
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue