mf desfire: change detection algorithm to check master key version

This commit is contained in:
gornekich 2024-03-07 19:29:18 +00:00
parent 43d1659200
commit b1a9904ea5
5 changed files with 43 additions and 16 deletions

View file

@ -225,8 +225,8 @@ static bool mf_desfire_poller_detect(NfcGenericEvent event, void* context) {
bool protocol_detected = false;
if(iso14443_4a_event->type == Iso14443_4aPollerEventTypeReady) {
MfDesfireKeySettings key_settings = {};
MfDesfireError error = mf_desfire_poller_read_key_settings(instance, &key_settings);
MfDesfireKeyVersion key_version = 0;
MfDesfireError error = mf_desfire_poller_read_key_version(instance, 0, &key_version);
protocol_detected = (error == MfDesfireErrorNone);
}

View file

@ -91,6 +91,21 @@ MfDesfireError
MfDesfireError
mf_desfire_poller_read_key_settings(MfDesfirePoller* instance, MfDesfireKeySettings* data);
/**
* @brief Read key version on MfDesfire card.
*
* Must ONLY be used inside the callback function.
*
* @param[in, out] instance pointer to the instance to be used in the transaction.
* @param[out] key_num key number.
* @param[in] data pointer to the MfDesfireKeyVersion structure to be filled with key version data.
* @return MfDesfireErrorNone on success, an error code on failure.
*/
MfDesfireError mf_desfire_poller_read_key_version(
MfDesfirePoller* instance,
uint8_t key_num,
MfDesfireKeyVersion* data);
/**
* @brief Read key versions on MfDesfire card.
*

View file

@ -139,6 +139,28 @@ MfDesfireError
return error;
}
MfDesfireError mf_desfire_poller_read_key_version(
MfDesfirePoller* instance,
uint8_t key_num,
MfDesfireKeyVersion* data) {
furi_assert(instance);
furi_assert(data);
bit_buffer_set_size_bytes(instance->input_buffer, sizeof(uint8_t) * 2);
bit_buffer_set_byte(instance->input_buffer, 0, MF_DESFIRE_CMD_GET_KEY_VERSION);
bit_buffer_set_byte(instance->input_buffer, 1, key_num);
MfDesfireError error =
mf_desfire_send_chunks(instance, instance->input_buffer, instance->result_buffer);
if(error == MfDesfireErrorNone) {
if(!mf_desfire_key_version_parse(data, instance->result_buffer)) {
error = MfDesfireErrorProtocol;
}
}
return error;
}
MfDesfireError mf_desfire_poller_read_key_versions(
MfDesfirePoller* instance,
SimpleArray* data,
@ -148,22 +170,11 @@ MfDesfireError mf_desfire_poller_read_key_versions(
simple_array_init(data, count);
bit_buffer_set_size_bytes(instance->input_buffer, sizeof(uint8_t) * 2);
bit_buffer_set_byte(instance->input_buffer, 0, MF_DESFIRE_CMD_GET_KEY_VERSION);
MfDesfireError error = MfDesfireErrorNone;
for(uint32_t i = 0; i < count; ++i) {
bit_buffer_set_byte(instance->input_buffer, 1, i);
error = mf_desfire_send_chunks(instance, instance->input_buffer, instance->result_buffer);
error = mf_desfire_poller_read_key_version(instance, i, simple_array_get(data, i));
if(error != MfDesfireErrorNone) break;
if(!mf_desfire_key_version_parse(simple_array_get(data, i), instance->result_buffer)) {
error = MfDesfireErrorProtocol;
break;
}
}
return error;

View file

@ -1,5 +1,5 @@
entry,status,name,type,params
Version,+,58.0,,
Version,+,58.1,,
Header,+,applications/services/bt/bt_service/bt.h,,
Header,+,applications/services/cli/cli.h,,
Header,+,applications/services/cli/cli_vcp.h,,

1 entry status name type params
2 Version + 58.0 58.1
3 Header + applications/services/bt/bt_service/bt.h
4 Header + applications/services/cli/cli.h
5 Header + applications/services/cli/cli_vcp.h

View file

@ -1,5 +1,5 @@
entry,status,name,type,params
Version,+,58.0,,
Version,+,58.1,,
Header,+,applications/drivers/subghz/cc1101_ext/cc1101_ext_interconnect.h,,
Header,+,applications/services/bt/bt_service/bt.h,,
Header,+,applications/services/cli/cli.h,,
@ -2444,6 +2444,7 @@ Function,+,mf_desfire_poller_read_file_settings_multi,MfDesfireError,"MfDesfireP
Function,+,mf_desfire_poller_read_file_value,MfDesfireError,"MfDesfirePoller*, MfDesfireFileId, MfDesfireFileData*"
Function,+,mf_desfire_poller_read_free_memory,MfDesfireError,"MfDesfirePoller*, MfDesfireFreeMemory*"
Function,+,mf_desfire_poller_read_key_settings,MfDesfireError,"MfDesfirePoller*, MfDesfireKeySettings*"
Function,+,mf_desfire_poller_read_key_version,MfDesfireError,"MfDesfirePoller*, uint8_t, MfDesfireKeyVersion*"
Function,+,mf_desfire_poller_read_key_versions,MfDesfireError,"MfDesfirePoller*, SimpleArray*, uint32_t"
Function,+,mf_desfire_poller_read_version,MfDesfireError,"MfDesfirePoller*, MfDesfireVersion*"
Function,+,mf_desfire_poller_select_application,MfDesfireError,"MfDesfirePoller*, const MfDesfireApplicationId*"

1 entry status name type params
2 Version + 58.0 58.1
3 Header + applications/drivers/subghz/cc1101_ext/cc1101_ext_interconnect.h
4 Header + applications/services/bt/bt_service/bt.h
5 Header + applications/services/cli/cli.h
2444 Function + mf_desfire_poller_read_file_value MfDesfireError MfDesfirePoller*, MfDesfireFileId, MfDesfireFileData*
2445 Function + mf_desfire_poller_read_free_memory MfDesfireError MfDesfirePoller*, MfDesfireFreeMemory*
2446 Function + mf_desfire_poller_read_key_settings MfDesfireError MfDesfirePoller*, MfDesfireKeySettings*
2447 Function + mf_desfire_poller_read_key_version MfDesfireError MfDesfirePoller*, uint8_t, MfDesfireKeyVersion*
2448 Function + mf_desfire_poller_read_key_versions MfDesfireError MfDesfirePoller*, SimpleArray*, uint32_t
2449 Function + mf_desfire_poller_read_version MfDesfireError MfDesfirePoller*, MfDesfireVersion*
2450 Function + mf_desfire_poller_select_application MfDesfireError MfDesfirePoller*, const MfDesfireApplicationId*