Do not fail crypto error without reporting
Make sure last_pcd_error is set when failing on crypto errors. While there: - make sure warn()/warnx() are inside WITH_DEBUG, - set last_pcd_error and res before calling abort() - #include <stdlib.h> for abort()
This commit is contained in:
parent
5e5a0828af
commit
494233d33b
1 changed files with 13 additions and 8 deletions
|
@ -56,6 +56,7 @@
|
||||||
#include <openssl/aes.h>
|
#include <openssl/aes.h>
|
||||||
#include <openssl/des.h>
|
#include <openssl/des.h>
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
#include <err.h>
|
#include <err.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <strings.h>
|
#include <strings.h>
|
||||||
|
@ -422,12 +423,13 @@ mifare_cryto_preprocess_data (FreefareTag tag, void *data, size_t *nbytes, off_t
|
||||||
mifare_cypher_blocks_chained (tag, NULL, NULL, res + offset, *nbytes - offset, MCD_SEND, (AS_NEW == MIFARE_DESFIRE (tag)->authentication_scheme) ? MCO_ENCYPHER : MCO_DECYPHER);
|
mifare_cypher_blocks_chained (tag, NULL, NULL, res + offset, *nbytes - offset, MCD_SEND, (AS_NEW == MIFARE_DESFIRE (tag)->authentication_scheme) ? MCO_ENCYPHER : MCO_DECYPHER);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
warnx ("Unknown communication settings");
|
MIFARE_DESFIRE (tag)->last_pcd_error = CRYPTO_ERROR;
|
||||||
#ifdef WITH_DEBUG
|
|
||||||
abort ();
|
|
||||||
#endif
|
|
||||||
*nbytes = -1;
|
*nbytes = -1;
|
||||||
res = NULL;
|
res = NULL;
|
||||||
|
#ifdef WITH_DEBUG
|
||||||
|
warnx ("Unknown communication settings");
|
||||||
|
abort ();
|
||||||
|
#endif
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -464,6 +466,7 @@ mifare_cryto_postprocess_data (FreefareTag tag, void *data, ssize_t *nbytes, int
|
||||||
if (communication_settings & MAC_VERIFY) {
|
if (communication_settings & MAC_VERIFY) {
|
||||||
*nbytes -= key_macing_length (key);
|
*nbytes -= key_macing_length (key);
|
||||||
if (*nbytes <= 0) {
|
if (*nbytes <= 0) {
|
||||||
|
MIFARE_DESFIRE (tag)->last_pcd_error = CRYPTO_ERROR;
|
||||||
*nbytes = -1;
|
*nbytes = -1;
|
||||||
res = NULL;
|
res = NULL;
|
||||||
#ifdef WITH_DEBUG
|
#ifdef WITH_DEBUG
|
||||||
|
@ -499,6 +502,7 @@ mifare_cryto_postprocess_data (FreefareTag tag, void *data, ssize_t *nbytes, int
|
||||||
break;
|
break;
|
||||||
if (communication_settings & CMAC_VERIFY) {
|
if (communication_settings & CMAC_VERIFY) {
|
||||||
if (*nbytes < 9) {
|
if (*nbytes < 9) {
|
||||||
|
MIFARE_DESFIRE (tag)->last_pcd_error = CRYPTO_ERROR;
|
||||||
*nbytes = -1;
|
*nbytes = -1;
|
||||||
res = NULL;
|
res = NULL;
|
||||||
#ifdef WITH_DEBUG
|
#ifdef WITH_DEBUG
|
||||||
|
@ -654,12 +658,13 @@ mifare_cryto_postprocess_data (FreefareTag tag, void *data, ssize_t *nbytes, int
|
||||||
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
warnx ("Unknown communication settings");
|
MIFARE_DESFIRE (tag)->last_pcd_error = CRYPTO_ERROR;
|
||||||
#ifdef WITH_DEBUG
|
|
||||||
abort ();
|
|
||||||
#endif
|
|
||||||
*nbytes = -1;
|
*nbytes = -1;
|
||||||
res = NULL;
|
res = NULL;
|
||||||
|
#ifdef WITH_DEBUG
|
||||||
|
warnx ("Unknown communication settings");
|
||||||
|
abort ();
|
||||||
|
#endif
|
||||||
break;
|
break;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue