native-update 3.4.2 → 4.0.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/AI-INTEGRATION-GUIDE.md +26 -16
- package/NativeUpdate.podspec +2 -2
- package/README.md +24 -20
- package/android/build.gradle +37 -33
- package/android/gradle/wrapper/gradle-wrapper.properties +2 -2
- package/android/proguard-rules.pro +0 -3
- package/android/src/main/java/com/aoneahsan/nativeupdate/BackgroundNotificationManager.kt +45 -49
- package/android/src/main/java/com/aoneahsan/nativeupdate/BackgroundUpdateManager.kt +12 -10
- package/android/src/main/java/com/aoneahsan/nativeupdate/BackgroundUpdatePlugin.kt +12 -21
- package/android/src/main/java/com/aoneahsan/nativeupdate/BackgroundUpdateWorker.kt +3 -34
- package/android/src/main/java/com/aoneahsan/nativeupdate/LiveUpdatePlugin.kt +206 -72
- package/android/src/main/java/com/aoneahsan/nativeupdate/NativeUpdatePlugin.kt +74 -37
- package/android/src/main/java/com/aoneahsan/nativeupdate/SecurityManager.kt +169 -179
- package/android/variables.gradle +2 -2
- package/cli/commands/bundle-verify.js +4 -1
- package/cli/commands/keys-generate.js +12 -46
- package/cli/index.js +4 -7
- package/cli/package.json +2 -1
- package/dist/esm/core/config.d.ts +3 -0
- package/dist/esm/core/config.js +17 -0
- package/dist/esm/core/plugin-manager.js +4 -2
- package/dist/esm/core/security.js +2 -5
- package/dist/esm/core/update-check.d.ts +2 -0
- package/dist/esm/core/update-check.js +5 -3
- package/dist/esm/definitions.d.ts +43 -2
- package/dist/esm/live-update/delta-processor.d.ts +6 -20
- package/dist/esm/live-update/delta-processor.js +75 -119
- package/dist/esm/plugin.d.ts +0 -3
- package/dist/esm/plugin.js +172 -12
- package/dist/esm/security/crypto.js +2 -5
- package/dist/esm/web.d.ts +1 -9
- package/dist/esm/web.js +4 -56
- package/dist/plugin.cjs +1 -1
- package/dist/plugin.esm.js +1 -1
- package/dist/plugin.js +2 -2
- package/docs/CHANGELOG.md +49 -0
- package/docs/KNOWN_LIMITATIONS.md +4 -3
- package/docs/MIGRATION.md +32 -3
- package/docs/server-requirements.md +40 -29
- package/ios/Plugin/BackgroundUpdate/BackgroundNotificationManager.swift +6 -2
- package/ios/Plugin/BackgroundUpdate/BackgroundUpdatePlugin.swift +21 -30
- package/ios/Plugin/LiveUpdate/LiveUpdatePlugin.swift +269 -61
- package/ios/Plugin/NativeUpdatePlugin.m +8 -1
- package/ios/Plugin/NativeUpdatePlugin.swift +71 -34
- package/ios/Plugin/Security/SecurityManager.swift +100 -99
- package/package.json +25 -13
|
@@ -19,6 +19,12 @@ public class NativeUpdatePlugin: CAPPlugin {
|
|
|
19
19
|
appReviewPlugin = AppReviewPlugin(plugin: self)
|
|
20
20
|
backgroundUpdatePlugin = BackgroundUpdatePlugin()
|
|
21
21
|
securityManager = SecurityManager()
|
|
22
|
+
backgroundUpdatePlugin.load()
|
|
23
|
+
backgroundUpdatePlugin.configureProviders(
|
|
24
|
+
appUpdate: { [weak self] in await self?.appUpdatePlugin.getAppUpdateInfoAsync() },
|
|
25
|
+
liveUpdate: { [weak self] in await self?.liveUpdatePlugin.getLatestVersionAsync() },
|
|
26
|
+
eventListener: { [weak self] event, data in self?.notifyListeners(event, data: data) }
|
|
27
|
+
)
|
|
22
28
|
|
|
23
29
|
// Set up listeners
|
|
24
30
|
liveUpdatePlugin.setProgressListener { [weak self] progress in
|
|
@@ -45,15 +51,15 @@ public class NativeUpdatePlugin: CAPPlugin {
|
|
|
45
51
|
|
|
46
52
|
@objc func initialize(_ call: CAPPluginCall) {
|
|
47
53
|
do {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
54
|
+
guard !isInitialized else {
|
|
55
|
+
call.reject("Configuration is locked after initialization; call reset() first")
|
|
56
|
+
return
|
|
57
|
+
}
|
|
58
|
+
guard let config = configuration(from: call) else {
|
|
59
|
+
call.reject("Configuration object is required")
|
|
60
|
+
return
|
|
61
|
+
}
|
|
62
|
+
try applyConfiguration(config)
|
|
57
63
|
isInitialized = true
|
|
58
64
|
call.resolve()
|
|
59
65
|
} catch {
|
|
@@ -91,41 +97,36 @@ public class NativeUpdatePlugin: CAPPlugin {
|
|
|
91
97
|
// configure(UpdateConfig) — nested sections
|
|
92
98
|
// Before this fix only the wrapped shape reached native, so the
|
|
93
99
|
// flat initialize() every consumer uses configured NOTHING here.
|
|
94
|
-
|
|
95
|
-
|
|
100
|
+
guard !isInitialized else {
|
|
101
|
+
call.reject("Configuration is locked after initialization; call reset() first")
|
|
102
|
+
return
|
|
103
|
+
}
|
|
104
|
+
guard let config = configuration(from: call) else {
|
|
96
105
|
call.reject("Configuration object is required")
|
|
97
106
|
return
|
|
98
107
|
}
|
|
99
108
|
|
|
100
109
|
do {
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
try securityManager.configure(securityConfig)
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
// Configure sub-plugins
|
|
107
|
-
if let liveUpdateConfig = (config["liveUpdate"] as? [String: Any]) ?? Self.buildFlatLiveUpdateConfig(from: config) {
|
|
108
|
-
try liveUpdatePlugin.configure(liveUpdateConfig)
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
if let appUpdateConfig = config["appUpdate"] as? [String: Any] {
|
|
112
|
-
try appUpdatePlugin.configure(appUpdateConfig)
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
if let appReviewConfig = config["appReview"] as? [String: Any] {
|
|
116
|
-
try appReviewPlugin.configure(appReviewConfig)
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
if let backgroundUpdateConfig = config["backgroundUpdate"] as? [String: Any] {
|
|
120
|
-
try backgroundUpdatePlugin.configure(backgroundUpdateConfig)
|
|
121
|
-
}
|
|
122
|
-
|
|
110
|
+
try applyConfiguration(config)
|
|
111
|
+
isInitialized = true
|
|
123
112
|
call.resolve()
|
|
124
113
|
} catch {
|
|
125
114
|
call.reject("Configuration failed", error.localizedDescription)
|
|
126
115
|
}
|
|
127
116
|
}
|
|
128
117
|
|
|
118
|
+
private func configuration(from call: CAPPluginCall) -> [String: Any]? {
|
|
119
|
+
call.getObject("config").map { $0 as [String: Any] } ?? (call.options as? [String: Any])
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
private func applyConfiguration(_ config: [String: Any]) throws {
|
|
123
|
+
try securityManager.configure(config)
|
|
124
|
+
if let live = Self.normalizeLiveUpdateConfig(from: config) { try liveUpdatePlugin.configure(live) }
|
|
125
|
+
if let value = config["appUpdate"] as? [String: Any] { try appUpdatePlugin.configure(value) }
|
|
126
|
+
if let value = config["appReview"] as? [String: Any] { try appReviewPlugin.configure(value) }
|
|
127
|
+
if let value = config["backgroundUpdate"] as? [String: Any] { try backgroundUpdatePlugin.configure(value) }
|
|
128
|
+
}
|
|
129
|
+
|
|
129
130
|
/// Normalize a flat PluginInitConfig (serverUrl/baseUrl, apiKey, appId,
|
|
130
131
|
/// channel, publicKey at the top level) into the liveUpdate config shape
|
|
131
132
|
/// the sub-plugin reads. Returns nil when the payload carries no
|
|
@@ -143,10 +144,41 @@ public class NativeUpdatePlugin: CAPPlugin {
|
|
|
143
144
|
if let appId = config["appId"] as? String { liveUpdate["appId"] = appId }
|
|
144
145
|
if let channel = config["channel"] as? String { liveUpdate["channel"] = channel }
|
|
145
146
|
if let publicKey = config["publicKey"] as? String { liveUpdate["publicKey"] = publicKey }
|
|
147
|
+
if let requireSignature = config["requireSignature"] as? Bool { liveUpdate["requireSignature"] = requireSignature }
|
|
148
|
+
if let allowUnsigned = config["allowUnsignedDevelopmentUpdates"] as? Bool {
|
|
149
|
+
liveUpdate["allowUnsignedDevelopmentUpdates"] = allowUnsigned
|
|
150
|
+
}
|
|
151
|
+
if let maxBundleSize = config["maxBundleSize"] as? NSNumber { liveUpdate["maxBundleSize"] = maxBundleSize }
|
|
152
|
+
if let maxUncompressedBundleSize = config["maxUncompressedBundleSize"] as? NSNumber {
|
|
153
|
+
liveUpdate["maxUncompressedBundleSize"] = maxUncompressedBundleSize
|
|
154
|
+
}
|
|
155
|
+
if let enableDeltaUpdates = config["enableDeltaUpdates"] as? Bool {
|
|
156
|
+
liveUpdate["enableDeltaUpdates"] = enableDeltaUpdates
|
|
157
|
+
}
|
|
158
|
+
if let allowedHosts = config["allowedHosts"] as? [String] { liveUpdate["allowedHosts"] = allowedHosts }
|
|
146
159
|
if let security = config["security"] as? [String: Any] { liveUpdate["security"] = security }
|
|
147
160
|
return liveUpdate
|
|
148
161
|
}
|
|
149
162
|
|
|
163
|
+
private static func normalizeLiveUpdateConfig(from config: [String: Any]) -> [String: Any]? {
|
|
164
|
+
guard var liveUpdate = (config["liveUpdate"] as? [String: Any]) ?? buildFlatLiveUpdateConfig(from: config) else {
|
|
165
|
+
return nil
|
|
166
|
+
}
|
|
167
|
+
if liveUpdate["security"] == nil { liveUpdate["security"] = config["security"] }
|
|
168
|
+
if liveUpdate["publicKey"] == nil { liveUpdate["publicKey"] = config["publicKey"] }
|
|
169
|
+
if liveUpdate["requireSignature"] == nil { liveUpdate["requireSignature"] = config["requireSignature"] }
|
|
170
|
+
if liveUpdate["allowUnsignedDevelopmentUpdates"] == nil {
|
|
171
|
+
liveUpdate["allowUnsignedDevelopmentUpdates"] = config["allowUnsignedDevelopmentUpdates"]
|
|
172
|
+
}
|
|
173
|
+
if liveUpdate["maxUncompressedBundleSize"] == nil {
|
|
174
|
+
liveUpdate["maxUncompressedBundleSize"] = config["maxUncompressedBundleSize"]
|
|
175
|
+
}
|
|
176
|
+
if liveUpdate["enableDeltaUpdates"] == nil {
|
|
177
|
+
liveUpdate["enableDeltaUpdates"] = config["enableDeltaUpdates"]
|
|
178
|
+
}
|
|
179
|
+
return liveUpdate
|
|
180
|
+
}
|
|
181
|
+
|
|
150
182
|
@objc func getSecurityInfo(_ call: CAPPluginCall) {
|
|
151
183
|
call.resolve(securityManager.getSecurityInfo())
|
|
152
184
|
}
|
|
@@ -209,6 +241,11 @@ public class NativeUpdatePlugin: CAPPlugin {
|
|
|
209
241
|
@objc func validateUpdate(_ call: CAPPluginCall) {
|
|
210
242
|
liveUpdatePlugin.validateUpdate(call)
|
|
211
243
|
}
|
|
244
|
+
|
|
245
|
+
@objc func cancelDownload(_ call: CAPPluginCall) { liveUpdatePlugin.cancelDownload(call) }
|
|
246
|
+
@objc func cancelAllDownloads(_ call: CAPPluginCall) { liveUpdatePlugin.cancelAllDownloads(call) }
|
|
247
|
+
@objc func isDownloading(_ call: CAPPluginCall) { liveUpdatePlugin.isDownloading(call) }
|
|
248
|
+
@objc func getActiveDownloadCount(_ call: CAPPluginCall) { liveUpdatePlugin.getActiveDownloadCount(call) }
|
|
212
249
|
|
|
213
250
|
// MARK: - App Update Methods
|
|
214
251
|
|
|
@@ -275,4 +312,4 @@ public class NativeUpdatePlugin: CAPPlugin {
|
|
|
275
312
|
@objc func requestNotificationPermissions(_ call: CAPPluginCall) {
|
|
276
313
|
backgroundUpdatePlugin.requestNotificationPermissions(call)
|
|
277
314
|
}
|
|
278
|
-
}
|
|
315
|
+
}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import Foundation
|
|
2
2
|
import Security
|
|
3
|
-
import CommonCrypto
|
|
4
3
|
import CryptoKit
|
|
5
4
|
|
|
6
5
|
class SecurityManager {
|
|
@@ -9,29 +8,48 @@ class SecurityManager {
|
|
|
9
8
|
|
|
10
9
|
func configure(_ config: [String: Any]) throws {
|
|
11
10
|
self.config = config
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
11
|
+
let security = securityConfig
|
|
12
|
+
guard security["enforceHttps"] as? Bool != false else {
|
|
13
|
+
throw NSError(domain: "NativeUpdateSecurity", code: 1, userInfo: [
|
|
14
|
+
NSLocalizedDescriptionKey: "HTTPS enforcement cannot be disabled"
|
|
15
|
+
])
|
|
16
|
+
}
|
|
17
|
+
if let pinning = security["certificatePinning"] as? [String: Any],
|
|
18
|
+
pinning["enabled"] as? Bool == true {
|
|
19
|
+
guard let pins = pinning["pins"] as? [[String: Any]], !pins.isEmpty else {
|
|
20
|
+
throw NSError(domain: "NativeUpdateSecurity", code: 2, userInfo: [
|
|
21
|
+
NSLocalizedDescriptionKey: "Certificate pinning requires at least one host pin"
|
|
22
|
+
])
|
|
23
|
+
}
|
|
24
|
+
let pinPattern = try NSRegularExpression(pattern: "^sha256/[A-Za-z0-9+/]{43}=$")
|
|
25
|
+
for pin in pins {
|
|
26
|
+
guard let hostname = pin["hostname"] as? String, !hostname.isEmpty,
|
|
27
|
+
let hashes = pin["sha256"] as? [String], !hashes.isEmpty,
|
|
28
|
+
hashes.allSatisfy({ pinPattern.firstMatch(in: $0, range: NSRange($0.startIndex..., in: $0)) != nil }) else {
|
|
29
|
+
throw NSError(domain: "NativeUpdateSecurity", code: 3, userInfo: [
|
|
30
|
+
NSLocalizedDescriptionKey: "Certificate pins require a hostname and sha256/<base64> hashes"
|
|
31
|
+
])
|
|
32
|
+
}
|
|
33
|
+
}
|
|
17
34
|
}
|
|
18
35
|
}
|
|
19
36
|
|
|
20
37
|
func getSecurityInfo() -> [String: Any] {
|
|
21
38
|
return [
|
|
22
|
-
"enforceHttps":
|
|
39
|
+
"enforceHttps": true,
|
|
23
40
|
"certificatePinning": [
|
|
24
|
-
"enabled": (
|
|
41
|
+
"enabled": (securityConfig["certificatePinning"] as? [String: Any])?["enabled"] as? Bool ?? false,
|
|
25
42
|
"pins": getCertificatePins()
|
|
26
43
|
],
|
|
27
|
-
"validateInputs":
|
|
44
|
+
"validateInputs": securityConfig["validateInputs"] as? Bool ?? true,
|
|
28
45
|
// Hard-coded true since v2 — secure storage is no longer opt-out.
|
|
29
|
-
"secureStorage": true
|
|
46
|
+
"secureStorage": true,
|
|
47
|
+
"signatureAlgorithm": "RSA-SHA256"
|
|
30
48
|
]
|
|
31
49
|
}
|
|
32
50
|
|
|
33
51
|
func getCertificatePins() -> [String: [String]] {
|
|
34
|
-
guard let pinningConfig =
|
|
52
|
+
guard let pinningConfig = securityConfig["certificatePinning"] as? [String: Any],
|
|
35
53
|
pinningConfig["enabled"] as? Bool == true,
|
|
36
54
|
let pins = pinningConfig["pins"] as? [[String: Any]] else {
|
|
37
55
|
return [:]
|
|
@@ -44,7 +62,7 @@ class SecurityManager {
|
|
|
44
62
|
let sha256Pins = pin["sha256"] as? [String] else {
|
|
45
63
|
continue
|
|
46
64
|
}
|
|
47
|
-
|
|
65
|
+
|
|
48
66
|
hostPins[hostname] = sha256Pins
|
|
49
67
|
}
|
|
50
68
|
|
|
@@ -52,81 +70,62 @@ class SecurityManager {
|
|
|
52
70
|
}
|
|
53
71
|
|
|
54
72
|
func validateUrl(_ url: String) -> Bool {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
guard let urlComponents = URLComponents(string: url),
|
|
62
|
-
let host = urlComponents.host else {
|
|
63
|
-
return false
|
|
64
|
-
}
|
|
65
|
-
return allowedHosts.contains(host)
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
return true
|
|
73
|
+
guard let components = URLComponents(string: url),
|
|
74
|
+
components.scheme?.lowercased() == "https",
|
|
75
|
+
let host = components.host?.lowercased(), !host.isEmpty,
|
|
76
|
+
components.user == nil, components.password == nil else { return false }
|
|
77
|
+
let allowedHosts = getAllowedHosts() ?? []
|
|
78
|
+
return allowedHosts.isEmpty || allowedHosts.map { $0.lowercased() }.contains(host)
|
|
69
79
|
}
|
|
70
80
|
|
|
71
81
|
func verifySignature(data: Data, signature: String, publicKeyString: String) -> Bool {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
guard let signatureData = Data(base64Encoded: signature) else {
|
|
98
|
-
print("Failed to decode signature")
|
|
99
|
-
return false
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
do {
|
|
103
|
-
// Create SecKey from public key data
|
|
104
|
-
let attributes: [String: Any] = [
|
|
105
|
-
kSecAttrKeyType as String: kSecAttrKeyTypeRSA,
|
|
106
|
-
kSecAttrKeyClass as String: kSecAttrKeyClassPublic,
|
|
107
|
-
kSecAttrKeySizeInBits as String: 2048
|
|
108
|
-
]
|
|
109
|
-
|
|
110
|
-
guard let secKey = SecKeyCreateWithData(publicKeyData as CFData, attributes as CFDictionary, nil) else {
|
|
111
|
-
print("Failed to create SecKey from public key data")
|
|
112
|
-
return false
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
// Verify signature using RSA-PSS (matching web implementation)
|
|
116
|
-
let algorithm = SecKeyAlgorithm.rsaSignatureMessagePSSSHA256
|
|
117
|
-
let result = SecKeyVerifySignature(secKey, algorithm, data as CFData, signatureData as CFData, nil)
|
|
118
|
-
|
|
119
|
-
if !result {
|
|
120
|
-
print("Signature verification failed")
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
return result
|
|
124
|
-
} catch {
|
|
125
|
-
print("Signature verification error: \(error)")
|
|
126
|
-
return false
|
|
82
|
+
guard let secKey = decodePublicKey(publicKeyString),
|
|
83
|
+
let signatureData = Data(base64Encoded: signature) else { return false }
|
|
84
|
+
|
|
85
|
+
// Backend contract: RSA-SHA256 with PKCS#1 v1.5 padding.
|
|
86
|
+
let algorithm = SecKeyAlgorithm.rsaSignatureMessagePKCS1v15SHA256
|
|
87
|
+
guard SecKeyIsAlgorithmSupported(secKey, .verify, algorithm) else { return false }
|
|
88
|
+
return SecKeyVerifySignature(secKey, algorithm, data as CFData, signatureData as CFData, nil)
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/** Verify a large bundle without materializing the entire ZIP in memory. */
|
|
92
|
+
func verifySignature(fileURL: URL, signature: String, publicKeyString: String) -> Bool {
|
|
93
|
+
guard let secKey = decodePublicKey(publicKeyString),
|
|
94
|
+
let signatureData = Data(base64Encoded: signature),
|
|
95
|
+
let stream = InputStream(url: fileURL) else { return false }
|
|
96
|
+
|
|
97
|
+
stream.open()
|
|
98
|
+
defer { stream.close() }
|
|
99
|
+
var hasher = SHA256()
|
|
100
|
+
let buffer = UnsafeMutablePointer<UInt8>.allocate(capacity: 64 * 1024)
|
|
101
|
+
defer { buffer.deallocate() }
|
|
102
|
+
while stream.hasBytesAvailable {
|
|
103
|
+
let count = stream.read(buffer, maxLength: 64 * 1024)
|
|
104
|
+
if count < 0 { return false }
|
|
105
|
+
if count == 0 { break }
|
|
106
|
+
hasher.update(data: Data(bytes: buffer, count: count))
|
|
127
107
|
}
|
|
108
|
+
|
|
109
|
+
let digest = Data(hasher.finalize())
|
|
110
|
+
let algorithm = SecKeyAlgorithm.rsaSignatureDigestPKCS1v15SHA256
|
|
111
|
+
guard SecKeyIsAlgorithmSupported(secKey, .verify, algorithm) else { return false }
|
|
112
|
+
return SecKeyVerifySignature(secKey, algorithm, digest as CFData, signatureData as CFData, nil)
|
|
128
113
|
}
|
|
129
|
-
|
|
114
|
+
|
|
115
|
+
private func decodePublicKey(_ publicKeyString: String) -> SecKey? {
|
|
116
|
+
let normalized = publicKeyString
|
|
117
|
+
.replacingOccurrences(of: "-----BEGIN PUBLIC KEY-----", with: "")
|
|
118
|
+
.replacingOccurrences(of: "-----END PUBLIC KEY-----", with: "")
|
|
119
|
+
.components(separatedBy: .whitespacesAndNewlines)
|
|
120
|
+
.joined()
|
|
121
|
+
guard let publicKeyData = Data(base64Encoded: normalized) else { return nil }
|
|
122
|
+
let attributes: [String: Any] = [
|
|
123
|
+
kSecAttrKeyType as String: kSecAttrKeyTypeRSA,
|
|
124
|
+
kSecAttrKeyClass as String: kSecAttrKeyClassPublic
|
|
125
|
+
]
|
|
126
|
+
return SecKeyCreateWithData(publicKeyData as CFData, attributes as CFDictionary, nil)
|
|
127
|
+
}
|
|
128
|
+
|
|
130
129
|
func calculateChecksum(for data: Data, algorithm: String = "SHA-256") -> String {
|
|
131
130
|
let digest: Data
|
|
132
131
|
|
|
@@ -171,9 +170,9 @@ class SecurityManager {
|
|
|
171
170
|
let cachesPath = FileManager.default.urls(for: .cachesDirectory, in: .userDomainMask).first!.path
|
|
172
171
|
let tempPath = NSTemporaryDirectory()
|
|
173
172
|
|
|
174
|
-
return standardizedPath
|
|
175
|
-
standardizedPath
|
|
176
|
-
standardizedPath
|
|
173
|
+
return isWithin(standardizedPath, root: documentsPath) ||
|
|
174
|
+
isWithin(standardizedPath, root: cachesPath) ||
|
|
175
|
+
isWithin(standardizedPath, root: tempPath)
|
|
177
176
|
}
|
|
178
177
|
|
|
179
178
|
func sanitizeInput(_ input: String) -> String {
|
|
@@ -183,7 +182,7 @@ class SecurityManager {
|
|
|
183
182
|
}
|
|
184
183
|
|
|
185
184
|
func isHttpsEnforced() -> Bool {
|
|
186
|
-
return
|
|
185
|
+
return true
|
|
187
186
|
}
|
|
188
187
|
|
|
189
188
|
/// Unconditionally true since v2. Kept so `getSecurityInfo()` still
|
|
@@ -193,11 +192,11 @@ class SecurityManager {
|
|
|
193
192
|
}
|
|
194
193
|
|
|
195
194
|
func isInputValidationEnabled() -> Bool {
|
|
196
|
-
return
|
|
195
|
+
return securityConfig["validateInputs"] as? Bool ?? true
|
|
197
196
|
}
|
|
198
197
|
|
|
199
198
|
func logSecurityEvent(_ event: String, details: String? = nil) {
|
|
200
|
-
guard
|
|
199
|
+
guard securityConfig["logSecurityEvents"] as? Bool == true else { return }
|
|
201
200
|
|
|
202
201
|
let message = "Security Event: \(event) \(details ?? "")"
|
|
203
202
|
print("🔒 \(message)")
|
|
@@ -209,20 +208,21 @@ class SecurityManager {
|
|
|
209
208
|
var hosts: [String] = []
|
|
210
209
|
|
|
211
210
|
// Add hosts from live update config
|
|
212
|
-
if let
|
|
213
|
-
let allowedHosts = liveUpdateConfig["allowedHosts"] as? [String] {
|
|
211
|
+
if let allowedHosts = config?["allowedHosts"] as? [String] {
|
|
214
212
|
hosts.append(contentsOf: allowedHosts)
|
|
215
213
|
}
|
|
216
214
|
|
|
217
|
-
// Add host from server URL
|
|
218
|
-
if let serverUrl = config?["serverUrl"] as? String,
|
|
219
|
-
let urlComponents = URLComponents(string: serverUrl),
|
|
220
|
-
let host = urlComponents.host {
|
|
221
|
-
hosts.append(host)
|
|
222
|
-
}
|
|
223
|
-
|
|
224
215
|
return hosts.isEmpty ? nil : Array(Set(hosts))
|
|
225
216
|
}
|
|
217
|
+
|
|
218
|
+
private var securityConfig: [String: Any] {
|
|
219
|
+
(config?["security"] as? [String: Any]) ?? config ?? [:]
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
private func isWithin(_ path: String, root: String) -> Bool {
|
|
223
|
+
let normalizedRoot = URL(fileURLWithPath: root).standardizedFileURL.path
|
|
224
|
+
return path == normalizedRoot || path.hasPrefix(normalizedRoot + "/")
|
|
225
|
+
}
|
|
226
226
|
}
|
|
227
227
|
|
|
228
228
|
// MARK: - Keychain Wrapper
|
|
@@ -237,7 +237,8 @@ private class KeychainWrapper {
|
|
|
237
237
|
kSecClass as String: kSecClassGenericPassword,
|
|
238
238
|
kSecAttrService as String: serviceName,
|
|
239
239
|
kSecAttrAccount as String: key,
|
|
240
|
-
kSecValueData as String: data
|
|
240
|
+
kSecValueData as String: data,
|
|
241
|
+
kSecAttrAccessible as String: kSecAttrAccessibleAfterFirstUnlockThisDeviceOnly
|
|
241
242
|
]
|
|
242
243
|
|
|
243
244
|
// Delete any existing item
|
|
@@ -285,4 +286,4 @@ extension Digest {
|
|
|
285
286
|
var data: Data {
|
|
286
287
|
Data(self)
|
|
287
288
|
}
|
|
288
|
-
}
|
|
289
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "native-update",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.1",
|
|
4
|
+
"packageManager": "yarn@4.17.0",
|
|
4
5
|
"engines": {
|
|
5
6
|
"node": ">=24.16.0"
|
|
6
7
|
},
|
|
@@ -39,6 +40,9 @@
|
|
|
39
40
|
"docs/KNOWN_LIMITATIONS.md",
|
|
40
41
|
"cli/",
|
|
41
42
|
"AI-INTEGRATION-GUIDE.md",
|
|
43
|
+
"!**/node_modules/**",
|
|
44
|
+
"!**/.yarn/**",
|
|
45
|
+
"!**/yarn.lock",
|
|
42
46
|
"!**/CLAUDE.md",
|
|
43
47
|
"!**/AGENTS.md"
|
|
44
48
|
],
|
|
@@ -79,8 +83,9 @@
|
|
|
79
83
|
"build:prod": "rimraf ./dist && tsc && NODE_ENV=production rollup -c rollup.config.js",
|
|
80
84
|
"clean": "rimraf ./dist",
|
|
81
85
|
"tsc": "tsc",
|
|
86
|
+
"test": "vitest run tests",
|
|
82
87
|
"watch": "tsc --watch",
|
|
83
|
-
"lint": "eslint .",
|
|
88
|
+
"lint": "eslint . --max-warnings 0",
|
|
84
89
|
"prettier": "prettier --write .",
|
|
85
90
|
"prepublishOnly": "yarn build:prod",
|
|
86
91
|
"swiftlint": "cd ios && swiftlint lint --fix --format --path Plugin --verbose"
|
|
@@ -90,25 +95,26 @@
|
|
|
90
95
|
"chalk": "^5.6.2",
|
|
91
96
|
"commander": "^15.0.0",
|
|
92
97
|
"express": "^5.2.1",
|
|
93
|
-
"ora": "^9.4.
|
|
98
|
+
"ora": "^9.4.1",
|
|
94
99
|
"prompts": "^2.4.2"
|
|
95
100
|
},
|
|
96
101
|
"devDependencies": {
|
|
97
|
-
"@capacitor/app": "^8.1.
|
|
98
|
-
"@capacitor/core": "^8.
|
|
99
|
-
"@capacitor/device": "^8.0.
|
|
102
|
+
"@capacitor/app": "^8.1.1",
|
|
103
|
+
"@capacitor/core": "^8.5.0",
|
|
104
|
+
"@capacitor/device": "^8.0.3",
|
|
100
105
|
"@capacitor/filesystem": "^8.1.2",
|
|
101
106
|
"@capacitor/preferences": "^8.0.1",
|
|
102
107
|
"@rollup/plugin-node-resolve": "^16.0.3",
|
|
103
108
|
"@rollup/plugin-terser": "^1.0.0",
|
|
104
|
-
"@types/node": "^26.
|
|
105
|
-
"@typescript-eslint/eslint-plugin": "^8.
|
|
106
|
-
"@typescript-eslint/parser": "^8.
|
|
107
|
-
"eslint": "^10.
|
|
108
|
-
"prettier": "^3.
|
|
109
|
+
"@types/node": "^26.1.2",
|
|
110
|
+
"@typescript-eslint/eslint-plugin": "^8.66.0",
|
|
111
|
+
"@typescript-eslint/parser": "^8.66.0",
|
|
112
|
+
"eslint": "^10.8.0",
|
|
113
|
+
"prettier": "^3.9.6",
|
|
109
114
|
"rimraf": "^6.1.3",
|
|
110
|
-
"rollup": "^4.62.
|
|
111
|
-
"typescript": "^6.0.3"
|
|
115
|
+
"rollup": "^4.62.4",
|
|
116
|
+
"typescript": "^6.0.3",
|
|
117
|
+
"vitest": "^4.1.10"
|
|
112
118
|
},
|
|
113
119
|
"peerDependencies": {
|
|
114
120
|
"@capacitor/core": "^8.0.1",
|
|
@@ -122,5 +128,11 @@
|
|
|
122
128
|
"android": {
|
|
123
129
|
"src": "android"
|
|
124
130
|
}
|
|
131
|
+
},
|
|
132
|
+
"resolutions": {
|
|
133
|
+
"brace-expansion": "5.0.9",
|
|
134
|
+
"node-gyp": "13.0.1",
|
|
135
|
+
"tar": "7.5.22",
|
|
136
|
+
"undici": "8.10.0"
|
|
125
137
|
}
|
|
126
138
|
}
|