{ "id": "173550", "key": "AC-6231", "fields": { "issuetype": { "id": "1", "description": "A problem which impairs or prevents the functions of the product.", "name": "Bug", "subtask": false }, "project": { "id": "12217", "key": "AC", "name": "Appcelerator - INBOX", "projectCategory": { "id": "10000", "description": "", "name": "Customer Service" } }, "resolution": { "id": "10000", "description": "", "name": "Done" }, "resolutiondate": "2019-05-06T23:26:06.000+0000", "created": "2019-04-28T12:52:16.000+0000", "labels": [ "database", "encrypted_database" ], "versions": [], "issuelinks": [], "assignee": { "name": "shossain", "key": "shossain", "displayName": "Shak Hossain", "active": false, "timeZone": "America/Los_Angeles" }, "updated": "2019-05-06T23:26:06.000+0000", "status": { "description": "A resolution has been taken, and it is awaiting verification by reporter. From here issues are either reopened, or are closed.", "name": "Resolved", "id": "5", "statusCategory": { "id": 3, "key": "done", "colorName": "green", "name": "Done" } }, "components": [ { "id": "14550", "name": "Appcelerator Modules", "description": "Please enter tickets related to Modules here." } ], "description": "I am transitioning my app to use SQLCipher through the 'appcelerator.encrypteddatabase' module.\r\n\r\nExisting devices will have an unencrypted SQLite database which the app will need to do a sqlcipher_export() on.\r\n\r\nSee documentation here [https://www.zetetic.net/sqlcipher/sqlcipher-api/#sqlcipher_export|https://www.zetetic.net/sqlcipher/sqlcipher-api/#sqlcipher_export]\r\n\r\nI am now able to get the ATTACH command to work. But I cannot use the database for anything afterwards. It is as though the encrypteddatabase module is holding on to a reference to the DB.\r\n\r\nSee my attached app.js example.\r\n\r\n1.You can click the first button as many times as you like to create and add data to an unencrypted DB.\r\n2. This will create an encrypted DB, attach it, export it.\r\n3. This will now cause an exception\r\n4. Restart the app\r\n5. Button 3 now works perfectly.\r\n\r\nI have tried everything I can think of to get around this, and there's nothing in the SQLCipher documentation that I appear to be doing wrong. \r\n\r\nThanks for your help!. [^app.js] \r\n\r\n", "attachment": [ { "id": "66575", "filename": "app.js", "author": { "name": "mark.henderson@snagr.co.uk", "key": "mark.henderson@snagr.co.uk", "displayName": "Mark Henderson", "active": true, "timeZone": "Europe/London" }, "created": "2019-04-29T09:31:11.000+0000", "size": 4148, "mimeType": "text/javascript" }, { "id": "66576", "filename": "Screen Shot 2019-04-29 at 4.37.51 PM.png", "author": { "name": "rmitro", "key": "rmitro", "displayName": "Rakhi Mitro", "active": false, "timeZone": "America/Los_Angeles" }, "created": "2019-04-29T10:39:32.000+0000", "size": 35899, "mimeType": "image/png" } ], "flagged": false, "summary": "Encrypted Database Module - Unable to use encrypted database after ATTACH Database operation", "creator": { "name": "mark.henderson@snagr.co.uk", "key": "mark.henderson@snagr.co.uk", "displayName": "Mark Henderson", "active": true, "timeZone": "Europe/London" }, "subtasks": [], "reporter": { "name": "mark.henderson@snagr.co.uk", "key": "mark.henderson@snagr.co.uk", "displayName": "Mark Henderson", "active": true, "timeZone": "Europe/London" }, "environment": "iOS/Android - 7.5.2GA | 8.0.0GA", "comment": { "comments": [ { "id": "448028", "author": { "name": "rmitro", "key": "rmitro", "displayName": "Rakhi Mitro", "active": false, "timeZone": "America/Los_Angeles" }, "body": "Hello [~mark.henderson@snagr.co.uk],\r\nThanks for reporting this . Are you using 7.5.2SDK for build? Can you please test on 8.0.0.GA? And also share the console logs here.", "updateAuthor": { "name": "rmitro", "key": "rmitro", "displayName": "Rakhi Mitro", "active": false, "timeZone": "America/Los_Angeles" }, "created": "2019-04-29T09:46:42.000+0000", "updated": "2019-04-29T09:46:42.000+0000" }, { "id": "448032", "author": { "name": "mark.henderson@snagr.co.uk", "key": "mark.henderson@snagr.co.uk", "displayName": "Mark Henderson", "active": true, "timeZone": "Europe/London" }, "body": "Technically I'm using 7.5.2GA for production. But for this test I've also tried with 8.0.0GA.\r\n\r\nI'm pretty sure this is a bug with EncryptedDatabase module, as I've re-written this code 5 different ways today and tried almost everything. Whatever is locking it is removed when you re-launch the app. But after the attach / export / detach the database is completely locked.\r\n\r\nI also tried the second method of exporting a plaintext database into a new encrypted database. But this module gives an error message 'incorrect number of arguments'. I can also see that this module is using SQLCipher v3 not v4, as I need to set DB Browser for SQLite to this mode in order to decrypt and view the database. So I think it should be updated internally if there is a bug.\r\n\r\nHere are the console logs: \r\n\r\n{code:java}\r\n[ERROR] : file is not a database\r\n[ERROR] : A SQLite database error occurred on database '/Users/mark/Library/Developer/CoreSimulator/Devices/1D771BB8-BA4E-4C52-ADBA-E08AEC0E4B91/data/Containers/Data/Application/C04413E4-9003-40E9-90F3-0F14D343D473/Library/Private Documents/encryptedDB.db.sql': Error Domain=com.plausiblelabs.EncPLDatabase Code=4 \"Cipher migrate: failed to attach new database.\" UserInfo={com.plausiblelabs.EncPLDatabase.error.vendor.string=file is not a database, NSLocalizedDescription=Cipher migrate: failed to attach new database., com.plausiblelabs.EncPLDatabase.error.vendor.code=26} (SQLite #26: file is not a database) (query: '')\r\n[ERROR] : Script Error {\r\n[ERROR] : column = 42;\r\n[ERROR] : line = 97;\r\n[ERROR] : message = \"Couldn't open database and migrate\";\r\n[ERROR] : nativeLocation = \"\";\r\n[ERROR] : nativeReason = \"encryptedDB.db\";\r\n[ERROR] : nativeStack = \"3 testAttach 0x000000010793f7fd -[AppceleratorEncrypteddatabaseDBProxy open:] + 560\\n4 testAttach 0x000000010793b519 -[AppceleratorEncrypteddatabaseModule open:] + 373\\n5 CoreFoundation 0x000000010def94cc __invoking___ + 140\\n6 CoreFoundation 0x000000010def6a45 -[NSInvocation invoke] + 325\\n7 TitaniumKit0x000000010cc02c89 -[KrollMethod call:] + 1385\\n8 TitaniumKit0x000000010cc01dcb __KrollCallAsFunction_block_invoke + 30\\n9 TitaniumKit0x000000010cc01bdc KrollCallAsFunction + 496\\n10 JavaScriptCore 0x0000000107ecc8d3 _ZN3JSC16JSCallbackObjectINS_20JSDestructibleObjectEE4callEPNS_9ExecStateE + 515\\n11 JavaScriptCore 0x00000001083724fc _ZN3JSC5LLInt9setUpCallEPNS_9ExecStateENS_22CodeSpecializationKindENS_7JSValueEPNS_17LLIntCallLinkInfoE + 380\\n12 JavaScriptCore 0x0000000107e97b63 llint_entry + 61648\\n13 JavaScriptCore 0x0000000107e888d9 vmEntryToJavaScript + 200\\n14 JavaScriptCore 0x000000010826e730 _ZN3JSC11Interpreter11executeCallEPNS_9ExecStateEPNS_8JSObjectENS_8CallTypeERKNS_8CallDataENS_7JSValueERKNS_7ArgListE + 464\\n15 JavaScriptCore 0x00000001084b3634 _ZN3JSC12profiledCallEPNS_9ExecStateENS_15ProfilingReasonENS_7JSValueENS_8CallTypeERKNS_8CallDataES3_RKNS_7ArgListE + 196\\n16 JavaScriptCore 0x0000000107ed36fe JSObjectCallAsFunction + 478\\n17 TitaniumKit0x000000010cbde3e2 __TiBindingEventProcess_block_invoke + 53\\n18 TitaniumKit0x000000010cbde30a TiBindingEventProcess + 723\\n19 TitaniumKit0x000000010cbffdf5 -[KrollContext invoke:] + 109\";\r\n[ERROR] : sourceURL = \"file:///Users/mark/Library/Developer/CoreSimulator/Devices/1D771BB8-BA4E-4C52-ADBA-E08AEC0E4B91/data/Containers/Bundle/Application/FE136192-6854-4DB9-893B-120FD5A806EE/testAttach.app/app.js\";\r\n[ERROR] : stack = \" at [native code]\\n at testExisting(/app.js:97:42)\";\r\n[ERROR] : toJSON = \"\";\r\n[ERROR] : }\r\n{code}\r\n\r\n\r\nThanks!", "updateAuthor": { "name": "mark.henderson@snagr.co.uk", "key": "mark.henderson@snagr.co.uk", "displayName": "Mark Henderson", "active": true, "timeZone": "Europe/London" }, "created": "2019-04-29T12:47:19.000+0000", "updated": "2019-04-29T12:47:19.000+0000" }, { "id": "448161", "author": { "name": "mark.henderson@snagr.co.uk", "key": "mark.henderson@snagr.co.uk", "displayName": "Mark Henderson", "active": true, "timeZone": "Europe/London" }, "body": "Hi Shak, do let me know if there's any other information you require. I'm happy to help with any testing etc.. Unfortunately as the module is closed source I can't do too much.\r\n", "updateAuthor": { "name": "mark.henderson@snagr.co.uk", "key": "mark.henderson@snagr.co.uk", "displayName": "Mark Henderson", "active": true, "timeZone": "Europe/London" }, "created": "2019-05-03T02:38:01.000+0000", "updated": "2019-05-03T02:38:01.000+0000" }, { "id": "448182", "author": { "name": "mark.henderson@snagr.co.uk", "key": "mark.henderson@snagr.co.uk", "displayName": "Mark Henderson", "active": true, "timeZone": "Europe/London" }, "body": "I seem to have got this working finally.. It seems for iOS by checking the cipher upgrade and also making sure that after initialising appcelerator.encrypteddatabase I only use that to open database connections, not Ti.Database anymore.\r\n\r\nHere's the change to the code in case it helps anyone else in the future:\r\n\r\n\r\n{code:java}\r\nfunction createEncryptedDBAttachAndExport() {\r\n \t\t \t\t\r\n\t\t//set password in case we are creating a new encrypted DB not opening\r\n\t\tEncryptedDatabase.password = 'testkey';\r\n\t\t\r\n\t\tvar newDB = EncryptedDatabase.open(newDBName);\r\n\t\tif (Ti.Platform.osname !== 'android') {\r\n\t\t\tTi.API.info('UpgradeRequired? ' + newDB.isCipherUpgradeRequired(newDBName));\r\n\t\t}\r\n\t\tvar encDBFilePath = newDB.file.nativePath;\r\n\t\tnewDB.close();\r\n\t\tnewDB = null;\r\n\t\t\r\n\t\t/*var origDB = Ti.Database.open(databaseName);\r\n\t\tvar origDBFilePath = origDB.file.nativePath;\r\n\t\torigDB.close();\r\n\t\torigDB = null;*/\r\n\t\r\n\t\r\n\t\t//set password back to plaintest database so we can export\r\n\t\tEncryptedDatabase.password = '';\r\n\t\t\r\n \t\tvar unEncryptedDB = EncryptedDatabase.open(databaseName);\r\n \t\tunEncryptedDB.execute(\"ATTACH DATABASE '\" + encDBFilePath + \"' AS encrypted KEY 'testkey'\");\r\n\t\tunEncryptedDB.execute(\"SELECT sqlcipher_export('encrypted')\");\r\n \t\tunEncryptedDB.execute(\"DETACH DATABASE encrypted\"); \t\t\r\n \t\tunEncryptedDB.close();\r\n \t\tunEncryptedDB = null;\r\n \t\t\r\n\t\t//reset key back again\r\n\t\tEncryptedDatabase.password = 'testkey';\r\n\t\t\r\n\t\t// wrong number of arguments exception if we try to go this way (must be old SQLCipher version I think)\r\n\t\t/*var unEncryptedDB = EncryptedDatabase.open(newDBName);\r\n\t\tunEncryptedDB.execute(\"PRAGMA key = 'testkey';\");\r\n \t\tunEncryptedDB.execute(\"ATTACH DATABASE '\" + origDBFilePath + \"' AS plain KEY ''\");\r\n\t\tunEncryptedDB.execute(\"SELECT sqlcipher_export('main', 'plain')\");\r\n \t\tunEncryptedDB.execute(\"DETACH DATABASE plain\"); \t\t\r\n \t\tunEncryptedDB.close();\r\n \t\tunEncryptedDB = null;*/\r\n\t\t\r\n\t\t\r\n\t\t\r\n \t}\r\n{code}\r\n", "updateAuthor": { "name": "mark.henderson@snagr.co.uk", "key": "mark.henderson@snagr.co.uk", "displayName": "Mark Henderson", "active": true, "timeZone": "Europe/London" }, "created": "2019-05-04T13:12:31.000+0000", "updated": "2019-05-04T13:12:31.000+0000" } ], "maxResults": 5, "total": 5, "startAt": 0 } } }