@capgo/capacitor-updater 7.0.33 → 7.0.35
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.
|
@@ -57,7 +57,7 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
57
57
|
private static final String statsUrlDefault = "https://plugin.capgo.app/stats";
|
|
58
58
|
private static final String channelUrlDefault = "https://plugin.capgo.app/channel_self";
|
|
59
59
|
|
|
60
|
-
private final String PLUGIN_VERSION = "7.0.
|
|
60
|
+
private final String PLUGIN_VERSION = "7.0.35";
|
|
61
61
|
private static final String DELAY_CONDITION_PREFERENCES = "";
|
|
62
62
|
|
|
63
63
|
private SharedPreferences.Editor editor;
|
|
@@ -140,50 +140,6 @@ import UIKit
|
|
|
140
140
|
}
|
|
141
141
|
}
|
|
142
142
|
|
|
143
|
-
private func decryptFileV2(filePath: URL, sessionKey: String, version: String) throws {
|
|
144
|
-
if self.publicKey.isEmpty || sessionKey.isEmpty || sessionKey.components(separatedBy: ":").count != 2 {
|
|
145
|
-
print("\(CapacitorUpdater.TAG) Cannot find public key or sessionKey")
|
|
146
|
-
return
|
|
147
|
-
}
|
|
148
|
-
do {
|
|
149
|
-
guard let rsaPublicKey: RSAPublicKey = .load(rsaPublicKey: self.publicKey) else {
|
|
150
|
-
print("cannot decode publicKey", self.publicKey)
|
|
151
|
-
throw CustomError.cannotDecode
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
let sessionKeyArray: [String] = sessionKey.components(separatedBy: ":")
|
|
155
|
-
guard let ivData: Data = Data(base64Encoded: sessionKeyArray[0]) else {
|
|
156
|
-
print("cannot decode sessionKey", sessionKey)
|
|
157
|
-
throw CustomError.cannotDecode
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
guard let sessionKeyDataEncrypted = Data(base64Encoded: sessionKeyArray[1]) else {
|
|
161
|
-
throw NSError(domain: "Invalid session key data", code: 1, userInfo: nil)
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
guard let sessionKeyDataDecrypted = rsaPublicKey.decrypt(data: sessionKeyDataEncrypted) else {
|
|
165
|
-
throw NSError(domain: "Failed to decrypt session key data", code: 2, userInfo: nil)
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
let aesPrivateKey = AES128Key(iv: ivData, aes128Key: sessionKeyDataDecrypted)
|
|
169
|
-
|
|
170
|
-
guard let encryptedData = try? Data(contentsOf: filePath) else {
|
|
171
|
-
throw NSError(domain: "Failed to read encrypted data", code: 3, userInfo: nil)
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
guard let decryptedData = aesPrivateKey.decrypt(data: encryptedData) else {
|
|
175
|
-
throw NSError(domain: "Failed to decrypt data", code: 4, userInfo: nil)
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
try decryptedData.write(to: filePath)
|
|
179
|
-
|
|
180
|
-
} catch {
|
|
181
|
-
print("\(CapacitorUpdater.TAG) Cannot decode: \(filePath.path)", error)
|
|
182
|
-
self.sendStats(action: "decrypt_fail", versionName: version)
|
|
183
|
-
throw CustomError.cannotDecode
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
|
|
187
143
|
private func unzipProgressHandler(entry: String, zipInfo: unz_file_info, entryNumber: Int, total: Int, destUnZip: URL, id: String, unzipError: inout NSError?) {
|
|
188
144
|
if entry.contains("\\") {
|
|
189
145
|
print("\(CapacitorUpdater.TAG) unzip: Windows path is not supported, please use unix path as required by zip RFC: \(entry)")
|
|
@@ -353,27 +309,6 @@ import UIKit
|
|
|
353
309
|
return actualHash == expectedHash
|
|
354
310
|
}
|
|
355
311
|
|
|
356
|
-
public func decryptChecksum(checksum: String, version: String) throws -> String {
|
|
357
|
-
if self.publicKey.isEmpty {
|
|
358
|
-
return checksum
|
|
359
|
-
}
|
|
360
|
-
do {
|
|
361
|
-
let checksumBytes: Data = Data(base64Encoded: checksum)!
|
|
362
|
-
guard let rsaPublicKey: RSAPublicKey = .load(rsaPublicKey: self.publicKey) else {
|
|
363
|
-
print("cannot decode publicKey", self.publicKey)
|
|
364
|
-
throw CustomError.cannotDecode
|
|
365
|
-
}
|
|
366
|
-
guard let decryptedChecksum = rsaPublicKey.decrypt(data: checksumBytes) else {
|
|
367
|
-
throw NSError(domain: "Failed to decrypt session key data", code: 2, userInfo: nil)
|
|
368
|
-
}
|
|
369
|
-
return decryptedChecksum.base64EncodedString()
|
|
370
|
-
} catch {
|
|
371
|
-
print("\(CapacitorUpdater.TAG) Cannot decrypt checksum: \(checksum)", error)
|
|
372
|
-
self.sendStats(action: "decrypt_fail", versionName: version)
|
|
373
|
-
throw CustomError.cannotDecode
|
|
374
|
-
}
|
|
375
|
-
}
|
|
376
|
-
|
|
377
312
|
public func downloadManifest(manifest: [ManifestEntry], version: String, sessionKey: String) throws -> BundleInfo {
|
|
378
313
|
let id = self.randomString(length: 10)
|
|
379
314
|
print("\(CapacitorUpdater.TAG) downloadManifest start \(id)")
|
|
@@ -715,7 +650,7 @@ import UIKit
|
|
|
715
650
|
|
|
716
651
|
let finalPath = tempDataPath.deletingLastPathComponent().appendingPathComponent("\(id)")
|
|
717
652
|
do {
|
|
718
|
-
try
|
|
653
|
+
try CryptoCipherV2.decryptFile(filePath: tempDataPath, publicKey: self.publicKey, sessionKey: sessionKey, version: version)
|
|
719
654
|
try FileManager.default.moveItem(at: tempDataPath, to: finalPath)
|
|
720
655
|
} catch {
|
|
721
656
|
print("\(CapacitorUpdater.TAG) Failed decrypt file : \(error)")
|
|
@@ -45,7 +45,7 @@ public class CapacitorUpdaterPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
|
45
45
|
CAPPluginMethod(name: "getNextBundle", returnType: CAPPluginReturnPromise)
|
|
46
46
|
]
|
|
47
47
|
public var implementation = CapacitorUpdater()
|
|
48
|
-
private let PLUGIN_VERSION: String = "7.0.
|
|
48
|
+
private let PLUGIN_VERSION: String = "7.0.35"
|
|
49
49
|
static let updateUrlDefault = "https://plugin.capgo.app/updates"
|
|
50
50
|
static let statsUrlDefault = "https://plugin.capgo.app/stats"
|
|
51
51
|
static let channelUrlDefault = "https://plugin.capgo.app/channel_self"
|
|
@@ -291,7 +291,7 @@ public class CapacitorUpdaterPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
|
291
291
|
DispatchQueue.global(qos: .background).async {
|
|
292
292
|
do {
|
|
293
293
|
let next = try self.implementation.download(url: url!, version: version, sessionKey: sessionKey)
|
|
294
|
-
checksum = try
|
|
294
|
+
checksum = try CryptoCipherV2.decryptChecksum(checksum: checksum, publicKey: self.implementation.publicKey, version: version)
|
|
295
295
|
if (checksum != "" || self.implementation.publicKey != "") && next.getChecksum() != checksum {
|
|
296
296
|
print("\(CapacitorUpdater.TAG) Error checksum", next.getChecksum(), checksum)
|
|
297
297
|
self.implementation.sendStats(action: "checksum_fail", versionName: next.getVersionName())
|
|
@@ -805,7 +805,7 @@ public class CapacitorUpdaterPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
|
805
805
|
self.endBackGroundTaskWithNotif(msg: "Latest version is in error state. Aborting update.", latestVersionName: latestVersionName, current: current)
|
|
806
806
|
return
|
|
807
807
|
}
|
|
808
|
-
res.checksum = try
|
|
808
|
+
res.checksum = try CryptoCipherV2.decryptChecksum(checksum: res.checksum, publicKey: self.implementation.publicKey, version: latestVersionName)
|
|
809
809
|
if res.checksum != "" && next.getChecksum() != res.checksum && res.manifest == nil {
|
|
810
810
|
print("\(CapacitorUpdater.TAG) Error checksum", next.getChecksum(), res.checksum)
|
|
811
811
|
self.implementation.sendStats(action: "checksum_fail", versionName: next.getVersionName())
|