Fix write_data() return value when data is enciphered.
We only have to return the number of bytes of raw data which are sent.
This commit is contained in:
parent
2750ed668c
commit
8caa2da31e
2 changed files with 42 additions and 3 deletions
|
@ -1353,6 +1353,7 @@ write_data (MifareTag tag, uint8_t command, uint8_t file_no, off_t offset, size_
|
||||||
BUFFER_APPEND_BYTES (cmd, data, length);
|
BUFFER_APPEND_BYTES (cmd, data, length);
|
||||||
|
|
||||||
uint8_t *p = mifare_cryto_preprocess_data (tag, cmd, &__cmd_n, 8, cs | MAC_COMMAND | CMAC_COMMAND | ENC_COMMAND);
|
uint8_t *p = mifare_cryto_preprocess_data (tag, cmd, &__cmd_n, 8, cs | MAC_COMMAND | CMAC_COMMAND | ENC_COMMAND);
|
||||||
|
size_t overhead_size = __cmd_n - length; // (CRC | padding) + headers
|
||||||
|
|
||||||
BUFFER_INIT(d, FRAME_PAYLOAD_SIZE);
|
BUFFER_INIT(d, FRAME_PAYLOAD_SIZE);
|
||||||
bytes_left = FRAME_PAYLOAD_SIZE - 8;
|
bytes_left = FRAME_PAYLOAD_SIZE - 8;
|
||||||
|
@ -1379,7 +1380,7 @@ write_data (MifareTag tag, uint8_t command, uint8_t file_no, off_t offset, size_
|
||||||
|
|
||||||
if (0x00 == p[__res_n-1]) {
|
if (0x00 == p[__res_n-1]) {
|
||||||
// Remove header length
|
// Remove header length
|
||||||
bytes_send -= 8;
|
bytes_send -= overhead_size;
|
||||||
} else {
|
} else {
|
||||||
// 0xAF (additionnal Frame) failure can happen here (wrong crypto method).
|
// 0xAF (additionnal Frame) failure can happen here (wrong crypto method).
|
||||||
MIFARE_DESFIRE (tag)->last_picc_error = p[__res_n-1];
|
MIFARE_DESFIRE (tag)->last_picc_error = p[__res_n-1];
|
||||||
|
|
|
@ -56,8 +56,6 @@ test_mifare_desfire_ev1_aes (void)
|
||||||
*/
|
*/
|
||||||
res = mifare_desfire_change_key_settings (tag, 0xF);
|
res = mifare_desfire_change_key_settings (tag, 0xF);
|
||||||
cut_assert_success ("mifare_desfire_change_key_settings()");
|
cut_assert_success ("mifare_desfire_change_key_settings()");
|
||||||
res = mifare_desfire_change_key_settings (tag, 0xF);
|
|
||||||
cut_assert_success ("mifare_desfire_change_key_settings()");
|
|
||||||
|
|
||||||
/* Change master key to AES */
|
/* Change master key to AES */
|
||||||
MifareDESFireKey key = mifare_desfire_aes_key_new_with_version (key_data_aes, key_data_aes_version);
|
MifareDESFireKey key = mifare_desfire_aes_key_new_with_version (key_data_aes, key_data_aes_version);
|
||||||
|
@ -828,3 +826,43 @@ test_mifare_desfire_ev1_aes (void)
|
||||||
free (aid_d);
|
free (aid_d);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
test_mifare_desfire_ev1_aes_write_data_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_std_data_file (tag, 9, MDCM_ENCIPHERED, 0x0000, 7);
|
||||||
|
cut_assert_success ("mifare_desfire_create_std_data_file()");
|
||||||
|
|
||||||
|
res = mifare_desfire_write_data (tag, 9, 0, 5, "Hello");
|
||||||
|
cut_assert_equal_int (5, res, cut_message ("Wrong value returned"));
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue