@capacitor-community/sqlite 3.3.3-test211 → 3.4.0-2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +37 -14
- package/android/build.gradle +1 -1
- package/android/src/main/java/com/getcapacitor/community/database/sqlite/CapacitorSQLite.java +127 -6
- package/android/src/main/java/com/getcapacitor/community/database/sqlite/CapacitorSQLitePlugin.java +95 -13
- package/android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/BiometricListener.java +8 -0
- package/android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/Database.java +5 -3
- package/android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/SqliteConfig.java +32 -0
- package/android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/UtilsBiometric.java +123 -0
- package/android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/UtilsSQLite.java +19 -0
- package/android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/UtilsSecret.java +7 -2
- package/dist/esm/definitions.d.ts +7 -0
- package/dist/esm/definitions.js.map +1 -1
- package/electron/dist/plugin.js +14 -21
- package/electron/dist/plugin.js.map +1 -1
- package/ios/Plugin/BiometricIDAuthentication.swift +79 -0
- package/ios/Plugin/CapacitorSQLite.swift +144 -24
- package/ios/Plugin/CapacitorSQLitePlugin.swift +52 -9
- package/ios/Plugin/Database.swift +17 -4
- package/ios/Plugin/Extensions/Notification.Name.swift +6 -2
- package/ios/Plugin/Models/KeychainServices.swift +1 -1
- package/ios/Plugin/SqliteConfig.swift +3 -0
- package/ios/Plugin/Utils/UtilsSQLCipher.swift +5 -4
- package/ios/Plugin/Utils/UtilsSecret.swift +54 -22
- package/package.json +6 -6
- package/CHANGELOG.md +0 -1247
package/README.md
CHANGED
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
<a href="https://www.npmjs.com/package/@capacitor-community/sqlite"><img src="https://img.shields.io/npm/dw/@capacitor-community/sqlite?style=flat-square" /></a>
|
|
17
17
|
<a href="https://www.npmjs.com/package/@capacitor-community/sqlite"><img src="https://img.shields.io/npm/v/@capacitor-community/sqlite?style=flat-square" /></a>
|
|
18
18
|
<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
|
|
19
|
-
<a href="#contributors-"><img src="https://img.shields.io/badge/all%20contributors-
|
|
19
|
+
<a href="#contributors-"><img src="https://img.shields.io/badge/all%20contributors-13-orange?style=flat-square" /></a>
|
|
20
20
|
<!-- ALL-CONTRIBUTORS-BADGE:END -->
|
|
21
21
|
</p>
|
|
22
22
|
|
|
@@ -28,6 +28,20 @@
|
|
|
28
28
|
|
|
29
29
|
## CAPACITOR 3 (Master)
|
|
30
30
|
|
|
31
|
+
🚨 Since release 3.4.0-2 ->> 🚨
|
|
32
|
+
|
|
33
|
+
- iOS & Android only
|
|
34
|
+
Adding biometric FaceID/TouchID to secure the pass phrase in the Keychain/SharedPreferences stores. see:
|
|
35
|
+
[Biometric_Authentication](https://github.com/capacitor-community/sqlite/blob/master/docs/Biometric-Authentication.md)
|
|
36
|
+
|
|
37
|
+
- iOS only
|
|
38
|
+
Fix identical pass phrase stored in the Keychain for differents applications using the plugin by adding an application prefix to the Keychain account.
|
|
39
|
+
Before the account `"CapacitorSQLitePlugin"` was used and was the same for all applications.
|
|
40
|
+
Now by adding `iosKeychainPrefix: 'YOUR_APP_NAME'`in the `capacitor.config.ts` of your application,
|
|
41
|
+
the account will be `"YOUR_APP_NAME_CapacitorSQLitePlugin"`
|
|
42
|
+
If you were having a pass phrase stored, first modify the `capacitor.config.ts` and then run the command `isSecretStored` which will manage the upgrade of the Keychain account.
|
|
43
|
+
🚨 Since release 3.4.0-2 <<- 🚨
|
|
44
|
+
|
|
31
45
|
🚨 Since release 3.3.3-2 ->> 🚨
|
|
32
46
|
|
|
33
47
|
- iOS only
|
|
@@ -80,6 +94,12 @@ The test has been achieved on:
|
|
|
80
94
|
|
|
81
95
|
- a [Ionic/Vue app](https://github.com/jepiqueau/vue-sqlite-app-starter)
|
|
82
96
|
|
|
97
|
+
- a [React Vite app](https://github.com/jepiqueau/react-vite-sqlite-app)
|
|
98
|
+
|
|
99
|
+
- a [Vue Vite app](https://github.com/jepiqueau/vuevite-app)
|
|
100
|
+
|
|
101
|
+
- a [Vue TypeORM app](https://github.com/jepiqueau/vue-typeorm-app)
|
|
102
|
+
|
|
83
103
|
|
|
84
104
|
## Browser Support
|
|
85
105
|
|
|
@@ -110,11 +130,11 @@ npx cap sync @capacitor-community/electron
|
|
|
110
130
|
|
|
111
131
|
#### For Angular framework
|
|
112
132
|
|
|
113
|
-
- copy manually the file `sql-wasm.wasm` from `
|
|
133
|
+
- copy manually the file `sql-wasm.wasm` from `node_modules/sql.js/dist/sql-wasm.wasm` to the `src/assets` folder of YOUR_APP
|
|
114
134
|
|
|
115
135
|
#### For Vue & React frameworks
|
|
116
136
|
|
|
117
|
-
- copy manually the file `sql-wasm.wasm` from `
|
|
137
|
+
- copy manually the file `sql-wasm.wasm` from `node_modules/sql.js/dist/sql-wasm.wasm` to the `public/assets` folder of YOUR_APP
|
|
118
138
|
|
|
119
139
|
### IOS
|
|
120
140
|
|
|
@@ -261,6 +281,8 @@ No configuration required for this plugin
|
|
|
261
281
|
|
|
262
282
|
- [Non_Conformed_Databases_Documentation](https://github.com/capacitor-community/sqlite/blob/master/docs/NonConformedDatabases.md)
|
|
263
283
|
|
|
284
|
+
- [Biometric_Authentication](https://github.com/capacitor-community/sqlite/blob/master/docs/Biometric-Authentication.md)
|
|
285
|
+
|
|
264
286
|
### Framework's Usage
|
|
265
287
|
|
|
266
288
|
- [Ionic/Angular_Usage_Documentation](https://github.com/capacitor-community/sqlite/blob/master/docs/Ionic-Angular-Usage.md)
|
|
@@ -319,17 +341,18 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
|
|
|
319
341
|
<table>
|
|
320
342
|
<tr>
|
|
321
343
|
<td align="center"><a href="https://github.com/jepiqueau"><img src="https://avatars3.githubusercontent.com/u/16580653?v=4" width="100px;" alt=""/><br /><sub><b>Jean Pierre Quéau</b></sub></a><br /><a href="https://github.com/capacitor-community/sqlite/commits?author=jepiqueau" title="Code">💻</a></td>
|
|
322
|
-
<td align="center"><a href="https://github.com/paulantoine2"><img src="https://avatars0.githubusercontent.com/u/22882943?s=64&v=4" width="100px;" alt=""/><br /><sub><b>Paul Antoine</b></sub></a><br /><a href="https://github.com/capacitor-community/sqlite/commits?author=
|
|
323
|
-
<td align="center"><a href="https://github.com/karyfars"><img src="https://avatars2.githubusercontent.com/u/303016?s=60&u=1ce232ae3c22eac7b0b4778e46fe079939c39b40&v=4" width="100px;" alt=""/><br /><sub><b>Karyfars</b></sub></a><br /><a href="https://github.com/capacitor-community/sqlite/commits?author=
|
|
324
|
-
<td align="center"><a href="https://github.com/chriswep"><img src="https://avatars2.githubusercontent.com/u/1055809?s=400&u=e555940f143da8be255743028d6838cb5c020b44&v=4" width="100px;" alt=""/><br /><sub><b>Chriswep</b></sub></a><br /><a href="https://github.com/capacitor-community/sqlite/commits?author=
|
|
325
|
-
<td align="center"><a href="https://github.com/nirajhinge"><img src="https://avatars.githubusercontent.com/u/54309996?v=4" width="100px;" alt=""/><br /><sub><b>Nirajhinge</b></sub></a><br /><a href="https://github.com/capacitor-community/sqlite/commits?author=
|
|
326
|
-
<td align="center"><a href="https://github.com/digaus"><img src="https://avatars.githubusercontent.com/u/15358538?v=4" width="100px;" alt=""/><br /><sub><b>Dirk Gausmann</b></sub></a><br /><a href="https://github.com/capacitor-community/sqlite/commits?author=
|
|
327
|
-
<td align="center"><a href="https://github.com/IT-MikeS"><img src="https://avatars.githubusercontent.com/u/20338451?v=4" width="100px;" alt=""/><br /><sub><b>Mike Summerfeldt</b></sub></a><br /><a href="https://github.com/capacitor-community/sqlite/commits?author=
|
|
328
|
-
<td align="center"><a href="https://github.com/peakcool"><img src="https://avatars.githubusercontent.com/u/14804014?v=4" width="100px;" alt=""/><br /><sub><b>Peakcool</b></sub></a><br /><a href="https://github.com/capacitor-community/sqlite/commits?author=
|
|
329
|
-
<td align="center"><a href="https://github.com/gion-andri"><img src="https://avatars.githubusercontent.com/u/540998?v=4" width="100px;" alt=""/><br /><sub><b>Gion-Andri Cantieni</b></sub></a><br /><a href="https://github.com/capacitor-community/sqlite/commits?author=
|
|
330
|
-
<td align="center"><a href="https://github.com/robingenz"><img src="https://avatars.githubusercontent.com/u/13857929?v=4" width="100px;" alt=""/><br /><sub><b>Robin Genz</b></sub></a><br /><a href="https://github.com/capacitor-community/sqlite/commits?author=
|
|
331
|
-
<td align="center"><a href="https://github.com/dewald-els"><img src="https://avatars.githubusercontent.com/u/10051247?v=4" width="100px;" alt=""/><br /><sub><b>Dewald Els</b></sub></a><br /><a href="https://github.com/capacitor-community/sqlite/commits?author=
|
|
332
|
-
</tr>
|
|
344
|
+
<td align="center"><a href="https://github.com/paulantoine2"><img src="https://avatars0.githubusercontent.com/u/22882943?s=64&v=4" width="100px;" alt=""/><br /><sub><b>Paul Antoine</b></sub></a><br /><a href="https://github.com/capacitor-community/sqlite/commits?author=paulantoine2" title="Code">💻</a></td>
|
|
345
|
+
<td align="center"><a href="https://github.com/karyfars"><img src="https://avatars2.githubusercontent.com/u/303016?s=60&u=1ce232ae3c22eac7b0b4778e46fe079939c39b40&v=4" width="100px;" alt=""/><br /><sub><b>Karyfars</b></sub></a><br /><a href="https://github.com/capacitor-community/sqlite/commits?author=karyfars" title="Code">💻</a></td>
|
|
346
|
+
<td align="center"><a href="https://github.com/chriswep"><img src="https://avatars2.githubusercontent.com/u/1055809?s=400&u=e555940f143da8be255743028d6838cb5c020b44&v=4" width="100px;" alt=""/><br /><sub><b>Chriswep</b></sub></a><br /><a href="https://github.com/capacitor-community/sqlite/commits?author=chriswep" title="Documentation">📖</a></td>
|
|
347
|
+
<td align="center"><a href="https://github.com/nirajhinge"><img src="https://avatars.githubusercontent.com/u/54309996?v=4" width="100px;" alt=""/><br /><sub><b>Nirajhinge</b></sub></a><br /><a href="https://github.com/capacitor-community/sqlite/commits?author=nirajhinge" title="Code">💻</a></td>
|
|
348
|
+
<td align="center"><a href="https://github.com/digaus"><img src="https://avatars.githubusercontent.com/u/15358538?v=4" width="100px;" alt=""/><br /><sub><b>Dirk Gausmann</b></sub></a><br /><a href="https://github.com/capacitor-community/sqlite/commits?author=digaus" title="Code">💻</a></td>
|
|
349
|
+
<td align="center"><a href="https://github.com/IT-MikeS"><img src="https://avatars.githubusercontent.com/u/20338451?v=4" width="100px;" alt=""/><br /><sub><b>Mike Summerfeldt</b></sub></a><br /><a href="https://github.com/capacitor-community/sqlite/commits?author=IT-MikeS" title="Code">💻</a></td>
|
|
350
|
+
<td align="center"><a href="https://github.com/peakcool"><img src="https://avatars.githubusercontent.com/u/14804014?v=4" width="100px;" alt=""/><br /><sub><b>Peakcool</b></sub></a><br /><a href="https://github.com/capacitor-community/sqlite/commits?author=peakcool" title="Code">💻</a></td>
|
|
351
|
+
<td align="center"><a href="https://github.com/gion-andri"><img src="https://avatars.githubusercontent.com/u/540998?v=4" width="100px;" alt=""/><br /><sub><b>Gion-Andri Cantieni</b></sub></a><br /><a href="https://github.com/capacitor-community/sqlite/commits?author=gion-andri" title="Documentation">📖</a></td>
|
|
352
|
+
<td align="center"><a href="https://github.com/robingenz"><img src="https://avatars.githubusercontent.com/u/13857929?v=4" width="100px;" alt=""/><br /><sub><b>Robin Genz</b></sub></a><br /><a href="https://github.com/capacitor-community/sqlite/commits?author=robingenz" title="Documentation">📖</a></td>
|
|
353
|
+
<td align="center"><a href="https://github.com/dewald-els"><img src="https://avatars.githubusercontent.com/u/10051247?v=4" width="100px;" alt=""/><br /><sub><b>Dewald Els</b></sub></a><br /><a href="https://github.com/capacitor-community/sqlite/commits?author=dewald-els" title="Code">💻</a></td>
|
|
354
|
+
<td align="center"><a href="https://github.com/joewoodhouse"><img src="https://avatars.githubusercontent.com/u/3168135?v=4" width="100px;" alt=""/><br /><sub><b>Joe Woodhouse</b></sub></a><br /><a href="https://github.com/capacitor-community/sqlite/commits?author=joewoodhouse" title="Documentation">📖</a></td> </tr>
|
|
355
|
+
<td align="center"><a href="https://github.com/ptasheq"><img src="https://avatars.githubusercontent.com/u/3025106?v=4" width="100px;" alt=""/><br /><sub><b>Ptasheq</b></sub></a><br /><a href="https://github.com/capacitor-community/sqlite/commits?author=ptasheq" title="Documentation">📖</a></td> </tr>
|
|
333
356
|
</table>
|
|
334
357
|
|
|
335
358
|
<!-- markdownlint-enable -->
|
package/android/build.gradle
CHANGED
|
@@ -61,6 +61,6 @@ dependencies {
|
|
|
61
61
|
implementation "androidx.sqlite:sqlite:2.1.0"
|
|
62
62
|
//security library
|
|
63
63
|
implementation "androidx.security:security-crypto:1.1.0-alpha03"
|
|
64
|
+
implementation "androidx.biometric:biometric:1.1.0"
|
|
64
65
|
annotationProcessor 'androidx.room:room-compiler:2.2.5'
|
|
65
|
-
|
|
66
66
|
}
|
package/android/src/main/java/com/getcapacitor/community/database/sqlite/CapacitorSQLite.java
CHANGED
|
@@ -4,14 +4,21 @@ import android.content.Context;
|
|
|
4
4
|
import android.content.SharedPreferences;
|
|
5
5
|
import android.text.TextUtils;
|
|
6
6
|
import android.util.Log;
|
|
7
|
+
import android.widget.Toast;
|
|
8
|
+
import androidx.biometric.BiometricManager;
|
|
9
|
+
import androidx.biometric.BiometricPrompt;
|
|
7
10
|
import androidx.security.crypto.EncryptedSharedPreferences;
|
|
8
11
|
import androidx.security.crypto.MasterKey;
|
|
9
12
|
import androidx.security.crypto.MasterKeys;
|
|
10
13
|
import com.getcapacitor.JSArray;
|
|
11
14
|
import com.getcapacitor.JSObject;
|
|
15
|
+
import com.getcapacitor.PluginCall;
|
|
16
|
+
import com.getcapacitor.community.database.sqlite.SQLite.BiometricListener;
|
|
12
17
|
import com.getcapacitor.community.database.sqlite.SQLite.Database;
|
|
13
18
|
import com.getcapacitor.community.database.sqlite.SQLite.ImportExportJson.JsonSQLite;
|
|
14
19
|
import com.getcapacitor.community.database.sqlite.SQLite.ImportExportJson.UtilsJson;
|
|
20
|
+
import com.getcapacitor.community.database.sqlite.SQLite.SqliteConfig;
|
|
21
|
+
import com.getcapacitor.community.database.sqlite.SQLite.UtilsBiometric;
|
|
15
22
|
import com.getcapacitor.community.database.sqlite.SQLite.UtilsFile;
|
|
16
23
|
import com.getcapacitor.community.database.sqlite.SQLite.UtilsMigrate;
|
|
17
24
|
import com.getcapacitor.community.database.sqlite.SQLite.UtilsNCDatabase;
|
|
@@ -19,15 +26,21 @@ import com.getcapacitor.community.database.sqlite.SQLite.UtilsSQLite;
|
|
|
19
26
|
import com.getcapacitor.community.database.sqlite.SQLite.UtilsSecret;
|
|
20
27
|
import java.io.File;
|
|
21
28
|
import java.io.IOException;
|
|
29
|
+
import java.nio.charset.Charset;
|
|
30
|
+
import java.nio.charset.StandardCharsets;
|
|
22
31
|
import java.security.GeneralSecurityException;
|
|
23
32
|
import java.util.ArrayList;
|
|
24
33
|
import java.util.Arrays;
|
|
25
34
|
import java.util.Collections;
|
|
26
35
|
import java.util.Dictionary;
|
|
27
36
|
import java.util.Enumeration;
|
|
37
|
+
import java.util.HashMap;
|
|
28
38
|
import java.util.HashSet;
|
|
29
39
|
import java.util.Hashtable;
|
|
40
|
+
import java.util.Map;
|
|
30
41
|
import java.util.Set;
|
|
42
|
+
import javax.crypto.BadPaddingException;
|
|
43
|
+
import javax.crypto.IllegalBlockSizeException;
|
|
31
44
|
import org.json.JSONException;
|
|
32
45
|
import org.json.JSONObject;
|
|
33
46
|
|
|
@@ -43,13 +56,86 @@ public class CapacitorSQLite {
|
|
|
43
56
|
private UtilsNCDatabase uNCDatabase = new UtilsNCDatabase();
|
|
44
57
|
private UtilsSecret uSecret;
|
|
45
58
|
private SharedPreferences sharedPreferences;
|
|
46
|
-
|
|
47
|
-
|
|
59
|
+
private MasterKey masterKeyAlias;
|
|
60
|
+
private BiometricManager biometricManager;
|
|
61
|
+
private SqliteConfig config;
|
|
62
|
+
private Boolean biometricAuth = false;
|
|
63
|
+
private String biometricTitle;
|
|
64
|
+
private String biometricSubTitle;
|
|
65
|
+
private int VALIDITY_DURATION = 1;
|
|
66
|
+
private RetHandler rHandler = new RetHandler();
|
|
67
|
+
private PluginCall call;
|
|
68
|
+
|
|
69
|
+
public CapacitorSQLite(Context context, SqliteConfig config) throws Exception {
|
|
48
70
|
this.context = context;
|
|
71
|
+
this.call = call;
|
|
72
|
+
this.config = config;
|
|
73
|
+
this.biometricAuth = this.config.getBiometricAuth();
|
|
74
|
+
this.biometricTitle = this.config.getBiometricTitle();
|
|
75
|
+
this.biometricSubTitle = this.config.getBiometricSubTitle();
|
|
49
76
|
try {
|
|
50
77
|
// create or retrieve masterkey from Android keystore
|
|
51
78
|
// it will be used to encrypt the passphrase for a database
|
|
52
|
-
|
|
79
|
+
|
|
80
|
+
if (biometricAuth) {
|
|
81
|
+
biometricManager = BiometricManager.from(this.context);
|
|
82
|
+
BiometricListener listener = new BiometricListener() {
|
|
83
|
+
@Override
|
|
84
|
+
public void onSuccess(BiometricPrompt.AuthenticationResult result) {
|
|
85
|
+
try {
|
|
86
|
+
masterKeyAlias =
|
|
87
|
+
new MasterKey.Builder(context)
|
|
88
|
+
.setKeyScheme(MasterKey.KeyScheme.AES256_GCM)
|
|
89
|
+
.setUserAuthenticationRequired(true, VALIDITY_DURATION)
|
|
90
|
+
.build();
|
|
91
|
+
setSharedPreferences();
|
|
92
|
+
notifyBiometricEvent(true, null);
|
|
93
|
+
return;
|
|
94
|
+
} catch (Exception e) {
|
|
95
|
+
String input = e.getMessage();
|
|
96
|
+
Log.e("MY_APP_TAG", input);
|
|
97
|
+
// Toast.makeText(context, input, Toast.LENGTH_LONG).show();
|
|
98
|
+
notifyBiometricEvent(false, input);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
@Override
|
|
103
|
+
public void onFailed() {
|
|
104
|
+
String input = "Error in authenticating biometric";
|
|
105
|
+
Log.e("MY_APP_TAG", input);
|
|
106
|
+
// Toast.makeText(context, input, Toast.LENGTH_LONG).show();
|
|
107
|
+
notifyBiometricEvent(false, input);
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
UtilsBiometric uBiom = new UtilsBiometric(context, biometricManager, listener);
|
|
111
|
+
if (uBiom.checkBiometricIsAvailable()) {
|
|
112
|
+
uBiom.showBiometricDialog(this.biometricTitle, this.biometricSubTitle);
|
|
113
|
+
} else {
|
|
114
|
+
masterKeyAlias = new MasterKey.Builder(context).setKeyScheme(MasterKey.KeyScheme.AES256_GCM).build();
|
|
115
|
+
setSharedPreferences();
|
|
116
|
+
}
|
|
117
|
+
} else {
|
|
118
|
+
masterKeyAlias = new MasterKey.Builder(context).setKeyScheme(MasterKey.KeyScheme.AES256_GCM).build();
|
|
119
|
+
setSharedPreferences();
|
|
120
|
+
}
|
|
121
|
+
} catch (Exception e) {
|
|
122
|
+
throw new Exception(e.getMessage());
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
private void notifyBiometricEvent(Boolean ret, String msg) {
|
|
127
|
+
Map<String, Object> info = new HashMap<String, Object>() {
|
|
128
|
+
{
|
|
129
|
+
put("result", ret);
|
|
130
|
+
put("message", msg);
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
Log.v(TAG, "$$$$$ in notifyBiometricEvent " + info);
|
|
134
|
+
NotificationCenter.defaultCenter().postNotification("biometricResults", info);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
private void setSharedPreferences() throws Exception {
|
|
138
|
+
try {
|
|
53
139
|
// get instance of the EncryptedSharedPreferences class
|
|
54
140
|
this.sharedPreferences =
|
|
55
141
|
EncryptedSharedPreferences.create(
|
|
@@ -107,12 +193,47 @@ public class CapacitorSQLite {
|
|
|
107
193
|
* @param oldPassphrase
|
|
108
194
|
* @throws Exception
|
|
109
195
|
*/
|
|
110
|
-
public void changeEncryptionSecret(String passphrase, String oldPassphrase) throws Exception {
|
|
196
|
+
public void changeEncryptionSecret(PluginCall call, String passphrase, String oldPassphrase) throws Exception {
|
|
197
|
+
this.call = call;
|
|
111
198
|
try {
|
|
112
199
|
// close all connections
|
|
113
200
|
closeAllConnections();
|
|
114
|
-
|
|
115
|
-
|
|
201
|
+
if (biometricAuth) {
|
|
202
|
+
BiometricListener listener = new BiometricListener() {
|
|
203
|
+
@Override
|
|
204
|
+
public void onSuccess(BiometricPrompt.AuthenticationResult result) {
|
|
205
|
+
try {
|
|
206
|
+
// change encryption secret
|
|
207
|
+
uSecret.changeEncryptionSecret(passphrase, oldPassphrase);
|
|
208
|
+
rHandler.retResult(call, null, null);
|
|
209
|
+
return;
|
|
210
|
+
} catch (Exception e) {
|
|
211
|
+
String input = e.getMessage();
|
|
212
|
+
Log.e("MY_APP_TAG", input);
|
|
213
|
+
Toast.makeText(context, input, Toast.LENGTH_LONG).show();
|
|
214
|
+
rHandler.retResult(call, null, e.getMessage());
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
@Override
|
|
219
|
+
public void onFailed() {
|
|
220
|
+
String input = "Error in authenticating biometric";
|
|
221
|
+
Log.e("MY_APP_TAG", input);
|
|
222
|
+
Toast.makeText(context, input, Toast.LENGTH_LONG).show();
|
|
223
|
+
rHandler.retResult(call, null, input);
|
|
224
|
+
}
|
|
225
|
+
};
|
|
226
|
+
|
|
227
|
+
UtilsBiometric uBiom = new UtilsBiometric(context, biometricManager, listener);
|
|
228
|
+
if (uBiom.checkBiometricIsAvailable()) {
|
|
229
|
+
uBiom.showBiometricDialog(biometricTitle, biometricSubTitle);
|
|
230
|
+
} else {
|
|
231
|
+
throw new Exception("Biometric features are currently unavailable.");
|
|
232
|
+
}
|
|
233
|
+
} else {
|
|
234
|
+
// change encryption secret
|
|
235
|
+
uSecret.changeEncryptionSecret(passphrase, oldPassphrase);
|
|
236
|
+
}
|
|
116
237
|
} catch (Exception e) {
|
|
117
238
|
throw new Exception(e.getMessage());
|
|
118
239
|
}
|
package/android/src/main/java/com/getcapacitor/community/database/sqlite/CapacitorSQLitePlugin.java
CHANGED
|
@@ -10,9 +10,11 @@ import com.getcapacitor.PluginMethod;
|
|
|
10
10
|
import com.getcapacitor.annotation.CapacitorPlugin;
|
|
11
11
|
import com.getcapacitor.community.database.sqlite.SQLite.Database;
|
|
12
12
|
import com.getcapacitor.community.database.sqlite.SQLite.ImportExportJson.JsonSQLite;
|
|
13
|
+
import com.getcapacitor.community.database.sqlite.SQLite.SqliteConfig;
|
|
13
14
|
import java.util.Dictionary;
|
|
14
15
|
import java.util.Hashtable;
|
|
15
16
|
import org.json.JSONArray;
|
|
17
|
+
import org.json.JSONException;
|
|
16
18
|
import org.json.JSONObject;
|
|
17
19
|
|
|
18
20
|
@CapacitorPlugin(name = "CapacitorSQLite")
|
|
@@ -20,9 +22,12 @@ public class CapacitorSQLitePlugin extends Plugin {
|
|
|
20
22
|
|
|
21
23
|
private static final String TAG = CapacitorSQLitePlugin.class.getName();
|
|
22
24
|
private Context context;
|
|
25
|
+
private SqliteConfig config;
|
|
23
26
|
private CapacitorSQLite implementation;
|
|
24
27
|
private Dictionary<String, Dictionary<Integer, JSONObject>> versionUpgrades = new Hashtable<>();
|
|
25
28
|
private RetHandler rHandler = new RetHandler();
|
|
29
|
+
private String passphrase = null;
|
|
30
|
+
private String oldpassphrase = null;
|
|
26
31
|
|
|
27
32
|
/**
|
|
28
33
|
* Load Method
|
|
@@ -31,8 +36,12 @@ public class CapacitorSQLitePlugin extends Plugin {
|
|
|
31
36
|
public void load() {
|
|
32
37
|
context = getContext();
|
|
33
38
|
try {
|
|
34
|
-
|
|
39
|
+
config = getSqliteConfig();
|
|
35
40
|
AddObserversToNotificationCenter();
|
|
41
|
+
implementation = new CapacitorSQLite(context, config);
|
|
42
|
+
} catch (JSONException e) {
|
|
43
|
+
implementation = null;
|
|
44
|
+
Log.e(TAG, "CapacitorSQLitePlugin: " + e.getMessage());
|
|
36
45
|
} catch (Exception e) {
|
|
37
46
|
implementation = null;
|
|
38
47
|
Log.e(TAG, "CapacitorSQLitePlugin: " + e.getMessage());
|
|
@@ -42,6 +51,7 @@ public class CapacitorSQLitePlugin extends Plugin {
|
|
|
42
51
|
/**
|
|
43
52
|
* Echo Method
|
|
44
53
|
* test the plugin
|
|
54
|
+
*
|
|
45
55
|
* @param call
|
|
46
56
|
*/
|
|
47
57
|
@PluginMethod
|
|
@@ -59,6 +69,7 @@ public class CapacitorSQLitePlugin extends Plugin {
|
|
|
59
69
|
/**
|
|
60
70
|
* IsSecretStored
|
|
61
71
|
* Check if a secret has been stored
|
|
72
|
+
*
|
|
62
73
|
* @param call
|
|
63
74
|
*/
|
|
64
75
|
@PluginMethod
|
|
@@ -77,6 +88,7 @@ public class CapacitorSQLitePlugin extends Plugin {
|
|
|
77
88
|
/**
|
|
78
89
|
* SetEncryptionSecret
|
|
79
90
|
* set a passphrase secret for a database
|
|
91
|
+
*
|
|
80
92
|
* @param call
|
|
81
93
|
*/
|
|
82
94
|
@PluginMethod
|
|
@@ -103,33 +115,40 @@ public class CapacitorSQLitePlugin extends Plugin {
|
|
|
103
115
|
* ChangeEncryptionSecret
|
|
104
116
|
* change a passphrase secret for a database
|
|
105
117
|
* with a new passphrase
|
|
118
|
+
*
|
|
106
119
|
* @param call
|
|
107
120
|
*/
|
|
108
121
|
@PluginMethod
|
|
109
122
|
public void changeEncryptionSecret(PluginCall call) {
|
|
110
|
-
String passphrase = null;
|
|
111
123
|
if (!call.getData().has("passphrase")) {
|
|
112
124
|
String msg = "SetEncryptionSecret: Must provide a passphrase";
|
|
113
125
|
rHandler.retResult(call, null, msg);
|
|
114
126
|
return;
|
|
115
127
|
}
|
|
116
128
|
passphrase = call.getString("passphrase");
|
|
117
|
-
|
|
129
|
+
|
|
118
130
|
if (!call.getData().has("oldpassphrase")) {
|
|
119
131
|
String msg = "SetEncryptionSecret: Must provide a oldpassphrase";
|
|
120
132
|
rHandler.retResult(call, null, msg);
|
|
121
133
|
return;
|
|
122
134
|
}
|
|
123
135
|
oldpassphrase = call.getString("oldpassphrase");
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
136
|
+
getActivity()
|
|
137
|
+
.runOnUiThread(
|
|
138
|
+
new Runnable() {
|
|
139
|
+
@Override
|
|
140
|
+
public void run() {
|
|
141
|
+
try {
|
|
142
|
+
implementation.changeEncryptionSecret(call, passphrase, oldpassphrase);
|
|
143
|
+
return;
|
|
144
|
+
} catch (Exception e) {
|
|
145
|
+
String msg = "ChangeEncryptionSecret: " + e.getMessage();
|
|
146
|
+
rHandler.retResult(call, null, msg);
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
);
|
|
133
152
|
}
|
|
134
153
|
|
|
135
154
|
@PluginMethod
|
|
@@ -162,6 +181,7 @@ public class CapacitorSQLitePlugin extends Plugin {
|
|
|
162
181
|
/**
|
|
163
182
|
* CreateNCConnection Method
|
|
164
183
|
* Create a non-conformed connection to a database
|
|
184
|
+
*
|
|
165
185
|
* @param call
|
|
166
186
|
*/
|
|
167
187
|
@PluginMethod
|
|
@@ -189,6 +209,7 @@ public class CapacitorSQLitePlugin extends Plugin {
|
|
|
189
209
|
/**
|
|
190
210
|
* CreateConnection Method
|
|
191
211
|
* Create a connection to a database
|
|
212
|
+
*
|
|
192
213
|
* @param call
|
|
193
214
|
*/
|
|
194
215
|
@PluginMethod
|
|
@@ -204,6 +225,7 @@ public class CapacitorSQLitePlugin extends Plugin {
|
|
|
204
225
|
}
|
|
205
226
|
dbName = call.getString("database");
|
|
206
227
|
dbVersion = call.getInt("version", 1);
|
|
228
|
+
|
|
207
229
|
boolean encrypted = call.getBoolean("encrypted", false);
|
|
208
230
|
if (encrypted) {
|
|
209
231
|
inMode = call.getString("mode", "no-encryption");
|
|
@@ -234,6 +256,7 @@ public class CapacitorSQLitePlugin extends Plugin {
|
|
|
234
256
|
/**
|
|
235
257
|
* Open Method
|
|
236
258
|
* Open a database
|
|
259
|
+
*
|
|
237
260
|
* @param call
|
|
238
261
|
*/
|
|
239
262
|
@PluginMethod
|
|
@@ -258,6 +281,7 @@ public class CapacitorSQLitePlugin extends Plugin {
|
|
|
258
281
|
/**
|
|
259
282
|
* Close Method
|
|
260
283
|
* Close a Database
|
|
284
|
+
*
|
|
261
285
|
* @param call
|
|
262
286
|
*/
|
|
263
287
|
@PluginMethod
|
|
@@ -282,6 +306,7 @@ public class CapacitorSQLitePlugin extends Plugin {
|
|
|
282
306
|
/**
|
|
283
307
|
* GetUrl Method
|
|
284
308
|
* Get a database Url
|
|
309
|
+
*
|
|
285
310
|
* @param call
|
|
286
311
|
*/
|
|
287
312
|
@PluginMethod
|
|
@@ -306,6 +331,7 @@ public class CapacitorSQLitePlugin extends Plugin {
|
|
|
306
331
|
/**
|
|
307
332
|
* GetVersion Method
|
|
308
333
|
* Get a database Version
|
|
334
|
+
*
|
|
309
335
|
* @param call
|
|
310
336
|
*/
|
|
311
337
|
@PluginMethod
|
|
@@ -330,6 +356,7 @@ public class CapacitorSQLitePlugin extends Plugin {
|
|
|
330
356
|
/**
|
|
331
357
|
* CloseNCConnection Method
|
|
332
358
|
* Close a non-conformed database connection
|
|
359
|
+
*
|
|
333
360
|
* @param call
|
|
334
361
|
*/
|
|
335
362
|
@PluginMethod
|
|
@@ -354,6 +381,7 @@ public class CapacitorSQLitePlugin extends Plugin {
|
|
|
354
381
|
/**
|
|
355
382
|
* CloseConnection Method
|
|
356
383
|
* Close the connection to a database
|
|
384
|
+
*
|
|
357
385
|
* @param call
|
|
358
386
|
*/
|
|
359
387
|
@PluginMethod
|
|
@@ -378,6 +406,7 @@ public class CapacitorSQLitePlugin extends Plugin {
|
|
|
378
406
|
/**
|
|
379
407
|
* CheckConnectionsConsistency Method
|
|
380
408
|
* Check the connections consistency JS <=> Native
|
|
409
|
+
*
|
|
381
410
|
* @param call
|
|
382
411
|
*/
|
|
383
412
|
@PluginMethod
|
|
@@ -402,6 +431,7 @@ public class CapacitorSQLitePlugin extends Plugin {
|
|
|
402
431
|
/**
|
|
403
432
|
* IsDatabase Method
|
|
404
433
|
* Check if the database file exists
|
|
434
|
+
*
|
|
405
435
|
* @param call
|
|
406
436
|
*/
|
|
407
437
|
@PluginMethod
|
|
@@ -425,6 +455,7 @@ public class CapacitorSQLitePlugin extends Plugin {
|
|
|
425
455
|
/**
|
|
426
456
|
* IsDatabase Method
|
|
427
457
|
* Check if the database file exists
|
|
458
|
+
*
|
|
428
459
|
* @param call
|
|
429
460
|
*/
|
|
430
461
|
@PluginMethod
|
|
@@ -448,6 +479,7 @@ public class CapacitorSQLitePlugin extends Plugin {
|
|
|
448
479
|
/**
|
|
449
480
|
* IsTableExists Method
|
|
450
481
|
* Check if a table exists in a database
|
|
482
|
+
*
|
|
451
483
|
* @param call
|
|
452
484
|
*/
|
|
453
485
|
@PluginMethod
|
|
@@ -575,6 +607,7 @@ public class CapacitorSQLitePlugin extends Plugin {
|
|
|
575
607
|
/**
|
|
576
608
|
* Execute Method
|
|
577
609
|
* Execute SQL statements provided in a String
|
|
610
|
+
*
|
|
578
611
|
* @param call
|
|
579
612
|
*/
|
|
580
613
|
@PluginMethod
|
|
@@ -609,6 +642,7 @@ public class CapacitorSQLitePlugin extends Plugin {
|
|
|
609
642
|
/**
|
|
610
643
|
* ExecuteSet Method
|
|
611
644
|
* Execute a Set of raw sql statement
|
|
645
|
+
*
|
|
612
646
|
* @param call
|
|
613
647
|
* @throws Exception
|
|
614
648
|
*/
|
|
@@ -660,6 +694,7 @@ public class CapacitorSQLitePlugin extends Plugin {
|
|
|
660
694
|
/**
|
|
661
695
|
* Run method
|
|
662
696
|
* Execute a raw sql statement
|
|
697
|
+
*
|
|
663
698
|
* @param call
|
|
664
699
|
*/
|
|
665
700
|
@PluginMethod
|
|
@@ -701,6 +736,7 @@ public class CapacitorSQLitePlugin extends Plugin {
|
|
|
701
736
|
/**
|
|
702
737
|
* Query Method
|
|
703
738
|
* Execute an sql query
|
|
739
|
+
*
|
|
704
740
|
* @param call
|
|
705
741
|
*/
|
|
706
742
|
@PluginMethod
|
|
@@ -737,6 +773,7 @@ public class CapacitorSQLitePlugin extends Plugin {
|
|
|
737
773
|
/**
|
|
738
774
|
* IsDBExists Method
|
|
739
775
|
* check if the database exists on the database folder
|
|
776
|
+
*
|
|
740
777
|
* @param call
|
|
741
778
|
*/
|
|
742
779
|
@PluginMethod
|
|
@@ -762,6 +799,7 @@ public class CapacitorSQLitePlugin extends Plugin {
|
|
|
762
799
|
/**
|
|
763
800
|
* IsDBOpen Method
|
|
764
801
|
* check if the database is opened
|
|
802
|
+
*
|
|
765
803
|
* @param call
|
|
766
804
|
*/
|
|
767
805
|
@PluginMethod
|
|
@@ -786,6 +824,7 @@ public class CapacitorSQLitePlugin extends Plugin {
|
|
|
786
824
|
/**
|
|
787
825
|
* DeleteDatabase Method
|
|
788
826
|
* delete a database from the database folder
|
|
827
|
+
*
|
|
789
828
|
* @param call
|
|
790
829
|
*/
|
|
791
830
|
@PluginMethod
|
|
@@ -810,6 +849,7 @@ public class CapacitorSQLitePlugin extends Plugin {
|
|
|
810
849
|
/**
|
|
811
850
|
* CreateSyncTable Method
|
|
812
851
|
* Create the synchronization table
|
|
852
|
+
*
|
|
813
853
|
* @param call
|
|
814
854
|
*/
|
|
815
855
|
@PluginMethod
|
|
@@ -836,6 +876,7 @@ public class CapacitorSQLitePlugin extends Plugin {
|
|
|
836
876
|
/**
|
|
837
877
|
* SetSyncDate Method
|
|
838
878
|
* set the synchronization date
|
|
879
|
+
*
|
|
839
880
|
* @param call
|
|
840
881
|
*/
|
|
841
882
|
@PluginMethod
|
|
@@ -867,6 +908,7 @@ public class CapacitorSQLitePlugin extends Plugin {
|
|
|
867
908
|
/**
|
|
868
909
|
* GetSyncDate Method
|
|
869
910
|
* Get the synchronization date
|
|
911
|
+
*
|
|
870
912
|
* @param call
|
|
871
913
|
*/
|
|
872
914
|
@PluginMethod
|
|
@@ -893,6 +935,7 @@ public class CapacitorSQLitePlugin extends Plugin {
|
|
|
893
935
|
/**
|
|
894
936
|
* AddUpgradeStatement Method
|
|
895
937
|
* Define an upgrade object when updating to a new version
|
|
938
|
+
*
|
|
896
939
|
* @param call
|
|
897
940
|
*/
|
|
898
941
|
@PluginMethod
|
|
@@ -925,6 +968,7 @@ public class CapacitorSQLitePlugin extends Plugin {
|
|
|
925
968
|
/**
|
|
926
969
|
* IsJsonValid
|
|
927
970
|
* Check the validity of a given Json object
|
|
971
|
+
*
|
|
928
972
|
* @param call
|
|
929
973
|
*/
|
|
930
974
|
@PluginMethod
|
|
@@ -940,7 +984,7 @@ public class CapacitorSQLitePlugin extends Plugin {
|
|
|
940
984
|
rHandler.retResult(call, res, null);
|
|
941
985
|
return;
|
|
942
986
|
} catch (Exception e) {
|
|
943
|
-
String msg = "
|
|
987
|
+
String msg = "IsJsonValid: " + e.getMessage();
|
|
944
988
|
rHandler.retResult(call, false, msg);
|
|
945
989
|
return;
|
|
946
990
|
}
|
|
@@ -949,6 +993,7 @@ public class CapacitorSQLitePlugin extends Plugin {
|
|
|
949
993
|
/**
|
|
950
994
|
* ImportFromJson Method
|
|
951
995
|
* Import from a given Json object
|
|
996
|
+
*
|
|
952
997
|
* @param call
|
|
953
998
|
*/
|
|
954
999
|
@PluginMethod
|
|
@@ -975,6 +1020,7 @@ public class CapacitorSQLitePlugin extends Plugin {
|
|
|
975
1020
|
/**
|
|
976
1021
|
* ExportToJson Method
|
|
977
1022
|
* Export the database to Json Object
|
|
1023
|
+
*
|
|
978
1024
|
* @param call
|
|
979
1025
|
*/
|
|
980
1026
|
@PluginMethod
|
|
@@ -1014,6 +1060,7 @@ public class CapacitorSQLitePlugin extends Plugin {
|
|
|
1014
1060
|
/**
|
|
1015
1061
|
* CopyFromAssets
|
|
1016
1062
|
* copy all databases from public/assets/databases to application folder
|
|
1063
|
+
*
|
|
1017
1064
|
* @param call
|
|
1018
1065
|
*/
|
|
1019
1066
|
@PluginMethod
|
|
@@ -1060,5 +1107,40 @@ public class CapacitorSQLitePlugin extends Plugin {
|
|
|
1060
1107
|
}
|
|
1061
1108
|
}
|
|
1062
1109
|
);
|
|
1110
|
+
NotificationCenter
|
|
1111
|
+
.defaultCenter()
|
|
1112
|
+
.addMethodForNotification(
|
|
1113
|
+
"biometricResults",
|
|
1114
|
+
new MyRunnable() {
|
|
1115
|
+
@Override
|
|
1116
|
+
public void run() {
|
|
1117
|
+
JSObject data = new JSObject();
|
|
1118
|
+
data.put("result", this.getInfo().get("result"));
|
|
1119
|
+
data.put("message", this.getInfo().get("message"));
|
|
1120
|
+
notifyListeners("sqliteBiometricEvent", data);
|
|
1121
|
+
return;
|
|
1122
|
+
}
|
|
1123
|
+
}
|
|
1124
|
+
);
|
|
1125
|
+
}
|
|
1126
|
+
|
|
1127
|
+
private SqliteConfig getSqliteConfig() throws JSONException {
|
|
1128
|
+
SqliteConfig config = new SqliteConfig();
|
|
1129
|
+
JSONObject androidBiometric = getConfig().getObject("androidBiometric");
|
|
1130
|
+
if (androidBiometric != null) {
|
|
1131
|
+
Boolean biometricAuth = androidBiometric.has("biometricAuth")
|
|
1132
|
+
? androidBiometric.getBoolean("biometricAuth")
|
|
1133
|
+
: config.getBiometricAuth();
|
|
1134
|
+
config.setBiometricAuth(biometricAuth);
|
|
1135
|
+
String biometricTitle = androidBiometric.has("biometricTitle")
|
|
1136
|
+
? androidBiometric.getString("biometricTitle")
|
|
1137
|
+
: config.getBiometricTitle();
|
|
1138
|
+
config.setBiometricTitle(biometricTitle);
|
|
1139
|
+
String biometricSubTitle = androidBiometric.has("biometricSubTitle")
|
|
1140
|
+
? androidBiometric.getString("biometricSubTitle")
|
|
1141
|
+
: config.getBiometricSubTitle();
|
|
1142
|
+
config.setBiometricSubTitle(biometricSubTitle);
|
|
1143
|
+
}
|
|
1144
|
+
return config;
|
|
1063
1145
|
}
|
|
1064
1146
|
}
|