@capgo/capacitor-updater 9.0.0 → 9.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/CapgoCapacitorUpdater.podspec +3 -6
- package/Package.swift +30 -0
- package/README.md +2406 -291
- package/android/build.gradle +37 -17
- package/android/consumer-rules.pro +48 -0
- package/android/proguard-rules.pro +23 -0
- package/android/src/main/AndroidManifest.xml +0 -1
- package/android/src/main/java/ee/forgr/capacitor_updater/AndroidAppExitReporter.java +92 -0
- package/android/src/main/java/ee/forgr/capacitor_updater/AppLifecycleObserver.java +115 -0
- package/android/src/main/java/ee/forgr/capacitor_updater/BundleInfo.java +227 -195
- package/android/src/main/java/ee/forgr/capacitor_updater/BundleStatus.java +24 -23
- package/android/src/main/java/ee/forgr/capacitor_updater/Callback.java +13 -0
- package/android/src/main/java/ee/forgr/capacitor_updater/CapacitorUpdaterPlugin.java +7927 -1243
- package/android/src/main/java/ee/forgr/capacitor_updater/CapgoUpdater.java +5785 -0
- package/android/src/main/java/ee/forgr/capacitor_updater/CryptoCipher.java +564 -121
- package/android/src/main/java/ee/forgr/capacitor_updater/DataManager.java +44 -0
- package/android/src/main/java/ee/forgr/capacitor_updater/DelayCondition.java +43 -49
- package/android/src/main/java/ee/forgr/capacitor_updater/DelayUntilNext.java +4 -4
- package/android/src/main/java/ee/forgr/capacitor_updater/DelayUpdateUtils.java +427 -0
- package/android/src/main/java/ee/forgr/capacitor_updater/DeviceIdHelper.java +230 -0
- package/android/src/main/java/ee/forgr/capacitor_updater/DownloadService.java +2041 -118
- package/android/src/main/java/ee/forgr/capacitor_updater/DownloadWorkerManager.java +301 -0
- package/android/src/main/java/ee/forgr/capacitor_updater/HeadlessUpdateWorker.java +569 -0
- package/android/src/main/java/ee/forgr/capacitor_updater/Http3.java +436 -0
- package/android/src/main/java/ee/forgr/capacitor_updater/HttpEngineTransport.java +604 -0
- package/android/src/main/java/ee/forgr/capacitor_updater/InternalUtils.java +79 -0
- package/android/src/main/java/ee/forgr/capacitor_updater/Logger.java +419 -0
- package/android/src/main/java/ee/forgr/capacitor_updater/NativeUpdatePrompt.java +303 -0
- package/android/src/main/java/ee/forgr/capacitor_updater/ShakeDetector.java +72 -0
- package/android/src/main/java/ee/forgr/capacitor_updater/ShakeMenu.java +963 -0
- package/android/src/main/java/ee/forgr/capacitor_updater/StatsBatchFailureDiagnostics.java +40 -0
- package/android/src/main/java/ee/forgr/capacitor_updater/ThreeFingerPinchDetector.java +323 -0
- package/android/src/main/java/ee/forgr/capacitor_updater/Version.java +306 -0
- package/dist/docs.json +4431 -840
- package/dist/esm/definitions.d.ts +2641 -225
- package/dist/esm/definitions.js +103 -1
- package/dist/esm/definitions.js.map +1 -1
- package/dist/esm/history.d.ts +1 -0
- package/dist/esm/history.js +283 -0
- package/dist/esm/history.js.map +1 -0
- package/dist/esm/index.d.ts +3 -2
- package/dist/esm/index.js +5 -4
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/web.d.ts +53 -42
- package/dist/esm/web.js +180 -37
- package/dist/esm/web.js.map +1 -1
- package/dist/plugin.cjs.js +570 -37
- package/dist/plugin.cjs.js.map +1 -1
- package/dist/plugin.js +570 -37
- package/dist/plugin.js.map +1 -1
- package/ios/Sources/CapacitorUpdaterPlugin/AES.swift +262 -0
- package/ios/Sources/CapacitorUpdaterPlugin/AppHealthTracker.swift +82 -0
- package/ios/Sources/CapacitorUpdaterPlugin/BundleInfo.swift +185 -0
- package/ios/Sources/CapacitorUpdaterPlugin/BundleStatus.swift +127 -0
- package/ios/Sources/CapacitorUpdaterPlugin/CapacitorUpdaterPlugin.swift +6813 -0
- package/ios/Sources/CapacitorUpdaterPlugin/CapgoRawRsa.swift +36 -0
- package/ios/Sources/CapacitorUpdaterPlugin/CapgoSemanticVersion.swift +200 -0
- package/ios/Sources/CapacitorUpdaterPlugin/CapgoUpdater.swift +5099 -0
- package/ios/Sources/CapacitorUpdaterPlugin/CryptoCipher.swift +387 -0
- package/ios/Sources/CapacitorUpdaterPlugin/DelayUpdateUtils.swift +343 -0
- package/ios/Sources/CapacitorUpdaterPlugin/DeviceIdHelper.swift +120 -0
- package/ios/Sources/CapacitorUpdaterPlugin/InternalUtils.swift +452 -0
- package/ios/Sources/CapacitorUpdaterPlugin/Logger.swift +380 -0
- package/ios/Sources/CapacitorUpdaterPlugin/NativeUpdatePrompt.swift +183 -0
- package/ios/Sources/CapacitorUpdaterPlugin/RSA.swift +96 -0
- package/ios/Sources/CapacitorUpdaterPlugin/RedirectPolicyDelegate.swift +97 -0
- package/ios/Sources/CapacitorUpdaterPlugin/ShakeMenu.swift +876 -0
- package/ios/{Plugin → Sources/CapacitorUpdaterPlugin}/UserDefaultsExtension.swift +0 -2
- package/ios/Sources/CapacitorUpdaterPlugin/WKWebView+CapgoObjcBridge.swift +20 -0
- package/ios/Sources/CapacitorUpdaterPlugin/WebViewStatsReporter.swift +304 -0
- package/ios/Sources/CapacitorUpdaterPlugin/ZipArchiveReader.swift +247 -0
- package/ios/Sources/CapacitorUpdaterPlugin/ZipCentralDirectory.swift +280 -0
- package/ios/Tests/CapacitorUpdaterPluginTests/BuiltinHashesTests.swift +210 -0
- package/ios/Tests/CapacitorUpdaterPluginTests/BundleHardeningTests.swift +292 -0
- package/ios/Tests/CapacitorUpdaterPluginTests/CapacitorUpdaterPluginTests.swift +6533 -0
- package/ios/Tests/CapacitorUpdaterPluginTests/CapgoSemanticVersionTests.swift +64 -0
- package/ios/Tests/CapacitorUpdaterPluginTests/ChecksumRequiredTests.swift +156 -0
- package/ios/Tests/CapacitorUpdaterPluginTests/CliCryptoFixtureTests.swift +314 -0
- package/ios/Tests/CapacitorUpdaterPluginTests/HttpsOnlyBuiltinMinimumTests.swift +653 -0
- package/ios/Tests/CapacitorUpdaterPluginTests/InstallPerfTests.swift +174 -0
- package/ios/Tests/CapacitorUpdaterPluginTests/ListChannelsTests.swift +74 -0
- package/ios/Tests/CapacitorUpdaterPluginTests/LoggerSecurityTests.swift +149 -0
- package/ios/Tests/CapacitorUpdaterPluginTests/NativeContractTests.swift +160 -0
- package/ios/Tests/CapacitorUpdaterPluginTests/NetworkTransportTests.swift +1109 -0
- package/ios/Tests/CapacitorUpdaterPluginTests/PopulateDeltaCacheTests.swift +573 -0
- package/ios/Tests/CapacitorUpdaterPluginTests/RedirectPolicyTests.swift +63 -0
- package/ios/Tests/CapacitorUpdaterPluginTests/RsaContractTests.swift +281 -0
- package/ios/Tests/CapacitorUpdaterPluginTests/SessionKeyRequiredTests.swift +196 -0
- package/ios/Tests/CapacitorUpdaterPluginTests/TestZipWriter.swift +235 -0
- package/ios/Tests/CapacitorUpdaterPluginTests/UpdateLifecycleTests.swift +470 -0
- package/ios/Tests/CapacitorUpdaterPluginTests/WebKitOverlayGuardTests.swift +32 -0
- package/ios/Tests/CapacitorUpdaterPluginTests/ZipArchiveReaderTests.swift +302 -0
- package/ios/Tests/CapacitorUpdaterPluginTests/ZipBundleExtractionTests.swift +122 -0
- package/package.json +80 -43
- package/scripts/builtin-hashes-lib.mjs +148 -0
- package/scripts/capacitor-builtin-hashes-hook.mjs +65 -0
- package/scripts/resolve-real-path.mjs +25 -0
- package/android/src/main/java/ee/forgr/capacitor_updater/CapacitorUpdater.java +0 -1130
- package/ios/Plugin/BundleInfo.swift +0 -113
- package/ios/Plugin/BundleStatus.swift +0 -48
- package/ios/Plugin/CapacitorUpdater.swift +0 -858
- package/ios/Plugin/CapacitorUpdaterPlugin.h +0 -10
- package/ios/Plugin/CapacitorUpdaterPlugin.m +0 -27
- package/ios/Plugin/CapacitorUpdaterPlugin.swift +0 -677
- package/ios/Plugin/CryptoCipher.swift +0 -240
- /package/{LICENCE → LICENSE} +0 -0
- /package/ios/{Plugin → Sources/CapacitorUpdaterPlugin}/DelayCondition.swift +0 -0
- /package/ios/{Plugin → Sources/CapacitorUpdaterPlugin}/DelayUntilNext.swift +0 -0
- /package/ios/{Plugin → Sources/CapacitorUpdaterPlugin}/Info.plist +0 -0
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
3
|
+
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
4
|
+
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import Foundation
|
|
8
|
+
|
|
9
|
+
/// URLSession delegate that refuses redirects from HTTPS to plain HTTP unless explicitly allowed.
|
|
10
|
+
/// A refused redirect cancels the task, so callers see a transport error instead of the 3xx body.
|
|
11
|
+
final class RedirectPolicyDelegate: NSObject, URLSessionTaskDelegate {
|
|
12
|
+
private let lock = NSLock()
|
|
13
|
+
private var allowDowngrade = false
|
|
14
|
+
private var httpsOnlyEnabled = true
|
|
15
|
+
/// When true every redirect target must be https, whatever `allowHttpsToHttpRedirect` says.
|
|
16
|
+
var httpsOnly: Bool {
|
|
17
|
+
get {
|
|
18
|
+
lock.lock()
|
|
19
|
+
defer { lock.unlock() }
|
|
20
|
+
return httpsOnlyEnabled
|
|
21
|
+
}
|
|
22
|
+
set {
|
|
23
|
+
lock.lock()
|
|
24
|
+
httpsOnlyEnabled = newValue
|
|
25
|
+
lock.unlock()
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
/// Called when a downgrade redirect is refused. Must not retain the updater strongly.
|
|
29
|
+
var onBlockedRedirect: ((URL?, URL?) -> Void)?
|
|
30
|
+
|
|
31
|
+
var allowHttpsToHttpRedirect: Bool {
|
|
32
|
+
get {
|
|
33
|
+
lock.lock()
|
|
34
|
+
defer { lock.unlock() }
|
|
35
|
+
return allowDowngrade
|
|
36
|
+
}
|
|
37
|
+
set {
|
|
38
|
+
lock.lock()
|
|
39
|
+
allowDowngrade = newValue
|
|
40
|
+
lock.unlock()
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
static func isHttpsToHttpDowngrade(from source: URL?, to target: URL?) -> Bool {
|
|
45
|
+
guard let sourceScheme = source?.scheme?.lowercased(), let targetScheme = target?.scheme?.lowercased() else {
|
|
46
|
+
return false
|
|
47
|
+
}
|
|
48
|
+
return sourceScheme == "https" && targetScheme == "http"
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
func urlSession(
|
|
52
|
+
_: URLSession,
|
|
53
|
+
task: URLSessionTask,
|
|
54
|
+
willPerformHTTPRedirection response: HTTPURLResponse,
|
|
55
|
+
newRequest request: URLRequest,
|
|
56
|
+
completionHandler: @escaping (URLRequest?) -> Void
|
|
57
|
+
) {
|
|
58
|
+
let source = response.url ?? task.currentRequest?.url
|
|
59
|
+
if httpsOnly && request.url?.scheme?.lowercased() != "https" {
|
|
60
|
+
onBlockedRedirect?(source, request.url)
|
|
61
|
+
completionHandler(nil)
|
|
62
|
+
task.cancel()
|
|
63
|
+
return
|
|
64
|
+
}
|
|
65
|
+
if !allowHttpsToHttpRedirect && Self.isHttpsToHttpDowngrade(from: source, to: request.url) {
|
|
66
|
+
onBlockedRedirect?(source, request.url)
|
|
67
|
+
completionHandler(nil)
|
|
68
|
+
task.cancel()
|
|
69
|
+
return
|
|
70
|
+
}
|
|
71
|
+
completionHandler(request)
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/// Task delegate attached only to https bundle and manifest download tasks, to log the negotiated protocol.
|
|
76
|
+
/// The session delegate (`RedirectPolicyDelegate`) does not collect metrics, so plain http downloads and API calls
|
|
77
|
+
/// keep the exact same delegate setup as before. Redirects still reach the session delegate, because this one does not
|
|
78
|
+
/// implement them. Must not retain the updater strongly.
|
|
79
|
+
final class DownloadMetricsDelegate: NSObject, URLSessionTaskDelegate {
|
|
80
|
+
/// Set once when the updater session is created, before any task runs.
|
|
81
|
+
var onMetrics: ((URLSessionTask, URLSessionTaskMetrics) -> Void)?
|
|
82
|
+
|
|
83
|
+
func urlSession(_: URLSession, task: URLSessionTask, didFinishCollecting metrics: URLSessionTaskMetrics) {
|
|
84
|
+
onMetrics?(task, metrics)
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
extension CapgoUpdater {
|
|
89
|
+
/// ALPN name of the last transaction that hit the network ("h3", "h2", "http/1.1"), nil when none did.
|
|
90
|
+
static func networkProtocol(of metrics: URLSessionTaskMetrics) -> String? {
|
|
91
|
+
return networkProtocol(of: metrics.transactionMetrics.map { $0.networkProtocolName })
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
static func networkProtocol(of names: [String?]) -> String? {
|
|
95
|
+
return names.last(where: { !($0 ?? "").isEmpty }) ?? nil
|
|
96
|
+
}
|
|
97
|
+
}
|