From 719f4bfcdef43de9815dbfb1c0cd816fddf36bba Mon Sep 17 00:00:00 2001 From: Colin O'Flynn Date: Sun, 10 Oct 2021 12:38:27 -0300 Subject: [PATCH] Fix MF-DESFIRE decoding when not using wrapped cmds --- client/src/cmdhflist.c | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/client/src/cmdhflist.c b/client/src/cmdhflist.c index 615695667..a9046afc8 100644 --- a/client/src/cmdhflist.c +++ b/client/src/cmdhflist.c @@ -899,13 +899,31 @@ void annotateMfDesfire(char *exp, size_t size, uint8_t *cmd, uint8_t cmdsize) { snprintf(exp, size, "DELETE FILE"); break; case MFDES_AUTHENTICATE: - snprintf(exp, size, "AUTH NATIVE (keyNo %d)", cmd[pos + 4]); + if (cmdsize > 6) { + //Assume wrapped + snprintf(exp, size, "AUTH NATIVE (keyNo %d)", cmd[pos + 4]); + } else { + //Assume unwrapped + snprintf(exp, size, "AUTH NATIVE (keyNo %d)", cmd[pos + 1]); + } break; // AUTHENTICATE_NATIVE case MFDES_AUTHENTICATE_ISO: - snprintf(exp, size, "AUTH ISO (keyNo %d)", cmd[pos + 4]); + if (cmdsize > 6) { + //Assume wrapped + snprintf(exp, size, "AUTH ISO (keyNo %d)", cmd[pos + 4]); + } else { + //Assume unwrapped + snprintf(exp, size, "AUTH ISO (keyNo %d)", cmd[pos + 1]); + } break; // AUTHENTICATE_STANDARD case MFDES_AUTHENTICATE_AES: - snprintf(exp, size, "AUTH AES (keyNo %d)", cmd[pos + 4]); + if (cmdsize > 6) { + //Assume wrapped + snprintf(exp, size, "AUTH AES (keyNo %d)", cmd[pos + 4]); + } else { + //Assume unwrapped + snprintf(exp, size, "AUTH AES (keyNo %d)", cmd[pos + 1]); + } break; case MFDES_AUTHENTICATE_EV2F: snprintf(exp, size, "AUTH EV2 First");