From 48b161d67ccacd0e63c609d32c1b92b5d6c71c20 Mon Sep 17 00:00:00 2001 From: Romain Tartiere Date: Sat, 18 Dec 2010 01:32:56 +0000 Subject: [PATCH] Invalidate authentication when changing the currently used key. --- libfreefare/mifare_desfire.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/libfreefare/mifare_desfire.c b/libfreefare/mifare_desfire.c index a312d3f..f42c69e 100644 --- a/libfreefare/mifare_desfire.c +++ b/libfreefare/mifare_desfire.c @@ -554,6 +554,15 @@ mifare_desfire_change_key (MifareTag tag, uint8_t key_no, MifareDESFireKey new_k ssize_t sn = __res_n; mifare_cryto_postprocess_data (tag, res, &sn, MDCM_PLAIN | CMAC_COMMAND | CMAC_VERIFY); + /* + * If we changed the current authenticated key, we are not authenticated + * anymore. + */ + if (key_no == MIFARE_DESFIRE (tag)->authenticated_key_no) { + free (MIFARE_DESFIRE (tag)->session_key); + MIFARE_DESFIRE (tag)->session_key = NULL; + } + return 0; }