iOS File decryption error when opening a file created via a Mac Catalyst app
RomainPct opened this issue · 3 comments
Goals
Be able to open a realm database which has been initialized on a mac catalyst app in an iOS app.
Expected Results
- Initialization of an encrypted realm database in a mac catalyst app
- Database file transfer to a device with iOS
- Be able to decrypt this file and use the realm database in the iOS app
Actual Results
Realm is unable to open the realm file using the same encryption key as the mac catalyst app.
`Unable to open a realm at path '/var/mobile/Containers/Data/Application/7A059308-3BEF-4F19-843E-2D1176473B89/Documents/my_encrypted_realm.realm': Realm file decryption failed Path:Exception backtrace:
0 Sesame 0x0000000102b33dd8 _ZN5realm4util6detail26ExceptionWithBacktraceBaseC2Ev + 48
1 Sesame 0x0000000102b3fdac ZN5realm4util22ExceptionWithBacktraceISt13runtime_errorEC2IJRKNSt3__112basic_stringIcNS5_11char_traitsIcEENS5_9allocatorIcEEEEEEEDpOT
- 100
2 Sesame 0x0000000102b3fb78 ZN5realm4util4File11AccessErrorC2ERKNSt3__112basic_stringIcNS3_11char_traitsIcEENS3_9allocatorIcEEEESB + 72
3 Sesame 0x0000000102b3fb0c ZN5realm15InvalidDatabaseC2ERKNSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEES9 + 76
4 Sesame 0x0000000102b3b7bc ZN5realm15InvalidDatabaseC1ERKNSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEES9 + 48
5 Sesame 0x0000000102b3b1d8 _ZN5realm9SlabAlloc11attach_fileERKNSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEERNS0_6ConfigE + 3836
6 Sesame 0x0000000102d165e8 _ZN5realm2DB7do_openERKNSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEEbbNS_9DBOptionsE + 3868
7 Sesame 0x0000000102d19220 _ZN5realm2DB4openERNS_11ReplicationENS_9DBOptionsE + 288
8 Sesame 0x0000000102d1f2bc _ZN5realm2DB6createERNS_11ReplicationENS_9DBOptionsE + 176
9 Sesame 0x0000000102838d74 _ZN5realm5_impl16RealmCoordinator7open_dbEv + 992
10 Sesame 0x0000000102837f7c _ZN5realm5_impl16RealmCoordinator12do_get_realmENS_5Realm6ConfigERNSt3__110shared_ptrIS2_EENS_4util8OptionalINS_9VersionIDEEERNS8_17CheckedUniqueLockE + 68
11 Sesame 0x0000000102837d98 _ZN5realm5_impl16RealmCoordinator9get_realmENS_5Realm6ConfigENS_4util8OptionalINS_9VersionIDEEE + 668
12 Sesame 0x00000001029455b0 _ZN5realm5Realm16get_shared_realmENS0_6ConfigE + 176
13 Sesame 0x00000001026c1f60 ﹍[RLMRealm realmWithConfiguration:queue:error:]﹍ 1796
14 Sesame 0x000000010274aa24 $sSo8RLMRealmC13configuration5queueABSo0A13ConfigurationC_So012OS_dispatch_C0CSgtKcfCTO + 156
15 Sesame 0x00000001027a970c $s10RealmSwift0A0V13configuration5queueA2C13ConfigurationV_So012OS_dispatch_D0CSgtKcfC + 216
16 Sesame 0x00000001023781d8 $s6SesameAAC18checkEncryptionKey010encryptionD012forRealmFileSb10Foundation4DataVSg_AF3URLVtF + 376
17 Sesame 0x0000000102371834 $s6Sesame12SynchronizerC19joinSynchronization12withPasswordAC0D5ErrorOSgSSSg_tF + 720
18 Sesame 0x0000000102359178 $s6Sesame20Login_ViewControllerC25loginSynchronizeNewDevice33_4820E7014C72F50FB5D2060DD857A76CLLyyF + 304
19 Sesame 0x000000010235a628 $s6Sesame20Login_ViewControllerC21textFieldShouldReturnySbSo06UITextF0CFTo + 100
20 UIKitCore 0x0000000186da9cb4 23311071-8AD7-3E8F-836A-BE5DC8A8B0DF + 15768756
21 UIKitCore 0x0000000186834130 23311071-8AD7-3E8F-836A-BE5DC8A8B0DF + 10043696
22 UIKitCore 0x000000018684ad94 23311071-8AD7-3E8F-836A-BE5DC8A8B0DF + 10136980
23 UIKitCore 0x0000000186873bdc 23311071-8AD7-3E8F-836A-BE5DC8A8B0DF + 10304476
24 UIKitCore 0x000000018684981c 23311071-8AD7-3E8F-836A-BE5DC8A8B0DF + 10131484
25 UIKitCore 0x0000000186849110 23311071-8AD7-3E8F-836A-BE5DC8A8B0DF + 10129680
26 UIKitCore 0x0000000186848c48 23311071-8AD7-3E8F-836A-BE5DC8A8B0DF + 10128456
27 UIKitCore 0x0000000186873bdc 23311071-8AD7-3E8F-836A-BE5DC8A8B0DF + 10304476
28 UIKitCore 0x0000000186848c04 23311071-8AD7-3E8F-836A-BE5DC8A8B0DF + 10128388
29 UIKitCore 0x000000018685e600 23311071-8AD7-3E8F-836A-BE5DC8A8B0DF + 10216960
30 UIKitCore 0x0000000186827924 23311071-8AD7-3E8F-836A-BE5DC8A8B0DF + 9992484
31 UIKitCore 0x000000018685df68 23311071-8AD7-3E8F-836A-BE5DC8A8B0DF + 10215272
32 UIKitCore 0x000000018685d140 23311071-8AD7-3E8F-836A-BE5DC8A8B0DF + 10211648
33 UIKitCore 0x00000001867927a4 23311071-8AD7-3E8F-836A-BE5DC8A8B0DF + 9381796
34 UIKitCore 0x00000001868681e0 23311071-8AD7-3E8F-836A-BE5DC8A8B0DF + 10256864
35 UIKitCore 0x0000000186868494 23311071-8AD7-3E8F-836A-BE5DC8A8B0DF + 10257556
36 UIKitCore 0x00000001868758b4 23311071-8AD7-3E8F-836A-BE5DC8A8B0DF + 10311860
37 UIKitCore 0x00000001868742e8 23311071-8AD7-3E8F-836A-BE5DC8A8B0DF + 10306280
38 UIKitCore 0x00000001868683f0 23311071-8AD7-3E8F-836A-BE5DC8A8B0DF + 10257392
39 UIKitCore 0x0000000186867ef0 23311071-8AD7-3E8F-836A-BE5DC8A8B0DF + 10256112
40 UIKitCore 0x0000000186aae5dc 23311071-8AD7-3E8F-836A-BE5DC8A8B0DF + 12641756
41 UIKitCore 0x0000000186aaff44 23311071-8AD7-3E8F-836A-BE5DC8A8B0DF + 12648260
42 UIKitCore 0x0000000186a892cc 23311071-8AD7-3E8F-836A-BE5DC8A8B0DF + 12489420
43 UIKitCore 0x0000000186b131ec 23311071-8AD7-3E8F-836A-BE5DC8A8B0DF + 13054444
44 UIKitCore 0x0000000186b161a4 23311071-8AD7-3E8F-836A-BE5DC8A8B0DF + 13066660
45 UIKitCore 0x0000000186b0d650 23311071-8AD7-3E8F-836A-BE5DC8A8B0DF + 13030992
46 CoreFoundation 0x000000018403176c 935533F2-35EE-314E-A760-E74521F68435 + 661356
47 CoreFoundation 0x0000000184031668 935533F2-35EE-314E-A760-E74521F68435 + 661096
48 CoreFoundation 0x0000000184030960 935533F2-35EE-314E-A760-E74521F68435 + 657760
49 CoreFoundation 0x000000018402aa8c 935533F2-35EE-314E-A760-E74521F68435 + 633484
50 CoreFoundation 0x000000018402a21c CFRunLoopRunSpecific + 600
51 GraphicsServices 0x000000019bb2e784 GSEventRunModal + 164
52 UIKitCore 0x0000000186a68fe0 23311071-8AD7-3E8F-836A-BE5DC8A8B0DF + 12357600
53 UIKitCore 0x0000000186a6e854 UIApplicationMain + 168
54 Sesame 0x00000001023a2564 main + 176
55 libdyld.dylib 0x0000000183cea6b0 785BEE7F-AC2C-388D-865C-36279D1B3DD1 + 5808.`
Steps for others to Reproduce
- Create a swift app which uses realm
- Enable the app for mac catalyst
- Build the app on mac catalyst and initialize a realm database
- Transfer the realm database to an iOS device
- Build the app for iOS and try to decrypt the realm file initialized on mac
Code Sample
Sample project to reproduce the bug : https://github.com/RomainPct/DemoRealmBug
Version of Realm and Tooling
Realm framework version: This bug appears on realm 5.3.5 as well as on 10.5.0
Xcode version: 12.2, 12.3 and before as well
iOS/OSX version: Mac OS Catalina as well as Mac OS Big Sur + iOS 13 as well as iOS 14
Dependency manager + version: SPM
Thank you for your answer and your help in order to solve this issue.
Hi @RomainPct,
Thank you for providing information about your issue including the code repo.
I checked it out and could not reproduce the issue immediately. In fact I got a completely different result.
The relevant part:
40 libdyld.dylib 0x0000000199a81588 E31C0887-C999-3047-9B80-203248EC2396 + 5512, NSLocalizedDescription=Unable to open a realm at path '/var/mobile/Containers/Data/Application/DBE04462-6B17-4E0F-80CC-BEB821B5D116/Documents/default.realm': Realm file decryption failed Path:Exception backtrace:
We will have to look further into this.
40 libdyld.dylib 0x0000000199a81588 E31C0887-C999-3047-9B80-203248EC2396 + 5512, NSLocalizedDescription=Unable to open a realm at path '/var/mobile/Containers/Data/Application/DBE04462-6B17-4E0F-80CC-BEB821B5D116/Documents/default.realm': Realm file decryption failed Path:Exception backtrace:
Same error for both of us @DominicFrei "Unable to open a realm at path ...: Realm file decryption failed"
Do you have any idea about how to solve that problem N
Closing as this is not something that is actually supported. See: realm/realm-core#4518 (comment)