From c4e657f8cdf8584996846e49ce108b392ac6c968 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Fri, 14 Mar 2014 22:49:27 +0100 Subject: [PATCH] Return EACCES when authentication to a DESFire tag fails Note that in case the tag didn't authenticate us, we've also tag->last_picc_error = AUTHENTICATION_ERROR But in the unlikely event that we didn't authenticate the tag (e.g. if the tag is fake and pretends the auth was ok) only errno = EACCES will be set --- libfreefare/mifare_desfire.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/libfreefare/mifare_desfire.c b/libfreefare/mifare_desfire.c index 2be7e60..d7f4e0f 100644 --- a/libfreefare/mifare_desfire.c +++ b/libfreefare/mifare_desfire.c @@ -192,6 +192,8 @@ static ssize_t read_data (MifareTag tag, uint8_t command, uint8_t file_no, off_ res[__##res##_n-2] = __res[__##res##_n-1]; \ __##res##_n--; \ if ((1 == __##res##_n) && (ADDITIONAL_FRAME != res[__##res##_n-1]) && (OPERATION_OK != res[__##res##_n-1])) { \ + if (res[0] == AUTHENTICATION_ERROR) \ + errno = EACCES; \ return MIFARE_DESFIRE (tag)->last_picc_error = res[0], -1; \ } \ memcpy (res, __res, __##res##_n - 1); \ @@ -416,6 +418,7 @@ authenticate (MifareTag tag, uint8_t cmd, uint8_t key_no, MifareDESFireKey key) hexdump (PCD_RndA_s, key_length, "PCD ", 0); hexdump (PICC_RndA_s, key_length, "PICC ", 0); #endif + errno = EACCES; return -1; }