@capacitor-community/sqlite 3.4.0 → 3.4.1-1
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 +7 -0
- package/android/src/main/java/com/getcapacitor/community/database/sqlite/CapacitorSQLite.java +125 -88
- package/android/src/main/java/com/getcapacitor/community/database/sqlite/CapacitorSQLitePlugin.java +449 -264
- package/android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/Database.java +17 -16
- package/android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/ImportExportJson/JsonSQLite.java +4 -1
- package/android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/SqliteConfig.java +9 -0
- package/dist/esm/definitions.js +1 -1
- package/dist/esm/definitions.js.map +1 -1
- package/dist/plugin.cjs.js +1 -1
- package/dist/plugin.cjs.js.map +1 -1
- package/dist/plugin.js +1 -1
- package/dist/plugin.js.map +1 -1
- package/ios/Plugin/CapacitorSQLite.swift +150 -109
- package/ios/Plugin/CapacitorSQLitePlugin.swift +17 -10
- package/ios/Plugin/Database.swift +18 -11
- package/ios/Plugin/SqliteConfig.swift +1 -0
- package/package.json +6 -6
package/README.md
CHANGED
|
@@ -28,6 +28,13 @@
|
|
|
28
28
|
|
|
29
29
|
## CAPACITOR 3 (Master)
|
|
30
30
|
|
|
31
|
+
🚨 Since release 3.4.1-1 ->> 🚨
|
|
32
|
+
|
|
33
|
+
- add iosIsEncryption, androidIsEncryption in capacitor.config.ts
|
|
34
|
+
When your application use only `non-encrypted dzatabases` set those parameter to false then iOS KeyChain & Android MasterKey are not defined.
|
|
35
|
+
|
|
36
|
+
🚨 Since release 3.4.1-1 <<- 🚨
|
|
37
|
+
|
|
31
38
|
🚨 Since release 3.4.0-2 ->> 🚨
|
|
32
39
|
|
|
33
40
|
- iOS & Android only
|
package/android/src/main/java/com/getcapacitor/community/database/sqlite/CapacitorSQLite.java
CHANGED
|
@@ -55,10 +55,11 @@ public class CapacitorSQLite {
|
|
|
55
55
|
private UtilsMigrate uMigrate = new UtilsMigrate();
|
|
56
56
|
private UtilsNCDatabase uNCDatabase = new UtilsNCDatabase();
|
|
57
57
|
private UtilsSecret uSecret;
|
|
58
|
-
private SharedPreferences sharedPreferences;
|
|
58
|
+
private SharedPreferences sharedPreferences = null;
|
|
59
59
|
private MasterKey masterKeyAlias;
|
|
60
60
|
private BiometricManager biometricManager;
|
|
61
61
|
private SqliteConfig config;
|
|
62
|
+
private Boolean isEncryption = true;
|
|
62
63
|
private Boolean biometricAuth = false;
|
|
63
64
|
private String biometricTitle;
|
|
64
65
|
private String biometricSubTitle;
|
|
@@ -70,53 +71,56 @@ public class CapacitorSQLite {
|
|
|
70
71
|
this.context = context;
|
|
71
72
|
this.call = call;
|
|
72
73
|
this.config = config;
|
|
74
|
+
this.isEncryption = this.config.getIsEncryption();
|
|
73
75
|
this.biometricAuth = this.config.getBiometricAuth();
|
|
74
76
|
this.biometricTitle = this.config.getBiometricTitle();
|
|
75
77
|
this.biometricSubTitle = this.config.getBiometricSubTitle();
|
|
76
78
|
try {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
.
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
79
|
+
if (isEncryption) {
|
|
80
|
+
// create or retrieve masterkey from Android keystore
|
|
81
|
+
// it will be used to encrypt the passphrase for a database
|
|
82
|
+
|
|
83
|
+
if (biometricAuth) {
|
|
84
|
+
biometricManager = BiometricManager.from(this.context);
|
|
85
|
+
BiometricListener listener = new BiometricListener() {
|
|
86
|
+
@Override
|
|
87
|
+
public void onSuccess(BiometricPrompt.AuthenticationResult result) {
|
|
88
|
+
try {
|
|
89
|
+
masterKeyAlias =
|
|
90
|
+
new MasterKey.Builder(context)
|
|
91
|
+
.setKeyScheme(MasterKey.KeyScheme.AES256_GCM)
|
|
92
|
+
.setUserAuthenticationRequired(true, VALIDITY_DURATION)
|
|
93
|
+
.build();
|
|
94
|
+
setSharedPreferences();
|
|
95
|
+
notifyBiometricEvent(true, null);
|
|
96
|
+
return;
|
|
97
|
+
} catch (Exception e) {
|
|
98
|
+
String input = e.getMessage();
|
|
99
|
+
Log.e("MY_APP_TAG", input);
|
|
100
|
+
// Toast.makeText(context, input, Toast.LENGTH_LONG).show();
|
|
101
|
+
notifyBiometricEvent(false, input);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
@Override
|
|
106
|
+
public void onFailed() {
|
|
107
|
+
String input = "Error in authenticating biometric";
|
|
96
108
|
Log.e("MY_APP_TAG", input);
|
|
97
|
-
//
|
|
109
|
+
// Toast.makeText(context, input, Toast.LENGTH_LONG).show();
|
|
98
110
|
notifyBiometricEvent(false, input);
|
|
99
111
|
}
|
|
112
|
+
};
|
|
113
|
+
UtilsBiometric uBiom = new UtilsBiometric(context, biometricManager, listener);
|
|
114
|
+
if (uBiom.checkBiometricIsAvailable()) {
|
|
115
|
+
uBiom.showBiometricDialog(this.biometricTitle, this.biometricSubTitle);
|
|
116
|
+
} else {
|
|
117
|
+
masterKeyAlias = new MasterKey.Builder(context).setKeyScheme(MasterKey.KeyScheme.AES256_GCM).build();
|
|
118
|
+
setSharedPreferences();
|
|
100
119
|
}
|
|
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
120
|
} else {
|
|
114
121
|
masterKeyAlias = new MasterKey.Builder(context).setKeyScheme(MasterKey.KeyScheme.AES256_GCM).build();
|
|
115
122
|
setSharedPreferences();
|
|
116
123
|
}
|
|
117
|
-
} else {
|
|
118
|
-
masterKeyAlias = new MasterKey.Builder(context).setKeyScheme(MasterKey.KeyScheme.AES256_GCM).build();
|
|
119
|
-
setSharedPreferences();
|
|
120
124
|
}
|
|
121
125
|
} catch (Exception e) {
|
|
122
126
|
throw new Exception(e.getMessage());
|
|
@@ -162,12 +166,16 @@ public class CapacitorSQLite {
|
|
|
162
166
|
|
|
163
167
|
public Boolean isSecretStored() throws Exception {
|
|
164
168
|
Boolean ret = false;
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
169
|
+
if (isEncryption) {
|
|
170
|
+
try {
|
|
171
|
+
String secret = uSecret.getPassphrase();
|
|
172
|
+
if (secret.length() > 0) ret = true;
|
|
173
|
+
return ret;
|
|
174
|
+
} catch (Exception e) {
|
|
175
|
+
throw new Exception(e.getMessage());
|
|
176
|
+
}
|
|
177
|
+
} else {
|
|
178
|
+
throw new Exception("No Encryption set in capacitor.config");
|
|
171
179
|
}
|
|
172
180
|
}
|
|
173
181
|
|
|
@@ -177,13 +185,17 @@ public class CapacitorSQLite {
|
|
|
177
185
|
* @throws Exception
|
|
178
186
|
*/
|
|
179
187
|
public void setEncryptionSecret(String passphrase) throws Exception {
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
188
|
+
if (isEncryption) {
|
|
189
|
+
try {
|
|
190
|
+
// close all connections
|
|
191
|
+
closeAllConnections();
|
|
192
|
+
// set encryption secret
|
|
193
|
+
uSecret.setEncryptionSecret(passphrase);
|
|
194
|
+
} catch (Exception e) {
|
|
195
|
+
throw new Exception(e.getMessage());
|
|
196
|
+
}
|
|
197
|
+
} else {
|
|
198
|
+
throw new Exception("No Encryption set in capacitor.config");
|
|
187
199
|
}
|
|
188
200
|
}
|
|
189
201
|
|
|
@@ -195,47 +207,51 @@ public class CapacitorSQLite {
|
|
|
195
207
|
*/
|
|
196
208
|
public void changeEncryptionSecret(PluginCall call, String passphrase, String oldPassphrase) throws Exception {
|
|
197
209
|
this.call = call;
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
210
|
+
if (isEncryption) {
|
|
211
|
+
try {
|
|
212
|
+
// close all connections
|
|
213
|
+
closeAllConnections();
|
|
214
|
+
if (biometricAuth) {
|
|
215
|
+
BiometricListener listener = new BiometricListener() {
|
|
216
|
+
@Override
|
|
217
|
+
public void onSuccess(BiometricPrompt.AuthenticationResult result) {
|
|
218
|
+
try {
|
|
219
|
+
// change encryption secret
|
|
220
|
+
uSecret.changeEncryptionSecret(passphrase, oldPassphrase);
|
|
221
|
+
rHandler.retResult(call, null, null);
|
|
222
|
+
return;
|
|
223
|
+
} catch (Exception e) {
|
|
224
|
+
String input = e.getMessage();
|
|
225
|
+
Log.e("MY_APP_TAG", input);
|
|
226
|
+
Toast.makeText(context, input, Toast.LENGTH_LONG).show();
|
|
227
|
+
rHandler.retResult(call, null, e.getMessage());
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
@Override
|
|
232
|
+
public void onFailed() {
|
|
233
|
+
String input = "Error in authenticating biometric";
|
|
212
234
|
Log.e("MY_APP_TAG", input);
|
|
213
235
|
Toast.makeText(context, input, Toast.LENGTH_LONG).show();
|
|
214
|
-
rHandler.retResult(call, null,
|
|
236
|
+
rHandler.retResult(call, null, input);
|
|
215
237
|
}
|
|
216
|
-
}
|
|
238
|
+
};
|
|
217
239
|
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
rHandler.retResult(call, null, input);
|
|
240
|
+
UtilsBiometric uBiom = new UtilsBiometric(context, biometricManager, listener);
|
|
241
|
+
if (uBiom.checkBiometricIsAvailable()) {
|
|
242
|
+
uBiom.showBiometricDialog(biometricTitle, biometricSubTitle);
|
|
243
|
+
} else {
|
|
244
|
+
throw new Exception("Biometric features are currently unavailable.");
|
|
224
245
|
}
|
|
225
|
-
};
|
|
226
|
-
|
|
227
|
-
UtilsBiometric uBiom = new UtilsBiometric(context, biometricManager, listener);
|
|
228
|
-
if (uBiom.checkBiometricIsAvailable()) {
|
|
229
|
-
uBiom.showBiometricDialog(biometricTitle, biometricSubTitle);
|
|
230
246
|
} else {
|
|
231
|
-
|
|
247
|
+
// change encryption secret
|
|
248
|
+
uSecret.changeEncryptionSecret(passphrase, oldPassphrase);
|
|
232
249
|
}
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
uSecret.changeEncryptionSecret(passphrase, oldPassphrase);
|
|
250
|
+
} catch (Exception e) {
|
|
251
|
+
throw new Exception(e.getMessage());
|
|
236
252
|
}
|
|
237
|
-
}
|
|
238
|
-
throw new Exception(
|
|
253
|
+
} else {
|
|
254
|
+
throw new Exception("No Encryption set in capacitor.config");
|
|
239
255
|
}
|
|
240
256
|
}
|
|
241
257
|
|
|
@@ -266,8 +282,20 @@ public class CapacitorSQLite {
|
|
|
266
282
|
String msg = "Connection " + dbName + " already exists";
|
|
267
283
|
throw new Exception(msg);
|
|
268
284
|
}
|
|
285
|
+
if (encrypted && !isEncryption) {
|
|
286
|
+
throw new Exception("Database cannot be encrypted as 'No Encryption' set in capacitor.config");
|
|
287
|
+
}
|
|
269
288
|
try {
|
|
270
|
-
Database db = new Database(
|
|
289
|
+
Database db = new Database(
|
|
290
|
+
context,
|
|
291
|
+
dbName + "SQLite.db",
|
|
292
|
+
encrypted,
|
|
293
|
+
mode,
|
|
294
|
+
version,
|
|
295
|
+
isEncryption,
|
|
296
|
+
vUpgObject,
|
|
297
|
+
sharedPreferences
|
|
298
|
+
);
|
|
271
299
|
if (db != null) {
|
|
272
300
|
dbDict.put(dbName, db);
|
|
273
301
|
return;
|
|
@@ -281,7 +309,7 @@ public class CapacitorSQLite {
|
|
|
281
309
|
}
|
|
282
310
|
|
|
283
311
|
/**
|
|
284
|
-
*
|
|
312
|
+
* CreateNCConnection
|
|
285
313
|
* @param dbPath
|
|
286
314
|
* @param version
|
|
287
315
|
* @throws Exception
|
|
@@ -299,7 +327,16 @@ public class CapacitorSQLite {
|
|
|
299
327
|
String msg = "Database " + dbPath + " does not exist";
|
|
300
328
|
throw new Exception(msg);
|
|
301
329
|
}
|
|
302
|
-
Database db = new Database(
|
|
330
|
+
Database db = new Database(
|
|
331
|
+
context,
|
|
332
|
+
dbPath,
|
|
333
|
+
false,
|
|
334
|
+
"no-encryption",
|
|
335
|
+
version,
|
|
336
|
+
isEncryption,
|
|
337
|
+
new Hashtable<>(),
|
|
338
|
+
sharedPreferences
|
|
339
|
+
);
|
|
303
340
|
if (db != null) {
|
|
304
341
|
dbDict.put(dbPath, db);
|
|
305
342
|
return;
|
|
@@ -874,7 +911,7 @@ public class CapacitorSQLite {
|
|
|
874
911
|
try {
|
|
875
912
|
JSObject jsonObject = new JSObject(parsingData);
|
|
876
913
|
JsonSQLite jsonSQL = new JsonSQLite();
|
|
877
|
-
Boolean isValid = jsonSQL.isJsonSQLite(jsonObject);
|
|
914
|
+
Boolean isValid = jsonSQL.isJsonSQLite(jsonObject, isEncryption);
|
|
878
915
|
return isValid;
|
|
879
916
|
} catch (Exception e) {
|
|
880
917
|
throw new Exception(e.getMessage());
|
|
@@ -885,7 +922,7 @@ public class CapacitorSQLite {
|
|
|
885
922
|
try {
|
|
886
923
|
JSObject jsonObject = new JSObject(parsingData);
|
|
887
924
|
JsonSQLite jsonSQL = new JsonSQLite();
|
|
888
|
-
Boolean isValid = jsonSQL.isJsonSQLite(jsonObject);
|
|
925
|
+
Boolean isValid = jsonSQL.isJsonSQLite(jsonObject, isEncryption);
|
|
889
926
|
if (!isValid) {
|
|
890
927
|
String msg = "Stringify Json Object not Valid";
|
|
891
928
|
throw new Exception(msg);
|
|
@@ -899,7 +936,7 @@ public class CapacitorSQLite {
|
|
|
899
936
|
if (encrypted) {
|
|
900
937
|
inMode = "secret";
|
|
901
938
|
}
|
|
902
|
-
Database db = new Database(context, dbName, encrypted, inMode, dbVersion, new Hashtable<>(), sharedPreferences);
|
|
939
|
+
Database db = new Database(context, dbName, encrypted, inMode, dbVersion, isEncryption, new Hashtable<>(), sharedPreferences);
|
|
903
940
|
db.open();
|
|
904
941
|
if (!db.isOpen()) {
|
|
905
942
|
String msg = dbName + "SQLite.db not opened";
|