@capgo/capacitor-updater 5.51.17 → 5.51.23
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 +51 -42
- package/android/src/main/java/ee/forgr/capacitor_updater/CapacitorUpdaterPlugin.java +44 -30
- package/android/src/main/java/ee/forgr/capacitor_updater/CapgoUpdater.java +437 -351
- package/android/src/main/java/ee/forgr/capacitor_updater/CryptoCipher.java +51 -18
- package/android/src/main/java/ee/forgr/capacitor_updater/DownloadService.java +330 -92
- package/android/src/main/java/ee/forgr/capacitor_updater/Logger.java +12 -1
- package/android/src/main/java/ee/forgr/capacitor_updater/ShakeMenu.java +12 -16
- package/dist/docs.json +4 -4
- package/dist/esm/definitions.d.ts +12 -9
- package/dist/esm/definitions.js.map +1 -1
- package/dist/esm/history.js +7 -7
- package/dist/esm/history.js.map +1 -1
- package/dist/plugin.cjs.js +7 -7
- package/dist/plugin.cjs.js.map +1 -1
- package/dist/plugin.js +7 -7
- package/dist/plugin.js.map +1 -1
- package/ios/Sources/CapacitorUpdaterPlugin/CapacitorUpdaterPlugin.swift +245 -95
- package/ios/Sources/CapacitorUpdaterPlugin/CapgoUpdater.swift +190 -35
- package/ios/Sources/CapacitorUpdaterPlugin/CryptoCipher.swift +39 -31
- package/ios/Sources/CapacitorUpdaterPlugin/DelayUpdateUtils.swift +16 -41
- package/ios/Sources/CapacitorUpdaterPlugin/ShakeMenu.swift +6 -3
- package/package.json +6 -8
|
@@ -134,6 +134,10 @@ import UIKit
|
|
|
134
134
|
case pathTraversal
|
|
135
135
|
}
|
|
136
136
|
|
|
137
|
+
static func containsPathTraversalSegment(_ relativePath: String) -> Bool {
|
|
138
|
+
return relativePath.split(separator: "/").contains(where: { $0 == ".." })
|
|
139
|
+
}
|
|
140
|
+
|
|
137
141
|
static func resolvePathInsideDirectory(baseDirectory: URL, relativePath: String) throws -> URL {
|
|
138
142
|
if relativePath.isEmpty {
|
|
139
143
|
throw SecurePathError.emptyPath
|
|
@@ -141,6 +145,9 @@ import UIKit
|
|
|
141
145
|
if relativePath.contains("\\") || relativePath.contains("\0") {
|
|
142
146
|
throw SecurePathError.windowsPath
|
|
143
147
|
}
|
|
148
|
+
if containsPathTraversalSegment(relativePath) {
|
|
149
|
+
throw SecurePathError.pathTraversal
|
|
150
|
+
}
|
|
144
151
|
if (relativePath as NSString).isAbsolutePath {
|
|
145
152
|
throw SecurePathError.absolutePath
|
|
146
153
|
}
|
|
@@ -151,19 +158,41 @@ import UIKit
|
|
|
151
158
|
let canonicalTarget = canonicalBase.appendingPathComponent(relativePath).standardizedFileURL
|
|
152
159
|
let canonicalTargetPath = canonicalTarget.path
|
|
153
160
|
|
|
154
|
-
|
|
161
|
+
// Require a strict child of the base. Equality would accept "." and wipe/write the root.
|
|
162
|
+
if !canonicalTargetPath.hasPrefix(normalizedBasePath) {
|
|
155
163
|
throw SecurePathError.pathTraversal
|
|
156
164
|
}
|
|
157
165
|
|
|
158
166
|
return canonicalTarget
|
|
159
167
|
}
|
|
160
168
|
|
|
169
|
+
static func resolveBundleDirectory(libraryDir: URL, bundleId: String) throws -> URL {
|
|
170
|
+
let bundleRoot = libraryDir.appendingPathComponent("NoCloud/ionic_built_snapshots")
|
|
171
|
+
return try resolvePathInsideDirectory(baseDirectory: bundleRoot, relativePath: bundleId)
|
|
172
|
+
}
|
|
173
|
+
|
|
161
174
|
static func resolveManifestTargetPath(baseDirectory: URL, fileName: String) throws -> URL {
|
|
162
175
|
let isBrotli = fileName.hasSuffix(".br")
|
|
163
176
|
let targetFileName = isBrotli ? String(fileName.dropLast(3)) : fileName
|
|
164
177
|
return try resolvePathInsideDirectory(baseDirectory: baseDirectory, relativePath: targetFileName)
|
|
165
178
|
}
|
|
166
179
|
|
|
180
|
+
static func rememberManifestTarget(_ seenTargets: inout Set<String>, targetFile: URL) -> Bool {
|
|
181
|
+
return seenTargets.insert(targetFile.standardizedFileURL.path).inserted
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
private struct ManifestDownloadTask {
|
|
185
|
+
let fileName: String
|
|
186
|
+
let downloadUrl: String
|
|
187
|
+
let finalFileHash: String
|
|
188
|
+
let isBrotli: Bool
|
|
189
|
+
let destFileName: String
|
|
190
|
+
let destFilePath: URL
|
|
191
|
+
let builtinFilePath: URL
|
|
192
|
+
let cacheFilePath: URL?
|
|
193
|
+
let legacyCacheFilePath: URL?
|
|
194
|
+
}
|
|
195
|
+
|
|
167
196
|
private func isTimedOutError(_ error: Error?) -> Bool {
|
|
168
197
|
guard let nsError = error as NSError? else {
|
|
169
198
|
return false
|
|
@@ -172,7 +201,15 @@ import UIKit
|
|
|
172
201
|
return nsError.domain == NSURLErrorDomain && nsError.code == NSURLErrorTimedOut
|
|
173
202
|
}
|
|
174
203
|
|
|
175
|
-
|
|
204
|
+
// lazy var is not thread-safe; concurrent manifest downloads can race first access when statsUrl is empty.
|
|
205
|
+
private var _alamofireSession: Session?
|
|
206
|
+
private let alamofireSessionLock = NSLock()
|
|
207
|
+
private var alamofireSession: Session {
|
|
208
|
+
alamofireSessionLock.lock()
|
|
209
|
+
defer { alamofireSessionLock.unlock() }
|
|
210
|
+
if let session = _alamofireSession {
|
|
211
|
+
return session
|
|
212
|
+
}
|
|
176
213
|
let configuration = URLSessionConfiguration.ephemeral
|
|
177
214
|
configuration.httpAdditionalHeaders = ["User-Agent": self.userAgent]
|
|
178
215
|
configuration.httpCookieStorage = nil
|
|
@@ -180,8 +217,10 @@ import UIKit
|
|
|
180
217
|
configuration.requestCachePolicy = .reloadIgnoringLocalCacheData
|
|
181
218
|
configuration.urlCache = nil
|
|
182
219
|
configuration.httpMaximumConnectionsPerHost = Self.manifestMaxConcurrentFiles
|
|
183
|
-
|
|
184
|
-
|
|
220
|
+
let session = Session(configuration: configuration)
|
|
221
|
+
_alamofireSession = session
|
|
222
|
+
return session
|
|
223
|
+
}
|
|
185
224
|
private let networkResponseQueue = DispatchQueue(label: "ee.forgr.capacitor-updater.network-response", qos: .utility)
|
|
186
225
|
|
|
187
226
|
public var notifyDownloadRaw: (String, Int, Bool, BundleInfo?) -> Void = { _, _, _, _ in }
|
|
@@ -422,6 +461,18 @@ import UIKit
|
|
|
422
461
|
return String((0..<length).map { _ in letters.randomElement()! })
|
|
423
462
|
}
|
|
424
463
|
|
|
464
|
+
private func requireSessionKeyForEncryptedUpdate(sessionKey: String, versionName: String? = nil) throws {
|
|
465
|
+
if !self.publicKey.isEmpty && !CryptoCipher.isValidSessionKey(sessionKey) {
|
|
466
|
+
logger.error("Public key present but no valid session key provided")
|
|
467
|
+
self.sendStats(action: "session_key_required", versionName: versionName)
|
|
468
|
+
throw NSError(
|
|
469
|
+
domain: "CapgoUpdater",
|
|
470
|
+
code: 1,
|
|
471
|
+
userInfo: [NSLocalizedDescriptionKey: "Session key required when public key is present"]
|
|
472
|
+
)
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
|
|
425
476
|
public func setPublicKey(_ publicKey: String) {
|
|
426
477
|
// Empty string means no encryption - proceed normally
|
|
427
478
|
if publicKey.isEmpty {
|
|
@@ -953,7 +1004,13 @@ import UIKit
|
|
|
953
1004
|
/// `manifest` must only contain entries the caller already checksum-verified
|
|
954
1005
|
/// (as `downloadManifest` does) — the hashes are trusted as-is, not re-checked.
|
|
955
1006
|
func populateDeltaCache(for id: String, manifest: [ManifestEntry]? = nil, sessionKey: String = "") {
|
|
956
|
-
let bundleDir
|
|
1007
|
+
let bundleDir: URL
|
|
1008
|
+
do {
|
|
1009
|
+
bundleDir = try self.getBundleDirectory(id: id)
|
|
1010
|
+
} catch {
|
|
1011
|
+
logger.debug("Skip delta cache population: invalid bundle id")
|
|
1012
|
+
return
|
|
1013
|
+
}
|
|
957
1014
|
let fileManager = FileManager.default
|
|
958
1015
|
|
|
959
1016
|
guard fileManager.fileExists(atPath: bundleDir.path) else {
|
|
@@ -1213,7 +1270,10 @@ import UIKit
|
|
|
1213
1270
|
guard var fileHash = entry.file_hash, !fileHash.isEmpty else {
|
|
1214
1271
|
return nil
|
|
1215
1272
|
}
|
|
1216
|
-
if !self.publicKey.isEmpty
|
|
1273
|
+
if !self.publicKey.isEmpty {
|
|
1274
|
+
if !CryptoCipher.isValidSessionKey(sessionKey) {
|
|
1275
|
+
return nil
|
|
1276
|
+
}
|
|
1217
1277
|
do {
|
|
1218
1278
|
fileHash = try CryptoCipher.decryptChecksum(checksum: fileHash, publicKey: self.publicKey)
|
|
1219
1279
|
} catch {
|
|
@@ -1374,10 +1434,11 @@ import UIKit
|
|
|
1374
1434
|
}
|
|
1375
1435
|
|
|
1376
1436
|
public func downloadManifest(manifest: [ManifestEntry], version: String, sessionKey: String, link: String? = nil, comment: String? = nil) throws -> BundleInfo {
|
|
1437
|
+
try self.requireSessionKeyForEncryptedUpdate(sessionKey: sessionKey, versionName: version)
|
|
1377
1438
|
try self.runBeforeDownload()
|
|
1378
1439
|
let id = self.randomString(length: 10)
|
|
1379
1440
|
logger.info("downloadManifest start \(id)")
|
|
1380
|
-
let destFolder = self.getBundleDirectory(id: id)
|
|
1441
|
+
let destFolder = try self.getBundleDirectory(id: id)
|
|
1381
1442
|
let builtinFolder = self.builtinFolderURL()
|
|
1382
1443
|
|
|
1383
1444
|
// Check disk space before starting manifest download (estimate 100KB per file, minimum 50MB)
|
|
@@ -1406,8 +1467,8 @@ import UIKit
|
|
|
1406
1467
|
var downloadError: Error?
|
|
1407
1468
|
let errorLock = NSLock()
|
|
1408
1469
|
|
|
1409
|
-
|
|
1410
|
-
var
|
|
1470
|
+
var tasks: [ManifestDownloadTask] = []
|
|
1471
|
+
var seenTargets = Set<String>()
|
|
1411
1472
|
|
|
1412
1473
|
for entry in manifest {
|
|
1413
1474
|
guard let fileName = entry.file_name,
|
|
@@ -1448,7 +1509,23 @@ import UIKit
|
|
|
1448
1509
|
var fileHash = entryFileHash
|
|
1449
1510
|
|
|
1450
1511
|
// Decrypt checksum if needed (done before creating operation)
|
|
1451
|
-
if !self.publicKey.isEmpty
|
|
1512
|
+
if !self.publicKey.isEmpty {
|
|
1513
|
+
if !CryptoCipher.isValidSessionKey(sessionKey) {
|
|
1514
|
+
let error = NSError(
|
|
1515
|
+
domain: "CapgoUpdater",
|
|
1516
|
+
code: 1,
|
|
1517
|
+
userInfo: [NSLocalizedDescriptionKey: "Session key required when public key is present"]
|
|
1518
|
+
)
|
|
1519
|
+
self.sendStats(action: "session_key_required", versionName: version)
|
|
1520
|
+
errorLock.lock()
|
|
1521
|
+
if downloadError == nil {
|
|
1522
|
+
downloadError = error
|
|
1523
|
+
}
|
|
1524
|
+
errorLock.unlock()
|
|
1525
|
+
hasError.value = true
|
|
1526
|
+
logger.error("Public key present but no valid session key provided")
|
|
1527
|
+
continue
|
|
1528
|
+
}
|
|
1452
1529
|
do {
|
|
1453
1530
|
fileHash = try CryptoCipher.decryptChecksum(checksum: fileHash, publicKey: self.publicKey)
|
|
1454
1531
|
} catch {
|
|
@@ -1479,6 +1556,24 @@ import UIKit
|
|
|
1479
1556
|
do {
|
|
1480
1557
|
destFilePath = try Self.resolveManifestTargetPath(baseDirectory: destFolder, fileName: fileName)
|
|
1481
1558
|
builtinFilePath = try Self.resolveManifestTargetPath(baseDirectory: builtinFolder, fileName: fileName)
|
|
1559
|
+
if !Self.rememberManifestTarget(&seenTargets, targetFile: destFilePath) {
|
|
1560
|
+
logger.error("Duplicate manifest target path: \(fileName)")
|
|
1561
|
+
self.sendStats(action: "manifest_path_fail", versionName: "\(version):\(fileName)")
|
|
1562
|
+
let error = NSError(
|
|
1563
|
+
domain: "ManifestEntryError",
|
|
1564
|
+
code: 3,
|
|
1565
|
+
userInfo: [
|
|
1566
|
+
NSLocalizedDescriptionKey: "Duplicate manifest target path for \(fileName)"
|
|
1567
|
+
]
|
|
1568
|
+
)
|
|
1569
|
+
errorLock.lock()
|
|
1570
|
+
if downloadError == nil {
|
|
1571
|
+
downloadError = error
|
|
1572
|
+
}
|
|
1573
|
+
errorLock.unlock()
|
|
1574
|
+
hasError.value = true
|
|
1575
|
+
continue
|
|
1576
|
+
}
|
|
1482
1577
|
} catch {
|
|
1483
1578
|
logger.error("Invalid manifest file path: \(fileName)")
|
|
1484
1579
|
self.sendStats(action: "manifest_path_fail", versionName: "\(version):\(fileName)")
|
|
@@ -1491,8 +1586,40 @@ import UIKit
|
|
|
1491
1586
|
continue
|
|
1492
1587
|
}
|
|
1493
1588
|
|
|
1494
|
-
|
|
1495
|
-
|
|
1589
|
+
tasks.append(
|
|
1590
|
+
ManifestDownloadTask(
|
|
1591
|
+
fileName: fileName,
|
|
1592
|
+
downloadUrl: downloadUrl,
|
|
1593
|
+
finalFileHash: finalFileHash,
|
|
1594
|
+
isBrotli: isBrotli,
|
|
1595
|
+
destFileName: destFileName,
|
|
1596
|
+
destFilePath: destFilePath,
|
|
1597
|
+
builtinFilePath: builtinFilePath,
|
|
1598
|
+
cacheFilePath: cacheFilePath,
|
|
1599
|
+
legacyCacheFilePath: legacyCacheFilePath
|
|
1600
|
+
)
|
|
1601
|
+
)
|
|
1602
|
+
}
|
|
1603
|
+
|
|
1604
|
+
if hasError.value {
|
|
1605
|
+
let resolvedError = downloadError ?? NSError(
|
|
1606
|
+
domain: "ManifestDownloadError",
|
|
1607
|
+
code: 1,
|
|
1608
|
+
userInfo: [NSLocalizedDescriptionKey: "Manifest download failed due to invalid or missing entries"]
|
|
1609
|
+
)
|
|
1610
|
+
let errorBundle = bundleInfo.setStatus(status: BundleStatus.ERROR.storedValue)
|
|
1611
|
+
self.saveBundleInfo(id: id, bundle: errorBundle)
|
|
1612
|
+
throw resolvedError
|
|
1613
|
+
}
|
|
1614
|
+
|
|
1615
|
+
var operations: [Operation] = []
|
|
1616
|
+
|
|
1617
|
+
for task in tasks {
|
|
1618
|
+
try FileManager.default.createDirectory(
|
|
1619
|
+
at: task.destFilePath.deletingLastPathComponent(),
|
|
1620
|
+
withIntermediateDirectories: true,
|
|
1621
|
+
attributes: nil
|
|
1622
|
+
)
|
|
1496
1623
|
|
|
1497
1624
|
let operation = BlockOperation { [weak self] in
|
|
1498
1625
|
guard let self = self else { return }
|
|
@@ -1500,26 +1627,29 @@ import UIKit
|
|
|
1500
1627
|
|
|
1501
1628
|
do {
|
|
1502
1629
|
// Try builtin first
|
|
1503
|
-
if FileManager.default.fileExists(atPath: builtinFilePath.path) &&
|
|
1504
|
-
|
|
1505
|
-
self.
|
|
1630
|
+
if FileManager.default.fileExists(atPath: task.builtinFilePath.path) &&
|
|
1631
|
+
self.verifyChecksum(file: task.builtinFilePath, expectedHash: task.finalFileHash) {
|
|
1632
|
+
try self.copyItemReplacing(from: task.builtinFilePath, to: task.destFilePath)
|
|
1633
|
+
self.logger.info("downloadManifest \(task.fileName) using builtin file \(id)")
|
|
1506
1634
|
}
|
|
1507
1635
|
// Try cache
|
|
1508
1636
|
else if
|
|
1509
|
-
(cacheFilePath != nil &&
|
|
1510
|
-
|
|
1511
|
-
|
|
1637
|
+
(task.cacheFilePath != nil &&
|
|
1638
|
+
self.tryCopyFromCache(from: task.cacheFilePath!, to: task.destFilePath, expectedHash: task.finalFileHash)) ||
|
|
1639
|
+
(task.legacyCacheFilePath != nil &&
|
|
1640
|
+
self.tryCopyFromCache(from: task.legacyCacheFilePath!, to: task.destFilePath, expectedHash: task.finalFileHash)) {
|
|
1641
|
+
self.logger.info("downloadManifest \(task.fileName) copy from cache \(id)")
|
|
1512
1642
|
}
|
|
1513
1643
|
// Download
|
|
1514
1644
|
else {
|
|
1515
1645
|
try self.downloadManifestFile(
|
|
1516
|
-
downloadUrl: downloadUrl,
|
|
1517
|
-
destFilePath: destFilePath,
|
|
1518
|
-
cacheFilePath: cacheFilePath,
|
|
1519
|
-
fileHash: finalFileHash,
|
|
1520
|
-
fileName: fileName,
|
|
1521
|
-
destFileName: destFileName,
|
|
1522
|
-
isBrotli: isBrotli,
|
|
1646
|
+
downloadUrl: task.downloadUrl,
|
|
1647
|
+
destFilePath: task.destFilePath,
|
|
1648
|
+
cacheFilePath: task.cacheFilePath,
|
|
1649
|
+
fileHash: task.finalFileHash,
|
|
1650
|
+
fileName: task.fileName,
|
|
1651
|
+
destFileName: task.destFileName,
|
|
1652
|
+
isBrotli: task.isBrotli,
|
|
1523
1653
|
sessionKey: sessionKey,
|
|
1524
1654
|
version: version,
|
|
1525
1655
|
bundleId: id
|
|
@@ -1537,8 +1667,8 @@ import UIKit
|
|
|
1537
1667
|
}
|
|
1538
1668
|
errorLock.unlock()
|
|
1539
1669
|
hasError.value = true
|
|
1540
|
-
self.logger.error("Manifest file download failed: \(fileName)")
|
|
1541
|
-
self.logger.debug("Bundle: \(id), File: \(fileName), Error: \(error.localizedDescription)")
|
|
1670
|
+
self.logger.error("Manifest file download failed: \(task.fileName)")
|
|
1671
|
+
self.logger.debug("Bundle: \(id), File: \(task.fileName), Error: \(error.localizedDescription)")
|
|
1542
1672
|
}
|
|
1543
1673
|
}
|
|
1544
1674
|
|
|
@@ -1675,7 +1805,7 @@ import UIKit
|
|
|
1675
1805
|
|
|
1676
1806
|
do {
|
|
1677
1807
|
var source = partialURL
|
|
1678
|
-
if !self.publicKey.isEmpty &&
|
|
1808
|
+
if !self.publicKey.isEmpty && CryptoCipher.isValidSessionKey(sessionKey) {
|
|
1679
1809
|
let work = cacheFolder.appendingPathComponent("work_\(UUID().uuidString)_\((fileName as NSString).lastPathComponent)")
|
|
1680
1810
|
try FileManager.default.copyItem(at: partialURL, to: work)
|
|
1681
1811
|
workURL = work
|
|
@@ -1977,6 +2107,7 @@ import UIKit
|
|
|
1977
2107
|
}
|
|
1978
2108
|
|
|
1979
2109
|
public func download(url: URL, version: String, sessionKey: String, link: String? = nil, comment: String? = nil) throws -> BundleInfo {
|
|
2110
|
+
try self.requireSessionKeyForEncryptedUpdate(sessionKey: sessionKey, versionName: version)
|
|
1980
2111
|
try self.runBeforeDownload()
|
|
1981
2112
|
let id: String = self.randomString(length: 10)
|
|
1982
2113
|
// Each download uses its own temp files keyed by bundle ID to prevent collisions
|
|
@@ -2257,6 +2388,15 @@ import UIKit
|
|
|
2257
2388
|
self.deleteLock.lock()
|
|
2258
2389
|
defer { self.deleteLock.unlock() }
|
|
2259
2390
|
|
|
2391
|
+
let destPersist: URL
|
|
2392
|
+
do {
|
|
2393
|
+
destPersist = try self.getBundleDirectory(id: id)
|
|
2394
|
+
} catch {
|
|
2395
|
+
logger.error("Cannot delete bundle with invalid id")
|
|
2396
|
+
logger.debug("Bundle ID: \(id), Error: \(error.localizedDescription)")
|
|
2397
|
+
return false
|
|
2398
|
+
}
|
|
2399
|
+
|
|
2260
2400
|
let deleted: BundleInfo = self.getBundleInfo(id: id)
|
|
2261
2401
|
if deleted.isBuiltin() || self.getCurrentBundleId() == id {
|
|
2262
2402
|
logger.info("Cannot delete current or builtin bundle")
|
|
@@ -2285,7 +2425,6 @@ import UIKit
|
|
|
2285
2425
|
return false
|
|
2286
2426
|
}
|
|
2287
2427
|
|
|
2288
|
-
let destPersist: URL = libraryDir.appendingPathComponent(bundleDirectory).appendingPathComponent(id)
|
|
2289
2428
|
let hadRegistry = self.hasStoredBundleInfo(id: id)
|
|
2290
2429
|
let hadFolder = FileManager.default.fileExists(atPath: destPersist.path)
|
|
2291
2430
|
if !hadRegistry && !hadFolder {
|
|
@@ -2589,8 +2728,8 @@ import UIKit
|
|
|
2589
2728
|
}
|
|
2590
2729
|
}
|
|
2591
2730
|
|
|
2592
|
-
public func getBundleDirectory(id: String) -> URL {
|
|
2593
|
-
return
|
|
2731
|
+
public func getBundleDirectory(id: String) throws -> URL {
|
|
2732
|
+
return try Self.resolveBundleDirectory(libraryDir: libraryDir, bundleId: id)
|
|
2594
2733
|
}
|
|
2595
2734
|
|
|
2596
2735
|
struct ResetState {
|
|
@@ -2644,7 +2783,12 @@ import UIKit
|
|
|
2644
2783
|
}
|
|
2645
2784
|
|
|
2646
2785
|
private func bundleExists(id: String) -> Bool {
|
|
2647
|
-
let destPersist: URL
|
|
2786
|
+
let destPersist: URL
|
|
2787
|
+
do {
|
|
2788
|
+
destPersist = try self.getBundleDirectory(id: id)
|
|
2789
|
+
} catch {
|
|
2790
|
+
return false
|
|
2791
|
+
}
|
|
2648
2792
|
let indexPersist: URL = destPersist.appendingPathComponent("index.html")
|
|
2649
2793
|
let bundleIndo: BundleInfo = self.getBundleInfo(id: id)
|
|
2650
2794
|
if
|
|
@@ -2667,7 +2811,12 @@ import UIKit
|
|
|
2667
2811
|
}
|
|
2668
2812
|
if bundleExists(id: id) {
|
|
2669
2813
|
let currentBundleName = self.getCurrentBundle().getVersionName()
|
|
2670
|
-
|
|
2814
|
+
guard let bundleDir = try? self.getBundleDirectory(id: id) else {
|
|
2815
|
+
self.setBundleStatus(id: id, status: BundleStatus.ERROR)
|
|
2816
|
+
self.sendStats(action: "set_fail", versionName: newBundle.getVersionName())
|
|
2817
|
+
return false
|
|
2818
|
+
}
|
|
2819
|
+
self.setCurrentBundle(bundle: bundleDir.path)
|
|
2671
2820
|
self.setBundleStatus(id: id, status: BundleStatus.PENDING)
|
|
2672
2821
|
self.sendStats(action: "set", versionName: newBundle.getVersionName(), oldVersionName: currentBundleName)
|
|
2673
2822
|
return true
|
|
@@ -2681,7 +2830,10 @@ import UIKit
|
|
|
2681
2830
|
guard !bundle.isBuiltin(), bundleExists(id: bundle.getId()) else {
|
|
2682
2831
|
return false
|
|
2683
2832
|
}
|
|
2684
|
-
|
|
2833
|
+
guard let bundleDir = try? self.getBundleDirectory(id: bundle.getId()) else {
|
|
2834
|
+
return false
|
|
2835
|
+
}
|
|
2836
|
+
self.setCurrentBundle(bundle: bundleDir.path)
|
|
2685
2837
|
return true
|
|
2686
2838
|
}
|
|
2687
2839
|
|
|
@@ -2696,7 +2848,10 @@ import UIKit
|
|
|
2696
2848
|
guard bundleExists(id: bundle.getId()) else {
|
|
2697
2849
|
return false
|
|
2698
2850
|
}
|
|
2699
|
-
|
|
2851
|
+
guard let bundleDir = try? self.getBundleDirectory(id: bundle.getId()) else {
|
|
2852
|
+
return false
|
|
2853
|
+
}
|
|
2854
|
+
self.setCurrentBundle(bundle: bundleDir.path)
|
|
2700
2855
|
return true
|
|
2701
2856
|
}
|
|
2702
2857
|
|
|
@@ -161,42 +161,43 @@ public struct CryptoCipher {
|
|
|
161
161
|
let bufferSize = checksumBufferBytes()
|
|
162
162
|
var sha256 = SHA256()
|
|
163
163
|
|
|
164
|
+
let fileHandle: FileHandle
|
|
164
165
|
do {
|
|
165
|
-
|
|
166
|
+
fileHandle = try FileHandle(forReadingFrom: filePath)
|
|
167
|
+
} catch {
|
|
168
|
+
logger.error("Cannot open file for checksum calculation")
|
|
169
|
+
logger.debug("Path: \(filePath.path), Error: \(error)")
|
|
170
|
+
return ""
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
defer {
|
|
166
174
|
do {
|
|
167
|
-
|
|
175
|
+
try fileHandle.close()
|
|
168
176
|
} catch {
|
|
169
|
-
logger.error("
|
|
170
|
-
logger.debug("
|
|
171
|
-
return ""
|
|
177
|
+
logger.error("Error closing file during checksum")
|
|
178
|
+
logger.debug("Error: \(error)")
|
|
172
179
|
}
|
|
180
|
+
}
|
|
173
181
|
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
182
|
+
while autoreleasepool(invoking: {
|
|
183
|
+
let fileData: Data
|
|
184
|
+
do {
|
|
185
|
+
fileData = try fileHandle.read(upToCount: bufferSize) ?? Data()
|
|
186
|
+
} catch {
|
|
187
|
+
logger.error("Error reading file during checksum")
|
|
188
|
+
logger.debug("Error: \(error)")
|
|
189
|
+
return false
|
|
181
190
|
}
|
|
182
191
|
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
return false // End of file
|
|
191
|
-
}
|
|
192
|
-
}) {}
|
|
192
|
+
if fileData.count > 0 {
|
|
193
|
+
sha256.update(data: fileData)
|
|
194
|
+
return true // Continue
|
|
195
|
+
} else {
|
|
196
|
+
return false // End of file
|
|
197
|
+
}
|
|
198
|
+
}) {}
|
|
193
199
|
|
|
194
|
-
|
|
195
|
-
} catch {
|
|
196
|
-
logger.error("Cannot calculate checksum")
|
|
197
|
-
logger.debug("Path: \(filePath.path), Error: \(error)")
|
|
198
|
-
return ""
|
|
199
|
-
}
|
|
200
|
+
return hexString(from: sha256)
|
|
200
201
|
}
|
|
201
202
|
|
|
202
203
|
final class RunningChecksum {
|
|
@@ -215,8 +216,7 @@ public struct CryptoCipher {
|
|
|
215
216
|
}
|
|
216
217
|
|
|
217
218
|
static func hexString(from sha256: SHA256) -> String {
|
|
218
|
-
|
|
219
|
-
return copy.finalize().compactMap { String(format: "%02x", $0) }.joined()
|
|
219
|
+
return sha256.finalize().compactMap { String(format: "%02x", $0) }.joined()
|
|
220
220
|
}
|
|
221
221
|
|
|
222
222
|
static func shortPathKey(_ fileName: String) -> String {
|
|
@@ -225,8 +225,16 @@ public struct CryptoCipher {
|
|
|
225
225
|
return String(hexString(from: sha256).prefix(16))
|
|
226
226
|
}
|
|
227
227
|
|
|
228
|
+
public static func isValidSessionKey(_ sessionKey: String) -> Bool {
|
|
229
|
+
if sessionKey.isEmpty {
|
|
230
|
+
return false
|
|
231
|
+
}
|
|
232
|
+
let sessionKeyParts = sessionKey.components(separatedBy: ":")
|
|
233
|
+
return sessionKeyParts.count == 2 && !sessionKeyParts[0].isEmpty && !sessionKeyParts[1].isEmpty
|
|
234
|
+
}
|
|
235
|
+
|
|
228
236
|
public static func decryptFile(filePath: URL, publicKey: String, sessionKey: String, version: String) throws {
|
|
229
|
-
if publicKey.isEmpty || sessionKey
|
|
237
|
+
if publicKey.isEmpty || !isValidSessionKey(sessionKey) {
|
|
230
238
|
logger.info("Encryption not set, no public key or session, ignored")
|
|
231
239
|
return
|
|
232
240
|
}
|
|
@@ -151,59 +151,34 @@ public class DelayUpdateUtils {
|
|
|
151
151
|
}
|
|
152
152
|
|
|
153
153
|
public func setMultiDelay(delayConditions: String) -> Bool {
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
return true
|
|
159
|
-
} catch {
|
|
160
|
-
logger.error("Failed to delay update, [Error calling 'setMultiDelay()']: \(error)")
|
|
161
|
-
return false
|
|
162
|
-
}
|
|
154
|
+
UserDefaults.standard.set(delayConditions, forKey: DelayUpdateUtils.DELAY_CONDITION_PREFERENCES)
|
|
155
|
+
UserDefaults.standard.synchronize()
|
|
156
|
+
logger.info("Delay update saved")
|
|
157
|
+
return true
|
|
163
158
|
}
|
|
164
159
|
|
|
165
160
|
public func setBackgroundTimestamp(_ backgroundTimestamp: Int64) {
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
logger.info("Background timestamp saved")
|
|
170
|
-
} catch {
|
|
171
|
-
logger.error("Failed to save background timestamp, [Error calling 'setBackgroundTimestamp()']: \(error)")
|
|
172
|
-
}
|
|
161
|
+
UserDefaults.standard.set(backgroundTimestamp, forKey: DelayUpdateUtils.BACKGROUND_TIMESTAMP_KEY)
|
|
162
|
+
UserDefaults.standard.synchronize()
|
|
163
|
+
logger.info("Background timestamp saved")
|
|
173
164
|
}
|
|
174
165
|
|
|
175
166
|
public func unsetBackgroundTimestamp() {
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
logger.info("Background timestamp removed")
|
|
180
|
-
} catch {
|
|
181
|
-
// swiftlint:disable:next line_length
|
|
182
|
-
logger.error("Failed to remove background timestamp, [Error calling 'unsetBackgroundTimestamp()']: \(error)")
|
|
183
|
-
}
|
|
167
|
+
UserDefaults.standard.removeObject(forKey: DelayUpdateUtils.BACKGROUND_TIMESTAMP_KEY)
|
|
168
|
+
UserDefaults.standard.synchronize()
|
|
169
|
+
logger.info("Background timestamp removed")
|
|
184
170
|
}
|
|
185
171
|
|
|
186
172
|
private func getBackgroundTimestamp() -> Int64 {
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
let timestamp = UserDefaults.standard.object(forKey: key) as? Int64 ?? 0
|
|
190
|
-
return timestamp
|
|
191
|
-
} catch {
|
|
192
|
-
logger.error("Failed to get background timestamp, [Error calling 'getBackgroundTimestamp()']: \(error)")
|
|
193
|
-
return 0
|
|
194
|
-
}
|
|
173
|
+
let key = DelayUpdateUtils.BACKGROUND_TIMESTAMP_KEY
|
|
174
|
+
return UserDefaults.standard.object(forKey: key) as? Int64 ?? 0
|
|
195
175
|
}
|
|
196
176
|
|
|
197
177
|
public func cancelDelay(source: String) -> Bool {
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
return true
|
|
203
|
-
} catch {
|
|
204
|
-
logger.error("Failed to cancel update delay: \(error)")
|
|
205
|
-
return false
|
|
206
|
-
}
|
|
178
|
+
UserDefaults.standard.removeObject(forKey: DelayUpdateUtils.DELAY_CONDITION_PREFERENCES)
|
|
179
|
+
UserDefaults.standard.synchronize()
|
|
180
|
+
logger.info("All delays canceled from \(source)")
|
|
181
|
+
return true
|
|
207
182
|
}
|
|
208
183
|
|
|
209
184
|
// MARK: - Helper methods
|
|
@@ -359,7 +359,10 @@ extension UIWindow {
|
|
|
359
359
|
if !next.isBuiltin() {
|
|
360
360
|
plugin.logger.info("Resetting to: \(next.toString())")
|
|
361
361
|
_ = updater.set(bundle: next)
|
|
362
|
-
let destHot = updater.getBundleDirectory(id: next.getId())
|
|
362
|
+
guard let destHot = try? updater.getBundleDirectory(id: next.getId()) else {
|
|
363
|
+
resetBuiltin()
|
|
364
|
+
return
|
|
365
|
+
}
|
|
363
366
|
plugin.logger.info("Reloading \(next.toString())")
|
|
364
367
|
bridge.setServerBasePath(destHot.path)
|
|
365
368
|
} else {
|
|
@@ -792,9 +795,9 @@ extension UIWindow {
|
|
|
792
795
|
message: "Update downloaded! Reload to apply version \(latest.version)?",
|
|
793
796
|
plugin: plugin,
|
|
794
797
|
bridge: bridge,
|
|
795
|
-
onReload: {
|
|
798
|
+
onReload: {
|
|
796
799
|
_ = updater.set(bundle: bundle)
|
|
797
|
-
_ = plugin
|
|
800
|
+
_ = plugin._reload()
|
|
798
801
|
}
|
|
799
802
|
)
|
|
800
803
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@capgo/capacitor-updater",
|
|
3
|
-
"version": "5.51.
|
|
3
|
+
"version": "5.51.23",
|
|
4
4
|
"license": "MPL-2.0",
|
|
5
5
|
"description": "Live update for capacitor apps",
|
|
6
6
|
"main": "dist/plugin.cjs.js",
|
|
@@ -63,7 +63,7 @@
|
|
|
63
63
|
"test:maestro:ios:smoke": "./scripts/test-maestro-ios.sh",
|
|
64
64
|
"lint": "bun run eslint && bun run prettier -- --check && bun run swiftlint -- lint",
|
|
65
65
|
"fmt": "bun run eslint -- --fix && bun run prettier -- --write && bun run swiftlint -- --fix --format",
|
|
66
|
-
"eslint": "eslint .
|
|
66
|
+
"eslint": "eslint .",
|
|
67
67
|
"prettier": "prettier-pretty-check \"**/*.{css,html,ts,js,java}\" --plugin=prettier-plugin-java",
|
|
68
68
|
"swiftlint": "node-swiftlint",
|
|
69
69
|
"docgen": "node scripts/generate-docs.js",
|
|
@@ -87,12 +87,13 @@
|
|
|
87
87
|
"@capacitor/core": "^5.0.0",
|
|
88
88
|
"@capacitor/docgen": "^0.3.0",
|
|
89
89
|
"@capacitor/ios": "^5.0.0",
|
|
90
|
-
"@ionic/eslint-config": "^0.
|
|
90
|
+
"@ionic/eslint-config": "^0.5.0",
|
|
91
|
+
"@typescript-eslint/eslint-plugin": "^8.70.0",
|
|
92
|
+
"@typescript-eslint/parser": "^8.70.0",
|
|
91
93
|
"@ionic/prettier-config": "^4.0.0",
|
|
92
94
|
"@ionic/swiftlint-config": "^2.0.0",
|
|
93
95
|
"@types/node": "^26.0.0",
|
|
94
|
-
"eslint": "^
|
|
95
|
-
"eslint-plugin-import": "^2.32.0",
|
|
96
|
+
"eslint": "^10.0.0",
|
|
96
97
|
"husky": "^9.1.7",
|
|
97
98
|
"prettier": "^3.6.2",
|
|
98
99
|
"prettier-plugin-java": "^2.7.4",
|
|
@@ -107,9 +108,6 @@
|
|
|
107
108
|
},
|
|
108
109
|
"prettier": "@ionic/prettier-config",
|
|
109
110
|
"swiftlint": "@ionic/swiftlint-config",
|
|
110
|
-
"eslintConfig": {
|
|
111
|
-
"extends": "@ionic/eslint-config/recommended"
|
|
112
|
-
},
|
|
113
111
|
"capacitor": {
|
|
114
112
|
"ios": {
|
|
115
113
|
"src": "ios"
|