From ec16eb557202c5f3f03c100fc7bde0aca1d5d18b Mon Sep 17 00:00:00 2001 From: Romain Tartiere Date: Sat, 23 Apr 2011 15:31:45 +0000 Subject: [PATCH] Fix mifare_desfire_create_value_file(). Fixes issue 59 Committed, thanks! PR: Issue 59 Submitted by: ervin.kaljola --- libfreefare/mifare_desfire.c | 4 +-- test/test_mifare_desfire_ev1_aes.c | 39 ++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 2 deletions(-) diff --git a/libfreefare/mifare_desfire.c b/libfreefare/mifare_desfire.c index 03242c4..1e87cfc 100644 --- a/libfreefare/mifare_desfire.c +++ b/libfreefare/mifare_desfire.c @@ -1328,12 +1328,12 @@ mifare_desfire_create_value_file (MifareTag tag, uint8_t file_no, uint8_t commun BUFFER_APPEND_LE (cmd, value, 4, sizeof (int32_t)); BUFFER_APPEND (cmd, limited_credit_enable); - char *p = mifare_cryto_preprocess_data (tag, cmd, &__cmd_n, 0, communication_settings | CMAC_COMMAND); + char *p = mifare_cryto_preprocess_data (tag, cmd, &__cmd_n, 0, MDCM_PLAIN | CMAC_COMMAND); DESFIRE_TRANSCEIVE2 (tag, p, __cmd_n, res); ssize_t sn = __res_n; - p = mifare_cryto_postprocess_data (tag, res, &sn, communication_settings | CMAC_COMMAND | CMAC_VERIFY); + p = mifare_cryto_postprocess_data (tag, res, &sn, MDCM_PLAIN | CMAC_COMMAND | CMAC_VERIFY); cached_file_settings_current[file_no] = false; diff --git a/test/test_mifare_desfire_ev1_aes.c b/test/test_mifare_desfire_ev1_aes.c index 61d21e8..676250b 100644 --- a/test/test_mifare_desfire_ev1_aes.c +++ b/test/test_mifare_desfire_ev1_aes.c @@ -870,3 +870,42 @@ test_mifare_desfire_ev1_aes_write_data_encyphered (void) free (aid); } + +void +test_mifare_desfire_ev1_aes_create_value_file_encyphered (void) +{ + int res; + + mifare_desfire_auto_authenticate (tag, 0); + + /* Wipeout the card */ + res = mifare_desfire_format_picc (tag); + cut_assert_success ("mifare_desfire_format_picc()"); + + MifareDESFireAID aid = mifare_desfire_aid_new (0x112233); + res = mifare_desfire_create_application (tag, aid, 0x0F, 0x83); + cut_assert_success ("mifare_desfire_create_application()"); + + res = mifare_desfire_select_application (tag, aid); + cut_assert_success ("mifare_desfire_select_application()"); + + MifareDESFireKey key = mifare_desfire_aes_key_new (key_data_aes); + res = mifare_desfire_authenticate_aes (tag, 0, key); + cut_assert_success ("mifare_desfire_authenticate_aes()"); + mifare_desfire_key_free (key); + + res = mifare_desfire_create_value_file (tag, 9, MDCM_ENCIPHERED, 0x0000, 0, 1000, 0, 0); + cut_assert_success ("mifare_desfire_create_value_file"); + + res = mifare_desfire_select_application (tag, NULL); + + cut_assert_success ("mifare_desfire_select_application()"); + + mifare_desfire_auto_authenticate (tag, 0); + + /* Wipeout the card */ + res = mifare_desfire_format_picc (tag); + cut_assert_success ("mifare_desfire_format_picc()"); + + free (aid); +}