@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.
Files changed (109) hide show
  1. package/CapgoCapacitorUpdater.podspec +3 -6
  2. package/Package.swift +30 -0
  3. package/README.md +2406 -291
  4. package/android/build.gradle +37 -17
  5. package/android/consumer-rules.pro +48 -0
  6. package/android/proguard-rules.pro +23 -0
  7. package/android/src/main/AndroidManifest.xml +0 -1
  8. package/android/src/main/java/ee/forgr/capacitor_updater/AndroidAppExitReporter.java +92 -0
  9. package/android/src/main/java/ee/forgr/capacitor_updater/AppLifecycleObserver.java +115 -0
  10. package/android/src/main/java/ee/forgr/capacitor_updater/BundleInfo.java +227 -195
  11. package/android/src/main/java/ee/forgr/capacitor_updater/BundleStatus.java +24 -23
  12. package/android/src/main/java/ee/forgr/capacitor_updater/Callback.java +13 -0
  13. package/android/src/main/java/ee/forgr/capacitor_updater/CapacitorUpdaterPlugin.java +7927 -1243
  14. package/android/src/main/java/ee/forgr/capacitor_updater/CapgoUpdater.java +5785 -0
  15. package/android/src/main/java/ee/forgr/capacitor_updater/CryptoCipher.java +564 -121
  16. package/android/src/main/java/ee/forgr/capacitor_updater/DataManager.java +44 -0
  17. package/android/src/main/java/ee/forgr/capacitor_updater/DelayCondition.java +43 -49
  18. package/android/src/main/java/ee/forgr/capacitor_updater/DelayUntilNext.java +4 -4
  19. package/android/src/main/java/ee/forgr/capacitor_updater/DelayUpdateUtils.java +427 -0
  20. package/android/src/main/java/ee/forgr/capacitor_updater/DeviceIdHelper.java +230 -0
  21. package/android/src/main/java/ee/forgr/capacitor_updater/DownloadService.java +2041 -118
  22. package/android/src/main/java/ee/forgr/capacitor_updater/DownloadWorkerManager.java +301 -0
  23. package/android/src/main/java/ee/forgr/capacitor_updater/HeadlessUpdateWorker.java +569 -0
  24. package/android/src/main/java/ee/forgr/capacitor_updater/Http3.java +436 -0
  25. package/android/src/main/java/ee/forgr/capacitor_updater/HttpEngineTransport.java +604 -0
  26. package/android/src/main/java/ee/forgr/capacitor_updater/InternalUtils.java +79 -0
  27. package/android/src/main/java/ee/forgr/capacitor_updater/Logger.java +419 -0
  28. package/android/src/main/java/ee/forgr/capacitor_updater/NativeUpdatePrompt.java +303 -0
  29. package/android/src/main/java/ee/forgr/capacitor_updater/ShakeDetector.java +72 -0
  30. package/android/src/main/java/ee/forgr/capacitor_updater/ShakeMenu.java +963 -0
  31. package/android/src/main/java/ee/forgr/capacitor_updater/StatsBatchFailureDiagnostics.java +40 -0
  32. package/android/src/main/java/ee/forgr/capacitor_updater/ThreeFingerPinchDetector.java +323 -0
  33. package/android/src/main/java/ee/forgr/capacitor_updater/Version.java +306 -0
  34. package/dist/docs.json +4431 -840
  35. package/dist/esm/definitions.d.ts +2641 -225
  36. package/dist/esm/definitions.js +103 -1
  37. package/dist/esm/definitions.js.map +1 -1
  38. package/dist/esm/history.d.ts +1 -0
  39. package/dist/esm/history.js +283 -0
  40. package/dist/esm/history.js.map +1 -0
  41. package/dist/esm/index.d.ts +3 -2
  42. package/dist/esm/index.js +5 -4
  43. package/dist/esm/index.js.map +1 -1
  44. package/dist/esm/web.d.ts +53 -42
  45. package/dist/esm/web.js +180 -37
  46. package/dist/esm/web.js.map +1 -1
  47. package/dist/plugin.cjs.js +570 -37
  48. package/dist/plugin.cjs.js.map +1 -1
  49. package/dist/plugin.js +570 -37
  50. package/dist/plugin.js.map +1 -1
  51. package/ios/Sources/CapacitorUpdaterPlugin/AES.swift +262 -0
  52. package/ios/Sources/CapacitorUpdaterPlugin/AppHealthTracker.swift +82 -0
  53. package/ios/Sources/CapacitorUpdaterPlugin/BundleInfo.swift +185 -0
  54. package/ios/Sources/CapacitorUpdaterPlugin/BundleStatus.swift +127 -0
  55. package/ios/Sources/CapacitorUpdaterPlugin/CapacitorUpdaterPlugin.swift +6813 -0
  56. package/ios/Sources/CapacitorUpdaterPlugin/CapgoRawRsa.swift +36 -0
  57. package/ios/Sources/CapacitorUpdaterPlugin/CapgoSemanticVersion.swift +200 -0
  58. package/ios/Sources/CapacitorUpdaterPlugin/CapgoUpdater.swift +5099 -0
  59. package/ios/Sources/CapacitorUpdaterPlugin/CryptoCipher.swift +387 -0
  60. package/ios/Sources/CapacitorUpdaterPlugin/DelayUpdateUtils.swift +343 -0
  61. package/ios/Sources/CapacitorUpdaterPlugin/DeviceIdHelper.swift +120 -0
  62. package/ios/Sources/CapacitorUpdaterPlugin/InternalUtils.swift +452 -0
  63. package/ios/Sources/CapacitorUpdaterPlugin/Logger.swift +380 -0
  64. package/ios/Sources/CapacitorUpdaterPlugin/NativeUpdatePrompt.swift +183 -0
  65. package/ios/Sources/CapacitorUpdaterPlugin/RSA.swift +96 -0
  66. package/ios/Sources/CapacitorUpdaterPlugin/RedirectPolicyDelegate.swift +97 -0
  67. package/ios/Sources/CapacitorUpdaterPlugin/ShakeMenu.swift +876 -0
  68. package/ios/{Plugin → Sources/CapacitorUpdaterPlugin}/UserDefaultsExtension.swift +0 -2
  69. package/ios/Sources/CapacitorUpdaterPlugin/WKWebView+CapgoObjcBridge.swift +20 -0
  70. package/ios/Sources/CapacitorUpdaterPlugin/WebViewStatsReporter.swift +304 -0
  71. package/ios/Sources/CapacitorUpdaterPlugin/ZipArchiveReader.swift +247 -0
  72. package/ios/Sources/CapacitorUpdaterPlugin/ZipCentralDirectory.swift +280 -0
  73. package/ios/Tests/CapacitorUpdaterPluginTests/BuiltinHashesTests.swift +210 -0
  74. package/ios/Tests/CapacitorUpdaterPluginTests/BundleHardeningTests.swift +292 -0
  75. package/ios/Tests/CapacitorUpdaterPluginTests/CapacitorUpdaterPluginTests.swift +6533 -0
  76. package/ios/Tests/CapacitorUpdaterPluginTests/CapgoSemanticVersionTests.swift +64 -0
  77. package/ios/Tests/CapacitorUpdaterPluginTests/ChecksumRequiredTests.swift +156 -0
  78. package/ios/Tests/CapacitorUpdaterPluginTests/CliCryptoFixtureTests.swift +314 -0
  79. package/ios/Tests/CapacitorUpdaterPluginTests/HttpsOnlyBuiltinMinimumTests.swift +653 -0
  80. package/ios/Tests/CapacitorUpdaterPluginTests/InstallPerfTests.swift +174 -0
  81. package/ios/Tests/CapacitorUpdaterPluginTests/ListChannelsTests.swift +74 -0
  82. package/ios/Tests/CapacitorUpdaterPluginTests/LoggerSecurityTests.swift +149 -0
  83. package/ios/Tests/CapacitorUpdaterPluginTests/NativeContractTests.swift +160 -0
  84. package/ios/Tests/CapacitorUpdaterPluginTests/NetworkTransportTests.swift +1109 -0
  85. package/ios/Tests/CapacitorUpdaterPluginTests/PopulateDeltaCacheTests.swift +573 -0
  86. package/ios/Tests/CapacitorUpdaterPluginTests/RedirectPolicyTests.swift +63 -0
  87. package/ios/Tests/CapacitorUpdaterPluginTests/RsaContractTests.swift +281 -0
  88. package/ios/Tests/CapacitorUpdaterPluginTests/SessionKeyRequiredTests.swift +196 -0
  89. package/ios/Tests/CapacitorUpdaterPluginTests/TestZipWriter.swift +235 -0
  90. package/ios/Tests/CapacitorUpdaterPluginTests/UpdateLifecycleTests.swift +470 -0
  91. package/ios/Tests/CapacitorUpdaterPluginTests/WebKitOverlayGuardTests.swift +32 -0
  92. package/ios/Tests/CapacitorUpdaterPluginTests/ZipArchiveReaderTests.swift +302 -0
  93. package/ios/Tests/CapacitorUpdaterPluginTests/ZipBundleExtractionTests.swift +122 -0
  94. package/package.json +80 -43
  95. package/scripts/builtin-hashes-lib.mjs +148 -0
  96. package/scripts/capacitor-builtin-hashes-hook.mjs +65 -0
  97. package/scripts/resolve-real-path.mjs +25 -0
  98. package/android/src/main/java/ee/forgr/capacitor_updater/CapacitorUpdater.java +0 -1130
  99. package/ios/Plugin/BundleInfo.swift +0 -113
  100. package/ios/Plugin/BundleStatus.swift +0 -48
  101. package/ios/Plugin/CapacitorUpdater.swift +0 -858
  102. package/ios/Plugin/CapacitorUpdaterPlugin.h +0 -10
  103. package/ios/Plugin/CapacitorUpdaterPlugin.m +0 -27
  104. package/ios/Plugin/CapacitorUpdaterPlugin.swift +0 -677
  105. package/ios/Plugin/CryptoCipher.swift +0 -240
  106. /package/{LICENCE → LICENSE} +0 -0
  107. /package/ios/{Plugin → Sources/CapacitorUpdaterPlugin}/DelayCondition.swift +0 -0
  108. /package/ios/{Plugin → Sources/CapacitorUpdaterPlugin}/DelayUntilNext.swift +0 -0
  109. /package/ios/{Plugin → Sources/CapacitorUpdaterPlugin}/Info.plist +0 -0
@@ -0,0 +1,36 @@
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
+ import Security
9
+ import os.log
10
+
11
+ /// Isolated raw RSA primitives for Capgo v2 checksum/session-key recovery.
12
+ /// SonarCloud automatic analysis has no Swift // NOSONAR; swift:S5542 is ignored
13
+ /// via `.sonarcloud.properties` multicriteria because `.rsaEncryptionRaw` is
14
+ /// intentional wire compatibility with Node `privateEncrypt` / `publicDecrypt`.
15
+ enum CapgoRawRsa {
16
+ private static let log = OSLog(subsystem: "ee.forgr.capacitor_updater", category: "RSA")
17
+
18
+ static func supportsCapgoRecovery(key: SecKey) -> Bool {
19
+ SecKeyGetBlockSize(key) == 256
20
+ && SecKeyIsAlgorithmSupported(key, .encrypt, .rsaEncryptionRaw) // NOSONAR intentional raw RSA for Node privateEncrypt / Capgo checksum recovery
21
+ }
22
+
23
+ static func recoverSignatureBlock(key: SecKey, data: Data) -> Data? {
24
+ var error: Unmanaged<CFError>?
25
+ guard let recovered = SecKeyCreateEncryptedData(key, .rsaEncryptionRaw, data as CFData, &error) as Data? else { // NOSONAR intentional raw RSA for Node privateEncrypt / Capgo checksum recovery
26
+ os_log(
27
+ "RSA raw recovery failed: %{public}@",
28
+ log: log,
29
+ type: .error,
30
+ String(describing: error?.takeRetainedValue())
31
+ )
32
+ return nil
33
+ }
34
+ return recovered
35
+ }
36
+ }
@@ -0,0 +1,200 @@
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
+ /// Minimal version value used for native version comparisons.
10
+ ///
11
+ /// Parsing and ordering intentionally mirror the lenient parser of the `Version` package
12
+ /// (mrackwitz/Version 0.8.0) that this type replaces, so existing comparisons keep the same results:
13
+ /// - `MAJOR[.MINOR[.PATCH]][-PRERELEASE][+BUILD]`, numeric components are ASCII digits (leading zeros allowed).
14
+ /// - Missing minor/patch compare as `0`.
15
+ /// - A version with a prerelease is lower than the same version without one.
16
+ /// - Prerelease identifiers are compared dot by dot: numerically when both are digits, lexically otherwise.
17
+ /// - Build metadata is ignored for equality and ordering.
18
+ public struct CapgoSemanticVersion: Comparable, Hashable, CustomStringConvertible {
19
+ public enum ParseError: Error {
20
+ case invalidComponents
21
+ case invalidMajorComponent
22
+ case invalidMinorComponent
23
+ case invalidPatchComponent
24
+ }
25
+
26
+ public let major: Int
27
+ public let minor: Int?
28
+ public let patch: Int?
29
+ public let prerelease: String?
30
+ public let build: String?
31
+
32
+ public var canonicalMinor: Int { minor ?? 0 }
33
+ public var canonicalPatch: Int { patch ?? 0 }
34
+
35
+ // Same pattern as the lenient `Version` parser (including its build group quirk: no dots in build metadata).
36
+ private static let versionPattern =
37
+ "\\A([0-9]+)(?:\\.([0-9]+))?(?:\\.([0-9]+))?(?:-([0-9A-Za-z-.]+))?(?:\\+([0-9A-Za-z-]+))??\\z"
38
+ private static let versionRegex = try? NSRegularExpression(pattern: versionPattern)
39
+
40
+ public init(major: Int, minor: Int? = nil, patch: Int? = nil, prerelease: String? = nil, build: String? = nil) {
41
+ self.major = max(0, major)
42
+ self.minor = minor.map { max(0, $0) }
43
+ self.patch = patch.map { max(0, $0) }
44
+ self.prerelease = prerelease
45
+ self.build = build
46
+ }
47
+
48
+ public init(_ string: String) throws {
49
+ guard let regex = Self.versionRegex else {
50
+ throw ParseError.invalidComponents
51
+ }
52
+ let nsString = string as NSString
53
+ guard let match = regex.firstMatch(in: string, options: [], range: NSRange(location: 0, length: nsString.length)),
54
+ match.numberOfRanges == 6 else {
55
+ throw ParseError.invalidComponents
56
+ }
57
+
58
+ func group(_ index: Int) -> String? {
59
+ let range = match.range(at: index)
60
+ return range.location == NSNotFound ? nil : nsString.substring(with: range)
61
+ }
62
+
63
+ guard let major = group(1).flatMap({ Int($0) }) else {
64
+ throw ParseError.invalidMajorComponent
65
+ }
66
+ let minorComponent = group(2)
67
+ let minor = minorComponent.flatMap { Int($0) }
68
+ if minorComponent != nil && minor == nil {
69
+ throw ParseError.invalidMinorComponent
70
+ }
71
+ let patchComponent = group(3)
72
+ let patch = patchComponent.flatMap { Int($0) }
73
+ if patchComponent != nil && patch == nil {
74
+ throw ParseError.invalidPatchComponent
75
+ }
76
+
77
+ self.major = major
78
+ self.minor = minor
79
+ self.patch = patch
80
+ self.prerelease = group(4)
81
+ self.build = group(5)
82
+ }
83
+
84
+ /// Compares only `MAJOR.MINOR.PATCH` of two version strings, with numeric components of any length
85
+ /// (no `Int` limit). Prerelease and build parts are ignored, missing minor/patch count as `0`, and extra
86
+ /// components (a `2.0.0.4` native version) are ignored, like Android's floor parser.
87
+ /// Returns nil when either string does not start with a digit.
88
+ static func compareNumericCore(_ lhs: String, _ rhs: String) -> ComparisonResult? {
89
+ guard let left = numericCore(lhs), let right = numericCore(rhs) else {
90
+ return nil
91
+ }
92
+ for (leftComponent, rightComponent) in zip(left, right) where leftComponent != rightComponent {
93
+ if leftComponent.count != rightComponent.count {
94
+ return leftComponent.count < rightComponent.count ? .orderedAscending : .orderedDescending
95
+ }
96
+ return leftComponent < rightComponent ? .orderedAscending : .orderedDescending
97
+ }
98
+ return .orderedSame
99
+ }
100
+
101
+ /// Major, minor and patch digit strings without leading zeros (missing components are "0"). Mirrors Android's
102
+ /// `parseCoreVersionComponents`: drop build metadata and whitespace, cut the prerelease at the first `-`, then
103
+ /// read the leading digits of the first three dot-separated tokens. This is deliberately looser than the public
104
+ /// version grammar, so native overrides such as `2.0.0.4` still get a floor instead of skipping it.
105
+ private static func numericCore(_ string: String) -> [String]? {
106
+ let withoutBuild = string.split(separator: "+", maxSplits: 1, omittingEmptySubsequences: false).first ?? ""
107
+ let compact = withoutBuild.filter { !$0.isWhitespace }
108
+ guard let first = compact.first, first.isASCII, first.isNumber else {
109
+ return nil
110
+ }
111
+ let core = compact.split(separator: "-", maxSplits: 1, omittingEmptySubsequences: false).first ?? ""
112
+ let tokens = core.split(separator: ".", omittingEmptySubsequences: false)
113
+ return (0..<3).map { index in
114
+ guard index < tokens.count else {
115
+ return "0"
116
+ }
117
+ let digits = tokens[index].prefix { $0.isASCII && $0.isNumber }.drop { $0 == "0" }
118
+ return digits.isEmpty ? "0" : String(digits)
119
+ }
120
+ }
121
+
122
+ public var description: String {
123
+ var result = "\(major)"
124
+ if let minor {
125
+ result += ".\(minor)"
126
+ }
127
+ if let patch {
128
+ result += ".\(patch)"
129
+ }
130
+ if let prerelease {
131
+ result += "-\(prerelease)"
132
+ }
133
+ if let build {
134
+ result += "+\(build)"
135
+ }
136
+ return result
137
+ }
138
+
139
+ public static func == (lhs: CapgoSemanticVersion, rhs: CapgoSemanticVersion) -> Bool {
140
+ return lhs.major == rhs.major
141
+ && lhs.canonicalMinor == rhs.canonicalMinor
142
+ && lhs.canonicalPatch == rhs.canonicalPatch
143
+ && lhs.prerelease == rhs.prerelease
144
+ }
145
+
146
+ public func hash(into hasher: inout Hasher) {
147
+ hasher.combine(major)
148
+ hasher.combine(canonicalMinor)
149
+ hasher.combine(canonicalPatch)
150
+ hasher.combine(prerelease)
151
+ }
152
+
153
+ public static func < (lhs: CapgoSemanticVersion, rhs: CapgoSemanticVersion) -> Bool {
154
+ if lhs.major != rhs.major {
155
+ return lhs.major < rhs.major
156
+ }
157
+ if lhs.canonicalMinor != rhs.canonicalMinor {
158
+ return lhs.canonicalMinor < rhs.canonicalMinor
159
+ }
160
+ if lhs.canonicalPatch != rhs.canonicalPatch {
161
+ return lhs.canonicalPatch < rhs.canonicalPatch
162
+ }
163
+
164
+ switch (lhs.prerelease, rhs.prerelease) {
165
+ case (.some, .none):
166
+ return true
167
+ case (.none, .some), (.none, .none):
168
+ return false
169
+ case let (.some(lpre), .some(rpre)):
170
+ return comparePrerelease(lpre, rpre) == .orderedAscending
171
+ }
172
+ }
173
+
174
+ private static func isNumericIdentifier(_ value: String) -> Bool {
175
+ return !value.isEmpty && value.utf8.allSatisfy { $0 >= 0x30 && $0 <= 0x39 }
176
+ }
177
+
178
+ private static func comparePrerelease(_ lhs: String, _ rhs: String) -> ComparisonResult {
179
+ let lhsComponents = lhs.components(separatedBy: ".")
180
+ let rhsComponents = rhs.components(separatedBy: ".")
181
+ if let (left, right) = zip(lhsComponents, rhsComponents).first(where: { $0.0 != $0.1 }) {
182
+ if isNumericIdentifier(left) && isNumericIdentifier(right) {
183
+ let leftValue = Int(left) ?? 0
184
+ let rightValue = Int(right) ?? 0
185
+ if leftValue == rightValue {
186
+ return .orderedSame
187
+ }
188
+ return leftValue < rightValue ? .orderedAscending : .orderedDescending
189
+ }
190
+ if left == right {
191
+ return .orderedSame
192
+ }
193
+ return left < right ? .orderedAscending : .orderedDescending
194
+ }
195
+ if lhsComponents.count != rhsComponents.count {
196
+ return lhsComponents.count < rhsComponents.count ? .orderedAscending : .orderedDescending
197
+ }
198
+ return .orderedSame
199
+ }
200
+ }