realm / realm-js

Realm is a mobile database: an alternative to SQLite & key-value stores
https://realm.io
Apache License 2.0
5.79k stars 577 forks source link

Realm file decryption failed iOS 13 #2920

Closed Youhy closed 4 years ago

Youhy commented 4 years ago

Goals

I have a react-native application. Trying to use encryption in realm database. I faced with the situation, when even examples from documentation not working.

const realm = await Realm.open({ schema: schema.schema, encryptionKey: new Int8Array(64) }); const credentials = realm.objects(CredentialObject.name) realm.close();

Expected Results

To be able to get data from realm

Actual Results

[Error: Unable to open a realm at path '/Users/yauhenipozdnyakov/Library/Developer/CoreSimulator/Devices/47DBD255-9C83-426D-83F4-87A8D2143DF5/data/Containers/Data/Application/8636CBDE-6F64-42F0-B2EB-35A020B5BD77/Documents/default.realm': Realm file decryption failed Path:Exception backtrace: 0 Velocity 0x0000000110214401 _ZN5realm15InvalidDatabaseC2ERKNSt3__112basic_stringIcNS1_11char_traitsIcEENS19allocatorIcEEEES9

Steps to Reproduce

Even copy pasta from realm site not working

Code Sample

const realm = await Realm.open({ schema: schema.schema, encryptionKey: new Int8Array(64), deleteRealmIfMigrationNeeded: true, }); console.log('setObject realm.close();'); realm.write(() => { realm.create(name, object); });

const realm = await Realm.open({ schema: schema.schema, encryptionKey: new Int8Array(64) }); const credentials = realm.objects(CredentialObject.name) realm.close();

Version of Realm and Tooling

tudiantuan commented 4 years ago

I have same problem! Workflow my app: I call service get key then convert it arrayBuffer(64). if open realm failed then I delete old table and create new table with new key.

teampanorbit commented 4 years ago

Facing similar issue. Please find the stack trace below. Do we have any workaround to make it work?

_ERROR: Connection[2]: Session[2]: In finalize_state_transfer, the realm /path_to_file/partially_downloaded.realm could not be opened, msg = Realm file decryption failed Path: /path_to_file/partially_downloaded.realm Exception backtrace: 0 0x000000010194ee2c _ZN5realm15InvalidDatabaseC2ERKNSt3112basic_stringIcNS1_11char_traitsIcEENS19allocatorIcEEEES9 + 60 1 0x000000010189dacc _ZN5realm9SlabAlloc11attach_fileERKNSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEERNS0_6ConfigE + 4720 2 0x0000000101948e04 _ZN5realm11SharedGroup7do_openERKNSt3112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEEbbNS_18SharedGroupOptionsE + 3088 3 0x00000001016a1e30 _ZN5realm11SharedGroup4openERNS_11ReplicationENS_18SharedGroupOptionsE + 292 4 0x0000000101a7ca8c _ZN5realm11SharedGroupC2ERNS_11ReplicationENS_18SharedGroupOptionsE + 864 5 0x0000000101abacec _ZN5realm5_impl19ClientStateDownload19finalize_async_openEv + 496 6 0x0000000101ab97f0 _ZN5realm5_impl19ClientStateDownload13receive_stateEyxyyyNS_10BinaryDataE + 1268 7 0x0000000101a95f9c _ZN5realm5_impl14ClientImplBase7Session21receive_state_messageEyxyyyNS_10BinaryDataE + 572 8 0x0000000101a92d3c _ZN5realm5_impl14ClientProtocol22parse_message_receivedINS0_14ClientImplBase10ConnectionEEEvRT_PKcm + 3852 9 0x0000000101a8de80 _ZN5realm5_impl14ClientImplBase10Connection33websocket_binary_message_receivedEPKcm + 60 10 0x0000000101b486d4 _ZN12_GLOBALN_19WebSocket17frame_reader_loopEv + 1536 11 0x0000000101a9cacc _ZN5realm4util7network7Service9AsyncOper29do_recycle_and_execute_helperINSt318functionIFvNS5_10error_codeEmEEEJS7_mEEEvbRbTDpT0 + 168 12 0x0000000101a9c908 _ZN5realm4util7network7Service9AsyncOper22do_recycle_and_executeINSt318functionIFvNS5_10error_codeEmEEEJRS7_RmEEEvbRTDpOT0 + 148 13 0x0000000101a9c464 _ZN5realm4util7network7Service14BasicStreamOpsINS1_3ssl6StreamEE16BufferedReadOperINSt318functionIFvNS8_10error_codeEmEEEE19recycle_and_executeEv + 240 14 0x0000000101b3a8b0 _ZN5realm4util7network7Service4Impl3runEv + 400 15 0x0000000101ad1ef8 _ZN5realm4sync6Client3runEv + 36 16 0x00000001016da0a4 _ZZN5realm5_impl10SyncClientC1ENSt3110unique_ptrINS_4util6LoggerENS2_14default_deleteIS5_EEEERKNS_16SyncClientConfigEENKUlvE0_clEv + 248 17 0x00000001016d9f60 _ZNSt31L8invokeIZN5realm5_impl10SyncClientC1ENS_10unique_ptrINS1_4util6LoggerENS_14default_deleteIS6_EEEERKNS1_16SyncClientConfigEEUlvE0_JEEEDTclclsr3std31E7forwardIT_Efp_Espclsr3std31E7forwardIT0_Efp0_EEEOSEDpOSF + 28 18 0x00000001016d9ebc _ZNSt31L16thread_executeINS_10unique_ptrINS_15thread_structENS_14default_deleteIS2_EEEEZN5realm5_impl10SyncClientC1ENS1_INS6_4util6LoggerENS3_ISA_EEEERKNS6_16SyncClientConfigEEUlvE0_JEJEEEvRNS_5tupleIJT_T0_DpT1_EEENS_15tuple_indicesIJXspT2_EEEE + 32 19 0x00000001016d95c0 _ZNSt3114__thread_proxyINS_5tupleIJNS_10unique_ptrINS_15__thread_structENS_14default_deleteIS3_EEEEZN5realm5_impl10SyncClientC1ENS2_INS7_4util6LoggerENS4_ISB_EEEERKNS7_16SyncClientConfigEEUlvE0EEEEEPvSJ + 116 20 libsystem_pthread.dylib 0x00000001831e02c0 + 128 21 libsystem_pthread.dylib 0x00000001831e0220 _pthread_start + 44 22 libsystem_pthread.dylib 0x00000001831e3cdc threadstart + 4

teampanorbit commented 4 years ago

Facing similar issue. Please find the stack trace below. Do we have any workaround to make it work?

_ERROR: Connection[2]: Session[2]: In finalize_state_transfer, the realm /path_to_file/partially_downloaded.realm could not be opened, msg = Realm file decryption failed Path: /path_to_file/partially_downloaded.realm Exception backtrace: 0 0x000000010194ee2c _ZN5realm15InvalidDatabaseC2ERKNSt3112basic_stringIcNS1_11char_traitsIcEENS19allocatorIcEEEES9 + 60 1 0x000000010189dacc _ZN5realm9SlabAlloc11attach_fileERKNSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEERNS0_6ConfigE + 4720 2 0x0000000101948e04 _ZN5realm11SharedGroup7do_openERKNSt3112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEEbbNS_18SharedGroupOptionsE + 3088 3 0x00000001016a1e30 _ZN5realm11SharedGroup4openERNS_11ReplicationENS_18SharedGroupOptionsE + 292 4 0x0000000101a7ca8c _ZN5realm11SharedGroupC2ERNS_11ReplicationENS_18SharedGroupOptionsE + 864 5 0x0000000101abacec _ZN5realm5_impl19ClientStateDownload19finalize_async_openEv + 496 6 0x0000000101ab97f0 _ZN5realm5_impl19ClientStateDownload13receive_stateEyxyyyNS_10BinaryDataE + 1268 7 0x0000000101a95f9c _ZN5realm5_impl14ClientImplBase7Session21receive_state_messageEyxyyyNS_10BinaryDataE + 572 8 0x0000000101a92d3c _ZN5realm5_impl14ClientProtocol22parse_message_receivedINS0_14ClientImplBase10ConnectionEEEvRT_PKcm + 3852 9 0x0000000101a8de80 _ZN5realm5_impl14ClientImplBase10Connection33websocket_binary_message_receivedEPKcm + 60 10 0x0000000101b486d4 _ZN12_GLOBALN_19WebSocket17frame_reader_loopEv + 1536 11 0x0000000101a9cacc _ZN5realm4util7network7Service9AsyncOper29do_recycle_and_execute_helperINSt318functionIFvNS5_10error_codeEmEEEJS7_mEEEvbRbTDpT0 + 168 12 0x0000000101a9c908 _ZN5realm4util7network7Service9AsyncOper22do_recycle_and_executeINSt318functionIFvNS5_10error_codeEmEEEJRS7_RmEEEvbRTDpOT0 + 148 13 0x0000000101a9c464 _ZN5realm4util7network7Service14BasicStreamOpsINS1_3ssl6StreamEE16BufferedReadOperINSt318functionIFvNS8_10error_codeEmEEEE19recycle_and_executeEv + 240 14 0x0000000101b3a8b0 _ZN5realm4util7network7Service4Impl3runEv + 400 15 0x0000000101ad1ef8 _ZN5realm4sync6Client3runEv + 36 16 0x00000001016da0a4 _ZZN5realm5_impl10SyncClientC1ENSt3110unique_ptrINS_4util6LoggerENS2_14default_deleteIS5_EEEERKNS_16SyncClientConfigEENKUlvE0_clEv + 248 17 0x00000001016d9f60 _ZNSt31L8invokeIZN5realm5_impl10SyncClientC1ENS_10unique_ptrINS1_4util6LoggerENS_14default_deleteIS6_EEEERKNS1_16SyncClientConfigEEUlvE0_JEEEDTclclsr3std31E7forwardIT_Efp_Espclsr3std31E7forwardIT0_Efp0_EEEOSEDpOSF + 28 18 0x00000001016d9ebc _ZNSt31L16thread_executeINS_10unique_ptrINS_15thread_structENS_14default_deleteIS2_EEEEZN5realm5_impl10SyncClientC1ENS1_INS6_4util6LoggerENS3_ISA_EEEERKNS6_16SyncClientConfigEEUlvE0_JEJEEEvRNS_5tupleIJT_T0_DpT1_EEENS_15tuple_indicesIJXspT2_EEEE + 32 19 0x00000001016d95c0 _ZNSt3114__thread_proxyINS_5tupleIJNS_10unique_ptrINS_15__thread_structENS_14default_deleteIS3_EEEEZN5realm5_impl10SyncClientC1ENS2_INS7_4util6LoggerENS4_ISB_EEEERKNS7_16SyncClientConfigEEUlvE0EEEEEPvSJ + 116 20 libsystem_pthread.dylib 0x00000001831e02c0 + 128 21 libsystem_pthread.dylib 0x00000001831e0220 _pthread_start + 44 22 libsystem_pthread.dylib 0x00000001831e3cdc threadstart + 4

Updating the realm version to 6.0.2 solved the problem.

kneth commented 4 years ago

I am closing as upgrading seems to solve it.