Skip to content
This repository has been archived by the owner on Aug 4, 2019. It is now read-only.

Commit

Permalink
We can change insensitive key generation closed #240
Browse files Browse the repository at this point in the history
  • Loading branch information
hamedaakhlaghi committed Apr 22, 2019
1 parent 472eac0 commit 63710ed
Show file tree
Hide file tree
Showing 8 changed files with 84 additions and 16 deletions.
35 changes: 26 additions & 9 deletions MobileToken.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,13 @@
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
AF3BAC43226D976D00AE7D2E /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy;
containerPortal = AFB39B442189A6A600302624 /* Project object */;
proxyType = 1;
remoteGlobalIDString = AF51CB21222BF07C003051D7;
remoteInfo = MobileTokenDebug;
};
AFB39B612189A6A700302624 /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy;
containerPortal = AFB39B442189A6A600302624 /* Project object */;
Expand Down Expand Up @@ -1619,6 +1626,7 @@
);
dependencies = (
AFB39B622189A6A700302624 /* PBXTargetDependency */,
AF3BAC44226D976D00AE7D2E /* PBXTargetDependency */,
);
name = MobileTokenTests;
productName = MobileTokenTests;
Expand Down Expand Up @@ -1664,7 +1672,7 @@
};
AFB39B5F2189A6A700302624 = {
CreatedOnToolsVersion = 10.0;
TestTargetID = AFB39B4B2189A6A600302624;
TestTargetID = AF51CB21222BF07C003051D7;
};
AFB39B6A2189A6A700302624 = {
CreatedOnToolsVersion = 10.0;
Expand Down Expand Up @@ -1852,6 +1860,7 @@
"${BUILT_PRODUCTS_DIR}/HUIPatternLockView-Swift/HUIPatternLockView_Swift.framework",
"${BUILT_PRODUCTS_DIR}/IQKeyboardManager/IQKeyboardManager.framework",
"${BUILT_PRODUCTS_DIR}/InputMask/InputMask.framework",
"${BUILT_PRODUCTS_DIR}/KeychainSwift/KeychainSwift.framework",
"${BUILT_PRODUCTS_DIR}/ObjectMapper/ObjectMapper.framework",
"${BUILT_PRODUCTS_DIR}/ObjectMapper+Realm/ObjectMapper_Realm.framework",
"${BUILT_PRODUCTS_DIR}/Onboard/Onboard.framework",
Expand Down Expand Up @@ -1881,6 +1890,7 @@
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/HUIPatternLockView_Swift.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/IQKeyboardManager.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/InputMask.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/KeychainSwift.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/ObjectMapper.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/ObjectMapper_Realm.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Onboard.framework",
Expand Down Expand Up @@ -2060,6 +2070,7 @@
"${BUILT_PRODUCTS_DIR}/HUIPatternLockView-Swift/HUIPatternLockView_Swift.framework",
"${BUILT_PRODUCTS_DIR}/IQKeyboardManager/IQKeyboardManager.framework",
"${BUILT_PRODUCTS_DIR}/InputMask/InputMask.framework",
"${BUILT_PRODUCTS_DIR}/KeychainSwift/KeychainSwift.framework",
"${BUILT_PRODUCTS_DIR}/ObjectMapper/ObjectMapper.framework",
"${BUILT_PRODUCTS_DIR}/ObjectMapper+Realm/ObjectMapper_Realm.framework",
"${BUILT_PRODUCTS_DIR}/Onboard/Onboard.framework",
Expand Down Expand Up @@ -2089,6 +2100,7 @@
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/HUIPatternLockView_Swift.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/IQKeyboardManager.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/InputMask.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/KeychainSwift.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/ObjectMapper.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/ObjectMapper_Realm.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Onboard.framework",
Expand Down Expand Up @@ -2389,6 +2401,11 @@
/* End PBXSourcesBuildPhase section */

/* Begin PBXTargetDependency section */
AF3BAC44226D976D00AE7D2E /* PBXTargetDependency */ = {
isa = PBXTargetDependency;
target = AF51CB21222BF07C003051D7 /* MobileTokenDebug */;
targetProxy = AF3BAC43226D976D00AE7D2E /* PBXContainerItemProxy */;
};
AFB39B622189A6A700302624 /* PBXTargetDependency */ = {
isa = PBXTargetDependency;
target = AFB39B4B2189A6A600302624 /* MobileToken */;
Expand Down Expand Up @@ -2442,7 +2459,7 @@
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
DEVELOPMENT_TEAM = E8R89PF79F;
INFOPLIST_FILE = "MobileToken/Info-debug.plist";
IPHONEOS_DEPLOYMENT_TARGET = 11.4;
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
Expand All @@ -2469,7 +2486,7 @@
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
DEVELOPMENT_TEAM = E8R89PF79F;
INFOPLIST_FILE = "MobileToken/Info-debug.plist";
IPHONEOS_DEPLOYMENT_TARGET = 11.4;
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
Expand All @@ -2496,7 +2513,7 @@
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
DEVELOPMENT_TEAM = E8R89PF79F;
INFOPLIST_FILE = "MobileToken/Info-debug.plist";
IPHONEOS_DEPLOYMENT_TARGET = 11.4;
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
Expand All @@ -2523,7 +2540,7 @@
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
DEVELOPMENT_TEAM = E8R89PF79F;
INFOPLIST_FILE = "MobileToken/Info-debug.plist";
IPHONEOS_DEPLOYMENT_TARGET = 11.4;
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
Expand Down Expand Up @@ -2650,7 +2667,7 @@
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 4.2;
TARGETED_DEVICE_FAMILY = "1,2";
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/MobileToken.app/MobileToken";
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/MobileTokenDebug.app/MobileTokenDebug";
};
name = DebugISCOP;
};
Expand Down Expand Up @@ -2781,7 +2798,7 @@
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 4.2;
TARGETED_DEVICE_FAMILY = "1,2";
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/MobileToken.app/MobileToken";
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/MobileTokenDebug.app/MobileTokenDebug";
};
name = ReleaseISCOP;
};
Expand Down Expand Up @@ -3006,7 +3023,7 @@
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 4.2;
TARGETED_DEVICE_FAMILY = "1,2";
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/MobileToken.app/MobileToken";
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/MobileTokenDebug.app/MobileTokenDebug";
};
name = DebugCarreneDev;
};
Expand All @@ -3028,7 +3045,7 @@
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 4.2;
TARGETED_DEVICE_FAMILY = "1,2";
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/MobileToken.app/MobileToken";
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/MobileTokenDebug.app/MobileTokenDebug";
};
name = ReleaseCarreneDev;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "NO"
buildForTesting = "YES"
buildForRunning = "NO"
buildForProfiling = "NO"
buildForArchiving = "NO"
Expand Down Expand Up @@ -42,6 +42,16 @@
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
<TestableReference
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "AFB39B5F2189A6A700302624"
BuildableName = "MobileTokenTests.xctest"
BlueprintName = "MobileTokenTests"
ReferencedContainer = "container:MobileToken.xcodeproj">
</BuildableReference>
</TestableReference>
</Testables>
<MacroExpansion>
<BuildableReference
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

import Foundation
import RealmSwift
import KeychainSwift

class RealmConfiguration {

Expand All @@ -16,14 +17,19 @@ class RealmConfiguration {
static func insensitiveDataConfiguration() -> Realm.Configuration {
var config = Realm.Configuration()
config.fileURL = config.fileURL!.deletingLastPathComponent().appendingPathComponent("insensitive.realm")
config.encryptionKey = insensitiveDataEncryptionKey.data(using: String.Encoding.utf8, allowLossyConversion: false)
// let key = insensitiveDataEncryptionKey.data(using: String.Encoding.utf8, allowLossyConversion: false)
let keychain = KeychainSwift()
let key = keychain.getData("my key")
print(type(of: key))
config.encryptionKey = key
return config
}

static func sensitiveDataConfiguration() -> Realm.Configuration {
var config = Realm.Configuration()
config.fileURL = config.fileURL!.deletingLastPathComponent().appendingPathComponent("sensitive.realm")
config.encryptionKey = sensitiveDataEncryptionKey.data(using: String.Encoding.utf8, allowLossyConversion: false)
let key = sensitiveDataEncryptionKey.data(using: String.Encoding.utf8, allowLossyConversion: false)
config.encryptionKey = key
return config
}

Expand Down
13 changes: 13 additions & 0 deletions MobileToken/ui/main/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import IQKeyboardManager
import Firebase
import Fabric
import UserNotifications
import KeychainSwift

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
Expand All @@ -18,6 +19,18 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
initialTheme()
initialIQKeyboard()
initialFirebase(application: application)

do {
let data = try CryptoUtil.generateRandomData(size: 64)
print(data.bytes)
let keychain = KeychainSwift()
let key = keychain.getData("my key")
if key == nil {
keychain.set(data, forKey: "my key", withAccess: .accessibleWhenUnlockedThisDeviceOnly)
}
} catch {

}
return true
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class PhoneConfirmationPresenter:PhoneConfirmationPresenterProtocol {
}

@objc func update() {

if(timeCount >= 0) {
view.setCounterTitleTime(time:String(self.timeString(time: Double(timeCount))))
if timeCount == 0 {
Expand Down
19 changes: 18 additions & 1 deletion MobileToken/util/CryptoUtil.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,23 @@ class CryptoUtil {
return key
}


static func generateRandomData(size: Int) throws -> Data {
var data = Data(count: size)
var d = data
let result = d.withUnsafeMutableBytes {
(mutableBytes: UnsafeMutablePointer<UInt8>) -> Int32 in
SecRandomCopyBytes(kSecRandomDefault, data.count, mutableBytes)
}

if result != errSecSuccess {
throw GenerateRandomDataError.UnableToGenerateRandomData
}
print(type(of: d))
return d
}

}

enum GenerateRandomDataError: Error {
case UnableToGenerateRandomData
}
3 changes: 2 additions & 1 deletion Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ abstract_target 'Common' do
pod 'Fabric', '~> 1.9.0'
pod 'Crashlytics', '~> 3.12.0'
pod 'PopupDialog', '~> 0.9'

pod 'KeychainSwift', '~> 14.0'

target 'MobileToken' do
end

Expand Down
6 changes: 5 additions & 1 deletion Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ PODS:
- HUIPatternLockView-Swift (2.0.1)
- InputMask (3.4.1)
- IQKeyboardManager (6.0.6)
- KeychainSwift (14.0.0)
- nanopb (0.3.901):
- nanopb/decode (= 0.3.901)
- nanopb/encode (= 0.3.901)
Expand Down Expand Up @@ -118,6 +119,7 @@ DEPENDENCIES:
- HUIPatternLockView-Swift (~> 2.0.1)
- InputMask (~> 3.4.0)
- IQKeyboardManager (~> 6.0.4)
- KeychainSwift
- oath (from `https://github.com/Carrene/oath.swift.git`, tag `0.4.0`)
- "ObjectMapper+Realm (~> 0.6)"
- Onboard (~> 2.3.3)
Expand Down Expand Up @@ -152,6 +154,7 @@ SPEC REPOS:
- HUIPatternLockView-Swift
- InputMask
- IQKeyboardManager
- KeychainSwift
- nanopb
- ObjectMapper
- "ObjectMapper+Realm"
Expand Down Expand Up @@ -199,6 +202,7 @@ SPEC CHECKSUMS:
HUIPatternLockView-Swift: 0f72d91ff3aeb01f5cad43f6093c5361522bb472
InputMask: 2c7d3faddbc724a8356a6ea269d60d9d6d7d2423
IQKeyboardManager: 6b4ecd3e59cf55a26133d802d4678721d7f88499
KeychainSwift: d3cce449feb5198907aa3c50ae7409fdbd9d3e20
nanopb: 2901f78ea1b7b4015c860c2fdd1ea2fee1a18d48
oath: 107b59d360ec1f9f0fce270d32b1e5052a59aa3a
ObjectMapper: 0d4402610f4e468903ae64629eec4784531e5c51
Expand All @@ -214,6 +218,6 @@ SPEC CHECKSUMS:
TTGSnackbar: 2cf4e7b6ffbe5cddf248a73f3ee952b71bee8ea3
XLActionController: d2ab12a967ae0fee0b4563b8d809c8fb13ebc636

PODFILE CHECKSUM: 493aeee52bd58d4b723cd032ec490ac4f1361929
PODFILE CHECKSUM: d5c3b1e3186bddd2d967b96cb7dc6ef528230ae0

COCOAPODS: 1.5.3

0 comments on commit 63710ed

Please sign in to comment.