@capacitor-community/sqlite 3.3.3 → 3.4.0-3
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 +31 -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/UtilsSQLCipher.java +7 -2
- 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/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
|
@@ -9,30 +9,42 @@
|
|
|
9
9
|
import Foundation
|
|
10
10
|
|
|
11
11
|
enum UtilsSecretError: Error {
|
|
12
|
+
case prefixPassphrase(message: String)
|
|
12
13
|
case setPassphrase(message: String)
|
|
13
14
|
case changePassphrase(message: String)
|
|
14
15
|
case setEncryptionSecret(message: String)
|
|
15
16
|
case changeEncryptionSecret(message: String)
|
|
16
17
|
}
|
|
17
18
|
|
|
19
|
+
let oldAccount: String = "CapacitorSQLitePlugin"
|
|
20
|
+
|
|
18
21
|
class UtilsSecret {
|
|
19
22
|
|
|
20
23
|
// MARK: - IsPassphrase
|
|
21
24
|
|
|
22
|
-
class func isPassphrase() -> Bool {
|
|
23
|
-
|
|
24
|
-
if getPassphrase()
|
|
25
|
-
|
|
25
|
+
class func isPassphrase(account: String) throws -> Bool {
|
|
26
|
+
|
|
27
|
+
if !getPassphrase(account: account).isEmpty {
|
|
28
|
+
return true
|
|
26
29
|
}
|
|
27
|
-
|
|
30
|
+
if !getPassphrase(account: oldAccount).isEmpty {
|
|
31
|
+
let passphrase = getPassphrase(account: oldAccount)
|
|
32
|
+
do {
|
|
33
|
+
try setPassphrase(account: account, passphrase: passphrase)
|
|
34
|
+
return true
|
|
35
|
+
} catch UtilsSecretError.prefixPassphrase(let message) {
|
|
36
|
+
throw UtilsSecretError.changePassphrase(message: message)
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return false
|
|
28
40
|
}
|
|
29
41
|
|
|
30
42
|
// MARK: - GetPassphrase
|
|
31
43
|
|
|
32
|
-
class func getPassphrase() -> String {
|
|
44
|
+
class func getPassphrase(account: String) -> String {
|
|
33
45
|
let kcw = KeychainWrapper()
|
|
34
46
|
if let password = try? kcw.getGenericPasswordFor(
|
|
35
|
-
account:
|
|
47
|
+
account: account,
|
|
36
48
|
service: "unlockSecret") {
|
|
37
49
|
return password
|
|
38
50
|
}
|
|
@@ -41,11 +53,11 @@ class UtilsSecret {
|
|
|
41
53
|
|
|
42
54
|
// MARK: - SetPassphrase
|
|
43
55
|
|
|
44
|
-
class func setPassphrase(passphrase: String) throws {
|
|
56
|
+
class func setPassphrase(account: String, passphrase: String) throws {
|
|
45
57
|
let kcw = KeychainWrapper()
|
|
46
58
|
do {
|
|
47
59
|
try kcw.storeGenericPasswordFor(
|
|
48
|
-
account:
|
|
60
|
+
account: account,
|
|
49
61
|
service: "unlockSecret",
|
|
50
62
|
password: passphrase)
|
|
51
63
|
} catch let error as KeychainWrapperError {
|
|
@@ -62,9 +74,9 @@ class UtilsSecret {
|
|
|
62
74
|
|
|
63
75
|
// MARK: - ValidatePassphrase
|
|
64
76
|
|
|
65
|
-
class func validatePassphrase(
|
|
77
|
+
class func validatePassphrase(account: String, passphrase: String) -> Bool {
|
|
66
78
|
var ret: Bool = false
|
|
67
|
-
let currentPassphrase = getPassphrase()
|
|
79
|
+
let currentPassphrase = getPassphrase(account: account)
|
|
68
80
|
if passphrase == currentPassphrase {
|
|
69
81
|
ret = true
|
|
70
82
|
}
|
|
@@ -73,10 +85,12 @@ class UtilsSecret {
|
|
|
73
85
|
|
|
74
86
|
// MARK: - ChangePassphrase
|
|
75
87
|
|
|
76
|
-
class func changePassphrase(
|
|
77
|
-
|
|
88
|
+
class func changePassphrase(account: String, oldPassphrase: String,
|
|
89
|
+
passphrase: String) throws -> Bool {
|
|
90
|
+
guard validatePassphrase(account: account,
|
|
91
|
+
passphrase: oldPassphrase) == true else { return false }
|
|
78
92
|
do {
|
|
79
|
-
try setPassphrase(passphrase: passphrase)
|
|
93
|
+
try setPassphrase(account: account, passphrase: passphrase)
|
|
80
94
|
return true
|
|
81
95
|
} catch UtilsSecretError.setPassphrase(let message) {
|
|
82
96
|
throw UtilsSecretError.changePassphrase(message: message)
|
|
@@ -86,15 +100,25 @@ class UtilsSecret {
|
|
|
86
100
|
// MARK: - SetEncryptionSecret
|
|
87
101
|
|
|
88
102
|
// swiftlint:disable function_body_length
|
|
89
|
-
|
|
103
|
+
// swiftlint:disable cyclomatic_complexity
|
|
104
|
+
class func setEncryptionSecret(prefix: String, passphrase: String,
|
|
90
105
|
databaseLocation: String) throws {
|
|
91
106
|
do {
|
|
107
|
+
if prefix.isEmpty {
|
|
108
|
+
let msg: String = "keychain prefix must not be empty"
|
|
109
|
+
throw UtilsSecretError.setEncryptionSecret(message: msg)
|
|
110
|
+
}
|
|
92
111
|
if passphrase.isEmpty {
|
|
93
112
|
let msg: String = "passphrase must not be empty"
|
|
94
113
|
throw UtilsSecretError.setEncryptionSecret(message: msg)
|
|
95
114
|
}
|
|
96
115
|
// store encrypted passphrase
|
|
97
|
-
|
|
116
|
+
let account = "\(prefix)_\(oldAccount)"
|
|
117
|
+
if !getPassphrase(account: account).isEmpty {
|
|
118
|
+
let msg: String = "passphrase already stored in keychain"
|
|
119
|
+
throw UtilsSecretError.setEncryptionSecret(message: msg)
|
|
120
|
+
}
|
|
121
|
+
try setPassphrase(account: account, passphrase: passphrase)
|
|
98
122
|
|
|
99
123
|
// get the list of databases
|
|
100
124
|
let databaseURL: URL = try UtilsFile.getDatabasesUrl().absoluteURL
|
|
@@ -106,7 +130,7 @@ class UtilsSecret {
|
|
|
106
130
|
for file: String in dbList {
|
|
107
131
|
let state: State = UtilsSQLCipher
|
|
108
132
|
.getDatabaseState(databaseLocation: databaseLocation,
|
|
109
|
-
databaseName: file)
|
|
133
|
+
databaseName: file, account: account)
|
|
110
134
|
if state.rawValue == "ENCRYPTEDGLOBALSECRET" {
|
|
111
135
|
let globalData: GlobalSQLite = GlobalSQLite()
|
|
112
136
|
let password: String = globalData.secret
|
|
@@ -140,25 +164,33 @@ class UtilsSecret {
|
|
|
140
164
|
}
|
|
141
165
|
|
|
142
166
|
}
|
|
167
|
+
// swiftlint:enable cyclomatic_complexity
|
|
143
168
|
// swiftlint:enable function_body_length
|
|
144
169
|
|
|
145
170
|
// MARK: - ChangeEncryptionSecret
|
|
146
171
|
|
|
147
172
|
// swiftlint:disable function_body_length
|
|
148
|
-
class func changeEncryptionSecret(passphrase: String,
|
|
173
|
+
class func changeEncryptionSecret(prefix: String, passphrase: String,
|
|
149
174
|
oldPassphrase: String,
|
|
150
175
|
databaseLocation: String) throws {
|
|
151
176
|
do {
|
|
177
|
+
if prefix.isEmpty {
|
|
178
|
+
let msg: String = "Keychain prefix must not " +
|
|
179
|
+
"be empty"
|
|
180
|
+
throw UtilsSecretError.changeEncryptionSecret(message: msg)
|
|
181
|
+
}
|
|
152
182
|
if passphrase.isEmpty || oldPassphrase.isEmpty {
|
|
153
183
|
let msg: String = "Passphrase and/or oldpassphrase must not " +
|
|
154
184
|
"be empty"
|
|
155
185
|
throw UtilsSecretError.changeEncryptionSecret(message: msg)
|
|
156
186
|
}
|
|
157
|
-
|
|
187
|
+
let account = "\(prefix)_\(oldAccount)"
|
|
188
|
+
guard try isPassphrase(account: account) == true else {
|
|
158
189
|
let msg: String = "Encryption secret has not been set"
|
|
159
190
|
throw UtilsSecretError.changeEncryptionSecret(message: msg)
|
|
160
191
|
}
|
|
161
|
-
guard validatePassphrase(
|
|
192
|
+
guard validatePassphrase(account: account,
|
|
193
|
+
passphrase: oldPassphrase) == true else {
|
|
162
194
|
let msg: String = "Given oldpassphrase is wrong"
|
|
163
195
|
throw UtilsSecretError.changeEncryptionSecret(message: msg)
|
|
164
196
|
}
|
|
@@ -173,7 +205,7 @@ class UtilsSecret {
|
|
|
173
205
|
for file: String in dbList {
|
|
174
206
|
let state: State = UtilsSQLCipher
|
|
175
207
|
.getDatabaseState(databaseLocation: databaseLocation,
|
|
176
|
-
databaseName: file)
|
|
208
|
+
databaseName: file, account: account)
|
|
177
209
|
if state.rawValue == "ENCRYPTEDSECRET" {
|
|
178
210
|
let dbPath: String = try UtilsFile
|
|
179
211
|
.getFilePath(databaseLocation: databaseLocation,
|
|
@@ -199,7 +231,7 @@ class UtilsSecret {
|
|
|
199
231
|
}
|
|
200
232
|
|
|
201
233
|
// store encrypted passphrase
|
|
202
|
-
try setPassphrase(passphrase: passphrase)
|
|
234
|
+
try setPassphrase(account: account, passphrase: passphrase)
|
|
203
235
|
|
|
204
236
|
} catch UtilsSecretError.setPassphrase(let message) {
|
|
205
237
|
throw UtilsSecretError.setEncryptionSecret(message: message)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@capacitor-community/sqlite",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.4.0-3",
|
|
4
4
|
"description": "Community plugin for native & electron SQLite databases",
|
|
5
5
|
"main": "dist/plugin.cjs.js",
|
|
6
6
|
"module": "dist/esm/index.js",
|
|
@@ -55,10 +55,10 @@
|
|
|
55
55
|
"prepublishOnly": "npm run build && npm run build-electron && npm run docgen"
|
|
56
56
|
},
|
|
57
57
|
"devDependencies": {
|
|
58
|
-
"@capacitor/android": "
|
|
59
|
-
"@capacitor/core": "3.
|
|
60
|
-
"@capacitor/docgen": "^0.
|
|
61
|
-
"@capacitor/ios": "
|
|
58
|
+
"@capacitor/android": "~3.4.0",
|
|
59
|
+
"@capacitor/core": "~3.4.0",
|
|
60
|
+
"@capacitor/docgen": "^0.1.1",
|
|
61
|
+
"@capacitor/ios": "~3.4.0",
|
|
62
62
|
"@ionic/eslint-config": "^0.3.0",
|
|
63
63
|
"@ionic/prettier-config": "^1.0.1",
|
|
64
64
|
"@ionic/swiftlint-config": "^1.1.2",
|
|
@@ -74,7 +74,7 @@
|
|
|
74
74
|
"typescript": "~4.0.5"
|
|
75
75
|
},
|
|
76
76
|
"peerDependencies": {
|
|
77
|
-
"@capacitor/core": "
|
|
77
|
+
"@capacitor/core": "~3.4.0"
|
|
78
78
|
},
|
|
79
79
|
"prettier": "@ionic/prettier-config",
|
|
80
80
|
"swiftlint": "@ionic/swiftlint-config",
|