Migration for iOS.

This commit is contained in:
M
2020-09-23 21:26:10 +03:00
parent 5f88c4bafd
commit b0a31147dd
18 changed files with 467 additions and 213 deletions
-50
View File
@@ -1,50 +0,0 @@
import Foundation
import CryptoSwift
class EncryptedFile {
private(set) var fileName: String
private(set) var url: URL
private let key: Array<UInt8>
private let salt: Array<UInt8>
init(url: URL, key: String, salt: String) {
self.key = key.data(using: .utf8)?.bytes ?? []
self.salt = salt.data(using: .utf8)?.bytes ?? []
self.url = url
self.fileName = url.lastPathComponent
}
func readRawContent() -> String? {
guard let binaryContent = try? Data(contentsOf: url) else {
return nil
}
return String(data: binaryContent, encoding: .utf8)
}
func decryptedContent() -> String? {
guard
let rawContent = readRawContent(),
let decryptedBytes = try? cipherBuilder().decrypt(rawContent.bytes) else {
return nil
}
let decryptedData = Data(decryptedBytes)
return String(data: decryptedData, encoding: .utf8)
}
func cipherBuilder() -> Cipher {
let PBKDF2key = try! PKCS5.PBKDF2(password: key, salt: salt, iterations: 4096, variant: .sha256).calculate()
return try! Blowfish(key: PBKDF2key, padding: .pkcs7)
}
}
func readTradesList(key: String, salt: String) -> String? {
let url = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first!.appendingPathComponent("trades_list.json")
return EncryptedFile(
url: url,
key: key,
salt: salt).decryptedContent()
}
+16
View File
@@ -0,0 +1,16 @@
import Foundation
import CryptoSwift
func decrypt(data: Data, key: String, salt: String) -> String? {
let keyBytes = key.data(using: .utf8)?.bytes ?? []
let saltBytes = salt.data(using: .utf8)?.bytes ?? []
guard let PBKDF2key = try? PKCS5.PBKDF2(password: keyBytes, salt: saltBytes, iterations: 4096, variant: .sha256).calculate(),
let cipher = try? Blowfish(key: PBKDF2key, padding: .pkcs7),
let decryptedBytes = try? cipher.decrypt(data.bytes) else {
return nil
}
let decryptedData = Data(decryptedBytes)
return String(data: decryptedData, encoding: .utf8)
}
+1 -1
View File
@@ -1 +1 @@
09c81fe0a3d701eb6da3bd2c6fc5ec65
bc336703210c48e30d7216fac3fe1c0f
+1
View File
@@ -1,5 +1,6 @@
# Uncomment this line to define a global platform for your project
platform :ios, '9.0'
source 'https://github.com/CocoaPods/Specs.git'
# CocoaPods analytics sends network stats synchronously affecting flutter build latency.
ENV['COCOAPODS_DISABLE_STATS'] = 'true'
+3 -3
View File
@@ -64,7 +64,7 @@ DEPENDENCIES:
- url_launcher (from `.symlinks/plugins/url_launcher/ios`)
SPEC REPOS:
trunk:
https://github.com/CocoaPods/Specs.git:
- CryptoSwift
- MTBBarcodeScanner
- Reachability
@@ -117,6 +117,6 @@ SPEC CHECKSUMS:
SwiftProtobuf: 4ef85479c18ca85b5482b343df9c319c62bda699
url_launcher: 6fef411d543ceb26efce54b05a0a40bfd74cbbef
PODFILE CHECKSUM: ade2ba43f8c2af4060c025bfd25a553d068ab914
PODFILE CHECKSUM: ba3d2157523e2f4dc333b987efdac6635da8125d
COCOAPODS: 1.8.4
COCOAPODS: 1.9.3
+6 -18
View File
@@ -7,7 +7,7 @@
objects = {
/* Begin PBXBuildFile section */
0C44A71A2518EF8000B570ED /* EncryptedFile.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0C44A7192518EF8000B570ED /* EncryptedFile.swift */; };
0C44A71A2518EF8000B570ED /* decrypt.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0C44A7192518EF8000B570ED /* decrypt.swift */; };
1498D2341E8E89220040F4C2 /* GeneratedPluginRegistrant.m in Sources */ = {isa = PBXBuildFile; fileRef = 1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */; };
20ED0868E1BD7E12278C0CB3 /* Pods_Runner.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B26E3F56D69167FBB1DC160A /* Pods_Runner.framework */; };
3B3967161E833CAA004F5970 /* AppFrameworkInfo.plist in Resources */ = {isa = PBXBuildFile; fileRef = 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */; };
@@ -17,21 +17,9 @@
97C147011CF9000F007C117D /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FF1CF9000F007C117D /* LaunchScreen.storyboard */; };
/* End PBXBuildFile section */
/* Begin PBXCopyFilesBuildPhase section */
9705A1C41CF9048500538489 /* Embed Frameworks */ = {
isa = PBXCopyFilesBuildPhase;
buildActionMask = 2147483647;
dstPath = "";
dstSubfolderSpec = 10;
files = (
);
name = "Embed Frameworks";
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXCopyFilesBuildPhase section */
/* Begin PBXFileReference section */
0C44A7192518EF8000B570ED /* EncryptedFile.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EncryptedFile.swift; sourceTree = "<group>"; };
0C44A7192518EF8000B570ED /* decrypt.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = decrypt.swift; sourceTree = "<group>"; };
0C9986A3251A932F00D566FD /* CryptoSwift.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = CryptoSwift.framework; sourceTree = BUILT_PRODUCTS_DIR; };
1498D2321E8E86230040F4C2 /* GeneratedPluginRegistrant.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GeneratedPluginRegistrant.h; sourceTree = "<group>"; };
1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GeneratedPluginRegistrant.m; sourceTree = "<group>"; };
20F67A1B2C2FCB2A3BB048C1 /* Pods-Runner.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.debug.xcconfig"; path = "Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig"; sourceTree = "<group>"; };
@@ -66,6 +54,7 @@
06957875428D0F5AAE053765 /* Frameworks */ = {
isa = PBXGroup;
children = (
0C9986A3251A932F00D566FD /* CryptoSwift.framework */,
B26E3F56D69167FBB1DC160A /* Pods_Runner.framework */,
);
name = Frameworks;
@@ -74,7 +63,7 @@
0C44A7182518EF4A00B570ED /* CakeWallet */ = {
isa = PBXGroup;
children = (
0C44A7192518EF8000B570ED /* EncryptedFile.swift */,
0C44A7192518EF8000B570ED /* decrypt.swift */,
);
path = CakeWallet;
sourceTree = "<group>";
@@ -147,7 +136,6 @@
97C146EA1CF9000F007C117D /* Sources */,
97C146EB1CF9000F007C117D /* Frameworks */,
97C146EC1CF9000F007C117D /* Resources */,
9705A1C41CF9048500538489 /* Embed Frameworks */,
3B06AD1E1E4923F5004D2608 /* Thin Binary */,
DD8DB3179CA4E511F9954A6F /* [CP] Embed Pods Frameworks */,
);
@@ -284,7 +272,7 @@
files = (
74858FAF1ED2DC5600515810 /* AppDelegate.swift in Sources */,
1498D2341E8E89220040F4C2 /* GeneratedPluginRegistrant.m in Sources */,
0C44A71A2518EF8000B570ED /* EncryptedFile.swift in Sources */,
0C44A71A2518EF8000B570ED /* decrypt.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
+27 -12
View File
@@ -14,26 +14,41 @@ import Flutter
(call: FlutterMethodCall, result: @escaping FlutterResult) -> Void in
switch call.method {
case "read_trade_list":
case "decrypt":
guard let args = call.arguments as? Dictionary<String, Any>,
let data = args["bytes"] as? FlutterStandardTypedData,
let key = args["key"] as? String,
let salt = args["salt"] as? String else {
return
}
let normalizedKey = key.replacingOccurrences(of: "-", with: "")
result(readTradesList(key: normalizedKey, salt: salt))
case "read_encrypted_file":
guard let args = call.arguments as? Dictionary<String, Any>,
let path = args["path"] as? String,
let key = args["key"] as? String,
let salt = args["salt"] as? String else {
result(nil)
return
}
let content = EncryptedFile(url: URL(fileURLWithPath: path), key: key, salt: salt).decryptedContent()
let content = decrypt(data: data.data, key: key, salt: salt)
result(content)
case "read_user_defaults":
guard let args = call.arguments as? Dictionary<String, Any>,
let key = args["key"] as? String,
let type = args["type"] as? String else {
result(nil)
return
}
var value: Any?
switch (type) {
case "string":
value = UserDefaults.standard.string(forKey: key)
case "int":
value = UserDefaults.standard.integer(forKey: key)
case "bool":
value = UserDefaults.standard.bool(forKey: key)
default:
break
}
result(value)
default:
break
result(FlutterMethodNotImplemented)
}
})