@capgo/capacitor-updater 8.51.8 → 8.51.9
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/android/src/main/java/ee/forgr/capacitor_updater/CapacitorUpdaterPlugin.java +1 -1
- package/android/src/main/java/ee/forgr/capacitor_updater/CapgoUpdater.java +62 -21
- package/android/src/main/java/ee/forgr/capacitor_updater/CryptoCipher.java +115 -20
- package/android/src/main/java/ee/forgr/capacitor_updater/DownloadService.java +142 -114
- package/ios/Sources/CapacitorUpdaterPlugin/AES.swift +119 -0
- package/ios/Sources/CapacitorUpdaterPlugin/CapacitorUpdaterPlugin.swift +1 -1
- package/ios/Sources/CapacitorUpdaterPlugin/CapgoUpdater.swift +249 -160
- package/ios/Sources/CapacitorUpdaterPlugin/CryptoCipher.swift +41 -29
- package/package.json +1 -1
|
@@ -141,8 +141,43 @@ public struct CryptoCipher {
|
|
|
141
141
|
}
|
|
142
142
|
}
|
|
143
143
|
|
|
144
|
+
private static let twoGiB: UInt64 = 2 * 1024 * 1024 * 1024
|
|
145
|
+
private static let threeGiB: UInt64 = 3 * 1024 * 1024 * 1024
|
|
146
|
+
private static let fourGiB: UInt64 = 4 * 1024 * 1024 * 1024
|
|
147
|
+
private static let eightGiB: UInt64 = 8 * 1024 * 1024 * 1024
|
|
148
|
+
private static let flagshipIoBufferBytes = 5 * 1024 * 1024
|
|
149
|
+
|
|
150
|
+
/// Checksum and copy share one ladder. 64-wide peak RAM = 64 * buffer.
|
|
151
|
+
/// <2GB: 64KB. <3GB: 256KB. <4GB: 512KB. <8GB: 1MB. Else 5MB (flagship / unknown).
|
|
152
|
+
static func ioBufferBytes(_ physicalRamBytes: UInt64 = ProcessInfo.processInfo.physicalMemory) -> Int {
|
|
153
|
+
if physicalRamBytes == 0 {
|
|
154
|
+
return flagshipIoBufferBytes
|
|
155
|
+
}
|
|
156
|
+
if physicalRamBytes < twoGiB {
|
|
157
|
+
return 64 * 1024
|
|
158
|
+
}
|
|
159
|
+
if physicalRamBytes < threeGiB {
|
|
160
|
+
return 256 * 1024
|
|
161
|
+
}
|
|
162
|
+
if physicalRamBytes < fourGiB {
|
|
163
|
+
return 512 * 1024
|
|
164
|
+
}
|
|
165
|
+
if physicalRamBytes < eightGiB {
|
|
166
|
+
return 1024 * 1024
|
|
167
|
+
}
|
|
168
|
+
return flagshipIoBufferBytes
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
static func checksumBufferBytes(_ physicalRamBytes: UInt64 = ProcessInfo.processInfo.physicalMemory) -> Int {
|
|
172
|
+
return ioBufferBytes(physicalRamBytes)
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
static func copyBufferBytes(_ physicalRamBytes: UInt64 = ProcessInfo.processInfo.physicalMemory) -> Int {
|
|
176
|
+
return ioBufferBytes(physicalRamBytes)
|
|
177
|
+
}
|
|
178
|
+
|
|
144
179
|
public static func calcChecksum(filePath: URL) -> String {
|
|
145
|
-
let bufferSize =
|
|
180
|
+
let bufferSize = checksumBufferBytes()
|
|
146
181
|
var sha256 = SHA256()
|
|
147
182
|
|
|
148
183
|
do {
|
|
@@ -243,42 +278,19 @@ public struct CryptoCipher {
|
|
|
243
278
|
|
|
244
279
|
let aesPrivateKey = AES128Key(iv: ivData, aes128Key: sessionKeyDataDecrypted, logger: logger)
|
|
245
280
|
|
|
246
|
-
let
|
|
247
|
-
|
|
248
|
-
encryptedData = try Data(contentsOf: filePath)
|
|
249
|
-
} catch {
|
|
250
|
-
logger.error("Failed to read encrypted data")
|
|
251
|
-
logger.debug("Error: \(error)")
|
|
252
|
-
throw NSError(domain: "Failed to read encrypted data", code: 3, userInfo: nil)
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
if encryptedData.isEmpty {
|
|
281
|
+
let encryptedSize = (try FileManager.default.attributesOfItem(atPath: filePath.path)[.size] as? NSNumber)?.uint64Value ?? 0
|
|
282
|
+
if encryptedSize == 0 {
|
|
256
283
|
logger.error("Encrypted file data is empty")
|
|
257
284
|
throw NSError(domain: "Empty encrypted data", code: 6, userInfo: nil)
|
|
258
285
|
}
|
|
259
286
|
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
if decryptedData.isEmpty {
|
|
287
|
+
try aesPrivateKey.decrypt(from: filePath, to: filePath)
|
|
288
|
+
let decryptedSize = (try FileManager.default.attributesOfItem(atPath: filePath.path)[.size] as? NSNumber)?.uint64Value ?? 0
|
|
289
|
+
if decryptedSize == 0 {
|
|
266
290
|
logger.error("Decrypted data is empty")
|
|
267
291
|
throw NSError(domain: "Empty decrypted data", code: 7, userInfo: nil)
|
|
268
292
|
}
|
|
269
293
|
|
|
270
|
-
do {
|
|
271
|
-
try decryptedData.write(to: filePath, options: .atomic)
|
|
272
|
-
if !FileManager.default.fileExists(atPath: filePath.path) {
|
|
273
|
-
logger.error("File was not created after write")
|
|
274
|
-
throw NSError(domain: "File write failed", code: 8, userInfo: nil)
|
|
275
|
-
}
|
|
276
|
-
} catch {
|
|
277
|
-
logger.error("Error writing decrypted file")
|
|
278
|
-
logger.debug("Error: \(error)")
|
|
279
|
-
throw error
|
|
280
|
-
}
|
|
281
|
-
|
|
282
294
|
} catch {
|
|
283
295
|
logger.error("File decryption failed")
|
|
284
296
|
throw CustomError.cannotDecode
|