DesfirePrintContext prints session state

This commit is contained in:
merlokk 2021-07-04 12:47:09 +03:00
parent 5271cb96c3
commit 6124b49c99
4 changed files with 36 additions and 9 deletions

View file

@ -5195,7 +5195,7 @@ static int CmdHF14ADesGetAIDs(const char *Cmd) {
DropField();
return PM3_ESOFT;
}
if (DesfireIsAuthenticated(&dctx)) {
if (verbose)
PrintAndLogEx(ERR, "Desfire " _GREEN_("authenticated") , res);

View file

@ -390,12 +390,9 @@ void mifare_kdf_an10922(const desfirekey_t key, const uint8_t *data, size_t len)
free(buffer);
}
size_t key_block_size(const desfirekey_t key) {
if (key == NULL) {
return 0;
}
size_t desfire_get_key_block_length(enum DESFIRE_CRYPTOALGO key_type) {
size_t block_size = 8;
switch (key->type) {
switch (key_type) {
case T_DES:
case T_3DES:
case T_3K3DES:
@ -408,6 +405,13 @@ size_t key_block_size(const desfirekey_t key) {
return block_size;
}
size_t key_block_size(const desfirekey_t key) {
if (key == NULL) {
return 0;
}
return desfire_get_key_block_length(key->type);
}
size_t key_size(const enum DESFIRE_CRYPTOALGO algo) {
switch (algo) {
case T_DES:

View file

@ -82,6 +82,7 @@ enum DESFIRE_CRYPTOALGO {
};
int desfire_get_key_length(enum DESFIRE_CRYPTOALGO key_type);
size_t desfire_get_key_block_length(enum DESFIRE_CRYPTOALGO key_type);
enum DESFIRE_AUTH_SCHEME {
AS_LEGACY,

View file

@ -227,9 +227,31 @@ void DesfireClearSession(DesfireContext *ctx) {
}
void DesfirePrintContext(DesfireContext *ctx) {
//PrintAndLogEx(INFO, "algo: %s", CLIGetOptionListStr(algo_opts, ARRAY_LENGTH(algo_opts), algores));
PrintAndLogEx(INFO, "Key num: %d Key algo: %s Key[%d]: %s", ctx->keyNum, CLIGetOptionListStr(DesfireAlgoOpts, ctx->keyType), key_size(ctx->keyType), sprint_hex(ctx->key, key_size(ctx->keyType)));
}
PrintAndLogEx(INFO, "Key num: %d Key algo: %s Key[%d]: %s",
ctx->keyNum,
CLIGetOptionListStr(DesfireAlgoOpts, ctx->keyType),
key_size(ctx->keyType),
sprint_hex(ctx->key,
key_size(ctx->keyType)));
if (ctx->kdfAlgo != MFDES_KDF_ALGO_NONE)
PrintAndLogEx(INFO, "KDF algo: %s KDF input[%d]: %s", CLIGetOptionListStr(DesfireKDFAlgoOpts, ctx->kdfAlgo), ctx->kdfInputLen, sprint_hex(ctx->kdfInput, ctx->kdfInputLen));
PrintAndLogEx(INFO, "Secure channel: %s Command set: %s Communication mode: %s",
CLIGetOptionListStr(DesfireSecureChannelOpts, ctx->secureChannel),
CLIGetOptionListStr(DesfireCommandSetOpts, ctx->cmdSet),
CLIGetOptionListStr(DesfireCommunicationModeOpts, ctx->commMode));
if (DesfireIsAuthenticated(ctx)) {
PrintAndLogEx(INFO, "Session key MAC [%d]: %s ENC: %s IV [%d]: %s",
key_size(ctx->keyType),
sprint_hex(ctx->sessionKeyMAC, key_size(ctx->keyType)),
sprint_hex(ctx->sessionKeyEnc, key_size(ctx->keyType)),
desfire_get_key_block_length(ctx->keyType),
sprint_hex(ctx->sessionKeyEnc, desfire_get_key_block_length(ctx->keyType)));
}
}
void DesfireSetKey(DesfireContext *ctx, uint8_t keyNum, enum DESFIRE_CRYPTOALGO keyType, uint8_t *key) {
DesfireClearContext(ctx);