mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-08-19 21:03:48 -07:00
KS X 6924 - Implement the initialize card function
This commit is contained in:
parent
18258af4f2
commit
b19117b6ab
3 changed files with 87 additions and 0 deletions
|
@ -237,6 +237,55 @@ static int CmdHFKSX6924Select(const char *Cmd) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int CmdHFKSX6924InitializeCard(const char *Cmd) {
|
||||||
|
CLIParserContext *ctx;
|
||||||
|
CLIParserInit(&ctx, "hf ksx6924 initializecard",
|
||||||
|
"Perform transaction initialization. (Mpda)\n",
|
||||||
|
"Usage:\n\thf ksx6924 initializecard 000003e8 -> Mpda\n");
|
||||||
|
|
||||||
|
void *argtable[] = {
|
||||||
|
arg_param_begin,
|
||||||
|
arg_lit0("kK", "keep", "keep field ON for next command"),
|
||||||
|
arg_lit0("aA", "apdu", "show APDU reqests and responses"),
|
||||||
|
arg_strx1(NULL, NULL, "<Mpda 4byte hex>", NULL),
|
||||||
|
arg_param_end
|
||||||
|
};
|
||||||
|
CLIExecWithReturn(ctx, Cmd, argtable, true);
|
||||||
|
|
||||||
|
bool leaveSignalON = arg_get_lit(ctx, 1);
|
||||||
|
bool APDULogging = arg_get_lit(ctx, 2);
|
||||||
|
uint8_t data[APDU_RES_LEN] = {0};
|
||||||
|
int datalen = 0;
|
||||||
|
CLIGetHexWithReturn(ctx, 3, data, &datalen);
|
||||||
|
CLIParserFree(ctx);
|
||||||
|
SetAPDULogging(APDULogging);
|
||||||
|
|
||||||
|
if (datalen != 4) {
|
||||||
|
PrintAndLogEx(WARNING, "Mpda parameter must be 4 byte long (eg: 000003e8)");
|
||||||
|
goto end;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ret = KSX6924TrySelect();
|
||||||
|
if (!ret) {
|
||||||
|
goto end;
|
||||||
|
}
|
||||||
|
|
||||||
|
PrintAndLogEx(NORMAL, "Initialize Card : Mpda -> %02X %02X %02X %02X", data[0], data[1], data[2], data[3]);
|
||||||
|
uint8_t response[25];
|
||||||
|
if (!KSX6924InitializeCard(data[0], data[1], data[2], data[3], response)) {
|
||||||
|
PrintAndLogEx(FAILED, "Initialize Card Error");
|
||||||
|
goto end;
|
||||||
|
}
|
||||||
|
|
||||||
|
PrintAndLogEx(NORMAL, "Response : %s", sprint_hex(response, sizeof(response)));
|
||||||
|
|
||||||
|
end:
|
||||||
|
if (!leaveSignalON) {
|
||||||
|
DropField();
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static int CmdHFKSX6924PRec(const char *Cmd) {
|
static int CmdHFKSX6924PRec(const char *Cmd) {
|
||||||
CLIParserContext *ctx;
|
CLIParserContext *ctx;
|
||||||
CLIParserInit(&ctx, "hf ksx6924 prec",
|
CLIParserInit(&ctx, "hf ksx6924 prec",
|
||||||
|
|
|
@ -445,6 +445,41 @@ fail:
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Perform transaction initialization.
|
||||||
|
*/
|
||||||
|
bool KSX6924InitializeCard(uint8_t mpda1, uint8_t mpda2, uint8_t mpda3, uint8_t mpda4, uint8_t *result) {
|
||||||
|
if (result == NULL) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint16_t sw;
|
||||||
|
size_t result_len;
|
||||||
|
uint8_t rawResult[1 /* ALGep */ + 1 /* VKep */ + 4 /* BALep */ + 1 /* IDcenter */ + 8 /* IDep */ + 4 /* NTep */ + 4 /* Sign1 */ + 2 /* sw */];
|
||||||
|
memset(rawResult, 0, sizeof(rawResult));
|
||||||
|
uint8_t data[] = {mpda1, mpda2, mpda3, mpda4};
|
||||||
|
int res = FIDOExchange((sAPDU_t) {0x90, 0x02, 0x00, 0x00, 0x04, data}, rawResult, sizeof(rawResult),
|
||||||
|
&result_len, &sw);
|
||||||
|
if (res) {
|
||||||
|
// error communicating
|
||||||
|
goto fail;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sw != 0x9000) {
|
||||||
|
// card returned error
|
||||||
|
goto fail;
|
||||||
|
}
|
||||||
|
|
||||||
|
//*result = ntohl(*(uint32_t*)(rawResult));
|
||||||
|
memcpy(result, rawResult, result_len + 2 /* sw */);
|
||||||
|
return true;
|
||||||
|
|
||||||
|
fail:
|
||||||
|
*result = 0;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Issues a proprietary "get record" command (CLA=90, INS=4C).
|
* Issues a proprietary "get record" command (CLA=90, INS=4C).
|
||||||
*
|
*
|
||||||
|
|
|
@ -86,6 +86,9 @@ bool KSX6924TrySelect(void);
|
||||||
// selected.
|
// selected.
|
||||||
bool KSX6924GetBalance(uint32_t *result);
|
bool KSX6924GetBalance(uint32_t *result);
|
||||||
|
|
||||||
|
// Perform transaction initialization.
|
||||||
|
bool KSX6924InitializeCard(uint8_t mpda1, uint8_t mpda2, uint8_t mpda3, uint8_t mpda4, uint8_t *result);
|
||||||
|
|
||||||
// Proprietary get record command. Function unknown.
|
// Proprietary get record command. Function unknown.
|
||||||
// result must be 10 bytes long.
|
// result must be 10 bytes long.
|
||||||
bool KSX6924ProprietaryGetRecord(
|
bool KSX6924ProprietaryGetRecord(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue