diff --git a/CHANGELOG.md b/CHANGELOG.md index e4c394bf..e0d1a153 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,15 @@ +# 5.0.5-1 (2023-07-01) + +### Chore + + - Update to @capacitor/core@5.0.5 + - Update to @capacitor/ios@5.0.5 + - Update to @capacitor/android@5.0.5 + +### Bug Fixes + + - Electron fix encryption + # 5.0.4 (2023-06-29) ### Removed Features diff --git a/android/.gradle/buildOutputCleanup/buildOutputCleanup.lock b/android/.gradle/buildOutputCleanup/buildOutputCleanup.lock index f2d84fbc..e8231efb 100644 Binary files a/android/.gradle/buildOutputCleanup/buildOutputCleanup.lock and b/android/.gradle/buildOutputCleanup/buildOutputCleanup.lock differ diff --git a/electron/src/electron-utils/utilsFile.ts b/electron/src/electron-utils/utilsFile.ts index 9807bcf3..e0ca3b8b 100644 --- a/electron/src/electron-utils/utilsFile.ts +++ b/electron/src/electron-utils/utilsFile.ts @@ -53,7 +53,6 @@ export class UtilsFile { this.isEncryption = this.capConfig.plugins.CapacitorSQLite.electronIsEncryption ? this.capConfig.plugins.CapacitorSQLite.electronIsEncryption : false; - console.log(`$$$$$$ this.isEncryption: ${this.isEncryption} $$$$$$`); this.osType = this.Os.type(); switch (this.osType) { case 'Darwin': @@ -84,7 +83,6 @@ export class UtilsFile { * @returns */ public getIsEncryption(): boolean { - console.log(`>>>>>> getIsEncryption this.isEncryption: ${this.isEncryption} >>>>>>`); return this.isEncryption; } /** @@ -598,6 +596,26 @@ export class UtilsFile { fileStream.on('finish', resolve); }); } + public readFileAsPromise(path: string, options: {start: number, end: number}): Promise { + return new Promise((resolve, reject) => { + const fileStream = this.NodeFs.createReadStream(path, options); + + const chunks: any[] = []; + fileStream.on('data', (data: any) => { + chunks.push(data); + }); + + fileStream.on('close', () => { + resolve(chunks.toString()); + }); + + fileStream.on('error', (err:any) => { + const msg = err.message ? err.message : err; + reject(msg); + }); + }); + } + /** * CreateFolderIfNotExists * Create directory diff --git a/electron/src/electron-utils/utilsSQLite.ts b/electron/src/electron-utils/utilsSQLite.ts index a9333847..231d2ec7 100644 --- a/electron/src/electron-utils/utilsSQLite.ts +++ b/electron/src/electron-utils/utilsSQLite.ts @@ -947,13 +947,13 @@ export class UtilsSQLite { throw new Error(`${msg} ${errmsg}`); } } - public isDatabaseEncrypted(dbName: string): boolean { + public async isDatabaseEncrypted(dbName: string): Promise { const msg = "isDatabaseEncrypted"; try { const isExists: boolean = this.fileUtil.isFileExists(dbName); if(isExists) { - const filePath = this.fileUtil.getFilePath(dbName + 'SQLite.db'); - return this.isDBEncrypted(filePath); + const filePath = this.fileUtil.getFilePath(dbName); + return await this.isDBEncrypted(filePath); } else { throw new Error(`${msg}: Database ${dbName} does not exist`); } @@ -964,16 +964,11 @@ export class UtilsSQLite { } } - public isDBEncrypted(filePath: string): boolean { + public async isDBEncrypted(filePath: string): Promise { try { - const mDB = this.openOrCreateDatabase( - filePath, - "", - true, - ); - this.getVersion(mDB); - this.closeDB(mDB); - return false; + const retStr = await this.fileUtil.readFileAsPromise(filePath, {start:0, end:12}); + if (retStr === 'SQLite format') return false; + else return true; } catch (error) { return true; } @@ -1032,5 +1027,4 @@ export class UtilsSQLite { } return retStmt; } - } diff --git a/electron/src/electron-utils/utilsSecret.ts b/electron/src/electron-utils/utilsSecret.ts index 8f79df98..2f5b4a8a 100644 --- a/electron/src/electron-utils/utilsSecret.ts +++ b/electron/src/electron-utils/utilsSecret.ts @@ -19,7 +19,6 @@ export class UtilsSecret { public setEncryptSecret(passphrase: string): void { try { let oldpassphrase = this.getPassphrase(); - console.log(`>>>> setEncryptSecret oldpassphrase: ${oldpassphrase}`) if(oldpassphrase.length > 0 ) { throw new Error(`setEncryptSecret: passphrase already stored`); } else { @@ -27,7 +26,6 @@ export class UtilsSecret { if(oldpassphrase.length <= 0 ) { throw new Error(`setEncryptSecret: globalUtil is null`); } - console.log(`>>>> setEncryptSecret oldpassphrase: ${oldpassphrase}, passphrase ${passphrase}`) // check if some databases were encrypted with the initial secret 'sqlite secret' this.changeDatabaseSecret(oldpassphrase, passphrase).then(() => { @@ -82,20 +80,13 @@ export class UtilsSecret { } private async changeDatabaseSecret(oldpassphrase: string, newpassphrase: string): Promise { try { - console.log(`>>> changeDatabaseSecret oldpassphrase: ${oldpassphrase}`); - console.log(`>>> changeDatabaseSecret newpassphrase: ${newpassphrase}`); // get the database folder const pathDatabase = this.fileUtil.getDatabasesPath(); - console.log(`>>> changeDatabaseSecret pathDatabase: ${pathDatabase}`); // get the list of databases const files: string[] = await this.fileUtil.getFileList(pathDatabase); - console.log(`>>> changeDatabaseSecret files: ${files}`); - files.forEach(dbName => { - console.log(`>>> changeDatabaseSecret dbName: ${dbName}`); + files.forEach(async dbName => { const filePath = this.fileUtil.getFilePath(dbName); - console.log(`>>> changeDatabaseSecret filePath: ${filePath}`); - const isEncrypt: boolean = this.sqliteUtil.isDBEncrypted(filePath); - console.log(`>>> changeDatabaseSecret isEncrypt: ${isEncrypt}`); + const isEncrypt: boolean = await this.sqliteUtil.isDBEncrypted(filePath); if(isEncrypt) { this.sqliteUtil.changePassword(filePath, oldpassphrase, newpassphrase); @@ -108,7 +99,6 @@ export class UtilsSecret { } public getPassphrase(): string { const data = this.storage.getSync('userData'); - console.log(`>>>>>> data: `, data) const keys = Object.keys(data); if(data == null || keys.length <= 0) return ""; if (Object.keys(data).includes('passphrase')) { @@ -120,7 +110,6 @@ export class UtilsSecret { public setPassphrase(passphrase: string): void { const data = this.storage.getSync('userData'); data.passphrase = passphrase; - console.log(`>>>>>> set data: `, data) this.storage.set('userData', data,function (error:any) { if(error) throw new Error(`setPassphrase: ${error.message}`); }); @@ -128,7 +117,6 @@ export class UtilsSecret { public removePassphrase(): void { const data = this.storage.getSync('userData'); delete data.passphrase; - console.log(`>>>>>> set data: `, data) this.storage.set('userData', data,function (error:any) { if(error) throw new Error(`removePassphrase: ${error.message}`); }); diff --git a/electron/src/index.ts b/electron/src/index.ts index 6d5b8c75..8f8ef231 100644 --- a/electron/src/index.ts +++ b/electron/src/index.ts @@ -62,7 +62,6 @@ export class CapacitorSQLite implements CapacitorSQLitePlugin { if (!optionKeys.includes('database')) { throw new Error('Must provide a database name'); } - const dbName: string = options.database; const version: number = options.version ? options.version : 1; @@ -112,13 +111,11 @@ export class CapacitorSQLite implements CapacitorSQLitePlugin { const readonly: boolean = options.readonly ? options.readonly : false; const connName = readonly ? 'RO_' + dbName : 'RW_' + dbName; const database = this.getDatabaseConnectionOrThrowError(connName); - console.log(`@@@@@ connName: ${connName}`); try { if (database.isDBOpen()) { // close the database database.dbClose(); - console.log(`@@@@@ after database.dbClose()`); } } catch (err) { throw new Error( @@ -236,7 +233,6 @@ export class CapacitorSQLite implements CapacitorSQLitePlugin { throw new Error(`Execute: ${msg}`); } try { - console.log(`in index.ts statements`) const executeResult: number = database.executeSQL( statements, transaction, @@ -738,7 +734,6 @@ export class CapacitorSQLite implements CapacitorSQLitePlugin { // get the list of databases const files: string[] = await this.fileUtil.getFileList(pathDatabase); - if (files.length > 0) { return { values: files }; } else { @@ -833,7 +828,6 @@ export class CapacitorSQLite implements CapacitorSQLitePlugin { throw new Error(`setEncryptionSecret: passphrase already in store`); } await this.closeAllConnections(); - console.log(`setEncryptionSecret after closeAllConnections`); this.secretUtil.setEncryptSecret(passphrase); return; } catch(err) { @@ -852,8 +846,6 @@ export class CapacitorSQLite implements CapacitorSQLitePlugin { if(oldpassphrase.length <= 0) { throw new Error(`changeEncryptionSecret: You must give the oldpassphrase`); } - console.log(`##### oldsecret: ${oldsecret}`) - console.log(`##### oldpassphrase: ${oldpassphrase}`) if(oldpassphrase !== oldsecret) { throw new Error(`changeEncryptionSecret: the given oldpassphrase is wrong`); } @@ -896,7 +888,7 @@ export class CapacitorSQLite implements CapacitorSQLitePlugin { ): Promise { const dbName: string = this.getOptionValue(options, 'database'); try { - const isEncrypt: boolean = this.sqliteUtil.isDatabaseEncrypted(dbName + 'SQLite.db'); + const isEncrypt: boolean = await this.sqliteUtil.isDatabaseEncrypted(dbName + 'SQLite.db'); return {result: isEncrypt}; } catch(err) { throw new Error(`isDatabaseEncrypted: ${err}`); diff --git a/package-lock.json b/package-lock.json index 24f25db3..a4fd4708 100644 --- a/package-lock.json +++ b/package-lock.json @@ -12,11 +12,11 @@ "jeep-sqlite": "^2.3.6" }, "devDependencies": { - "@capacitor/android": "^5.0.0", - "@capacitor/cli": "^5.0.0", - "@capacitor/core": "^5.0.0", + "@capacitor/android": "^5.0.5", + "@capacitor/cli": "^5.0.5", + "@capacitor/core": "^5.0.5", "@capacitor/docgen": "^0.0.17", - "@capacitor/ios": "^5.0.0", + "@capacitor/ios": "^5.0.5", "@ionic/eslint-config": "^0.3.0", "@ionic/prettier-config": "^1.0.1", "@ionic/swiftlint-config": "^1.1.2", @@ -139,18 +139,18 @@ } }, "node_modules/@capacitor/android": { - "version": "5.0.4", - "resolved": "https://registry.npmjs.org/@capacitor/android/-/android-5.0.4.tgz", - "integrity": "sha512-WtXmjRQ0bCtFkwBID/jVEPbqnh0uR9wTSgkW7QNzogDuA0iyJJI2nxDfT9knUmg6mne/CnfTXg093zzdc13C0w==", + "version": "5.0.5", + "resolved": "https://registry.npmjs.org/@capacitor/android/-/android-5.0.5.tgz", + "integrity": "sha512-vH5Qoy+p2Egsu1GtPtOsihHcEI2fCGCIHwlUGPaXXGysudzpzWtJZ5JZNlycJyfRdjECrjkutgbNaHLog+YlXQ==", "dev": true, "peerDependencies": { "@capacitor/core": "^5.0.0" } }, "node_modules/@capacitor/cli": { - "version": "5.0.4", - "resolved": "https://registry.npmjs.org/@capacitor/cli/-/cli-5.0.4.tgz", - "integrity": "sha512-ALzAZlU1L0lwrxtBcvYeu6tFt5i3cLglQdsbohGLqAhipMWW/QNuafIJshxMMR8lMeBAEVYizdDOxEUFHcnWOQ==", + "version": "5.0.5", + "resolved": "https://registry.npmjs.org/@capacitor/cli/-/cli-5.0.5.tgz", + "integrity": "sha512-Mf+lr2L98NfDZki3e5jdG176LUH0rf+OFoMa/oFf6dp4iHwQjS1HiHN5iaGcfJ5RWt432SMEB0dOgicXPb4KCQ==", "dev": true, "dependencies": { "@ionic/cli-framework-output": "^2.2.5", @@ -249,9 +249,9 @@ } }, "node_modules/@capacitor/core": { - "version": "5.0.4", - "resolved": "https://registry.npmjs.org/@capacitor/core/-/core-5.0.4.tgz", - "integrity": "sha512-BFvziz9jM87pLHW2sXPNIzwrdmI5mAP0tBsBHgXoCO2+wVdpvIMYCpcst5BuTULaMz5JBFZZ6g6nqwgfs+SMCA==", + "version": "5.0.5", + "resolved": "https://registry.npmjs.org/@capacitor/core/-/core-5.0.5.tgz", + "integrity": "sha512-sulwWXEhYI6cBIj1WnH9k+a8z1f4XTRDtdh3YfXNdeV36UT7T55GCeGrPoQMm7ww6iWyGuv1VEzVIuZFga8rtw==", "dev": true, "dependencies": { "tslib": "^2.1.0" @@ -290,9 +290,9 @@ } }, "node_modules/@capacitor/ios": { - "version": "5.0.4", - "resolved": "https://registry.npmjs.org/@capacitor/ios/-/ios-5.0.4.tgz", - "integrity": "sha512-JVyggBTbHR1OWqxTRysgGKhZHDuM0AQwCIbylvEpza5X0zmaltbQxVC83abcwOKsgNJnrcuv+HUgV+LXg8Dk4Q==", + "version": "5.0.5", + "resolved": "https://registry.npmjs.org/@capacitor/ios/-/ios-5.0.5.tgz", + "integrity": "sha512-U72TPbKN1HlUqEGCOPsCBp6j93Qu1TazWUuA8Q1yfcGDfSOE0zMDNl3eU7XO5OyzpV7z9lf8NJdehimezVl7sA==", "dev": true, "peerDependencies": { "@capacitor/core": "^5.0.0" diff --git a/package.json b/package.json index 7785efa9..90d4efaa 100644 --- a/package.json +++ b/package.json @@ -56,11 +56,11 @@ "prepublishOnly": "npm run build && npm run build-electron && npm run docgen" }, "devDependencies": { - "@capacitor/android": "^5.0.0", - "@capacitor/cli": "^5.0.0", - "@capacitor/core": "^5.0.0", + "@capacitor/android": "^5.0.5", + "@capacitor/cli": "^5.0.5", + "@capacitor/core": "^5.0.5", "@capacitor/docgen": "^0.0.17", - "@capacitor/ios": "^5.0.0", + "@capacitor/ios": "^5.0.5", "@ionic/eslint-config": "^0.3.0", "@ionic/prettier-config": "^1.0.1", "@ionic/swiftlint-config": "^1.1.2", diff --git a/src/definitions.ts b/src/definitions.ts index 1adbfe0e..d171c790 100644 --- a/src/definitions.ts +++ b/src/definitions.ts @@ -1570,7 +1570,10 @@ export class SQLiteConnection implements ISQLiteConnection { async getDatabaseList(): Promise { try { const res = await this.sqlite.getDatabaseList(); - return Promise.resolve(res); + const values: string[] = res.values; + values.sort(); + const ret = {values: values}; + return Promise.resolve(ret); } catch (err) { return Promise.reject(err); }