@capgo/capacitor-updater 7.13.16 → 7.13.18
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 +1 -0
- package/android/src/main/java/ee/forgr/capacitor_updater/CapacitorUpdaterPlugin.java +1 -1
- package/ios/Sources/CapacitorUpdaterPlugin/AES.swift +69 -0
- package/ios/Sources/CapacitorUpdaterPlugin/BigInt.swift +55 -0
- package/ios/Sources/CapacitorUpdaterPlugin/BundleInfo.swift +113 -0
- package/ios/Sources/CapacitorUpdaterPlugin/BundleStatus.swift +48 -0
- package/ios/Sources/CapacitorUpdaterPlugin/CapacitorUpdaterPlugin.swift +1182 -0
- package/ios/Sources/CapacitorUpdaterPlugin/CapgoUpdater.swift +1301 -0
- package/ios/Sources/CapacitorUpdaterPlugin/CryptoCipher.swift +187 -0
- package/ios/Sources/CapacitorUpdaterPlugin/DelayCondition.swift +74 -0
- package/ios/Sources/CapacitorUpdaterPlugin/DelayUntilNext.swift +30 -0
- package/ios/Sources/CapacitorUpdaterPlugin/DelayUpdateUtils.swift +222 -0
- package/ios/Sources/CapacitorUpdaterPlugin/Info.plist +28 -0
- package/ios/Sources/CapacitorUpdaterPlugin/InternalUtils.swift +303 -0
- package/ios/Sources/CapacitorUpdaterPlugin/Logger.swift +310 -0
- package/ios/Sources/CapacitorUpdaterPlugin/RSA.swift +274 -0
- package/ios/Sources/CapacitorUpdaterPlugin/ShakeMenu.swift +112 -0
- package/ios/Sources/CapacitorUpdaterPlugin/UserDefaultsExtension.swift +46 -0
- package/package.json +2 -2
|
@@ -16,6 +16,7 @@ Pod::Spec.new do |s|
|
|
|
16
16
|
s.dependency 'SSZipArchive', '2.4.3'
|
|
17
17
|
s.dependency 'Alamofire', '5.10.2'
|
|
18
18
|
s.dependency 'Version', '0.8.0'
|
|
19
|
+
# We cannot update to latest because it not published anymore in cocoa https://github.com/attaswift/BigInt/issues/94
|
|
19
20
|
s.dependency 'BigInt', '5.2.0'
|
|
20
21
|
s.swift_version = '5.1'
|
|
21
22
|
end
|
|
@@ -58,7 +58,7 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
58
58
|
private static final String statsUrlDefault = "https://plugin.capgo.app/stats";
|
|
59
59
|
private static final String channelUrlDefault = "https://plugin.capgo.app/channel_self";
|
|
60
60
|
|
|
61
|
-
private final String PLUGIN_VERSION = "7.13.
|
|
61
|
+
private final String PLUGIN_VERSION = "7.13.18";
|
|
62
62
|
private static final String DELAY_CONDITION_PREFERENCES = "";
|
|
63
63
|
|
|
64
64
|
private SharedPreferences.Editor editor;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import BigInt
|
|
2
|
+
import Foundation
|
|
3
|
+
import CommonCrypto
|
|
4
|
+
import CryptoKit
|
|
5
|
+
|
|
6
|
+
///
|
|
7
|
+
/// Constants
|
|
8
|
+
///
|
|
9
|
+
private enum AESConstants {
|
|
10
|
+
static let aesAlgorithm: CCAlgorithm = CCAlgorithm(kCCAlgorithmAES)
|
|
11
|
+
static let aesOptions: CCOptions = CCOptions(kCCOptionPKCS7Padding)
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
// We do all this stuff because ios is shit and open source libraries allow to do decryption with public key
|
|
15
|
+
// So we have to do it manually, while in nodejs or Java it's ok and done at language level.
|
|
16
|
+
|
|
17
|
+
///
|
|
18
|
+
/// The AES key. Contains both the initialization vector and secret key.
|
|
19
|
+
///
|
|
20
|
+
public struct AES128Key {
|
|
21
|
+
/// Initialization vector
|
|
22
|
+
private let iv: Data
|
|
23
|
+
private let logger: Logger
|
|
24
|
+
private let aes128Key: Data
|
|
25
|
+
#if DEBUG
|
|
26
|
+
public var __debug_iv: Data { iv }
|
|
27
|
+
public var __debug_aes128Key: Data { aes128Key }
|
|
28
|
+
#endif
|
|
29
|
+
init(iv: Data, aes128Key: Data, logger: Logger) {
|
|
30
|
+
self.iv = iv
|
|
31
|
+
self.aes128Key = aes128Key
|
|
32
|
+
self.logger = logger
|
|
33
|
+
}
|
|
34
|
+
///
|
|
35
|
+
/// Takes the data and uses the private key to decrypt it. Will call `CCCrypt` in CommonCrypto
|
|
36
|
+
/// and provide it `ivData` for the initialization vector. Will use cipher block chaining (CBC) as
|
|
37
|
+
/// the mode of operation.
|
|
38
|
+
///
|
|
39
|
+
/// Returns the decrypted data.
|
|
40
|
+
///
|
|
41
|
+
public func decrypt(data: Data) -> Data? {
|
|
42
|
+
let encryptedData: UnsafePointer<UInt8> = (data as NSData).bytes.bindMemory(to: UInt8.self, capacity: data.count)
|
|
43
|
+
let encryptedDataLength: Int = data.count
|
|
44
|
+
|
|
45
|
+
if let result: NSMutableData = NSMutableData(length: encryptedDataLength) {
|
|
46
|
+
let keyData: UnsafePointer<UInt8> = (self.aes128Key as NSData).bytes.bindMemory(to: UInt8.self, capacity: self.aes128Key.count)
|
|
47
|
+
let keyLength: size_t = size_t(self.aes128Key.count)
|
|
48
|
+
let ivData: UnsafePointer<UInt8> = (iv as NSData).bytes.bindMemory(to: UInt8.self, capacity: self.iv.count)
|
|
49
|
+
|
|
50
|
+
let decryptedData: UnsafeMutablePointer<UInt8> = UnsafeMutablePointer<UInt8>(result.mutableBytes.assumingMemoryBound(to: UInt8.self))
|
|
51
|
+
let decryptedDataLength: size_t = size_t(result.length)
|
|
52
|
+
|
|
53
|
+
var decryptedLength: size_t = 0
|
|
54
|
+
|
|
55
|
+
let status: CCCryptorStatus = CCCrypt(CCOperation(kCCDecrypt), AESConstants.aesAlgorithm, AESConstants.aesOptions, keyData, keyLength, ivData, encryptedData, encryptedDataLength, decryptedData, decryptedDataLength, &decryptedLength)
|
|
56
|
+
|
|
57
|
+
if Int32(status) == Int32(kCCSuccess) {
|
|
58
|
+
result.length = Int(decryptedLength)
|
|
59
|
+
return result as Data
|
|
60
|
+
} else {
|
|
61
|
+
logger.error("AES decryption failed with status: \(status)")
|
|
62
|
+
return nil
|
|
63
|
+
}
|
|
64
|
+
} else {
|
|
65
|
+
logger.error("Failed to allocate memory for AES decryption")
|
|
66
|
+
return nil
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import BigInt
|
|
2
|
+
|
|
3
|
+
// Extension to serialize BigInt to bytes array
|
|
4
|
+
extension BigInt {
|
|
5
|
+
func serializeToBytes() -> [UInt8] {
|
|
6
|
+
let byteCount = (self.bitWidth + 7) / 8
|
|
7
|
+
var bytes = [UInt8](repeating: 0, count: byteCount)
|
|
8
|
+
|
|
9
|
+
var value = self
|
|
10
|
+
for i in 0..<byteCount {
|
|
11
|
+
bytes[byteCount - i - 1] = UInt8(truncatingIfNeeded: value & 0xFF)
|
|
12
|
+
value >>= 8
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
return bytes
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// Add this custom power function to ensure safer handling of power operations
|
|
20
|
+
|
|
21
|
+
// Manual exponentiation using the square-and-multiply algorithm
|
|
22
|
+
// which is more efficient and avoids using the built-in functions that might handle BigInt differently
|
|
23
|
+
extension BigInt {
|
|
24
|
+
func manualPower(_ exponent: BigInt, modulus: BigInt) -> BigInt {
|
|
25
|
+
// Quick checks
|
|
26
|
+
if modulus == 0 {
|
|
27
|
+
return 0
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
if exponent == 0 {
|
|
31
|
+
return 1
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
guard let base = self.magnitude as? BigUInt,
|
|
35
|
+
let exp = exponent.magnitude as? BigUInt,
|
|
36
|
+
let mod = modulus.magnitude as? BigUInt else {
|
|
37
|
+
return 0
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// Square and multiply algorithm for modular exponentiation
|
|
41
|
+
var result = BigUInt(1)
|
|
42
|
+
var x = base % mod
|
|
43
|
+
var e = exp
|
|
44
|
+
|
|
45
|
+
while e > 0 {
|
|
46
|
+
if e & 1 == 1 {
|
|
47
|
+
result = (result * x) % mod
|
|
48
|
+
}
|
|
49
|
+
x = (x * x) % mod
|
|
50
|
+
e >>= 1
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return BigInt(result)
|
|
54
|
+
}
|
|
55
|
+
}
|
|
@@ -0,0 +1,113 @@
|
|
|
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
|
+
@objc public class BundleInfo: NSObject, Decodable, Encodable {
|
|
10
|
+
public static let ID_BUILTIN: String = "builtin"
|
|
11
|
+
public static let VERSION_UNKNOWN: String = "unknown"
|
|
12
|
+
public static let DOWNLOADED_BUILTIN: String = "1970-01-01T00:00:00.000Z"
|
|
13
|
+
|
|
14
|
+
private let downloaded: String
|
|
15
|
+
private let id: String
|
|
16
|
+
private let version: String
|
|
17
|
+
private let checksum: String
|
|
18
|
+
private let status: BundleStatus
|
|
19
|
+
|
|
20
|
+
convenience init(id: String, version: String, status: BundleStatus, downloaded: Date, checksum: String) {
|
|
21
|
+
self.init(id: id, version: version, status: status, downloaded: downloaded.iso8601withFractionalSeconds, checksum: checksum)
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
init(id: String, version: String, status: BundleStatus, downloaded: String = BundleInfo.DOWNLOADED_BUILTIN, checksum: String) {
|
|
25
|
+
self.downloaded = downloaded.trim()
|
|
26
|
+
self.id = id
|
|
27
|
+
self.version = version
|
|
28
|
+
self.checksum = checksum
|
|
29
|
+
self.status = status
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
enum CodingKeys: String, CodingKey {
|
|
33
|
+
case downloaded, id, version, status, checksum
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
public func isBuiltin() -> Bool {
|
|
37
|
+
return BundleInfo.ID_BUILTIN == self.id
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
public func isUnknown() -> Bool {
|
|
41
|
+
return BundleInfo.VERSION_UNKNOWN == self.id
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
public func isErrorStatus() -> Bool {
|
|
45
|
+
return BundleStatus.ERROR == self.status
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
public func isDeleted() -> Bool {
|
|
49
|
+
return BundleStatus.DELETED == self.status
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
public func isDownloaded() -> Bool {
|
|
53
|
+
return !self.isBuiltin() && self.downloaded != "" && self.downloaded != BundleInfo.DOWNLOADED_BUILTIN && !self.isDeleted()
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
public func getDownloaded() -> String {
|
|
57
|
+
return self.isBuiltin() ? BundleInfo.DOWNLOADED_BUILTIN : self.downloaded
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
public func getChecksum() -> String {
|
|
61
|
+
return self.isBuiltin() ? "" : self.checksum
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
public func setChecksum(checksum: String) -> BundleInfo {
|
|
65
|
+
return BundleInfo(id: self.id, version: self.version, status: self.status, downloaded: self.downloaded, checksum: checksum)
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
public func setDownloaded(downloaded: Date) -> BundleInfo {
|
|
69
|
+
return BundleInfo(id: self.id, version: self.version, status: self.status, downloaded: downloaded, checksum: self.checksum)
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
public func getId() -> String {
|
|
73
|
+
return self.isBuiltin() ? BundleInfo.ID_BUILTIN : self.id
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
public func setId(id: String) -> BundleInfo {
|
|
77
|
+
return BundleInfo(id: id, version: self.version, status: self.status, downloaded: self.downloaded, checksum: self.checksum)
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
public func getVersionName() -> String {
|
|
81
|
+
return self.version.isEmpty ? BundleInfo.ID_BUILTIN : self.version
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
public func setVersionName(version: String) -> BundleInfo {
|
|
85
|
+
return BundleInfo(id: self.id, version: version, status: self.status, downloaded: self.downloaded, checksum: self.checksum)
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
public func getStatus() -> String {
|
|
89
|
+
return self.isBuiltin() ? BundleStatus.SUCCESS.localizedString : self.status.localizedString
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
public func setStatus(status: String) -> BundleInfo {
|
|
93
|
+
return BundleInfo(id: self.id, version: self.version, status: BundleStatus(localizedString: status)!, downloaded: self.downloaded, checksum: self.checksum)
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
public func toJSON() -> [String: String] {
|
|
97
|
+
return [
|
|
98
|
+
"id": self.getId(),
|
|
99
|
+
"version": self.getVersionName(),
|
|
100
|
+
"downloaded": self.getDownloaded(),
|
|
101
|
+
"checksum": self.getChecksum(),
|
|
102
|
+
"status": self.getStatus()
|
|
103
|
+
]
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
public static func == (lhs: BundleInfo, rhs: BundleInfo) -> Bool {
|
|
107
|
+
return lhs.getVersionName() == rhs.getVersionName()
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
public func toString() -> String {
|
|
111
|
+
return "{ \"id\": \"\(self.getId())\", \"version\": \"\(self.getVersionName())\", \"downloaded\": \"\(self.getDownloaded())\", \"checksum\": \"\(self.getChecksum())\", \"status\": \"\(self.getStatus())\"}"
|
|
112
|
+
}
|
|
113
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
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
|
+
struct LocalizedString: ExpressibleByStringLiteral, Equatable {
|
|
10
|
+
|
|
11
|
+
let v: String
|
|
12
|
+
|
|
13
|
+
init(key: String) {
|
|
14
|
+
self.v = NSLocalizedString(key, comment: "")
|
|
15
|
+
}
|
|
16
|
+
init(localized: String) {
|
|
17
|
+
self.v = localized
|
|
18
|
+
}
|
|
19
|
+
init(stringLiteral value: String) {
|
|
20
|
+
self.init(key: value)
|
|
21
|
+
}
|
|
22
|
+
init(extendedGraphemeClusterLiteral value: String) {
|
|
23
|
+
self.init(key: value)
|
|
24
|
+
}
|
|
25
|
+
init(unicodeScalarLiteral value: String) {
|
|
26
|
+
self.init(key: value)
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
func ==(lhs: LocalizedString, rhs: LocalizedString) -> Bool {
|
|
31
|
+
return lhs.v == rhs.v
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
enum BundleStatus: LocalizedString, Decodable, Encodable {
|
|
35
|
+
case SUCCESS = "success"
|
|
36
|
+
case ERROR = "error"
|
|
37
|
+
case PENDING = "pending"
|
|
38
|
+
case DELETED = "deleted"
|
|
39
|
+
case DOWNLOADING = "downloading"
|
|
40
|
+
|
|
41
|
+
var localizedString: String {
|
|
42
|
+
return self.rawValue.v
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
init?(localizedString: String) {
|
|
46
|
+
self.init(rawValue: LocalizedString(localized: localizedString))
|
|
47
|
+
}
|
|
48
|
+
}
|