diff --git a/applications/main/nfc/application.fam b/applications/main/nfc/application.fam index 12a28b604..4f0d10a52 100644 --- a/applications/main/nfc/application.fam +++ b/applications/main/nfc/application.fam @@ -38,6 +38,15 @@ App( sources=["plugins/supported_cards/opal.c"], ) +App( + appid="mykey_parser", + apptype=FlipperAppType.PLUGIN, + entry_point="mykey_plugin_ep", + targets=["f7"], + requires=["nfc"], + sources=["plugins/supported_cards/mykey.c"], +) + App( appid="myki_parser", apptype=FlipperAppType.PLUGIN, @@ -56,15 +65,6 @@ App( sources=["plugins/supported_cards/troika.c"], ) -App( - appid="social_moscow_parser", - apptype=FlipperAppType.PLUGIN, - entry_point="social_moscow_plugin_ep", - targets=["f7"], - requires=["nfc"], - sources=["plugins/supported_cards/social_moscow.c"], -) - App( appid="plantain_parser", apptype=FlipperAppType.PLUGIN, @@ -83,6 +83,15 @@ App( sources=["plugins/supported_cards/two_cities.c"], ) +App( + appid="aime_parser", + apptype=FlipperAppType.PLUGIN, + entry_point="aime_plugin_ep", + targets=["f7"], + requires=["nfc"], + sources=["plugins/supported_cards/aime.c"], +) + App( appid="umarsh_parser", apptype=FlipperAppType.PLUGIN, @@ -92,6 +101,15 @@ App( sources=["plugins/supported_cards/umarsh.c"], ) +App( + appid="social_moscow_parser", + apptype=FlipperAppType.PLUGIN, + entry_point="social_moscow_plugin_ep", + targets=["f7"], + requires=["nfc"], + sources=["plugins/supported_cards/social_moscow.c"], +) + App( appid="metromoney_parser", apptype=FlipperAppType.PLUGIN, @@ -110,15 +128,6 @@ App( sources=["plugins/supported_cards/kazan.c"], ) -App( - appid="aime_parser", - apptype=FlipperAppType.PLUGIN, - entry_point="aime_plugin_ep", - targets=["f7"], - requires=["nfc"], - sources=["plugins/supported_cards/aime.c"], -) - App( appid="saflok_parser", apptype=FlipperAppType.PLUGIN, @@ -128,15 +137,6 @@ App( sources=["plugins/supported_cards/saflok.c"], ) -App( - appid="mykey_parser", - apptype=FlipperAppType.PLUGIN, - entry_point="mykey_plugin_ep", - targets=["f7"], - requires=["nfc"], - sources=["plugins/supported_cards/mykey.c"], -) - App( appid="sonicare_parser", apptype=FlipperAppType.PLUGIN, diff --git a/applications/main/nfc/plugins/supported_cards/mykey.c b/applications/main/nfc/plugins/supported_cards/mykey.c index d7a0ea4fd..69fd18ee3 100644 --- a/applications/main/nfc/plugins/supported_cards/mykey.c +++ b/applications/main/nfc/plugins/supported_cards/mykey.c @@ -1,119 +1,112 @@ #include "nfc_supported_card_plugin.h" + #include -#include -#include -#include +#include +#include -//Structures data of mykey card -enum { - MYKEY_BLOCK_KEY_ID = 0x07, - MYKEY_BLOCK_PRODUCTION_DATE = 0x08, - MYKEY_BLOCK_VENDOR_ID_1 = 0x18, - MYKEY_BLOCK_VENDOR_ID_2 = 0x19, - MYKEY_BLOCK_CURRENT_CREDIT = 0x21, - MYKEY_BLOCK_PREVIOUS_CREDIT = 0x23, - MYKEY_DEFAULT_VENDOR_ID = 0xFEDC0123, - MYKEY_DEFAULT_VENDOR_ID_1 = 0xFEDC, - MYKEY_DEFAULT_VENDOR_ID_2 = 0x0123, -}; +#define TAG "MyKey" -typedef enum { - LockIdStatusNone, - LockIdStatusActive, -} LockIdStatus; +const uint32_t blankBlock18 = 0x480FCD8F, blankBlock19 = 0x070082C0; -/* Function to obtain the UID as a 32-bit */ -uint32_t get_uid(const uint8_t uid[8]) { - return (uid[7] | (uid[6] << 8) | (uid[5] << 16) | (uid[4] << 24)); +static bool mykey_is_blank(const St25tbData* data) { + return data->blocks[0x18] == blankBlock18 && data->blocks[0x19] == blankBlock19; } -/* OTP calculation (reverse block 6, incremental. 1,2,3, ecc.) */ -uint32_t new_get_count_down_counter(uint32_t b6) { - return ~(b6 << 24 | (b6 & 0x0000FF00) << 8 | (b6 & 0x00FF0000) >> 8 | b6 >> 24); -} - -/* Function to check if the vendor is bound */ -int get_is_bound(uint32_t vendor_id) { - return (vendor_id != MYKEY_DEFAULT_VENDOR_ID); -} - -/* MK = UID * VENDOR */ -uint32_t get_master_key(uint32_t uid, uint32_t vendor_id) { - return uid * (vendor_id + 1); -} - -/* SK (Encryption key) = MK * OTP */ -uint32_t get_encryption_key(uint32_t master_key, uint32_t count_down_counter) { - return master_key * (count_down_counter + 1); -} - -/* Encode or decode a MyKey block */ -uint32_t encode_decode_block(uint32_t input) { - /* - * Swap all values using XOR - * 32 bit: 1111222233334444 - */ - input ^= (input & 0x00C00000) << 6 | (input & 0x0000C000) << 12 | (input & 0x000000C0) << 18 | - (input & 0x000C0000) >> 6 | (input & 0x00030000) >> 12 | (input & 0x00000300) >> 6; - input ^= (input & 0x30000000) >> 6 | (input & 0x0C000000) >> 12 | (input & 0x03000000) >> 18 | - (input & 0x00003000) << 6 | (input & 0x00000030) << 12 | (input & 0x0000000C) << 6; - input ^= (input & 0x00C00000) << 6 | (input & 0x0000C000) << 12 | (input & 0x000000C0) << 18 | - (input & 0x000C0000) >> 6 | (input & 0x00030000) >> 12 | (input & 0x00000300) >> 6; - return input; -} - -uint32_t get_block(uint32_t block) { - return encode_decode_block(__bswap32(block)); -} - -uint32_t get_xored_block(uint32_t block, uint32_t key) { - return encode_decode_block(__bswap32(block) ^ key); -} - -uint32_t get_vendor(uint32_t b1, uint32_t b2) { - return b1 << 16 | (b2 & 0x0000FFFF); +static bool mykey_has_lockid(const St25tbData* data) { + return (data->blocks[5] & 0xFF) == 0x7F; } static bool mykey_parse(const NfcDevice* device, FuriString* parsed_data) { furi_assert(device); furi_assert(parsed_data); - bool parsed = false; + const St25tbData* data = nfc_device_get_data(device, NfcProtocolSt25tb); - do { - //Get data - const St25tbData* data = nfc_device_get_data(device, NfcProtocolSt25tb); + if(data->type != St25tbType04k && data->type != St25tbTypeX4k) { + FURI_LOG_D(TAG, "bad type"); + return false; + } - //Calc data - uint32_t _uid = get_uid(data->uid); - uint32_t _count_down_counter_new = new_get_count_down_counter(__bswap32(data->blocks[6])); - uint32_t _vendor_id = get_vendor( - get_block(data->blocks[MYKEY_BLOCK_VENDOR_ID_1]), - get_block(data->blocks[MYKEY_BLOCK_VENDOR_ID_2])); - uint32_t _master_key = get_master_key(_uid, _vendor_id); - uint32_t _encryption_key = get_encryption_key(_master_key, _count_down_counter_new); - uint16_t credit = - get_xored_block(data->blocks[MYKEY_BLOCK_CURRENT_CREDIT], _encryption_key); - uint16_t _previous_credit = get_block(data->blocks[MYKEY_BLOCK_PREVIOUS_CREDIT]); - bool _is_bound = get_is_bound(_vendor_id); + for(int i = 0; i < 5; i++) { + if(data->blocks[i] != 0xFFFFFFFF) { + FURI_LOG_D(TAG, "bad otp block %d", i); + return false; + } + } - //parse data - furi_string_cat_printf(parsed_data, "\e#MyKey Card\n"); - furi_string_cat_printf(parsed_data, "UID: %08lX\n", _uid); - furi_string_cat_printf(parsed_data, "Vendor ID: %08lX\n", _vendor_id); + if((data->blocks[8] >> 16 & 0xFF) > 0x31 || (data->blocks[8] >> 8 & 0xFF) > 0x12) { + FURI_LOG_D(TAG, "bad mfg date"); + return false; + } + + if(data->system_otp_block != 0xFEFFFFFF) { + FURI_LOG_D(TAG, "bad sys otp block"); + return false; + } + + furi_string_cat(parsed_data, "\e#MyKey\n"); + + if(data->blocks[6] == 0) { // Tag is actually a MyKey but it has been bricked by a reader + furi_string_cat(parsed_data, "\e#Bricked!\nBlock 6 is 0!"); + return true; + } + + bool is_blank = mykey_is_blank(data); + furi_string_cat_printf(parsed_data, "Serial#: %08lX\n", __bswap32(data->blocks[7])); + furi_string_cat_printf(parsed_data, "Blank: %s\n", is_blank ? "yes" : "no"); + furi_string_cat_printf(parsed_data, "LockID: %s\n", mykey_has_lockid(data) ? "maybe" : "no"); + + uint32_t block8 = data->blocks[8]; + furi_string_cat_printf( + parsed_data, + "Prod. date: %02lX/%02lX/%04lX", + block8 >> 16 & 0xFF, + block8 >> 8 & 0xFF, + 0x2000 + (block8 & 0xFF)); + + if(!is_blank) { furi_string_cat_printf( - parsed_data, "Current Credit: %d.%02d E \n", credit / 100, credit % 100); - furi_string_cat_printf( - parsed_data, - "Previus Credit: %d.%02d E \n", - _previous_credit / 100, - _previous_credit % 100); - furi_string_cat_printf(parsed_data, "Is Bound: %s\n", _is_bound ? "yes" : "no"); + parsed_data, "\nOp. count: %ld\n", __bswap32(data->blocks[0x12] & 0xFFFFFF00)); - parsed = true; - } while(false); + uint32_t block3C = data->blocks[0x3C]; + if(block3C == 0xFFFFFFFF) { + furi_string_cat(parsed_data, "No history available!"); + } else { + block3C ^= data->blocks[0x07]; + uint32_t startingOffset = ((block3C & 0x30000000) >> 28) | + ((block3C & 0x00100000) >> 18); + furi_check(startingOffset < 8); + for(int txnOffset = 8; txnOffset > 0; txnOffset--) { + uint32_t txnBlock = + __bswap32(data->blocks[0x34 + ((startingOffset + txnOffset) % 8)]); - return parsed; + if(txnBlock == 0xFFFFFFFF) { + break; + } + + uint8_t day = txnBlock >> 27; + uint8_t month = txnBlock >> 23 & 0xF; + uint16_t year = 2000 + (txnBlock >> 16 & 0x7F); + uint16_t credit = txnBlock & 0xFFFF; + + if(txnOffset == 8) { + furi_string_cat_printf( + parsed_data, "Current credit: %d.%02d euros\n", credit / 100, credit % 100); + furi_string_cat(parsed_data, "Op. history (newest first):"); + } + + furi_string_cat_printf( + parsed_data, + "\n %02d/%02d/%04d %d.%02d", + day, + month, + year, + credit / 100, + credit % 100); + } + } + } + return true; } /* Actual implementation of app<>plugin interface */ @@ -134,4 +127,4 @@ static const FlipperAppPluginDescriptor mykey_plugin_descriptor = { /* Plugin entry point - must return a pointer to const descriptor */ const FlipperAppPluginDescriptor* mykey_plugin_ep() { return &mykey_plugin_descriptor; -} \ No newline at end of file +} diff --git a/applications/main/nfc/resources/nfc/assets/mf_classic_dict.nfc b/applications/main/nfc/resources/nfc/assets/mf_classic_dict.nfc index ed576013c..aa36a86aa 100644 --- a/applications/main/nfc/resources/nfc/assets/mf_classic_dict.nfc +++ b/applications/main/nfc/resources/nfc/assets/mf_classic_dict.nfc @@ -4142,3 +4142,6 @@ B2AFBF2331D4 AEE297CB2FD6 3DA5DFA54604 0CF1A2AA1F8D +# Volgograd (Russia) Volna transport cards keys +2B787A063D5D +D37C8F1793F7