@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,235 @@
|
|
|
1
|
+
import Compression
|
|
2
|
+
import Foundation
|
|
3
|
+
|
|
4
|
+
/// Test-only ZIP writer used to build fixtures for the in-repo ZIP reader.
|
|
5
|
+
/// Supports stored and deflate entries, unix modes (directories, symlinks) and optional ZIP64 records.
|
|
6
|
+
struct TestZipWriter {
|
|
7
|
+
enum Method: UInt16 {
|
|
8
|
+
case stored = 0
|
|
9
|
+
case deflate = 8
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
struct EntrySpec {
|
|
13
|
+
var path: String
|
|
14
|
+
var data: Data
|
|
15
|
+
var method: Method = .stored
|
|
16
|
+
/// Unix mode stored in the high 16 bits of the external attributes (e.g. 0o100644, 0o040755, 0o120777).
|
|
17
|
+
var unixMode: UInt32?
|
|
18
|
+
var generalPurposeFlags: UInt16 = 0x0800 // UTF-8 names
|
|
19
|
+
var forceZip64: Bool = false
|
|
20
|
+
/// Raw name bytes, used instead of the UTF-8 encoding of `path` when set.
|
|
21
|
+
var rawName: Data?
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
private(set) var entries: [EntrySpec] = []
|
|
25
|
+
|
|
26
|
+
mutating func addFile(_ path: String, _ data: Data, method: Method = .stored, unixMode: UInt32? = 0o100644) {
|
|
27
|
+
entries.append(EntrySpec(path: path, data: data, method: method, unixMode: unixMode))
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
mutating func addDirectory(_ path: String) {
|
|
31
|
+
entries.append(EntrySpec(path: path.hasSuffix("/") ? path : "\(path)/", data: Data(), unixMode: 0o040755))
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
mutating func addSymlink(_ path: String, target: String, method: Method = .stored) {
|
|
35
|
+
entries.append(EntrySpec(path: path, data: Data(target.utf8), method: method, unixMode: 0o120777))
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
mutating func add(_ spec: EntrySpec) {
|
|
39
|
+
entries.append(spec)
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
func build(zip64: Bool = false, comment: String = "") -> Data {
|
|
43
|
+
var output = Data()
|
|
44
|
+
var central = Data()
|
|
45
|
+
for entry in entries {
|
|
46
|
+
let offset = UInt64(output.count)
|
|
47
|
+
let record = Record(entry: entry, zip64: zip64 || entry.forceZip64)
|
|
48
|
+
output.append(record.localHeaderAndPayload())
|
|
49
|
+
central.append(record.centralDirectoryEntry(localHeaderOffset: offset))
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
let centralOffset = UInt64(output.count)
|
|
53
|
+
output.append(central)
|
|
54
|
+
if zip64 {
|
|
55
|
+
output.append(zip64EndRecords(centralSize: central.count, centralOffset: centralOffset, recordOffset: UInt64(output.count)))
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
let commentData = Data(comment.utf8)
|
|
59
|
+
output.appendUInt32(0x0605_4b50)
|
|
60
|
+
output.appendUInt16(0)
|
|
61
|
+
output.appendUInt16(0)
|
|
62
|
+
output.appendUInt16(zip64 ? 0xFFFF : UInt16(entries.count))
|
|
63
|
+
output.appendUInt16(zip64 ? 0xFFFF : UInt16(entries.count))
|
|
64
|
+
output.appendUInt32(zip64 ? 0xFFFF_FFFF : UInt32(central.count))
|
|
65
|
+
output.appendUInt32(zip64 ? 0xFFFF_FFFF : UInt32(centralOffset))
|
|
66
|
+
output.appendUInt16(UInt16(commentData.count))
|
|
67
|
+
output.append(commentData)
|
|
68
|
+
return output
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
private func zip64EndRecords(centralSize: Int, centralOffset: UInt64, recordOffset: UInt64) -> Data {
|
|
72
|
+
var output = Data()
|
|
73
|
+
output.appendUInt32(0x0606_4b50)
|
|
74
|
+
output.appendUInt64(44)
|
|
75
|
+
output.appendUInt16((3 << 8) | 63)
|
|
76
|
+
output.appendUInt16(45)
|
|
77
|
+
output.appendUInt32(0)
|
|
78
|
+
output.appendUInt32(0)
|
|
79
|
+
output.appendUInt64(UInt64(entries.count))
|
|
80
|
+
output.appendUInt64(UInt64(entries.count))
|
|
81
|
+
output.appendUInt64(UInt64(centralSize))
|
|
82
|
+
output.appendUInt64(centralOffset)
|
|
83
|
+
|
|
84
|
+
output.appendUInt32(0x0706_4b50)
|
|
85
|
+
output.appendUInt32(0)
|
|
86
|
+
output.appendUInt64(recordOffset)
|
|
87
|
+
output.appendUInt32(1)
|
|
88
|
+
return output
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
private struct Record {
|
|
92
|
+
let entry: EntrySpec
|
|
93
|
+
let zip64: Bool
|
|
94
|
+
let nameData: Data
|
|
95
|
+
let payload: Data
|
|
96
|
+
let crc: UInt32
|
|
97
|
+
|
|
98
|
+
init(entry: EntrySpec, zip64: Bool) {
|
|
99
|
+
self.entry = entry
|
|
100
|
+
self.zip64 = zip64
|
|
101
|
+
self.nameData = entry.rawName ?? Data(entry.path.utf8)
|
|
102
|
+
self.payload = entry.method == .deflate ? TestZipWriter.deflate(entry.data) : entry.data
|
|
103
|
+
self.crc = TestZipWriter.crc32(entry.data)
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
func localHeaderAndPayload() -> Data {
|
|
107
|
+
var extra = Data()
|
|
108
|
+
if zip64 {
|
|
109
|
+
extra.appendUInt16(0x0001)
|
|
110
|
+
extra.appendUInt16(16)
|
|
111
|
+
extra.appendUInt64(UInt64(entry.data.count))
|
|
112
|
+
extra.appendUInt64(UInt64(payload.count))
|
|
113
|
+
}
|
|
114
|
+
var output = Data()
|
|
115
|
+
output.appendUInt32(0x0403_4b50)
|
|
116
|
+
output.appendUInt16(zip64 ? 45 : 20)
|
|
117
|
+
output.appendUInt16(entry.generalPurposeFlags)
|
|
118
|
+
output.appendUInt16(entry.method.rawValue)
|
|
119
|
+
output.appendUInt32(0) // time + date
|
|
120
|
+
output.appendUInt32(crc)
|
|
121
|
+
output.appendUInt32(zip64 ? 0xFFFF_FFFF : UInt32(payload.count))
|
|
122
|
+
output.appendUInt32(zip64 ? 0xFFFF_FFFF : UInt32(entry.data.count))
|
|
123
|
+
output.appendUInt16(UInt16(nameData.count))
|
|
124
|
+
output.appendUInt16(UInt16(extra.count))
|
|
125
|
+
output.append(nameData)
|
|
126
|
+
output.append(extra)
|
|
127
|
+
output.append(payload)
|
|
128
|
+
return output
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
func centralDirectoryEntry(localHeaderOffset: UInt64) -> Data {
|
|
132
|
+
var extra = Data()
|
|
133
|
+
if zip64 {
|
|
134
|
+
extra.appendUInt16(0x0001)
|
|
135
|
+
extra.appendUInt16(24)
|
|
136
|
+
extra.appendUInt64(UInt64(entry.data.count))
|
|
137
|
+
extra.appendUInt64(UInt64(payload.count))
|
|
138
|
+
extra.appendUInt64(localHeaderOffset)
|
|
139
|
+
}
|
|
140
|
+
var output = Data()
|
|
141
|
+
output.appendUInt32(0x0201_4b50)
|
|
142
|
+
output.appendUInt16(entry.unixMode != nil ? (3 << 8) | 63 : 20)
|
|
143
|
+
output.appendUInt16(zip64 ? 45 : 20)
|
|
144
|
+
output.appendUInt16(entry.generalPurposeFlags)
|
|
145
|
+
output.appendUInt16(entry.method.rawValue)
|
|
146
|
+
output.appendUInt32(0) // time + date
|
|
147
|
+
output.appendUInt32(crc)
|
|
148
|
+
output.appendUInt32(zip64 ? 0xFFFF_FFFF : UInt32(payload.count))
|
|
149
|
+
output.appendUInt32(zip64 ? 0xFFFF_FFFF : UInt32(entry.data.count))
|
|
150
|
+
output.appendUInt16(UInt16(nameData.count))
|
|
151
|
+
output.appendUInt16(UInt16(extra.count))
|
|
152
|
+
output.appendUInt16(0) // comment length
|
|
153
|
+
output.appendUInt16(0) // disk number
|
|
154
|
+
output.appendUInt16(0) // internal attributes
|
|
155
|
+
output.appendUInt32((entry.unixMode ?? 0) << 16)
|
|
156
|
+
output.appendUInt32(zip64 ? 0xFFFF_FFFF : UInt32(localHeaderOffset))
|
|
157
|
+
output.append(nameData)
|
|
158
|
+
output.append(extra)
|
|
159
|
+
return output
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
func write(to url: URL, zip64: Bool = false) throws {
|
|
164
|
+
try build(zip64: zip64).write(to: url)
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/// Raw DEFLATE (RFC 1951) encoding via Apple's Compression framework, streamed so large inputs work.
|
|
168
|
+
static func deflate(_ data: Data) -> Data {
|
|
169
|
+
let stream = UnsafeMutablePointer<compression_stream>.allocate(capacity: 1)
|
|
170
|
+
defer { stream.deallocate() }
|
|
171
|
+
guard compression_stream_init(stream, COMPRESSION_STREAM_ENCODE, COMPRESSION_ZLIB) == COMPRESSION_STATUS_OK else {
|
|
172
|
+
fatalError("compression_stream_init failed")
|
|
173
|
+
}
|
|
174
|
+
defer { compression_stream_destroy(stream) }
|
|
175
|
+
|
|
176
|
+
let bufferSize = 64 * 1024
|
|
177
|
+
let destination = UnsafeMutablePointer<UInt8>.allocate(capacity: bufferSize)
|
|
178
|
+
defer { destination.deallocate() }
|
|
179
|
+
var output = Data()
|
|
180
|
+
|
|
181
|
+
data.withUnsafeBytes { (raw: UnsafeRawBufferPointer) in
|
|
182
|
+
let base = raw.bindMemory(to: UInt8.self).baseAddress
|
|
183
|
+
// An empty input still needs a valid source pointer.
|
|
184
|
+
var emptyByte: UInt8 = 0
|
|
185
|
+
withUnsafePointer(to: &emptyByte) { emptyPointer in
|
|
186
|
+
stream.pointee.src_ptr = base ?? emptyPointer
|
|
187
|
+
stream.pointee.src_size = data.count
|
|
188
|
+
var status = COMPRESSION_STATUS_OK
|
|
189
|
+
repeat {
|
|
190
|
+
stream.pointee.dst_ptr = destination
|
|
191
|
+
stream.pointee.dst_size = bufferSize
|
|
192
|
+
status = compression_stream_process(stream, Int32(COMPRESSION_STREAM_FINALIZE.rawValue))
|
|
193
|
+
output.append(destination, count: bufferSize - stream.pointee.dst_size)
|
|
194
|
+
} while status == COMPRESSION_STATUS_OK
|
|
195
|
+
precondition(status == COMPRESSION_STATUS_END, "deflate failed")
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
return output
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
private static let crcTable: [UInt32] = (0..<256).map { index -> UInt32 in
|
|
202
|
+
var value = UInt32(index)
|
|
203
|
+
for _ in 0..<8 {
|
|
204
|
+
value = (value & 1) != 0 ? (0xEDB8_8320 ^ (value >> 1)) : (value >> 1)
|
|
205
|
+
}
|
|
206
|
+
return value
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
static func crc32(_ data: Data) -> UInt32 {
|
|
210
|
+
var crc: UInt32 = 0xFFFF_FFFF
|
|
211
|
+
for byte in data {
|
|
212
|
+
crc = crcTable[Int((crc ^ UInt32(byte)) & 0xFF)] ^ (crc >> 8)
|
|
213
|
+
}
|
|
214
|
+
return crc ^ 0xFFFF_FFFF
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
extension Data {
|
|
219
|
+
mutating func appendUInt16(_ value: UInt16) {
|
|
220
|
+
append(UInt8(value & 0xFF))
|
|
221
|
+
append(UInt8((value >> 8) & 0xFF))
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
mutating func appendUInt32(_ value: UInt32) {
|
|
225
|
+
for shift in stride(from: 0, to: 32, by: 8) {
|
|
226
|
+
append(UInt8((value >> UInt32(shift)) & 0xFF))
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
mutating func appendUInt64(_ value: UInt64) {
|
|
231
|
+
for shift in stride(from: 0, to: 64, by: 8) {
|
|
232
|
+
append(UInt8((value >> UInt64(shift)) & 0xFF))
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
}
|