@capgo/capacitor-updater 6.40.0 → 6.40.5
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/README.md +135 -0
- package/android/src/main/java/ee/forgr/capacitor_updater/CapacitorUpdaterPlugin.java +1 -1
- package/android/src/main/java/ee/forgr/capacitor_updater/CapgoUpdater.java +56 -34
- package/android/src/main/java/ee/forgr/capacitor_updater/CryptoCipher.java +10 -14
- package/dist/docs.json +557 -1
- package/dist/esm/definitions.d.ts +320 -0
- package/dist/esm/definitions.js +1 -0
- package/dist/esm/definitions.js.map +1 -1
- package/dist/esm/index.d.ts +0 -1
- package/dist/esm/index.js +0 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/plugin.cjs.js +1 -1
- package/dist/plugin.cjs.js.map +1 -1
- package/dist/plugin.js +2 -2
- package/dist/plugin.js.map +1 -1
- package/ios/Sources/CapacitorUpdaterPlugin/AES.swift +26 -8
- package/ios/Sources/CapacitorUpdaterPlugin/BigInt.swift +9 -9
- package/ios/Sources/CapacitorUpdaterPlugin/BundleInfo.swift +51 -14
- package/ios/Sources/CapacitorUpdaterPlugin/BundleStatus.swift +11 -11
- package/ios/Sources/CapacitorUpdaterPlugin/CapacitorUpdaterPlugin.swift +1 -1
- package/ios/Sources/CapacitorUpdaterPlugin/CapgoUpdater.swift +99 -51
- package/ios/Sources/CapacitorUpdaterPlugin/CryptoCipher.swift +37 -20
- package/ios/Sources/CapacitorUpdaterPlugin/DelayUpdateUtils.swift +23 -7
- package/ios/Sources/CapacitorUpdaterPlugin/InternalUtils.swift +10 -1
- package/ios/Sources/CapacitorUpdaterPlugin/Logger.swift +9 -9
- package/ios/Sources/CapacitorUpdaterPlugin/ShakeMenu.swift +6 -5
- package/package.json +1 -1
|
@@ -157,7 +157,8 @@ import UIKit
|
|
|
157
157
|
case .success:
|
|
158
158
|
self.logger.info("Rate limit statistic sent")
|
|
159
159
|
case let .failure(error):
|
|
160
|
-
self.logger.error("Error sending rate limit statistic
|
|
160
|
+
self.logger.error("Error sending rate limit statistic")
|
|
161
|
+
self.logger.debug("Error: \(error.localizedDescription)")
|
|
161
162
|
}
|
|
162
163
|
semaphore.signal()
|
|
163
164
|
}
|
|
@@ -203,7 +204,8 @@ import UIKit
|
|
|
203
204
|
do {
|
|
204
205
|
try FileManager.default.createDirectory(atPath: source.path, withIntermediateDirectories: true, attributes: nil)
|
|
205
206
|
} catch {
|
|
206
|
-
logger.error("Cannot
|
|
207
|
+
logger.error("Cannot create directory")
|
|
208
|
+
logger.debug("Directory path: \(source.path)")
|
|
207
209
|
throw CustomError.cannotCreateDirectory
|
|
208
210
|
}
|
|
209
211
|
}
|
|
@@ -213,7 +215,8 @@ import UIKit
|
|
|
213
215
|
do {
|
|
214
216
|
try FileManager.default.removeItem(atPath: source.path)
|
|
215
217
|
} catch {
|
|
216
|
-
logger.error("File not removed
|
|
218
|
+
logger.error("File not removed")
|
|
219
|
+
logger.debug("Path: \(source.path)")
|
|
217
220
|
throw CustomError.cannotDeleteDirectory
|
|
218
221
|
}
|
|
219
222
|
}
|
|
@@ -230,7 +233,8 @@ import UIKit
|
|
|
230
233
|
return false
|
|
231
234
|
}
|
|
232
235
|
} catch {
|
|
233
|
-
logger.error("File not moved
|
|
236
|
+
logger.error("File not moved")
|
|
237
|
+
logger.debug("Source: \(source.path), Dest: \(dest.path)")
|
|
234
238
|
throw CustomError.cannotUnflat
|
|
235
239
|
}
|
|
236
240
|
}
|
|
@@ -238,7 +242,8 @@ import UIKit
|
|
|
238
242
|
private func validateZipEntry(path: String, destUnZip: URL) throws {
|
|
239
243
|
// Check for Windows paths
|
|
240
244
|
if path.contains("\\") {
|
|
241
|
-
logger.error("
|
|
245
|
+
logger.error("Unzip failed: Windows path not supported")
|
|
246
|
+
logger.debug("Invalid path: \(path)")
|
|
242
247
|
self.sendStats(action: "windows_path_fail")
|
|
243
248
|
throw CustomError.cannotUnzip
|
|
244
249
|
}
|
|
@@ -320,7 +325,8 @@ import UIKit
|
|
|
320
325
|
try FileManager.default.removeItem(at: sourceZip)
|
|
321
326
|
}
|
|
322
327
|
} catch {
|
|
323
|
-
logger.error("Could not delete source zip
|
|
328
|
+
logger.error("Could not delete source zip")
|
|
329
|
+
logger.debug("Path: \(sourceZip.path), Error: \(error)")
|
|
324
330
|
}
|
|
325
331
|
}
|
|
326
332
|
|
|
@@ -395,8 +401,9 @@ import UIKit
|
|
|
395
401
|
latest.comment = comment
|
|
396
402
|
}
|
|
397
403
|
case let .failure(error):
|
|
398
|
-
self.logger.error("Error getting
|
|
399
|
-
|
|
404
|
+
self.logger.error("Error getting latest version")
|
|
405
|
+
self.logger.debug("Response: \(response.value.debugDescription), Error: \(error)")
|
|
406
|
+
latest.message = "Error getting Latest"
|
|
400
407
|
latest.error = "response_error"
|
|
401
408
|
latest.statusCode = response.response?.statusCode ?? 0
|
|
402
409
|
}
|
|
@@ -464,7 +471,8 @@ import UIKit
|
|
|
464
471
|
fileHash = try CryptoCipher.decryptChecksum(checksum: fileHash, publicKey: self.publicKey)
|
|
465
472
|
} catch {
|
|
466
473
|
downloadError = error
|
|
467
|
-
logger.error("
|
|
474
|
+
logger.error("Checksum decryption failed")
|
|
475
|
+
logger.debug("Bundle: \(id), File: \(fileName), Error: \(error)")
|
|
468
476
|
}
|
|
469
477
|
} else if self.hasOldPrivateKeyPropertyInConfig {
|
|
470
478
|
// V1 Encryption (privateKey) - deprecated but supported
|
|
@@ -496,7 +504,8 @@ import UIKit
|
|
|
496
504
|
self.notifyDownload(id: id, percent: self.calcTotalPercent(percent: Int((Double(completedFiles) / Double(totalFiles)) * 100), min: 10, max: 70))
|
|
497
505
|
} catch {
|
|
498
506
|
downloadError = error
|
|
499
|
-
logger.error("Failed to copy builtin file
|
|
507
|
+
logger.error("Failed to copy builtin file")
|
|
508
|
+
logger.debug("File: \(fileName), Error: \(error.localizedDescription)")
|
|
500
509
|
}
|
|
501
510
|
dispatchGroup.leave()
|
|
502
511
|
} else if self.tryCopyFromCache(from: cacheFilePath, to: destFilePath, expectedHash: fileHash) {
|
|
@@ -570,15 +579,18 @@ import UIKit
|
|
|
570
579
|
|
|
571
580
|
completedFiles += 1
|
|
572
581
|
self.notifyDownload(id: id, percent: self.calcTotalPercent(percent: Int((Double(completedFiles) / Double(totalFiles)) * 100), min: 10, max: 70))
|
|
573
|
-
self.logger.info("
|
|
582
|
+
self.logger.info("Manifest file downloaded and cached")
|
|
583
|
+
self.logger.debug("Bundle: \(id), File: \(fileName), Brotli: \(isBrotli), Encrypted: \(!self.publicKey.isEmpty && !sessionKey.isEmpty)")
|
|
574
584
|
} catch {
|
|
575
585
|
downloadError = error
|
|
576
|
-
self.logger.error("
|
|
586
|
+
self.logger.error("Manifest file download failed")
|
|
587
|
+
self.logger.debug("Bundle: \(id), File: \(fileName), Error: \(error.localizedDescription)")
|
|
577
588
|
}
|
|
578
589
|
case .failure(let error):
|
|
579
590
|
downloadError = error
|
|
580
591
|
self.sendStats(action: "download_manifest_file_fail", versionName: "\(version):\(fileName)")
|
|
581
|
-
self.logger.error("
|
|
592
|
+
self.logger.error("Manifest file download network error")
|
|
593
|
+
self.logger.debug("Bundle: \(id), File: \(fileName), Error: \(error.localizedDescription), Response: \(response.debugDescription)")
|
|
582
594
|
}
|
|
583
595
|
}
|
|
584
596
|
}
|
|
@@ -666,7 +678,8 @@ import UIKit
|
|
|
666
678
|
var status = compression_stream_init(streamPointer, COMPRESSION_STREAM_DECODE, COMPRESSION_BROTLI)
|
|
667
679
|
|
|
668
680
|
guard status != COMPRESSION_STATUS_ERROR else {
|
|
669
|
-
logger.error("
|
|
681
|
+
logger.error("Failed to initialize Brotli stream")
|
|
682
|
+
logger.debug("File: \(fileName), Status: \(status)")
|
|
670
683
|
return nil
|
|
671
684
|
}
|
|
672
685
|
|
|
@@ -688,7 +701,8 @@ import UIKit
|
|
|
688
701
|
if let baseAddress = rawBufferPointer.baseAddress {
|
|
689
702
|
streamPointer.pointee.src_ptr = baseAddress.assumingMemoryBound(to: UInt8.self)
|
|
690
703
|
} else {
|
|
691
|
-
logger.error("
|
|
704
|
+
logger.error("Failed to get base address for Brotli decompression")
|
|
705
|
+
logger.debug("File: \(fileName)")
|
|
692
706
|
status = COMPRESSION_STATUS_ERROR
|
|
693
707
|
return
|
|
694
708
|
}
|
|
@@ -698,7 +712,8 @@ import UIKit
|
|
|
698
712
|
if status == COMPRESSION_STATUS_ERROR {
|
|
699
713
|
let maxBytes = min(32, data.count)
|
|
700
714
|
let hexDump = data.prefix(maxBytes).map { String(format: "%02x", $0) }.joined(separator: " ")
|
|
701
|
-
logger.error("
|
|
715
|
+
logger.error("Brotli decompression failed")
|
|
716
|
+
logger.debug("File: \(fileName), First \(maxBytes) bytes: \(hexDump)")
|
|
702
717
|
break
|
|
703
718
|
}
|
|
704
719
|
|
|
@@ -712,18 +727,19 @@ import UIKit
|
|
|
712
727
|
if status == COMPRESSION_STATUS_END {
|
|
713
728
|
break
|
|
714
729
|
} else if status == COMPRESSION_STATUS_ERROR {
|
|
715
|
-
logger.error("
|
|
730
|
+
logger.error("Brotli process failed")
|
|
731
|
+
logger.debug("File: \(fileName), Status: \(status)")
|
|
716
732
|
if let text = String(data: data, encoding: .utf8) {
|
|
717
733
|
let asciiCount = text.unicodeScalars.filter { $0.isASCII }.count
|
|
718
734
|
let totalCount = text.unicodeScalars.count
|
|
719
735
|
if totalCount > 0 && Double(asciiCount) / Double(totalCount) >= 0.8 {
|
|
720
|
-
logger.
|
|
736
|
+
logger.debug("Input appears to be plain text: \(text)")
|
|
721
737
|
}
|
|
722
738
|
}
|
|
723
739
|
|
|
724
740
|
let maxBytes = min(32, data.count)
|
|
725
741
|
let hexDump = data.prefix(maxBytes).map { String(format: "%02x", $0) }.joined(separator: " ")
|
|
726
|
-
logger.
|
|
742
|
+
logger.debug("Raw data: \(hexDump)")
|
|
727
743
|
|
|
728
744
|
return nil
|
|
729
745
|
}
|
|
@@ -734,7 +750,8 @@ import UIKit
|
|
|
734
750
|
}
|
|
735
751
|
|
|
736
752
|
if input.count == 0 {
|
|
737
|
-
logger.error("
|
|
753
|
+
logger.error("Zero input size for Brotli decompression")
|
|
754
|
+
logger.debug("File: \(fileName)")
|
|
738
755
|
break
|
|
739
756
|
}
|
|
740
757
|
}
|
|
@@ -826,7 +843,8 @@ import UIKit
|
|
|
826
843
|
reachabilityManager?.stopListening()
|
|
827
844
|
|
|
828
845
|
if mainError != nil {
|
|
829
|
-
logger.error("Failed to download
|
|
846
|
+
logger.error("Failed to download bundle")
|
|
847
|
+
logger.debug("Error: \(String(describing: mainError))")
|
|
830
848
|
self.saveBundleInfo(id: id, bundle: BundleInfo(id: id, version: version, status: BundleStatus.ERROR, downloaded: Date(), checksum: checksum, link: link, comment: comment))
|
|
831
849
|
throw mainError!
|
|
832
850
|
}
|
|
@@ -837,7 +855,8 @@ import UIKit
|
|
|
837
855
|
try CryptoCipher.decryptFile(filePath: tempDataPath, publicKey: self.publicKey, sessionKey: sessionKey, version: version)
|
|
838
856
|
try FileManager.default.moveItem(at: tempDataPath, to: finalPath)
|
|
839
857
|
} catch {
|
|
840
|
-
logger.error("Failed decrypt file
|
|
858
|
+
logger.error("Failed to decrypt file")
|
|
859
|
+
logger.debug("Error: \(error)")
|
|
841
860
|
self.saveBundleInfo(id: id, bundle: BundleInfo(id: id, version: version, status: BundleStatus.ERROR, downloaded: Date(), checksum: checksum, link: link, comment: comment))
|
|
842
861
|
cleanDownloadData()
|
|
843
862
|
throw error
|
|
@@ -850,7 +869,8 @@ import UIKit
|
|
|
850
869
|
try self.saveDownloaded(sourceZip: finalPath, id: id, base: self.libraryDir.appendingPathComponent(self.bundleDirectory), notify: true)
|
|
851
870
|
|
|
852
871
|
} catch {
|
|
853
|
-
logger.error("Failed to unzip file
|
|
872
|
+
logger.error("Failed to unzip file")
|
|
873
|
+
logger.debug("Error: \(error)")
|
|
854
874
|
self.saveBundleInfo(id: id, bundle: BundleInfo(id: id, version: version, status: BundleStatus.ERROR, downloaded: Date(), checksum: checksum, link: link, comment: comment))
|
|
855
875
|
// Best-effort cleanup of the decrypted zip file when unzip fails
|
|
856
876
|
do {
|
|
@@ -858,7 +878,8 @@ import UIKit
|
|
|
858
878
|
try FileManager.default.removeItem(at: finalPath)
|
|
859
879
|
}
|
|
860
880
|
} catch {
|
|
861
|
-
logger.error("Could not delete failed zip
|
|
881
|
+
logger.error("Could not delete failed zip")
|
|
882
|
+
logger.debug("Path: \(finalPath.path), Error: \(error)")
|
|
862
883
|
}
|
|
863
884
|
cleanDownloadData()
|
|
864
885
|
throw error
|
|
@@ -881,13 +902,15 @@ import UIKit
|
|
|
881
902
|
let fileManager = FileManager.default
|
|
882
903
|
if !fileManager.fileExists(atPath: tempDataPath.path) {
|
|
883
904
|
if !fileManager.createFile(atPath: tempDataPath.path, contents: Data()) {
|
|
884
|
-
logger.error("Cannot ensure
|
|
905
|
+
logger.error("Cannot ensure temp data file exists")
|
|
906
|
+
logger.debug("Path: \(tempDataPath.path)")
|
|
885
907
|
}
|
|
886
908
|
}
|
|
887
909
|
|
|
888
910
|
if !fileManager.fileExists(atPath: updateInfo.path) {
|
|
889
911
|
if !fileManager.createFile(atPath: updateInfo.path, contents: Data()) {
|
|
890
|
-
logger.error("Cannot ensure
|
|
912
|
+
logger.error("Cannot ensure update info file exists")
|
|
913
|
+
logger.debug("Path: \(updateInfo.path)")
|
|
891
914
|
}
|
|
892
915
|
}
|
|
893
916
|
}
|
|
@@ -899,7 +922,8 @@ import UIKit
|
|
|
899
922
|
do {
|
|
900
923
|
try fileManager.removeItem(at: tempDataPath)
|
|
901
924
|
} catch {
|
|
902
|
-
logger.error("Could not delete
|
|
925
|
+
logger.error("Could not delete temp data file")
|
|
926
|
+
logger.debug("Path: \(tempDataPath), Error: \(error)")
|
|
903
927
|
}
|
|
904
928
|
}
|
|
905
929
|
// Deleting update.dat
|
|
@@ -907,7 +931,8 @@ import UIKit
|
|
|
907
931
|
do {
|
|
908
932
|
try fileManager.removeItem(at: updateInfo)
|
|
909
933
|
} catch {
|
|
910
|
-
logger.error("Could not delete
|
|
934
|
+
logger.error("Could not delete update info file")
|
|
935
|
+
logger.debug("Path: \(updateInfo), Error: \(error)")
|
|
911
936
|
}
|
|
912
937
|
}
|
|
913
938
|
}
|
|
@@ -926,7 +951,8 @@ import UIKit
|
|
|
926
951
|
fileHandle.closeFile()
|
|
927
952
|
}
|
|
928
953
|
} catch {
|
|
929
|
-
logger.error("Failed to write data
|
|
954
|
+
logger.error("Failed to write partial data")
|
|
955
|
+
logger.debug("Byte offset: \(byteOffset), Error: \(error)")
|
|
930
956
|
}
|
|
931
957
|
self.tempData.removeAll() // Clearing tempData to avoid writing the same data multiple times
|
|
932
958
|
}
|
|
@@ -935,7 +961,8 @@ import UIKit
|
|
|
935
961
|
do {
|
|
936
962
|
try "\(version)".write(to: updateInfo, atomically: true, encoding: .utf8)
|
|
937
963
|
} catch {
|
|
938
|
-
logger.error("Failed to save progress
|
|
964
|
+
logger.error("Failed to save download progress")
|
|
965
|
+
logger.debug("Error: \(error)")
|
|
939
966
|
}
|
|
940
967
|
}
|
|
941
968
|
private func getLocalUpdateVersion() -> String { // Return the version that was tried to be downloaded on last download attempt
|
|
@@ -957,7 +984,8 @@ import UIKit
|
|
|
957
984
|
return fileSize.int64Value
|
|
958
985
|
}
|
|
959
986
|
} catch {
|
|
960
|
-
logger.error("Could not retrieve
|
|
987
|
+
logger.error("Could not retrieve download progress size")
|
|
988
|
+
logger.debug("Error: \(error)")
|
|
961
989
|
}
|
|
962
990
|
return 0
|
|
963
991
|
}
|
|
@@ -1001,7 +1029,8 @@ import UIKit
|
|
|
1001
1029
|
public func delete(id: String, removeInfo: Bool) -> Bool {
|
|
1002
1030
|
let deleted: BundleInfo = self.getBundleInfo(id: id)
|
|
1003
1031
|
if deleted.isBuiltin() || self.getCurrentBundleId() == id {
|
|
1004
|
-
logger.info("Cannot delete
|
|
1032
|
+
logger.info("Cannot delete current or builtin bundle")
|
|
1033
|
+
logger.debug("Bundle ID: \(id)")
|
|
1005
1034
|
return false
|
|
1006
1035
|
}
|
|
1007
1036
|
|
|
@@ -1010,7 +1039,8 @@ import UIKit
|
|
|
1010
1039
|
!next.isDeleted() &&
|
|
1011
1040
|
!next.isErrorStatus() &&
|
|
1012
1041
|
next.getId() == id {
|
|
1013
|
-
logger.info("Cannot delete the next bundle
|
|
1042
|
+
logger.info("Cannot delete the next bundle")
|
|
1043
|
+
logger.debug("Bundle ID: \(id)")
|
|
1014
1044
|
return false
|
|
1015
1045
|
}
|
|
1016
1046
|
|
|
@@ -1018,7 +1048,8 @@ import UIKit
|
|
|
1018
1048
|
do {
|
|
1019
1049
|
try FileManager.default.removeItem(atPath: destPersist.path)
|
|
1020
1050
|
} catch {
|
|
1021
|
-
logger.error("
|
|
1051
|
+
logger.error("Bundle folder not removed")
|
|
1052
|
+
logger.debug("Path: \(destPersist.path)")
|
|
1022
1053
|
// even if, we don;t care. Android doesn't care
|
|
1023
1054
|
if removeInfo {
|
|
1024
1055
|
self.removeBundleInfo(id: id)
|
|
@@ -1031,7 +1062,8 @@ import UIKit
|
|
|
1031
1062
|
} else {
|
|
1032
1063
|
self.saveBundleInfo(id: id, bundle: deleted.setStatus(status: BundleStatus.DELETED.localizedString))
|
|
1033
1064
|
}
|
|
1034
|
-
logger.info("
|
|
1065
|
+
logger.info("Bundle deleted successfully")
|
|
1066
|
+
logger.debug("Version: \(deleted.getVersionName())")
|
|
1035
1067
|
self.sendStats(action: "delete", versionName: deleted.getVersionName())
|
|
1036
1068
|
return true
|
|
1037
1069
|
}
|
|
@@ -1059,7 +1091,8 @@ import UIKit
|
|
|
1059
1091
|
try fileManager.removeItem(at: cacheFolder)
|
|
1060
1092
|
logger.info("Cleaned up delta cache folder")
|
|
1061
1093
|
} catch {
|
|
1062
|
-
logger.error("Failed to cleanup delta cache
|
|
1094
|
+
logger.error("Failed to cleanup delta cache")
|
|
1095
|
+
logger.debug("Error: \(error.localizedDescription)")
|
|
1063
1096
|
}
|
|
1064
1097
|
}
|
|
1065
1098
|
|
|
@@ -1099,13 +1132,16 @@ import UIKit
|
|
|
1099
1132
|
do {
|
|
1100
1133
|
try fileManager.removeItem(at: url)
|
|
1101
1134
|
self.removeBundleInfo(id: id)
|
|
1102
|
-
logger.info("Deleted orphan bundle directory
|
|
1135
|
+
logger.info("Deleted orphan bundle directory")
|
|
1136
|
+
logger.debug("Bundle ID: \(id)")
|
|
1103
1137
|
} catch {
|
|
1104
|
-
logger.error("Failed to delete orphan bundle directory
|
|
1138
|
+
logger.error("Failed to delete orphan bundle directory")
|
|
1139
|
+
logger.debug("Bundle ID: \(id), Error: \(error.localizedDescription)")
|
|
1105
1140
|
}
|
|
1106
1141
|
}
|
|
1107
1142
|
} catch {
|
|
1108
|
-
logger.error("Failed to enumerate bundle directory for cleanup
|
|
1143
|
+
logger.error("Failed to enumerate bundle directory for cleanup")
|
|
1144
|
+
logger.debug("Error: \(error.localizedDescription)")
|
|
1109
1145
|
}
|
|
1110
1146
|
}
|
|
1111
1147
|
|
|
@@ -1136,13 +1172,16 @@ import UIKit
|
|
|
1136
1172
|
|
|
1137
1173
|
do {
|
|
1138
1174
|
try fileManager.removeItem(at: url)
|
|
1139
|
-
logger.info("Deleted orphaned temp unzip folder
|
|
1175
|
+
logger.info("Deleted orphaned temp unzip folder")
|
|
1176
|
+
logger.debug("Folder: \(folderName)")
|
|
1140
1177
|
} catch {
|
|
1141
|
-
logger.error("Failed to delete orphaned temp folder
|
|
1178
|
+
logger.error("Failed to delete orphaned temp folder")
|
|
1179
|
+
logger.debug("Folder: \(folderName), Error: \(error.localizedDescription)")
|
|
1142
1180
|
}
|
|
1143
1181
|
}
|
|
1144
1182
|
} catch {
|
|
1145
|
-
logger.error("Failed to enumerate library directory for temp folder cleanup
|
|
1183
|
+
logger.error("Failed to enumerate library directory for temp folder cleanup")
|
|
1184
|
+
logger.debug("Error: \(error.localizedDescription)")
|
|
1146
1185
|
}
|
|
1147
1186
|
}
|
|
1148
1187
|
|
|
@@ -1218,9 +1257,11 @@ import UIKit
|
|
|
1218
1257
|
if autoDeletePrevious && !fallback.isBuiltin() && fallback.getId() != bundle.getId() {
|
|
1219
1258
|
let res = self.delete(id: fallback.getId())
|
|
1220
1259
|
if res {
|
|
1221
|
-
logger.info("Deleted previous bundle
|
|
1260
|
+
logger.info("Deleted previous bundle")
|
|
1261
|
+
logger.debug("Bundle: \(fallback.toString())")
|
|
1222
1262
|
} else {
|
|
1223
|
-
logger.error("Failed to delete previous bundle
|
|
1263
|
+
logger.error("Failed to delete previous bundle")
|
|
1264
|
+
logger.debug("Bundle: \(fallback.toString())")
|
|
1224
1265
|
}
|
|
1225
1266
|
}
|
|
1226
1267
|
self.setFallbackBundle(fallback: bundle)
|
|
@@ -1301,7 +1342,8 @@ import UIKit
|
|
|
1301
1342
|
}
|
|
1302
1343
|
}
|
|
1303
1344
|
case let .failure(error):
|
|
1304
|
-
self.logger.error("Error
|
|
1345
|
+
self.logger.error("Error setting channel")
|
|
1346
|
+
self.logger.debug("Error: \(error)")
|
|
1305
1347
|
setChannel.error = "Request failed: \(error.localizedDescription)"
|
|
1306
1348
|
}
|
|
1307
1349
|
semaphore.signal()
|
|
@@ -1364,7 +1406,8 @@ import UIKit
|
|
|
1364
1406
|
}
|
|
1365
1407
|
}
|
|
1366
1408
|
|
|
1367
|
-
self.logger.error("Error
|
|
1409
|
+
self.logger.error("Error getting channel")
|
|
1410
|
+
self.logger.debug("Error: \(error)")
|
|
1368
1411
|
getChannel.error = "Request failed: \(error.localizedDescription)"
|
|
1369
1412
|
}
|
|
1370
1413
|
}
|
|
@@ -1454,7 +1497,8 @@ import UIKit
|
|
|
1454
1497
|
}
|
|
1455
1498
|
}
|
|
1456
1499
|
case let .failure(error):
|
|
1457
|
-
self.logger.error("Error
|
|
1500
|
+
self.logger.error("Error listing channels")
|
|
1501
|
+
self.logger.debug("Error: \(error)")
|
|
1458
1502
|
listChannels.error = "Request failed: \(error.localizedDescription)"
|
|
1459
1503
|
}
|
|
1460
1504
|
}
|
|
@@ -1500,9 +1544,11 @@ import UIKit
|
|
|
1500
1544
|
|
|
1501
1545
|
switch response.result {
|
|
1502
1546
|
case .success:
|
|
1503
|
-
self.logger.info("Stats sent
|
|
1547
|
+
self.logger.info("Stats sent successfully")
|
|
1548
|
+
self.logger.debug("Action: \(action), Version: \(versionName)")
|
|
1504
1549
|
case let .failure(error):
|
|
1505
|
-
self.logger.error("Error sending stats
|
|
1550
|
+
self.logger.error("Error sending stats")
|
|
1551
|
+
self.logger.debug("Response: \(response.value?.debugDescription ?? "nil"), Error: \(error.localizedDescription)")
|
|
1506
1552
|
}
|
|
1507
1553
|
semaphore.signal()
|
|
1508
1554
|
}
|
|
@@ -1526,7 +1572,8 @@ import UIKit
|
|
|
1526
1572
|
do {
|
|
1527
1573
|
result = try UserDefaults.standard.getObj(forKey: "\(trueId)\(self.INFO_SUFFIX)", castTo: BundleInfo.self)
|
|
1528
1574
|
} catch {
|
|
1529
|
-
logger.error("Failed to parse
|
|
1575
|
+
logger.error("Failed to parse bundle info")
|
|
1576
|
+
logger.debug("Bundle ID: \(trueId), Error: \(error.localizedDescription)")
|
|
1530
1577
|
result = BundleInfo(id: trueId, version: "", status: BundleStatus.PENDING, checksum: "")
|
|
1531
1578
|
}
|
|
1532
1579
|
}
|
|
@@ -1561,7 +1608,8 @@ import UIKit
|
|
|
1561
1608
|
do {
|
|
1562
1609
|
try UserDefaults.standard.setObj(update, forKey: "\(id)\(self.INFO_SUFFIX)")
|
|
1563
1610
|
} catch {
|
|
1564
|
-
logger.error("Failed to save
|
|
1611
|
+
logger.error("Failed to save bundle info")
|
|
1612
|
+
logger.debug("Bundle ID: \(id), Error: \(error.localizedDescription)")
|
|
1565
1613
|
}
|
|
1566
1614
|
}
|
|
1567
1615
|
UserDefaults.standard.synchronize()
|
|
@@ -18,8 +18,8 @@ public struct CryptoCipher {
|
|
|
18
18
|
private static func hexStringToData(_ hex: String) -> Data? {
|
|
19
19
|
var data = Data()
|
|
20
20
|
var hexIterator = hex.makeIterator()
|
|
21
|
-
while let
|
|
22
|
-
guard let byte = UInt8(String([
|
|
21
|
+
while let char1 = hexIterator.next(), let char2 = hexIterator.next() {
|
|
22
|
+
guard let byte = UInt8(String([char1, char2]), radix: 16) else {
|
|
23
23
|
return nil
|
|
24
24
|
}
|
|
25
25
|
data.append(byte)
|
|
@@ -45,7 +45,8 @@ public struct CryptoCipher {
|
|
|
45
45
|
if isHexString(checksum) {
|
|
46
46
|
// Hex encoded (new format from CLI for plugin versions >= 5.30.0, 6.30.0, 7.30.0)
|
|
47
47
|
guard let hexData = hexStringToData(checksum) else {
|
|
48
|
-
logger.error("Cannot decode checksum as hex
|
|
48
|
+
logger.error("Cannot decode checksum as hex")
|
|
49
|
+
logger.debug("Checksum value: \(checksum)")
|
|
49
50
|
throw CustomError.cannotDecode
|
|
50
51
|
}
|
|
51
52
|
checksumBytes = hexData
|
|
@@ -54,12 +55,14 @@ public struct CryptoCipher {
|
|
|
54
55
|
// TODO: remove backwards compatibility
|
|
55
56
|
// Base64 encoded (old format for backwards compatibility)
|
|
56
57
|
guard let base64Data = Data(base64Encoded: checksum) else {
|
|
57
|
-
logger.error("Cannot decode checksum as base64
|
|
58
|
+
logger.error("Cannot decode checksum as base64")
|
|
59
|
+
logger.debug("Checksum value: \(checksum)")
|
|
58
60
|
throw CustomError.cannotDecode
|
|
59
61
|
}
|
|
60
62
|
checksumBytes = base64Data
|
|
61
63
|
detectedFormat = "base64"
|
|
62
64
|
}
|
|
65
|
+
// swiftlint:disable:next line_length
|
|
63
66
|
logger.debug("Received encrypted checksum format: \(detectedFormat) (length: \(checksum.count) chars, \(checksumBytes.count) bytes)")
|
|
64
67
|
|
|
65
68
|
if checksumBytes.isEmpty {
|
|
@@ -86,15 +89,18 @@ public struct CryptoCipher {
|
|
|
86
89
|
detectedAlgorithm = "SHA-256"
|
|
87
90
|
} else if decryptedChecksum.count == 4 {
|
|
88
91
|
detectedAlgorithm = "CRC32 (deprecated)"
|
|
89
|
-
logger.error("CRC32 checksum detected
|
|
92
|
+
logger.error("CRC32 checksum detected - deprecated algorithm")
|
|
90
93
|
} else {
|
|
91
94
|
detectedAlgorithm = "unknown (\(decryptedChecksum.count) bytes)"
|
|
92
|
-
logger.error("Unknown checksum algorithm detected
|
|
95
|
+
logger.error("Unknown checksum algorithm detected")
|
|
96
|
+
logger.debug("Byte count: \(decryptedChecksum.count), Expected: 32 (SHA-256)")
|
|
93
97
|
}
|
|
98
|
+
// swiftlint:disable:next line_length
|
|
94
99
|
logger.debug("Decrypted checksum: \(detectedAlgorithm) hex format (length: \(result.count) chars, \(decryptedChecksum.count) bytes)")
|
|
95
100
|
return result
|
|
96
101
|
} catch {
|
|
97
|
-
logger.error("
|
|
102
|
+
logger.error("Checksum decryption failed")
|
|
103
|
+
logger.debug("Error: \(error.localizedDescription)")
|
|
98
104
|
throw CustomError.cannotDecode
|
|
99
105
|
}
|
|
100
106
|
}
|
|
@@ -121,9 +127,10 @@ public struct CryptoCipher {
|
|
|
121
127
|
let algorithm = detectChecksumAlgorithm(hexChecksum)
|
|
122
128
|
logger.debug("\(label): \(algorithm) hex format (length: \(hexChecksum.count) chars)")
|
|
123
129
|
if algorithm.contains("CRC32") {
|
|
124
|
-
logger.error("CRC32 checksum detected
|
|
130
|
+
logger.error("CRC32 checksum detected - deprecated algorithm")
|
|
125
131
|
} else if algorithm.contains("unknown") {
|
|
126
|
-
logger.error("Unknown checksum algorithm detected
|
|
132
|
+
logger.error("Unknown checksum algorithm detected")
|
|
133
|
+
logger.debug("Char count: \(hexChecksum.count), Expected: 64 (SHA-256)")
|
|
127
134
|
}
|
|
128
135
|
}
|
|
129
136
|
|
|
@@ -136,7 +143,8 @@ public struct CryptoCipher {
|
|
|
136
143
|
do {
|
|
137
144
|
fileHandle = try FileHandle(forReadingFrom: filePath)
|
|
138
145
|
} catch {
|
|
139
|
-
logger.error("Cannot open file for checksum
|
|
146
|
+
logger.error("Cannot open file for checksum calculation")
|
|
147
|
+
logger.debug("Path: \(filePath.path), Error: \(error)")
|
|
140
148
|
return ""
|
|
141
149
|
}
|
|
142
150
|
|
|
@@ -144,7 +152,8 @@ public struct CryptoCipher {
|
|
|
144
152
|
do {
|
|
145
153
|
try fileHandle.close()
|
|
146
154
|
} catch {
|
|
147
|
-
logger.error("Error closing file
|
|
155
|
+
logger.error("Error closing file during checksum")
|
|
156
|
+
logger.debug("Error: \(error)")
|
|
148
157
|
}
|
|
149
158
|
}
|
|
150
159
|
|
|
@@ -153,7 +162,8 @@ public struct CryptoCipher {
|
|
|
153
162
|
do {
|
|
154
163
|
fileData = try fileHandle.read(upToCount: bufferSize) ?? Data()
|
|
155
164
|
} catch {
|
|
156
|
-
logger.error("Error reading file
|
|
165
|
+
logger.error("Error reading file during checksum")
|
|
166
|
+
logger.debug("Error: \(error)")
|
|
157
167
|
return false
|
|
158
168
|
}
|
|
159
169
|
|
|
@@ -168,7 +178,8 @@ public struct CryptoCipher {
|
|
|
168
178
|
let digest = sha256.finalize()
|
|
169
179
|
return digest.compactMap { String(format: "%02x", $0) }.joined()
|
|
170
180
|
} catch {
|
|
171
|
-
logger.error("Cannot
|
|
181
|
+
logger.error("Cannot calculate checksum")
|
|
182
|
+
logger.debug("Path: \(filePath.path), Error: \(error)")
|
|
172
183
|
return ""
|
|
173
184
|
}
|
|
174
185
|
}
|
|
@@ -195,17 +206,20 @@ public struct CryptoCipher {
|
|
|
195
206
|
let encryptedKeyBase64 = sessionKeyComponents[1]
|
|
196
207
|
|
|
197
208
|
guard let ivData = Data(base64Encoded: ivBase64) else {
|
|
198
|
-
logger.error("Cannot decode sessionKey IV
|
|
209
|
+
logger.error("Cannot decode sessionKey IV")
|
|
210
|
+
logger.debug("IV value: \(ivBase64)")
|
|
199
211
|
throw CustomError.cannotDecode
|
|
200
212
|
}
|
|
201
213
|
|
|
202
214
|
if ivData.count != 16 {
|
|
203
|
-
logger.error("IV data has invalid length
|
|
215
|
+
logger.error("IV data has invalid length")
|
|
216
|
+
logger.debug("Length: \(ivData.count), Expected: 16")
|
|
204
217
|
throw CustomError.cannotDecode
|
|
205
218
|
}
|
|
206
219
|
|
|
207
220
|
guard let sessionKeyDataEncrypted = Data(base64Encoded: encryptedKeyBase64) else {
|
|
208
|
-
logger.error("Cannot decode sessionKey data
|
|
221
|
+
logger.error("Cannot decode sessionKey data")
|
|
222
|
+
logger.debug("Key value: \(encryptedKeyBase64)")
|
|
209
223
|
throw NSError(domain: "Invalid session key data", code: 1, userInfo: nil)
|
|
210
224
|
}
|
|
211
225
|
|
|
@@ -215,7 +229,8 @@ public struct CryptoCipher {
|
|
|
215
229
|
}
|
|
216
230
|
|
|
217
231
|
if sessionKeyDataDecrypted.count != 16 {
|
|
218
|
-
logger.error("Decrypted session key has invalid length
|
|
232
|
+
logger.error("Decrypted session key has invalid length")
|
|
233
|
+
logger.debug("Length: \(sessionKeyDataDecrypted.count), Expected: 16")
|
|
219
234
|
throw NSError(domain: "Invalid decrypted session key", code: 5, userInfo: nil)
|
|
220
235
|
}
|
|
221
236
|
|
|
@@ -225,7 +240,8 @@ public struct CryptoCipher {
|
|
|
225
240
|
do {
|
|
226
241
|
encryptedData = try Data(contentsOf: filePath)
|
|
227
242
|
} catch {
|
|
228
|
-
logger.error("Failed to read encrypted data
|
|
243
|
+
logger.error("Failed to read encrypted data")
|
|
244
|
+
logger.debug("Error: \(error)")
|
|
229
245
|
throw NSError(domain: "Failed to read encrypted data", code: 3, userInfo: nil)
|
|
230
246
|
}
|
|
231
247
|
|
|
@@ -251,12 +267,13 @@ public struct CryptoCipher {
|
|
|
251
267
|
throw NSError(domain: "File write failed", code: 8, userInfo: nil)
|
|
252
268
|
}
|
|
253
269
|
} catch {
|
|
254
|
-
logger.error("Error writing decrypted file
|
|
270
|
+
logger.error("Error writing decrypted file")
|
|
271
|
+
logger.debug("Error: \(error)")
|
|
255
272
|
throw error
|
|
256
273
|
}
|
|
257
274
|
|
|
258
275
|
} catch {
|
|
259
|
-
logger.error("
|
|
276
|
+
logger.error("File decryption failed")
|
|
260
277
|
throw CustomError.cannotDecode
|
|
261
278
|
}
|
|
262
279
|
}
|