SubGhz: reading keys from encrypted files (#803)

* SubGhz: add file with manufactory codes, and the ability to add your own manufactory codes for KeeLog
* SubGhz: add encrypt RAW data, add decrypt and get RAW data
* SubGhz: add encrypt  magic_xor_atomo
* SubGhz: parsing atomo using file encrypt
* SubGhz: fix calculating the size of the read buffer
* SubGhz: parsing Nice FLOR S using file encrypt
* SubGhz: add file encrypt nice_flor_s_tx, fix name load file
* SubGhz: fix checking read buffer size
* Update subghz_keystore.c
* SubGhz: fix calculating the size of the read buffer

Co-authored-by: あく <alleteam@gmail.com>
This commit is contained in:
Skorpionm 2021-11-03 20:41:07 +04:00 committed by GitHub
parent 300302cb7c
commit 6d548637f2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 445 additions and 457 deletions

View File

@ -188,7 +188,8 @@ SubGhz* subghz_alloc() {
string_init(subghz->error_str);
subghz_parser_load_keeloq_file(subghz->txrx->parser, "/ext/subghz/keeloq_mfcodes");
subghz_parser_load_nice_flor_s_file(subghz->txrx->parser, "/ext/subghz/nice_floor_s_rx");
subghz_parser_load_keeloq_file(subghz->txrx->parser, "/ext/subghz/keeloq_mfcodes_user");
subghz_parser_load_nice_flor_s_file(subghz->txrx->parser, "/ext/subghz/nice_flor_s_rx");
subghz_parser_load_came_atomo_file(subghz->txrx->parser, "/ext/subghz/came_atomo");
//subghz_parser_enable_dump_text(subghz->protocol, subghz_text_callback, subghz);

View File

@ -212,7 +212,9 @@ void subghz_cli_command_rx(Cli* cli, string_t args, void* context) {
SubGhzParser* parser = subghz_parser_alloc();
subghz_parser_load_keeloq_file(parser, "/ext/subghz/keeloq_mfcodes");
subghz_parser_load_nice_flor_s_file(parser, "/ext/subghz/nice_floor_s_rx");
subghz_parser_load_keeloq_file(parser, "/ext/subghz/keeloq_mfcodes_user");
subghz_parser_load_nice_flor_s_file(parser, "/ext/subghz/nice_flor_s_rx");
subghz_parser_load_came_atomo_file(parser, "/ext/subghz/came_atomo");
subghz_parser_enable_dump_text(parser, subghz_cli_command_rx_text_callback, instance);
// Configure radio
@ -260,10 +262,12 @@ void subghz_cli_command_rx(Cli* cli, string_t args, void* context) {
void subghz_cli_command_print_usage() {
printf("Usage:\r\n");
printf("subghz_crypto <cmd> <args>\r\n");
printf("subghz <cmd> <args>\r\n");
printf("Cmd list:\r\n");
printf(
"\tkeeloq <plain_text_file> <encrypted_file> <IV:16 bytes in hex>\t - Encrypt keeloq manufacture keys\r\n");
"\tencrypt_keeloq <path_decrypted_file> <path_encrypted_file> <IV:16 bytes in hex>\t - Encrypt keeloq manufacture keys\r\n");
printf(
"\tencrypt_raw <path_decrypted_file> <path_encrypted_file> <IV:16 bytes in hex>\t - Encrypt RAW data\r\n");
}
void subghz_cli_command_encrypt_keeloq(Cli* cli, string_t args) {
@ -308,6 +312,42 @@ void subghz_cli_command_encrypt_keeloq(Cli* cli, string_t args) {
string_clear(source);
}
void subghz_cli_command_encrypt_raw(Cli* cli, string_t args) {
uint8_t iv[16];
string_t source;
string_t destination;
string_init(source);
string_init(destination);
do {
if(!args_read_string_and_trim(args, source)) {
subghz_cli_command_print_usage();
break;
}
if(!args_read_string_and_trim(args, destination)) {
subghz_cli_command_print_usage();
break;
}
if(!args_read_hex_bytes(args, iv, 16)) {
subghz_cli_command_print_usage();
break;
}
if(!subghz_keystore_raw_encrypted_save(
string_get_cstr(source), string_get_cstr(destination), iv)) {
printf("Failed to save Keystore");
break;
}
} while(false);
string_clear(destination);
string_clear(source);
}
void subghz_cli_command(Cli* cli, string_t args, void* context) {
string_t cmd;
string_init(cmd);
@ -323,6 +363,11 @@ void subghz_cli_command(Cli* cli, string_t args, void* context) {
break;
}
if(string_cmp_str(cmd, "encrypt_raw") == 0) {
subghz_cli_command_encrypt_raw(cli, args);
break;
}
subghz_cli_command_print_usage();
} while(false);

View File

@ -0,0 +1,6 @@
Filetype: Flipper SubGhz Keystore RAW File
Version: 0
Encryption: 1
IV: 47 69 6D 6D 65 20 74 68 65 63 6F 6F 6B 69 65 73
Encrypt_data: RAW
E0BDF15D68F29AE787E7FCEE6C3611C90A92305D677B8FFFBE225196F5DC04CAEAE1102B4AB830E76C9C14DBA7FA5BD1F30864ABAF51387222FDCC0BA87E4FF709812D5C59DD953859AFD698A0EA2ECEFA0DC49652861EF4CF1864843F135DB8680E0C5C9EEC3BC548E2EB696DC8CA1B0F627347D2C476B410CF03A0F4D1EFB36DFB0574FE8F48FB61910CA539EC04583CA170A51822225A1D3E86C07219FE92E5DE9F557A45E611D74028BAF56E7F2C53DBA8DC53DA89B642FAC0A9A0BAC1756BDA0833ACB09F56E0FA3080CBE9E6A04B235F3AC82BB955FBFD779C59725E6D1875E04E0E84ABD0C3C1C8FAB247EC2755ACEC9961244E0D79AE710E4C7D33E9

View File

@ -23,289 +23,5 @@ C38CBE29F22D0E83E58A52E94AA2485DA8E702FBDB89D27249473CB8A19AEF61
9F0EB580F7474985E8460E1682451E213778B77A9CAB4734B75C5386851050BF
2364EBB8237363B21226565675B9F478482CADAE41E795C27287E26137797C10
775C9A28BA50D759FB438D0200121F01F7DB11986D44D3960F745EAA1E7A2CE2AD92AD718AFCD98BC3269C39F65ADC53
26FB0DDEF3E3AED16D6DBC93AD1A12F9F871AB9E73EA13DAD2715E22F7EE5D27
07BAF6D32302D597E31CB38A205A0D27C6EAE886BF1D7E5EAA911E07DFF9D71007E64F66D92CF3140F3308D35894E690
8AE3F4737608320BCD4FDC51336EBE8C40056D0ACC85D54A74C30F7087F1128F5021255EF36356EDEF1E789AB23541ED
E46E90AA42DD6E95020E31FA2AFE067DF4C47B2C5B101207DD13A72F56BCB2D66666E42B195EA7A800D27DB4469E198C
5DA74C2C12F022379CB8359F11C465464570B822A7EE86B0426FA116F1B3E294
6192E98C705F08FD82BFF01315FBD219FC77E47C65F53668E8429FDF7FCC657A
4EC88DC9084B4EA7DCB4AFDF63445CC8B842BC17821D108775FB8FA8DFFEB7F845B32F1C2536FEA4B2E6B8F8526C8FB0
BBDA1F8A815C6586CFD235653B9E58F9AE3A97F4EBF5945F9EB6CA5C1BFE4FE3
060BBA81DBD222C312D4925A35B20D102FD77BF921EFB986BD776E9FF372A627
F320DDB2963E06DCB2068E0BDDA207068EF43608521BD73965E72A86948CE6D53C7C3AE298C781C128E0FEEC2F5A3913
592BB6BEC2D30AD7BDFEB234F330C243313A4FE96D85BE27B457963574DD851A1255E8D0EA85BC1CDF132F3F3D0D6085
38E5E20E9A444453A932C0368E8A09048D4E592EB5F4505053223B67A9D80BFBCE2EEC96C4622B2EA9AFF35105F07BAA
31BE3FC6E58EAE2778F96C18E8D79A23C3E0772B53AFC3F68382F7C3823ECE29
CFBEA2A3468585001CA05D7402C48F59695FF312D294E2CBB3F1700EEFFFF85C
9A712D7FAD46F68B1679B08CE47DE4A58D6AB76BC0ED3842B10CFE8B146AD43F
77320813C638A37D3B6E7A172A1EEBA626E06D8A13F8193A0330921776CC90F7
20C422A7B35649176A5D3B2CEDA5A64C49ADA6F7774FF014173EC2CA256940BC
81BC110B279FC7FD9F0FD2AB12360E3132F8B066F6D512FB11C93700B651D03F
79097CEDE56399A19038DAE41C0D7840E676CECE7E860FF80F2AA016E1DB4C6E
FC29AB949C97B45DB4344670483D7D38DE4D969DC40B4A2D49D902CD867937F9
37358C7E2DFFFA7BB794B367C0DAC4474EFE1A2BC14EDC5F3DB3A796BB5C5E00
FDD7E5E1ED52244B828D6D8E5BB06BB24B5E36EC29485EA25BCB44855168E6EE
DC97CD3B94036A1877AF836CBC6EEFFEF7A728119857787271B922316F36ACF4
D947681EC3D77CA6DEF28647D6395E0334386C7BCBD60C24148A3299A08B25B2
DC95208BC6206A7F1F388933BA89920E559BC02B57124A4C7AF4E3F150AC6909
E399ACC6D617B0C84F0CCD3B2E017684971761A0E3998DFDD1212D1B3AFC833B
7F28B85A66B4D1D3C56388C89E6AFF5F15F62EC43E1A0114B6EEF77B80E61A22
50B5825CB4A97CC8ED457F3851370723441583E6060BF5FCC707870DFCEE297F
DD8EB05EBC7D00585DAB70C7083C3EC1C688F6D638D663DB1A3B32B7DEDC8E8E
5D7344AE669170A120B65D622B1EA1B774C391B4BF467862771CD187EAA2B526
7031F01CD763974734B95E3B466403C2032FCEB45A2EDC9B5E65B5E122C0CC8E
91A9C77CE9C7BA309244ABB7685FEFD85EEC25416B166FEBF0E914C345BDE2E9
56B2CD788B62B4D69D7BE317444D1C49B098124FF2728129FDEAEE6C802F68A7
5070A127707CE7707265DBD50746D9BF98D5125B9EF57EE4687073EA06C329B0
23AE7B3F7F0C37D08E80182E1689BCDA9DFBC4D73F9AC2AC0064A9DA656E87E3
6018F724D158F64FD3AFD2D6FB1F45768DBBF8527292621B0C1E821DFEA601B1
F337DD4907C18F55814A3733230988C6AACF4BB1FFBC34E83B0EE38EA7DD69EF
6729CF64062453E9F258A2D57D5EA7ACC316E9D90A8DB3E0BCB8B945947C6C21
DF3755632B2ED4E5F77AED01F656F075043A2B7AD5D1186D959BCEEAD09C745A
784327D41235A105990E4698CCC45D7AEECC460011D045BA54234244466F5C47
2ECC93294BD18252B777A1859CD4E2C77BF8EE590BDC4D97D9EC516D85108889
84AA6F4A08EE665F3DFC9F58CA2E3FC1DF0F476AF8818031C6FE4A984B59AFC1
A58DD957933CDF5F04FBAB6B5C71E6F8925B8BE383743752D720848C297E0DF0
B9460B6133D8C231E13D6697555D10D3EB5E2758C549846BC7E5421A016D8D25
B72A12B23AEA00362D758E1E2C829487A36A996D1F0030ACA4648912C98553A8
EA9E2AFED722717FE35EB292CA54ABDB4140093DE8E86F72AE01C22D99F9CF40
5C4EE54D4273A76B7268231D7B6CC4B7EA6E8D2699B263C44A472AD2AF434BDA
4D62CFCBFA3638E24DDC5FC6BC0CC45963B142027A5E44A6669590F5CE590BA0
1D282D45D1805BDB996E066807052FB7235A8E4C3EC6C440C5B576B3D32BFE4C
4073AD510F89F3A95F73872D52B04000740F7DD52D3F6F56943071AEC41E26C4
D527E0982438FDFE3C2C5EC8039EB97D4A7FFC7F2B13EDD0CCBB8B439B70ABD5
E1DB0AF7B85889C917E4BA66ADF3DD832BC774B5C9531A17B3FDC35CCFAF2F9C
5E631C5D400A99C7A3CC1456E912C3325C646428C9156DDC51D24809213EBABC
9089344688AF4D740062963EA35B89FB71D9ABDB6E8D400551AABCA750F78B3E
A33596A074901E992109EE10E8E27A7F6669AA9024701E68446C6D46A2E1B07D
76B97DD16853426AC75B14100453207C1725F0D78AF315FCA8FBED5C7BCC2D44
E90409F8CE4940EA67B943E0848265BDA8648E07865C2054716CC8B03556E312
2577637463D510AA827AF03E2943A78AB18784B63E0EC17C2C5B6762511371C5
050D84D9BB5D04DD2674542872E77A065016D0F2D8582B1C1CB8178CEEC3AE53
98B127524AB0258075E20A5ACC08B94FAE31E87E402B49EA2172A6DDB3F0E991
B754EA3DDBCB5173158E57C6BEB62B62ABAF239A3CC22543F6A80BC2BC1834D9
100FC4F5286A31E4B83517E6076D3F3B834DB0FD9CB4234212171367A9BBDAB8
836A9869AD8DD0AF53480BC2F39290438ED63F0F6C0376859F75E7D865F9E555
55FACDEB9C3276942B02B400F51BFF4A37948EE541242E7491CFC4D72AC18726
F3EC80C3433F722969AC3328771379D19047A12793FDD007F07F41E3F5C8E5FC
70753EC988773789983F9D6F2597A4101054E4DFFAC201485D572F7D726744A1
4F8E927318CEE32A75134EC9F480D402550B8260EA043CDE51CB3D262DF125E0
EE087504CD1AB9631F3909C6D60A57E5C759320B377AD47EE73883292B98E6DC
418C931303452A58352F0EEDB9C4CEF22C0464F51040DC30B5FDB81249303626
676B238AEA7798E4830A801B9A80C378B181A3D63AD737106A5CF8E4EBFC61C6
2B9D24BD81E95BD9CB4736257808DA32F7B8BC88A72CFCB4DD0AECBE9DA8AD2E
B7D705574C3F1D5537065F63AE2268465437773EE896D204835900C3938D4AE8
725FB4701EC3A2D25E46935760F4F50E3339D1B0291A602573AC53CEF95DC85E
13B05A6904D3BED30EA84484E33404A63B69CFD862CB4F3912A72FA0ACBBC611
889F9AB8B3B0FBD7C1B0EB607C7ACE0F20FDBDE81399A2D9CF1D46E6A88F53C8
0040A2C446CC985C44FB1D99DAB13258CD1CEF6BA5F749F84334FEACABE335E4
A1657A3F2BBC3DF62C40CC03EA0721AA574D489E77CAA27CFD3A8A627CB923A3
1388B81F9706A85809088778C42CDE23FAA9EAD0C2CFEB9B967589E90BDD00EC
0EDD657448C00B5FCF5046F226BA492297F177768A1387DA43F864A90F1F1358
3A5A47B50BF72FBF84F86BC6332EB6270EB6BA20C24092F3D0B54B6C3B6AE637
A25D8310CA1B07153858F34125D267A12D97B4DB528794AE87372F637BEAA9F0
FCCFF2857D53F58DD24DEE5193B8613C9CACC924CBD4F33DADA772B3C2A0AF75
A115C75BBF955E1F062E6DBEC171D8837BB6756F30E75818930AB776F80FC81E
95083E751A4780170D8FAFEAAF96DF2E62102402024D4915FF6FA73E1CD9F0D5
980225891E9215A82BFEF6D3DB867D7C05F11575EBB8AED653E1C088A7294391
637160DA818D35774DDD0C375A04D6E0C7F98976FFBD8FFE39FC00E449523D89
FF74098CF07EDFD4004467A7CEC8C8115DFE3D098F2C711882C3F13D6342BF46
CF6E8EBD58DD777682BB9F674B419C6C8D68F5B2388C0486753717D213431E5F
5A9BA50793C6EAA464ADB00910B896F90C548DAB18A45F434436792A56F988CC
9FE1F19F8DC290BCB6B99490901D9E73D10A6EE2D1AA1A253297D66D05A08A19
CDD197057D7B347FF474B58D838CAF614D392E8DED92B01B8C2AE16F79183A8C
DCFD8DC6D58663F0CB1285C49ABC501B13209425AF7436DC66B4D6F0529D09DA
F8956D6BACDA1F294222DDE8E28C6C791A77FF206286C648AA659149B247744A
C494E4123788BF65E95CC39C2F9BEA0C78BA2105D40689F3E7340FEECE0B5B94
5677786C1222C825BEB177E8E0C64D9B7909717E278C90FAEC70514B7034B5A3
4575A4397F19DCDEB0C7BB67819F257F6F2B5A53E7D9E08F9F68ED7D854175B4
29EC9B87DD201CCCFDD32AC67C0212A4C5E45C8188DFBBE97AFF531FDBD1BBA9
36676541800B391DF20F3A4B4A3DCAE018D85441A93B44F984D2EEB334FD5EDC
278D8E83B662C96C69BE962E271CCD6FDAEB54F563C47997A53AD6960E8C182A
5921F8F8D961B45657FB9965AFF8A567606780C336B42EDA1959F40CD57C1803
5AD31697C382622CFD185CC2C4F44D6DB1BAA60496AF0AEFDEB50CB0A5CF2EDA
307CBE4B2460EE096CCF772B0CA56D645CA6C5EAE31FFE0C556ACF31DDE6167D
AE86EB56FF82199331F537BD7FF0CE23422EB046DA9C1D0B2A7C813A4D4A9581
D5DDF54FF56E597AD788239811C57FB4DCCDDEB317F6BC9559040825072E3FD7
35EFA98E7357B81EB5C7F56DD7B2D1A483218BCE2907EED0CE4425C99288A058
0410EC96551233A745EAC2FA1BE834FEADCB68B9845F9E0512DFFEE6FE353DCB
7E39E6D875FFB17AC2C5F74A3F44DFB5063E5510712B63E8BA7E083292F3DB7B
C83A67EC31B70AE70CBAC65E07EB69BF311889F5FD246B0D1588CE1A28AE5050
C6FCE1BAF6D3CA19DEACD9987A1C01D9D519B65291F626AB44E1E269E9056BE8
1CDDAAFCE3C5A993B3C3652690429C942A318C973C691039AB876ADE2074BD9D
A241551F6F3043409C30923BF84CAED8713D817B6F41B2AC9C0119C66D30DA41
980C89F97CDB118F001B761D653C2E11A794E7ADB7F16008FC05F0A56035BF1C
884FE309C42B674A2470163D701AF14C3D30ADF08666C760F9F3C34F1680441A
FB1FB9F2BA799C8DD5DAFFB1AC15DC46FAF478D46FDF9E12E7088DC77A422BF9
DA01C3CDB758913DE16155BFDD65C65409810EC8E9867CEC02BCFD72E2B950D1
7534A560B93845A636858A8B28ED85A3ABB2AC4C41A5CD3165F25D24F24F3939
2DF741FA05AD1B9A37BD8C4FDD2BEB700EF725453E18B7759C4794A5B7EDE8EB
43929E8F10B77E268830C7177D74BFDB66EF6B9905FB29431C84497CBD65F6D1
02E44D1195FBD103955697C717DD56FA528F1CF5070A8F8E18762DCCEDC3A962
8E87CDBD5F3C32DAFF141E319067AD16C9E21BA40D2415A170D18F52E5A62D22
D486356DF83EBCF1F1640E92691E5AE4CCE3E152C220AE442DC0A775F6947AD6
1077A1B9328DB998042D2ADF38AD0106ADF46A77F32355754E452FBC0A469098
7B74AA4B2FAB2DC0EAD74D69C704AD38EEE36CC2D8AB2502EE343DA30196553F
6740BA2FFFD10FDE150A5201C6CF7E1D9769F14F97B98862262D2635218CEF29
885DD977C1E12CCE8D6AD357B92FC6F63F83F05F5B86F394B6399966E61893CF
64F67ED26DACF20A9E4A7A9EFA72FE7240A380E541B4002D73CF00B0ADC7B19A
DFEDE2DD576074FED8F73B02AE0210B0AA879A87F6D932271E8813DDC76AC77D
CE1AF48A5FFED24CC740C6F64E91C3685D728EC69C7F0688405AD4E99E634AED
CD63A5B50A65986A911CA3B3E1B7F9C771B01196ADAAD7C8EC6260210BC29B4E
58EE98F41F78055175035D5CDDD21BED4053590625104B36413BAF3ADDD8229A
959B154EF0AACC4F774C19638B44B66371DFE6EF1DF052E496A661DA59FE05FD
E335E0998DCF0E837E063681CFCDE4F8DDBF27AA6A8A35747CBF9C228DBAB702
C49EEDB1E6C01D25EB8BAD188F037F19359E446D3A8F48B1C7E23E436DF1AE45
DCC19EEE6456B084EA5BCA8F8A4AD9C47172B99BCC6169061AF41279B404238E
A8C973DC0B2F166735BEEC99A3ED20F85880B00510A45421C0F1D717BBF9A156
9B4D7E9E4DB69842677E2B6A9F213AA57F185B20DAB654EC67FF271E9487ED60
5DC7950E2C5BE03B8258B71CEC2058BF56828EFB9C4225B1EADD2FFDF0664386
F2D860D71D3E42E7F72955A0CE11D61F2C90CE472CFD1D31ECAC2C8A509B50FE
ED2C41030278699235A3AC77C0B6319802ACC027CD8309856165AD00F0DAE4D9
1BF2E2829A3BFECE4ECF1CCC72CE6AAE2B56B452518BF3C9B17C8F8256AE928A
B969D1A53D4BD1A8F69155289C00C125AEE6C9E2F90AB25303ADD505802398C3
ECACAEF175C463BE8453B2A066066E04889F7F0DFEC946395B978D6D4952AA2E
8ADA7555CF7C4CE737C9BA757551AAEDD627384602855A0F1D821DE5842ADE21
3D1B18573858D2D0A8CB9B49DA0233D2842EB9F112BC770EE2F5A42F5EFD7590
C3DAAB1F580B1362D2EC15A2BDEEAA4C896DD70BACDF0493ACB2FC8989EF0D2D
23105727BC6574EE976182161CF1771D74593A7996C46073DD67FD33C9EC2CD7
260D8C270A2E1D2E7B2D27E95A67F8B055FB949EE0BA3F6633F6315F9452CB7B
01EF784BD2C68C6F614DDEA3CA071E9198371B9E447CEFCA13FCF1D55FBCB43F
137A61AA31C309B62554466772540A3E2D8AC39D355802FEB0B4774A4BAE1CFC
D0D1424ACC1DD84BB0F465527C5695BF51C5927A0D4B4E0C5618E4B6BD122997
A855D26D665DC9F0330E18126D4DA2B8E9E3E19B759B8156E4754C4E857DBB64
A724138E61049B6D8AB6E7184D1295FB9A69BF07B532DD0B3FDC023AB9A5FC82
E2847126E66A64F7EA28127387748645E177076F10484C4CA45DE5B3EA7E9D6F
D76858E8B9BF7F2C0174FD09DF321E94679B48479CD0D587F54E3679553B619B
36800839D131F70EE2068F96BB02643C7F426BEFAAF5856257972D8851D6E29C
8B624C420FD61C8BC1E52A5CFAD5266E2D18C4FD5FF43DBF78C7A8226DEF6639
AABC2B1A9B712DB66927C905BDEF2BA2ADCEEFE724AAF1632F31E39472676714
95218D5732BA5EBF6DEBAD1E6FA555E29984A7BE46E330BC20C37E70488C0444
3773E0A7C8D3414CC82B5AAE824CF8642D2EF7B4E43D3E83121B16965A64B258
C42B0AB5D4BAB1492075DF0DE7F1FB50B456B051C8F6828CB065231BA26D7553
19556D3678712A5A4410B6BF8DBAC5FBAE150EA913C88D2B665F5E9368F624EC
DB36DBB87E90F7E634D75C7F1D805D0174682EF9735947C093AD71B1DD1D4CD8
E2E65BC8940DD65A3667E6C97281288529DFE74FCFA2A81ECC380CA4B0205A9D
3124EC9C34FC420B6CF558EFC6F26BD50F68C7BA05A955B70392A2B70FB4D846
84F1491142661D310717A0BD502A4C4F80E6899B1C87FDC299F7B36461C4ABBB
E8F2ABEAD6634B4F25394945E5A872B88A3290F2AF608098FAD12813F957F08D
11DD782EF77044201D868480D4E214DB4F3444B287CDF220794248813D3976D8
186C13A3ECBEF66EF22C274C5BF70C69E983344ECB87CCE81D70BD8377E3F9FC
5794C3EFDF643B966DEC9D4BD7346A21B50151E5D6F93C6128F254619D3E0E3E
E826D3CC27F4B6871D9F673C8BEE923C65C402C9796DC5DD97421A8DF41714F5
5D8FABA6A841153495CBC26BC1E1028E79A80968B21D3D9C8741C52326C6D984
522A8066B98D192BC0B382E63FA78BFA13E269017FD9D45654C4CC5C2CBC44DA
4016C5AA79A9BC220B75DB3A567E96BE42187F16DA68978FB72372162A26B75F
3E06036DE65F7B1939330F814D421C65CF554D96F51EEA6E234A9D6134FDAEBE
9F1D109F1F2EA1B61165B37CF06DDB639DC5399910C32AEF018F13B2A2588AC4
9E03C05A4755ACEDD423F519C0A5BDE768A5E31A1D838E4291644DBCA13A5EAC
BAC85AD6C0AC38B1A2310B400B01C4123B2CFDC538970EFBFB7FA163E782A511
302582B243190740D35720296CC39677D8BD01D3CC64FF973AFD6E1F263B10D6
156F82DEFA0F67028A1F7991AF6B60E687906AFEA924DBC7101B39FC9A552D3A
3404FB2E9E26EA75FC0528448E5B485DC778C251E9A3CE184F9D40F14EC6A9C3
8276A6D8AEAF0E03390D8E3CD9D7354278C6160F962676F34CB8B6CE28078885
D8B1EEF27BBDF1969FAF22867AA6C279731EDF53EF04FF3B98F43694B4592343
F2222B0270158E747AEC5EAA6B089A65226215493BE87FB91A3EAFC90A372687
1AB91DD2BE17F42854A07C9F38E695AA1E25522BFAEFE14F29F290AE2C71D922
1E1508CBCE833DB8C6646AC9AAF1887B810AB665D7F977EB9E58E93D019876F9
86244E8C0ED7F76958253EFB2CAB0DCCD29CB9938A782AFC750B2DBFA30A6E86
8F03E504FD67759F56654362A03D30EBA832906C707DE366D2805597B8AEB714
C34E85BB66E31BCE7D67C01D798B6A7677DDE29E90C6C6C804D62BBBDB528AED
75C3DFB504201558CFFE18747DE040C107352B1B948BDBE078B3F1424391BE12
28AE60B66E1DC10672C19F3BEBB3F1E8577572FD369C4222ABF86AFCD1FCD872
BE7E570DDB7FBC182318B9E75E1A9E46608A8EE7F7A0F7F582447C0A069300D3
9585AC78D3A0A7F0D40F9627C036050CF4BDA47434C0A2859F39414B633A8440
9C26270AA00F380CEE6F3A0106AF660632A6958CBB74542EC180A1FFC6C446AB
5C7E8D9DB28D6F75F018C1D97D8C5CC4001E6EAA9047B93FE68AC80627CBBEF9
5514AC7A222CF0E307D0B6005A925B48BDE8DEA13855927DA5283D50CA891E01
CD7F74788986AE6B3A49BE66C9BCB944DDE8673803C4BDE9616B711BF2B3E026
ED04B459CE1BA6ED357A4CF10415D1AC1894048018390349F046B4CBD8E5EEC2
360C271A88E83F0CBE5BED38165D4E2843042DAB6A432FC24D284B15D2DAF2E9
FF75CB77B9D843B404427717DF7FEFEB334093543CB484C5D45CE3A948D7E566
CB06B4D92F347F51F10F546C189E701947C36BA28E29DB610F2F412714563BC2
E3053DF9589F15FEDD58194699A3D2E8770FAED7421DFE95C9EE190D96A56F0E
08FBBAFFFAAD0161987AEEBED582AC906D969CE4DA8A56700DD9CDA8904222A9
4BBD08F49F4A595F4CE5B624E0392F76D5B581872399799B424D7030B28949E4
583702FFC046B709D75FB8BA08BDA5FBE20173310B85D5A211B89F1CDAFC215F
A1661573042C07AEF4D22D69F7D06C86870B9ABF412B1E8158D955CD7DE6DAC6
2602A0A40189C956B8031B7160175662EEF54988778743578BBF458E044E0A89
1D4449BC3803A85DBA19F3C15941299E19DCA38F79FDEB225CA05E7C4C3D271A
0339877572DEE3392179798AB95C1F49B8078476CA03E0D060C021B17C23E7C1
63316028E9F85B0ADECEA6CAA05131FA252A2ED16816D8FA084B30167F29CF66
763A74DC68F8CE7CFE6A6CA58A88A3991FCB6BE92142196D9B045EC2EE146A4D
F7692816D9577DCFBC3180454D3538C670EE69A1FB9B40058A259A1CADAD4C69
3D0BC36BE57CF8D227E5D0451170B612878701140AB1A3FC0A1F3568F0EFE9B8
0A62EB499FC0926B90E59358BF0E3136E7D1CAEE53306FE9354F70A48E4A9D18
DA814249505412CBBD8C3E318E6A62F03ED89C505B911089DADD57E5F6A0F379
CBE56810D848B879FD7FB26FED0E67F6C3D989C5F0A562CD83442B16B69CE534
942F500D0A7DBE1DAA3FE8EE8C1291485948A1AA6E091F379F6F5E2AF5F9C73F
EACE2ACABA9DA57A3811BE7C177E2FA931B3B83EC95CA64E7238D16FBEFEAD2C
A0D63EAB75E08F2B49A451F128B25425D37C3338B862190B6566A49418CAA785
7FE6880200405E447F6C0F6A01C3074A66D2B47E185BBB0D5E29AEF072A01DD7
63A777F286A66A094AF1FFBC7EAA8161D37BCF49EF55F880C72C6906D8CD4F8B
52703BA0637F01DFD4AF315BFA23CD41E52A155C35B9739BB57777DBC69CA455
3439F58AB810EC86F133A1206BD8BE84138CA2E70E4F96D8D24FC052B8EDB702
D403A5A137735635F68254E6FEAD77B4F20A2756FD42E1F42A0583FD3D10C2B6
55D45AA25091B4638EF39AE9F3239DB441F17F9E138410C3C138E005ECEF49BF
05C0589687E28E7D6614245F43B1B1E92421331C51D58B70C8778581041CE512
68D2C4D636160A0804902E166AD991D90987956D33EE3A8382F882E5A04087E4
2720A34E50C1D90C829BCC5E666E79B8C9EB3CCDBE1C234EB345533A3A53F910
F064F519DB53109C4E086490462B587133B69A9FA417ADAD3ED1C97D85567838
7882B15818EAA42ACC3342C79841EF358524E49BA64EBB00AB574219BD369C77
0D819F1BCD04911D681633347D817A7E83887C3C037CE83330E9D3A2A97587BC
FD1048C43DF4F8EBF2E2D03A76C4AA37A74FCD64235AEAA861E5187041FC758B
F62D4A41A9BBA2653292A9F9252C34D408F6DCF7C31E0556C36F59119C77B685
F83EE4DD3E93171DFB178BAA7D05ECEC54A65BA1DE7AA0B08D03BF59F9677568
4AE3EC337D3D5900D86998462C1AF19F056D16EDCDC135AF75F34E49B81AE48D
24C1A8DC4730288BE4C3CFB2A7E71022B71AE5DD68A1B6E1CC36534183F9E797
A9EBDBB7301E090C9C2629F8D854398C90E8052F482503851AACDACFF6F0070B
4F5A864D898A77E02A8F181077751016D811B837DA3F33A2067EAE72A41EDD75
A2D4B8D51FA8E1148A053C39005B0B8A9F0C5702A64750AC64BF353C4338F6E1
C659ED65157E6FFBE4B956DFB95FBAEF1745F0314A9729179E92B3F1162B9495
BC17D9D85193BDCA5FA50ABA581221BE6F5E8AAFAB2D90646AF6ABC501E60662
E517B72076E211C90114FB9127B6CA57DE995355916602F3A50A0B61E6CACDA5
1C0E79317116FB017B19A47018B2F8EF078A8F6A51E49929E08D27E2ED31D3AB
E0502C15BF9D459326841DAB7617B58F482FA502CA5FB719D06CEBFC73FB5495
016187A2D8AA8BBB15DC34E3920930D96B372607D842624405EEAFC5A641FA5F
FA34C64218ED6CFB15307044B1C38123C939EB12A239E0C2C198D47B8799B99A
5AC59ADA228C1E069CF9D106D3171465B150BBC004D138D451517473FB2E946F
C47F6CD3C8E4C373C43E448F3EC791956DEE7F06EDC3EAABFD96681DBF7CC160
82EB8353D5F481D0E3F3C1BE42EB6F6F80A452412C0C3C9FD951A1942322E8E3
DF8CC0F85A18BEEFC613237F7D112DF23F2214E091F6C100A47093541F6A1920
0DCBC7478CD07868E1C10AD3626AC324230F328E4ED59C0F4CE98758C407C24B
AB1D1526799185CE4168A2BB0E98F4CEE8843EC95ADAFE4E00A369461317183D
47FE38F4C59F6BD043D89A6A799864971A65370CB5AC7282D7169EBF31074753
CB253FB6096DB3209054C21322A28E742B616BBA97B972043E4FF210A938B994
4FE2CDCB89E9DB6A98A6A7CA7374616B54517FE6C62867662727715A8D0995C0
45074540C5C990A33E7C3B7ECDD685829FF5ACAE75972F9F2E04CA1C2AB2D86F
4D1A95CE69460FBBAF8F3ECF7C211F918D7AF8F99506E96D95C9091BEB9C0519
8D8501E5088AC8709AAEE23C83D6E9BADE67F8504A6BDE957AC244E2CF650041
3DE31455D33AD144D10914036D272A91D6D2EFE52BF413A5C3B9BFA171AECC64
2B02071E56B85BA4D231C18B9BCCD660B7C51ABAE0CECC4DC52A565360E1A42B
DF515620894AE9456652FF296426255EF9929D011990CF2839B41F450D063597
015075989DE322CB41085D8DD967C1D1589B478F6A45426636E792940317A384
29E64270826B9B1573F685493E91DD87A3AD9BF2D10D4E895022EBF7A4760C73
F11566B2E6F30ED9B78E3B344668ACE41659796578FACE69C79B16E3D6494C31
130C0F515C26A04B6FAACE34268AB974F20DD4EF15054C0A15E34013CBBAF9CF
2B11A8D043F717A2BD6A5F56715BA3C571FED25161591749334F32DA236E5856
F03B8C9B647A4104BDEB577AAB033781CA2A8EACA243163D5A050BF874396559
334AB0839A8680289F1F297273467613CFCD834446DA52D7A2BA146EFDA4CD8E
C05E250AF0D5E82E417DD8394B8062DBBBC3C07E477A847F311D0CAC912EF9BB
2345D436F59B669297DE8E80BD27FEA98A1DCE61AD4EEF729CDFAC5345EAB8A7
D7DA143A0C5934D50F09EFF485F70D3C71C5BD5B5B57C4DC7F3414069432F24C
1DF4BABBE29ADF834701C36A850F2EFA8DF92D3E28003F7760A87AB9D8BD91EB
71E183330B18FBCF8ED091F2488D3D29B98258C89B6019DCE7C79F8CF5BDCA92
EEBB58DE2561795984E933CBD2B4C4BD8EAFEF97C91539917370F7E9A2240265
D62E7BF1A7C56653AAC132838C360B2D0DFC5BC800C726159FABD1263B7F19EC
12104E12AE577D5437023F945C476FD1654FF9826244F3692C8C186A79566106
3805C3704EE0C994FCEAF24CCD9A45CDDF6F2DF60F63D6665742E74880804E1F
CCF7B9B5D0C6CFEBE487938ACFAE89884A6CAD16A51515EBA9FF272DC9A57DEC
FD4403D41887E6CAE505C2AD9631AD3779F95BF70137B61E9901B3B7058C7DB1
EE31F0FC516D508AF085BB6F1CB0FDF73CC0BBD7F5EA9891E0D87D7832E4AB1F
A1C5A8391F4132A560CA4693DCF8104CB7F5888F33C7D6586729FD65F57D5158
F92194BD8136F05EA48843C514F9465A9D0D7925A364D40B4853C666F726CEE5
3DE0E5D07EC75D4FC5B51AF56A371643F206B213263503B9DBE0D3EEE71D8B37
E904F9A524C9541AC4CF7195AA3A8D8265BE1B93890D8549F2C9ACE4731733A9
4D1B906082ED3E8A59368BACFACEC1886EC52451EC8FF4C444F26DD668C101B9
840686B283654FADB08AF6F9E439359B6D41ACFC068845195769033D6618A823
8AF622CB10FFD2C85F113EF81F1FF542DD4435BA8ED93CEEBEC1E3A16AE0CE88
6911E7EAFFAC15B4E3ABDAD271E92EAEFE1F2E288789EC7599AAA32986273306
5387D67534234AFD8BAB90DC74BA39598B938526CBFAF14F75AA36A29C13836A31897A86D2E1178AE66191E771A7FEA4

View File

@ -0,0 +1,11 @@
# for adding manufacture keys
# AABBCCDDEEFFAABB:X:NAME\r\n
# AABBCCDDEEFFAABB - man 64 bit
# X - encryption method 1 - Simple Learning, 2 - Normal_Learning,
# 0 - iterates over both previous and man in direct and reverse byte sequence
# NAME - name (string without spaces) max 64 characters long
Filetype: Flipper SubGhz Keystore File
Version: 0
Encryption: 0
AABBCCDDEEFFAABB:1:Test1
AABBCCDDEEFFAABB:1:Test2

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -1,6 +1,7 @@
#include "subghz_protocol_came_atomo.h"
#include "subghz_protocol_common.h"
#include <lib/toolbox/manchester-decoder.h>
#include "../subghz_keystore.h"
#define SUBGHZ_NO_CAME_ATOMO_RAINBOW_TABLE 0xFFFFFFFFFFFFFFFF
@ -25,14 +26,8 @@ SubGhzProtocolCameAtomo* subghz_protocol_came_atomo_alloc() {
instance->common.te_delta = 250;
instance->common.type_protocol = SubGhzProtocolCommonTypeStatic;
instance->common.to_string = (SubGhzProtocolCommonToStr)subghz_protocol_came_atomo_to_str;
// instance->common.to_save_string =
// (SubGhzProtocolCommonGetStrSave)subghz_protocol_came_atomo_to_save_str;
//instance->common.to_load_protocol_from_file =
// (SubGhzProtocolCommonLoadFromFile)subghz_protocol_came_atomo_to_load_protocol_from_file;
instance->common.to_load_protocol =
(SubGhzProtocolCommonLoadFromRAW)subghz_decoder_came_atomo_to_load_protocol;
// instance->common.get_upload_protocol =
// (SubGhzProtocolCommonEncoderGetUpLoad)subghz_protocol_came_atomo_send_key;
return instance;
}
@ -62,20 +57,14 @@ uint64_t subghz_came_atomo_get_atomo_magic_xor_in_file(
uint32_t address = number_atomo_magic_xor * sizeof(uint64_t);
uint64_t atomo_magic_xor = 0;
FileWorker* file_worker = file_worker_alloc(true);
if(file_worker_open(
file_worker, instance->rainbow_table_file_name, FSAM_READ, FSOM_OPEN_EXISTING)) {
file_worker_seek(file_worker, address, true);
file_worker_read(file_worker, &buffer, sizeof(uint64_t));
if(subghz_keystore_raw_get_data(
instance->rainbow_table_file_name, address, buffer, sizeof(uint64_t))) {
for(size_t i = 0; i < sizeof(uint64_t); i++) {
atomo_magic_xor = (atomo_magic_xor << 8) | buffer[i];
}
} else {
atomo_magic_xor = SUBGHZ_NO_CAME_ATOMO_RAINBOW_TABLE;
}
file_worker_close(file_worker);
file_worker_free(file_worker);
return atomo_magic_xor;
}
@ -265,64 +254,6 @@ void subghz_protocol_came_atomo_to_str(SubGhzProtocolCameAtomo* instance, string
instance->common.cnt);
}
// void subghz_protocol_came_atomo_to_save_str(SubGhzProtocolCameAtomo* instance, string_t output) {
// string_printf(
// output,
// "Protocol: %s\n"
// "Bit: %d\n"
// "Key: %08lX%08lX\r\n",
// instance->common.name,
// instance->common.code_last_count_bit,
// (uint32_t)(instance->common.code_last_found >> 32),
// (uint32_t)(instance->common.code_last_found & 0xFFFFFFFF));
// }
// bool subghz_protocol_came_atomo_to_load_protocol_from_file(
// FileWorker* file_worker,
// SubGhzProtocolCameAtomo* instance,
// const char* file_path) {
// bool loaded = false;
// string_t temp_str;
// string_init(temp_str);
// int res = 0;
// int data = 0;
// do {
// // Read and parse bit data from 2nd line
// if(!file_worker_read_until(file_worker, temp_str, '\n')) {
// break;
// }
// res = sscanf(string_get_cstr(temp_str), "Bit: %d\n", &data);
// if(res != 1) {
// break;
// }
// instance->common.code_last_count_bit = (uint8_t)data;
// // Read and parse key data from 3nd line
// if(!file_worker_read_until(file_worker, temp_str, '\n')) {
// break;
// }
// // strlen("Key: ") = 5
// string_right(temp_str, 5);
// uint8_t buf_key[8] = {0};
// if(!subghz_protocol_common_read_hex(temp_str, buf_key, 8)) {
// break;
// }
// for(uint8_t i = 0; i < 8; i++) {
// instance->common.code_last_found = instance->common.code_last_found << 8 | buf_key[i];
// }
// loaded = true;
// } while(0);
// string_clear(temp_str);
// subghz_protocol_came_atomo_remote_controller(instance);
// return loaded;
// }
void subghz_decoder_came_atomo_to_load_protocol(SubGhzProtocolCameAtomo* instance, void* context) {
furi_assert(context);
furi_assert(instance);

View File

@ -23,16 +23,6 @@ void subghz_protocol_came_atomo_free(SubGhzProtocolCameAtomo* instance);
*/
void subghz_protocol_came_atomo_name_file(SubGhzProtocolCameAtomo* instance, const char* name);
// /** Get upload protocol
// *
// * @param instance - SubGhzProtocolCameAtomo instance
// * @param encoder - SubGhzProtocolCommonEncoder encoder
// * @return bool
// */
// bool subghz_protocol_came_atomo_send_key(
// SubGhzProtocolCameAtomo* instance,
// SubGhzProtocolCommonEncoder* encoder);
/** Reset internal state
* @param instance - SubGhzProtocolCameAtomo instance
*/
@ -55,25 +45,6 @@ void subghz_protocol_came_atomo_parse(
*/
void subghz_protocol_came_atomo_to_str(SubGhzProtocolCameAtomo* instance, string_t output);
// /** Get a string to save the protocol
// *
// * @param instance - SubGhzProtocolCameAtomo instance
// * @param output - the resulting string
// */
// void subghz_protocol_came_atomo_to_save_str(SubGhzProtocolCameAtomo* instance, string_t output);
// /** Loading protocol from file
// *
// * @param file_worker - FileWorker file_worker
// * @param instance - SubGhzProtocolCameAtomo instance
// * @param file_path - file path
// * @return bool
// */
// bool subghz_protocol_came_atomo_to_load_protocol_from_file(
// FileWorker* file_worker,
// SubGhzProtocolCameAtomo* instance,
// const char* file_path);
/** Loading protocol from bin data
*
* @param instance - SubGhzProtocolCameAtomo instance

View File

@ -167,7 +167,7 @@ void subghz_protocol_faac_slh_to_str(SubGhzProtocolFaacSLH* instance, string_t o
string_cat_printf(
output,
"%s %dbit\r\n"
"Key:0x%lX%08lX\r\n"
"Key:%lX%08lX\r\n"
"Fix:%08lX \r\n"
"Hop:%08lX \r\n"
"Sn:%07lX Btn:%lX\r\n",

View File

@ -69,7 +69,7 @@ uint8_t subghz_protocol_keeloq_check_remote_controller_selector(
M_EACH(manufacture_code, *subghz_keystore_get_data(instance->keystore), SubGhzKeyArray_t) {
switch(manufacture_code->type) {
case KEELOQ_LEARNING_SIMPLE:
//Simple Learning
// Simple Learning
decrypt = subghz_protocol_keeloq_common_decrypt(hop, manufacture_code->key);
if((decrypt >> 28 == btn) &&
(((((uint16_t)(decrypt >> 16)) & 0x3FF) == end_serial) ||

View File

@ -2,6 +2,7 @@
#include <furi.h>
#include "file-worker.h"
#include "../subghz_keystore.h"
/*
* https://phreakerclub.com/1615
* https://phreakerclub.com/forum/showthread.php?t=2360
@ -103,17 +104,13 @@ void subghz_protocol_nice_flor_s_send_key(
uint8_t subghz_nice_flor_s_get_byte_in_file(SubGhzProtocolNiceFlorS* instance, uint32_t address) {
if(!instance->rainbow_table_file_name) return 0;
uint8_t buffer = 0;
FileWorker* file_worker = file_worker_alloc(true);
if(file_worker_open(
file_worker, instance->rainbow_table_file_name, FSAM_READ, FSOM_OPEN_EXISTING)) {
file_worker_seek(file_worker, address, true);
file_worker_read(file_worker, &buffer, 1);
uint8_t buffer[1] = {0};
if(subghz_keystore_raw_get_data(
instance->rainbow_table_file_name, address, buffer, sizeof(uint8_t))) {
return buffer[0];
} else {
return 0;
}
file_worker_close(file_worker);
file_worker_free(file_worker);
return buffer;
}
/** Decrypt protocol Nice Flor S

View File

@ -12,11 +12,12 @@
#define FILE_BUFFER_SIZE 64
#define SUBGHZ_KEYSTORE_FILE_TYPE "Flipper SubGhz Keystore File"
#define SUBGHZ_KEYSTORE_FILE_RAW_TYPE "Flipper SubGhz Keystore RAW File"
#define SUBGHZ_KEYSTORE_FILE_VERSION 0
#define SUBGHZ_KEYSTORE_FILE_ENCRYPTION_KEY_SLOT 1
#define SUBGHZ_KEYSTORE_FILE_DECRYPTED_LINE_SIZE 512
#define SUBGHZ_KEYSTORE_FILE_ENCRYPTED_LINE_SIZE (SUBGHZ_KEYSTORE_FILE_DECRYPTED_LINE_SIZE*2)
#define SUBGHZ_KEYSTORE_FILE_ENCRYPTED_LINE_SIZE (SUBGHZ_KEYSTORE_FILE_DECRYPTED_LINE_SIZE * 2)
typedef enum {
SubGhzKeystoreEncryptionNone,
@ -39,16 +40,20 @@ void subghz_keystore_free(SubGhzKeystore* instance) {
furi_assert(instance);
for
M_EACH(manufacture_code, instance->data, SubGhzKeyArray_t) {
string_clear(manufacture_code->name);
manufacture_code->key = 0;
}
M_EACH(manufacture_code, instance->data, SubGhzKeyArray_t) {
string_clear(manufacture_code->name);
manufacture_code->key = 0;
}
SubGhzKeyArray_clear(instance->data);
free(instance);
}
static void subghz_keystore_add_key(SubGhzKeystore* instance, const char* name, uint64_t key, uint16_t type) {
static void subghz_keystore_add_key(
SubGhzKeystore* instance,
const char* name,
uint64_t key,
uint16_t type) {
SubGhzKey* manufacture_code = SubGhzKeyArray_push_raw(instance->data);
string_init_set_str(manufacture_code->name, name);
manufacture_code->key = key;
@ -62,7 +67,7 @@ static bool subghz_keystore_process_line(SubGhzKeystore* instance, char* line) {
char name[65] = {0};
int ret = sscanf(line, "%16s:%hu:%64s", skey, &type, name);
key = strtoull(skey, NULL, 16);
if (ret == 3) {
if(ret == 3) {
subghz_keystore_add_key(instance, name, key, type);
return true;
} else {
@ -76,21 +81,20 @@ static void subghz_keystore_mess_with_iv(uint8_t* iv) {
// Sharing them will bring some discomfort to legal owners
// And potential legal action against you
// While you reading this code think about your own personal responsibility
asm volatile(
"movs r0, #0x0 \n"
"movs r1, #0x0 \n"
"movs r2, #0x0 \n"
"movs r3, #0x0 \n"
"nani: \n"
"ldrb r1, [r0, %0]\n"
"mov r2, r1 \n"
"add r1, r3 \n"
"mov r3, r2 \n"
"strb r1, [r0, %0]\n"
"adds r0, #0x1 \n"
"cmp r0, #0xF \n"
"bls nani \n"
:
asm volatile("movs r0, #0x0 \n"
"movs r1, #0x0 \n"
"movs r2, #0x0 \n"
"movs r3, #0x0 \n"
"nani: \n"
"ldrb r1, [r0, %0]\n"
"mov r2, r1 \n"
"add r1, r3 \n"
"mov r3, r2 \n"
"strb r1, [r0, %0]\n"
"adds r0, #0x1 \n"
"cmp r0, #0xF \n"
"bls nani \n"
:
: "r"(iv)
: "r0", "r1", "r2", "r3", "memory");
}
@ -103,29 +107,30 @@ static bool subghz_keystore_read_file(SubGhzKeystore* instance, File* file, uint
char* encrypted_line = furi_alloc(SUBGHZ_KEYSTORE_FILE_ENCRYPTED_LINE_SIZE);
size_t encrypted_line_cursor = 0;
if (iv) furi_hal_crypto_store_load_key(SUBGHZ_KEYSTORE_FILE_ENCRYPTION_KEY_SLOT, iv);
if(iv) furi_hal_crypto_store_load_key(SUBGHZ_KEYSTORE_FILE_ENCRYPTION_KEY_SLOT, iv);
size_t ret = 0;
do {
ret = storage_file_read(file, buffer, FILE_BUFFER_SIZE);
for (uint16_t i=0; i < ret; i++) {
if (buffer[i] == '\n' && encrypted_line_cursor > 0) {
for(uint16_t i = 0; i < ret; i++) {
if(buffer[i] == '\n' && encrypted_line_cursor > 0) {
// Process line
if(iv) {
// Data alignment check, 32 instead of 16 because of hex encoding
size_t len = strlen(encrypted_line);
if (len % 32 == 0) {
if(len % 32 == 0) {
// Inplace hex to bin conversion
for (size_t i=0; i<len; i+=2) {
uint8_t hi_nibble=0;
uint8_t lo_nibble=0;
for(size_t i = 0; i < len; i += 2) {
uint8_t hi_nibble = 0;
uint8_t lo_nibble = 0;
hex_char_to_hex_nibble(encrypted_line[i], &hi_nibble);
hex_char_to_hex_nibble(encrypted_line[i+1], &lo_nibble);
encrypted_line[i/2] = (hi_nibble<<4) | lo_nibble;
hex_char_to_hex_nibble(encrypted_line[i + 1], &lo_nibble);
encrypted_line[i / 2] = (hi_nibble << 4) | lo_nibble;
}
len /= 2;
if(furi_hal_crypto_decrypt((uint8_t*)encrypted_line, (uint8_t*)decrypted_line, len)) {
if(furi_hal_crypto_decrypt(
(uint8_t*)encrypted_line, (uint8_t*)decrypted_line, len)) {
subghz_keystore_process_line(instance, decrypted_line);
} else {
FURI_LOG_E(SUBGHZ_KEYSTORE_TAG, "Decryption failed");
@ -133,7 +138,8 @@ static bool subghz_keystore_read_file(SubGhzKeystore* instance, File* file, uint
break;
}
} else {
FURI_LOG_E(SUBGHZ_KEYSTORE_TAG, "Invalid encrypted data: %s", encrypted_line);
FURI_LOG_E(
SUBGHZ_KEYSTORE_TAG, "Invalid encrypted data: %s", encrypted_line);
}
} else {
subghz_keystore_process_line(instance, encrypted_line);
@ -142,10 +148,10 @@ static bool subghz_keystore_read_file(SubGhzKeystore* instance, File* file, uint
memset(decrypted_line, 0, SUBGHZ_KEYSTORE_FILE_DECRYPTED_LINE_SIZE);
memset(encrypted_line, 0, SUBGHZ_KEYSTORE_FILE_ENCRYPTED_LINE_SIZE);
encrypted_line_cursor = 0;
} else if (buffer[i] == '\r' || buffer[i] == '\n') {
} else if(buffer[i] == '\r' || buffer[i] == '\n') {
// do not add line endings to the buffer
} else {
if (encrypted_line_cursor < SUBGHZ_KEYSTORE_FILE_ENCRYPTED_LINE_SIZE) {
if(encrypted_line_cursor < SUBGHZ_KEYSTORE_FILE_ENCRYPTED_LINE_SIZE) {
encrypted_line[encrypted_line_cursor] = buffer[i];
encrypted_line_cursor++;
} else {
@ -157,7 +163,7 @@ static bool subghz_keystore_read_file(SubGhzKeystore* instance, File* file, uint
}
} while(ret > 0 && result);
if (iv) furi_hal_crypto_store_unload_key(SUBGHZ_KEYSTORE_FILE_ENCRYPTION_KEY_SLOT);
if(iv) furi_hal_crypto_store_unload_key(SUBGHZ_KEYSTORE_FILE_ENCRYPTION_KEY_SLOT);
free(encrypted_line);
free(decrypted_line);
@ -192,16 +198,16 @@ bool subghz_keystore_load(SubGhzKeystore* instance, const char* file_name) {
break;
}
if (strcmp(string_get_cstr(filetype), SUBGHZ_KEYSTORE_FILE_TYPE) != 0
|| version != SUBGHZ_KEYSTORE_FILE_VERSION) {
if(strcmp(string_get_cstr(filetype), SUBGHZ_KEYSTORE_FILE_TYPE) != 0 ||
version != SUBGHZ_KEYSTORE_FILE_VERSION) {
FURI_LOG_E(SUBGHZ_KEYSTORE_TAG, "Type or version mismatch");
break;
}
File* file = flipper_file_get_file(flipper_file);
if (encryption == SubGhzKeystoreEncryptionNone) {
if(encryption == SubGhzKeystoreEncryptionNone) {
result = subghz_keystore_read_file(instance, file, NULL);
}else if (encryption == SubGhzKeystoreEncryptionAES256) {
} else if(encryption == SubGhzKeystoreEncryptionAES256) {
if(!flipper_file_read_hex_array(flipper_file, "IV", iv, 16)) {
FURI_LOG_E(SUBGHZ_KEYSTORE_TAG, "Missing IV");
break;
@ -237,7 +243,8 @@ bool subghz_keystore_save(SubGhzKeystore* instance, const char* file_name, uint8
FURI_LOG_E(SUBGHZ_KEYSTORE_TAG, "Unable to open file for write: %s", file_name);
break;
}
if(!flipper_file_write_header_cstr(flipper_file, SUBGHZ_KEYSTORE_FILE_TYPE, SUBGHZ_KEYSTORE_FILE_VERSION)) {
if(!flipper_file_write_header_cstr(
flipper_file, SUBGHZ_KEYSTORE_FILE_TYPE, SUBGHZ_KEYSTORE_FILE_VERSION)) {
FURI_LOG_E(SUBGHZ_KEYSTORE_TAG, "Unable to add header");
break;
}
@ -260,43 +267,46 @@ bool subghz_keystore_save(SubGhzKeystore* instance, const char* file_name, uint8
File* file = flipper_file_get_file(flipper_file);
size_t encrypted_line_count = 0;
for
M_EACH(
key,
instance->data,
SubGhzKeyArray_t) {
M_EACH(key, instance->data, SubGhzKeyArray_t) {
// Wipe buffer before packing
memset(decrypted_line, 0, SUBGHZ_KEYSTORE_FILE_DECRYPTED_LINE_SIZE);
memset(encrypted_line, 0, SUBGHZ_KEYSTORE_FILE_ENCRYPTED_LINE_SIZE);
// Form unecreypted line
int len = snprintf(
decrypted_line, SUBGHZ_KEYSTORE_FILE_DECRYPTED_LINE_SIZE,
decrypted_line,
SUBGHZ_KEYSTORE_FILE_DECRYPTED_LINE_SIZE,
"%08lX%08lX:%hu:%s",
(uint32_t)(key->key>>32), (uint32_t)key->key, key->type, string_get_cstr(key->name));
(uint32_t)(key->key >> 32),
(uint32_t)key->key,
key->type,
string_get_cstr(key->name));
// Verify length and align
furi_assert(len > 0);
if (len % 16 != 0) {
if(len % 16 != 0) {
len += (16 - len % 16);
}
furi_assert(len % 16 == 0);
furi_assert(len <= SUBGHZ_KEYSTORE_FILE_DECRYPTED_LINE_SIZE);
// Form encrypted line
if(!furi_hal_crypto_encrypt((uint8_t*)decrypted_line, (uint8_t*)encrypted_line, len)) {
if(!furi_hal_crypto_encrypt(
(uint8_t*)decrypted_line, (uint8_t*)encrypted_line, len)) {
FURI_LOG_E(SUBGHZ_KEYSTORE_TAG, "Encryption failed");
break;
}
// HEX Encode encrypted line
const char xx[]= "0123456789ABCDEF";
for (size_t i=0; i<len; i++) {
const char xx[] = "0123456789ABCDEF";
for(size_t i = 0; i < len; i++) {
size_t cursor = len - i - 1;
size_t hex_cursor = len*2 - i*2 - 1;
size_t hex_cursor = len * 2 - i * 2 - 1;
encrypted_line[hex_cursor] = xx[encrypted_line[cursor] & 0xF];
encrypted_line[hex_cursor-1] = xx[(encrypted_line[cursor]>>4) & 0xF];
encrypted_line[hex_cursor - 1] = xx[(encrypted_line[cursor] >> 4) & 0xF];
}
storage_file_write(file, encrypted_line, strlen(encrypted_line));
storage_file_write(file, "\n", 1);
encrypted_line_count++;
FURI_LOG_I(SUBGHZ_KEYSTORE_TAG, "Encrypted: `%s` -> `%s`", decrypted_line, encrypted_line);
FURI_LOG_I(
SUBGHZ_KEYSTORE_TAG, "Encrypted: `%s` -> `%s`", decrypted_line, encrypted_line);
}
furi_hal_crypto_store_unload_key(SUBGHZ_KEYSTORE_FILE_ENCRYPTION_KEY_SLOT);
result = encrypted_line_count == SubGhzKeyArray_size(instance->data);
@ -315,3 +325,272 @@ SubGhzKeyArray_t* subghz_keystore_get_data(SubGhzKeystore* instance) {
furi_assert(instance);
return &instance->data;
}
bool subghz_keystore_raw_encrypted_save(
const char* input_file_name,
const char* output_file_name,
uint8_t* iv) {
bool encrypted = false;
uint32_t version;
string_t filetype;
string_init(filetype);
SubGhzKeystoreEncryption encryption;
Storage* storage = furi_record_open("storage");
char* encrypted_line = furi_alloc(SUBGHZ_KEYSTORE_FILE_ENCRYPTED_LINE_SIZE);
FlipperFile* input_flipper_file = flipper_file_alloc(storage);
do {
if(!flipper_file_open_read(input_flipper_file, input_file_name)) {
FURI_LOG_E(SUBGHZ_KEYSTORE_TAG, "Unable to open file for read: %s", input_file_name);
break;
}
if(!flipper_file_read_header(input_flipper_file, filetype, &version)) {
FURI_LOG_E(SUBGHZ_KEYSTORE_TAG, "Missing or incorrect header");
break;
}
if(!flipper_file_read_uint32(input_flipper_file, "Encryption", (uint32_t*)&encryption)) {
FURI_LOG_E(SUBGHZ_KEYSTORE_TAG, "Missing encryption type");
break;
}
if(strcmp(string_get_cstr(filetype), SUBGHZ_KEYSTORE_FILE_RAW_TYPE) != 0 ||
version != SUBGHZ_KEYSTORE_FILE_VERSION) {
FURI_LOG_E(SUBGHZ_KEYSTORE_TAG, "Type or version mismatch");
break;
}
if(encryption != SubGhzKeystoreEncryptionNone) {
FURI_LOG_E(SUBGHZ_KEYSTORE_TAG, "Already encryption");
break;
}
File* input_file = flipper_file_get_file(input_flipper_file);
FlipperFile* output_flipper_file = flipper_file_alloc(storage);
if(!flipper_file_new_write(output_flipper_file, output_file_name)) {
FURI_LOG_E(SUBGHZ_KEYSTORE_TAG, "Unable to open file for write: %s", output_file_name);
break;
}
if(!flipper_file_write_header_cstr(
output_flipper_file, string_get_cstr(filetype), SUBGHZ_KEYSTORE_FILE_VERSION)) {
FURI_LOG_E(SUBGHZ_KEYSTORE_TAG, "Unable to add header");
break;
}
if(!flipper_file_write_uint32(
output_flipper_file, "Encryption", SubGhzKeystoreEncryptionAES256)) {
FURI_LOG_E(SUBGHZ_KEYSTORE_TAG, "Unable to add Encryption");
break;
}
if(!flipper_file_write_hex_array(output_flipper_file, "IV", iv, 16)) {
FURI_LOG_E(SUBGHZ_KEYSTORE_TAG, "Unable to add IV");
break;
}
if(!flipper_file_write_string_cstr(output_flipper_file, "Encrypt_data", "RAW")) {
FURI_LOG_E(SUBGHZ_KEYSTORE_TAG, "Unable to add Encrypt_data");
break;
}
subghz_keystore_mess_with_iv(iv);
if(!furi_hal_crypto_store_load_key(SUBGHZ_KEYSTORE_FILE_ENCRYPTION_KEY_SLOT, iv)) {
FURI_LOG_E(SUBGHZ_KEYSTORE_TAG, "Unable to load encryption key");
break;
}
File* output_file = flipper_file_get_file(output_flipper_file);
char buffer[FILE_BUFFER_SIZE];
bool result = true;
size_t ret = 0;
furi_assert(FILE_BUFFER_SIZE % 16 == 0);
//skip the end of the previous line "\n"
storage_file_read(input_file, buffer, 1);
do {
memset(buffer, 0, FILE_BUFFER_SIZE);
ret = storage_file_read(input_file, buffer, FILE_BUFFER_SIZE);
if(ret == 0) {
break;
}
for(uint16_t i = 0; i < FILE_BUFFER_SIZE - 1; i += 2) {
uint8_t hi_nibble = 0;
uint8_t lo_nibble = 0;
hex_char_to_hex_nibble(buffer[i], &hi_nibble);
hex_char_to_hex_nibble(buffer[i + 1], &lo_nibble);
buffer[i / 2] = (hi_nibble << 4) | lo_nibble;
}
memset(encrypted_line, 0, SUBGHZ_KEYSTORE_FILE_ENCRYPTED_LINE_SIZE);
// Form encrypted line
if(!furi_hal_crypto_encrypt(
(uint8_t*)buffer, (uint8_t*)encrypted_line, FILE_BUFFER_SIZE / 2)) {
FURI_LOG_E(SUBGHZ_KEYSTORE_TAG, "Encryption failed");
result = false;
break;
}
// HEX Encode encrypted line
const char xx[] = "0123456789ABCDEF";
for(size_t i = 0; i < FILE_BUFFER_SIZE / 2; i++) {
size_t cursor = FILE_BUFFER_SIZE / 2 - i - 1;
size_t hex_cursor = FILE_BUFFER_SIZE - i * 2 - 1;
encrypted_line[hex_cursor] = xx[encrypted_line[cursor] & 0xF];
encrypted_line[hex_cursor - 1] = xx[(encrypted_line[cursor] >> 4) & 0xF];
}
storage_file_write(output_file, encrypted_line, strlen(encrypted_line));
} while(ret > 0 && result);
flipper_file_close(output_flipper_file);
flipper_file_free(output_flipper_file);
furi_hal_crypto_store_unload_key(SUBGHZ_KEYSTORE_FILE_ENCRYPTION_KEY_SLOT);
if(!result) break;
encrypted = true;
} while(0);
flipper_file_close(input_flipper_file);
flipper_file_free(input_flipper_file);
free(encrypted_line);
furi_record_close("storage");
return encrypted;
}
bool subghz_keystore_raw_get_data(const char* file_name, size_t offset, uint8_t* data, size_t len) {
bool result = false;
uint8_t iv[16];
uint32_t version;
SubGhzKeystoreEncryption encryption;
string_t str_temp;
string_init(str_temp);
Storage* storage = furi_record_open("storage");
char* decrypted_line = furi_alloc(SUBGHZ_KEYSTORE_FILE_DECRYPTED_LINE_SIZE);
FlipperFile* flipper_file = flipper_file_alloc(storage);
do {
if(!flipper_file_open_read(flipper_file, file_name)) {
FURI_LOG_E(SUBGHZ_KEYSTORE_TAG, "Unable to open file for read: %s", file_name);
break;
}
if(!flipper_file_read_header(flipper_file, str_temp, &version)) {
FURI_LOG_E(SUBGHZ_KEYSTORE_TAG, "Missing or incorrect header");
break;
}
if(!flipper_file_read_uint32(flipper_file, "Encryption", (uint32_t*)&encryption)) {
FURI_LOG_E(SUBGHZ_KEYSTORE_TAG, "Missing encryption type");
break;
}
if(strcmp(string_get_cstr(str_temp), SUBGHZ_KEYSTORE_FILE_RAW_TYPE) != 0 ||
version != SUBGHZ_KEYSTORE_FILE_VERSION) {
FURI_LOG_E(SUBGHZ_KEYSTORE_TAG, "Type or version mismatch");
break;
}
File* file = flipper_file_get_file(flipper_file);
if(encryption != SubGhzKeystoreEncryptionAES256) {
FURI_LOG_E(SUBGHZ_KEYSTORE_TAG, "Unknown encryption");
break;
}
if(offset < 16) {
if(!flipper_file_read_hex_array(flipper_file, "IV", iv, 16)) {
FURI_LOG_E(SUBGHZ_KEYSTORE_TAG, "Missing IV");
break;
}
subghz_keystore_mess_with_iv(iv);
}
if(!flipper_file_read_string(flipper_file, "Encrypt_data", str_temp)) {
FURI_LOG_E(SUBGHZ_KEYSTORE_TAG, "Missing Encrypt_data");
break;
}
size_t bufer_size;
if(len <= (16 - offset % 16)) {
bufer_size = 32;
} else {
bufer_size = (((len) / 16) + 2) * 32;
}
furi_assert(SUBGHZ_KEYSTORE_FILE_DECRYPTED_LINE_SIZE >= bufer_size / 2);
char buffer[bufer_size];
size_t ret = 0;
bool decrypted = true;
//skip the end of the previous line "\n"
storage_file_read(file, buffer, 1);
size_t size = storage_file_size(file);
size -= storage_file_tell(file);
if(size < (offset * 2 + len * 2)) {
FURI_LOG_E(SUBGHZ_KEYSTORE_TAG, "Seek position exceeds file size");
break;
}
if(offset >= 16) {
storage_file_seek(file, ((offset / 16) - 1) * 32, false);
ret = storage_file_read(file, buffer, 32);
furi_assert(ret == 32);
for(uint16_t i = 0; i < ret - 1; i += 2) {
uint8_t hi_nibble = 0;
uint8_t lo_nibble = 0;
hex_char_to_hex_nibble(buffer[i], &hi_nibble);
hex_char_to_hex_nibble(buffer[i + 1], &lo_nibble);
iv[i / 2] = (hi_nibble << 4) | lo_nibble;
}
}
if(!furi_hal_crypto_store_load_key(SUBGHZ_KEYSTORE_FILE_ENCRYPTION_KEY_SLOT, iv)) {
FURI_LOG_E(SUBGHZ_KEYSTORE_TAG, "Unable to load encryption key");
break;
}
do {
memset(buffer, 0, bufer_size);
ret = storage_file_read(file, buffer, bufer_size);
furi_assert(ret == bufer_size);
for(uint16_t i = 0; i < ret - 1; i += 2) {
uint8_t hi_nibble = 0;
uint8_t lo_nibble = 0;
hex_char_to_hex_nibble(buffer[i], &hi_nibble);
hex_char_to_hex_nibble(buffer[i + 1], &lo_nibble);
buffer[i / 2] = (hi_nibble << 4) | lo_nibble;
}
memset(decrypted_line, 0, SUBGHZ_KEYSTORE_FILE_DECRYPTED_LINE_SIZE);
if(!furi_hal_crypto_decrypt(
(uint8_t*)buffer, (uint8_t*)decrypted_line, bufer_size / 2)) {
decrypted = false;
FURI_LOG_E(SUBGHZ_KEYSTORE_TAG, "Decryption failed");
break;
}
memcpy(data, (uint8_t*)decrypted_line + (offset - (offset / 16) * 16), len);
} while(0);
furi_hal_crypto_store_unload_key(SUBGHZ_KEYSTORE_FILE_ENCRYPTION_KEY_SLOT);
if(decrypted) result = true;
} while(0);
flipper_file_close(flipper_file);
flipper_file_free(flipper_file);
furi_record_close("storage");
free(decrypted_line);
string_clear(str_temp);
return result;
}

View File

@ -48,3 +48,22 @@ bool subghz_keystore_save(SubGhzKeystore* instance, const char* filename, uint8_
* @return SubGhzKeyArray_t*
*/
SubGhzKeyArray_t* subghz_keystore_get_data(SubGhzKeystore* instance);
/** Save RAW encrypted to file
*
* @param input_file_name - const char* full path to the input file
* @param output_file_name - const char* full path to the output file
*/
bool subghz_keystore_raw_encrypted_save(
const char* input_file_name,
const char* output_file_name,
uint8_t* iv);
/** Get decrypt RAW data to file
*
* @param file_name - const char* full path to the input file
* @param offset - offset from the start of the RAW data
* @param data - returned array
* @param len - required data length
*/
bool subghz_keystore_raw_get_data(const char* file_name, size_t offset, uint8_t* data, size_t len);