Dev add device checker (#108)

* Added device checker

* Localization

* Moved `isJailbroken`. Added tests

* Class renaming

* Removed comments

* Fixed xcsscheme

* Fix naming

* Renamed class
pull/2/head
Michael Scoff 7 years ago committed by GitHub
parent ab453f3b16
commit 01f1e42750
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 52
      Trust.xcodeproj/project.pbxproj
  2. 42
      Trust/Core/Coordinators/CheckDeviceCoordinator.swift
  3. 22
      Trust/Core/Helpers/DeviceChecker.swift
  4. 7
      Trust/Core/Helpers/JailbreakChecker.swift
  5. 13
      Trust/InCoordinator.swift
  6. 32
      TrustTests/Core/Coordinators/CheckDeviceCoordinatorTests.swift
  7. 16
      TrustTests/Factories/FakeJailbreakChecker.swift

@ -264,6 +264,11 @@
61F8AA951FCA4C9300488C6E /* BigIntTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 61F8AA941FCA4C9300488C6E /* BigIntTests.swift */; }; 61F8AA951FCA4C9300488C6E /* BigIntTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 61F8AA941FCA4C9300488C6E /* BigIntTests.swift */; };
61FC5ECF1FCFBAE500CCB12A /* EtherNumberFormatter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 61FC5ECE1FCFBAE500CCB12A /* EtherNumberFormatter.swift */; }; 61FC5ECF1FCFBAE500CCB12A /* EtherNumberFormatter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 61FC5ECE1FCFBAE500CCB12A /* EtherNumberFormatter.swift */; };
61FC5ED11FCFBDEB00CCB12A /* EtherNumberFormatterTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 61FC5ED01FCFBDEB00CCB12A /* EtherNumberFormatterTests.swift */; }; 61FC5ED11FCFBDEB00CCB12A /* EtherNumberFormatterTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 61FC5ED01FCFBDEB00CCB12A /* EtherNumberFormatterTests.swift */; };
CCA4FE331FD3655900749AE4 /* CheckDeviceCoordinatorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = CCA4FE321FD3655900749AE4 /* CheckDeviceCoordinatorTests.swift */; };
CCA4FE361FD4282400749AE4 /* DeviceChecker.swift in Sources */ = {isa = PBXBuildFile; fileRef = CCA4FE351FD4282400749AE4 /* DeviceChecker.swift */; };
CCA4FE381FD428B300749AE4 /* JailbreakChecker.swift in Sources */ = {isa = PBXBuildFile; fileRef = CCA4FE371FD428B300749AE4 /* JailbreakChecker.swift */; };
CCA4FE3A1FD42B4100749AE4 /* FakeJailbreakChecker.swift in Sources */ = {isa = PBXBuildFile; fileRef = CCA4FE391FD42B4100749AE4 /* FakeJailbreakChecker.swift */; };
CCCD74FD1FD2D38D004A087D /* CheckDeviceCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = CCCD74FC1FD2D38D004A087D /* CheckDeviceCoordinator.swift */; };
D9F052FDC5B72E024DD05F0D /* Pods_TrustTests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A48A17FC2CC895AF2BB871D0 /* Pods_TrustTests.framework */; }; D9F052FDC5B72E024DD05F0D /* Pods_TrustTests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A48A17FC2CC895AF2BB871D0 /* Pods_TrustTests.framework */; };
/* End PBXBuildFile section */ /* End PBXBuildFile section */
@ -555,6 +560,11 @@
A3B747245A27436E621E7E41 /* Pods-TrustUITests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-TrustUITests.release.xcconfig"; path = "Pods/Target Support Files/Pods-TrustUITests/Pods-TrustUITests.release.xcconfig"; sourceTree = "<group>"; }; A3B747245A27436E621E7E41 /* Pods-TrustUITests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-TrustUITests.release.xcconfig"; path = "Pods/Target Support Files/Pods-TrustUITests/Pods-TrustUITests.release.xcconfig"; sourceTree = "<group>"; };
A48A17FC2CC895AF2BB871D0 /* Pods_TrustTests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_TrustTests.framework; sourceTree = BUILT_PRODUCTS_DIR; }; A48A17FC2CC895AF2BB871D0 /* Pods_TrustTests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_TrustTests.framework; sourceTree = BUILT_PRODUCTS_DIR; };
B13A87D3BA5167741E5D0801 /* Pods-Trust.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Trust.release.xcconfig"; path = "Pods/Target Support Files/Pods-Trust/Pods-Trust.release.xcconfig"; sourceTree = "<group>"; }; B13A87D3BA5167741E5D0801 /* Pods-Trust.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Trust.release.xcconfig"; path = "Pods/Target Support Files/Pods-Trust/Pods-Trust.release.xcconfig"; sourceTree = "<group>"; };
CCA4FE321FD3655900749AE4 /* CheckDeviceCoordinatorTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CheckDeviceCoordinatorTests.swift; sourceTree = "<group>"; };
CCA4FE351FD4282400749AE4 /* DeviceChecker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DeviceChecker.swift; sourceTree = "<group>"; };
CCA4FE371FD428B300749AE4 /* JailbreakChecker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = JailbreakChecker.swift; sourceTree = "<group>"; };
CCA4FE391FD42B4100749AE4 /* FakeJailbreakChecker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FakeJailbreakChecker.swift; sourceTree = "<group>"; };
CCCD74FC1FD2D38D004A087D /* CheckDeviceCoordinator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CheckDeviceCoordinator.swift; sourceTree = "<group>"; };
DDF643F2D99BCE8E6139C057 /* Pods-TrustTests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-TrustTests.release.xcconfig"; path = "Pods/Target Support Files/Pods-TrustTests/Pods-TrustTests.release.xcconfig"; sourceTree = "<group>"; }; DDF643F2D99BCE8E6139C057 /* Pods-TrustTests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-TrustTests.release.xcconfig"; path = "Pods/Target Support Files/Pods-TrustTests/Pods-TrustTests.release.xcconfig"; sourceTree = "<group>"; };
/* End PBXFileReference section */ /* End PBXFileReference section */
@ -662,6 +672,7 @@
2912CD0E1F6A830700C6CBE3 /* TrustTests */ = { 2912CD0E1F6A830700C6CBE3 /* TrustTests */ = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
CCA4FE301FD3652100749AE4 /* Core */,
299B5E3C1FD143300051361C /* Export */, 299B5E3C1FD143300051361C /* Export */,
299B5E351FCBCDE10051361C /* Transfer */, 299B5E351FCBCDE10051361C /* Transfer */,
2931122F1FC971A400966EEA /* Exchange */, 2931122F1FC971A400966EEA /* Exchange */,
@ -1524,6 +1535,8 @@
29FC9BC31F830880000209CD /* Core */ = { 29FC9BC31F830880000209CD /* Core */ = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
CCA4FE341FD427CA00749AE4 /* Helpers */,
CCCD74FF1FD2D95F004A087D /* Coordinators */,
2931120E1FC4ADBE00966EEA /* ViewModels */, 2931120E1FC4ADBE00966EEA /* ViewModels */,
29FC9BC41F830880000209CD /* Initializers */, 29FC9BC41F830880000209CD /* Initializers */,
); );
@ -1604,6 +1617,7 @@
2961BD081FB14B6D00C4B840 /* Config.swift */, 2961BD081FB14B6D00C4B840 /* Config.swift */,
298542FF1FBEAE2F00CB5081 /* ChainState.swift */, 298542FF1FBEAE2F00CB5081 /* ChainState.swift */,
293112321FC971F600966EEA /* ExchangeToken.swift */, 293112321FC971F600966EEA /* ExchangeToken.swift */,
CCA4FE391FD42B4100749AE4 /* FakeJailbreakChecker.swift */,
); );
path = Factories; path = Factories;
sourceTree = "<group>"; sourceTree = "<group>";
@ -1647,6 +1661,39 @@
name = Pods; name = Pods;
sourceTree = "<group>"; sourceTree = "<group>";
}; };
CCA4FE301FD3652100749AE4 /* Core */ = {
isa = PBXGroup;
children = (
CCA4FE311FD3653300749AE4 /* Coordinators */,
);
path = Core;
sourceTree = "<group>";
};
CCA4FE311FD3653300749AE4 /* Coordinators */ = {
isa = PBXGroup;
children = (
CCA4FE321FD3655900749AE4 /* CheckDeviceCoordinatorTests.swift */,
);
path = Coordinators;
sourceTree = "<group>";
};
CCA4FE341FD427CA00749AE4 /* Helpers */ = {
isa = PBXGroup;
children = (
CCA4FE351FD4282400749AE4 /* DeviceChecker.swift */,
CCA4FE371FD428B300749AE4 /* JailbreakChecker.swift */,
);
path = Helpers;
sourceTree = "<group>";
};
CCCD74FF1FD2D95F004A087D /* Coordinators */ = {
isa = PBXGroup;
children = (
CCCD74FC1FD2D38D004A087D /* CheckDeviceCoordinator.swift */,
);
path = Coordinators;
sourceTree = "<group>";
};
FAD3F374A5C639BD900944DB /* Frameworks */ = { FAD3F374A5C639BD900944DB /* Frameworks */ = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
@ -2170,6 +2217,7 @@
293112281FC8174B00966EEA /* ExchangeConfig.swift in Sources */, 293112281FC8174B00966EEA /* ExchangeConfig.swift in Sources */,
2932045C1F8DCD6E0095B7C1 /* CurrencyRate.swift in Sources */, 2932045C1F8DCD6E0095B7C1 /* CurrencyRate.swift in Sources */,
291F52A51F6B762300B369AB /* EtherServiceRequest.swift in Sources */, 291F52A51F6B762300B369AB /* EtherServiceRequest.swift in Sources */,
CCA4FE361FD4282400749AE4 /* DeviceChecker.swift in Sources */,
298542FB1FBEA03300CB5081 /* SendInputErrors.swift in Sources */, 298542FB1FBEA03300CB5081 /* SendInputErrors.swift in Sources */,
29EB102A1F6CBD23000907A4 /* UIAlertController.swift in Sources */, 29EB102A1F6CBD23000907A4 /* UIAlertController.swift in Sources */,
293112151FC5550000966EEA /* ExchangeTokensCoordinator.swift in Sources */, 293112151FC5550000966EEA /* ExchangeTokensCoordinator.swift in Sources */,
@ -2236,12 +2284,14 @@
298542F31FBD594D00CB5081 /* SettingsViewModel.swift in Sources */, 298542F31FBD594D00CB5081 /* SettingsViewModel.swift in Sources */,
29B6AED11F7C881D00EC6DE3 /* TransactionCost.swift in Sources */, 29B6AED11F7C881D00EC6DE3 /* TransactionCost.swift in Sources */,
296106CA1F764AB60006164B /* TokensDataStore.swift in Sources */, 296106CA1F764AB60006164B /* TokensDataStore.swift in Sources */,
CCA4FE381FD428B300749AE4 /* JailbreakChecker.swift in Sources */,
291A1B651F974E8600ADEC80 /* WalletEntryPoint.swift in Sources */, 291A1B651F974E8600ADEC80 /* WalletEntryPoint.swift in Sources */,
2959960E1FAB05C200DB66A8 /* TransactionsEmptyView.swift in Sources */, 2959960E1FAB05C200DB66A8 /* TransactionsEmptyView.swift in Sources */,
29BB94931F6FC380009B09CC /* BalanceViewModel.swift in Sources */, 29BB94931F6FC380009B09CC /* BalanceViewModel.swift in Sources */,
292F75A91F88865A00585F8E /* TouchRegistrar.swift in Sources */, 292F75A91F88865A00585F8E /* TouchRegistrar.swift in Sources */,
29D03F1D1F712183006E548C /* Button.swift in Sources */, 29D03F1D1F712183006E548C /* Button.swift in Sources */,
291794FF1F95F5CE00539A30 /* Web3Request.swift in Sources */, 291794FF1F95F5CE00539A30 /* Web3Request.swift in Sources */,
CCCD74FD1FD2D38D004A087D /* CheckDeviceCoordinator.swift in Sources */,
29E2E33E1F7A2423000CF94A /* TransactionHeaderView.swift in Sources */, 29E2E33E1F7A2423000CF94A /* TransactionHeaderView.swift in Sources */,
291F52BF1F6C874E00B369AB /* AccountsViewController.swift in Sources */, 291F52BF1F6C874E00B369AB /* AccountsViewController.swift in Sources */,
2963B6AF1F9823E6003063C1 /* UnconfirmedTransaction.swift in Sources */, 2963B6AF1F9823E6003063C1 /* UnconfirmedTransaction.swift in Sources */,
@ -2264,6 +2314,7 @@
293112311FC971B600966EEA /* ExchangeTokensCoordinatorTests.swift in Sources */, 293112311FC971B600966EEA /* ExchangeTokensCoordinatorTests.swift in Sources */,
61F8AA951FCA4C9300488C6E /* BigIntTests.swift in Sources */, 61F8AA951FCA4C9300488C6E /* BigIntTests.swift in Sources */,
299573A41FA27A15006F17FD /* TestKeyStore.swift in Sources */, 299573A41FA27A15006F17FD /* TestKeyStore.swift in Sources */,
CCA4FE3A1FD42B4100749AE4 /* FakeJailbreakChecker.swift in Sources */,
29F114F81FA8165200114A29 /* SendCoordinatorTests.swift in Sources */, 29F114F81FA8165200114A29 /* SendCoordinatorTests.swift in Sources */,
293112331FC971F600966EEA /* ExchangeToken.swift in Sources */, 293112331FC971F600966EEA /* ExchangeToken.swift in Sources */,
299573A21FA1F369006F17FD /* QRURLParserTests.swift in Sources */, 299573A21FA1F369006F17FD /* QRURLParserTests.swift in Sources */,
@ -2276,6 +2327,7 @@
298543001FBEAE2F00CB5081 /* ChainState.swift in Sources */, 298543001FBEAE2F00CB5081 /* ChainState.swift in Sources */,
299B5E3F1FD143400051361C /* BackupViewModelTests.swift in Sources */, 299B5E3F1FD143400051361C /* BackupViewModelTests.swift in Sources */,
29AD8A0E1F93FF28008E10E7 /* WalletSession.swift in Sources */, 29AD8A0E1F93FF28008E10E7 /* WalletSession.swift in Sources */,
CCA4FE331FD3655900749AE4 /* CheckDeviceCoordinatorTests.swift in Sources */,
29FF13011F75EAD900AFD326 /* FakeKeystore.swift in Sources */, 29FF13011F75EAD900AFD326 /* FakeKeystore.swift in Sources */,
29FC9BCC1F831860000209CD /* PaymentCoordinator.swift in Sources */, 29FC9BCC1F831860000209CD /* PaymentCoordinator.swift in Sources */,
2961BD091FB14B6D00C4B840 /* Config.swift in Sources */, 2961BD091FB14B6D00C4B840 /* Config.swift in Sources */,

@ -0,0 +1,42 @@
// Copyright SIX DAY LLC. All rights reserved.
import Foundation
import UIKit
class CheckDeviceCoordinator: Coordinator {
var coordinators: [Coordinator] = []
let navigationController: UINavigationController
let jailbreakChecker: JailbreakChecker
lazy var alertViewController: UIAlertController = {
let controller = UIAlertController(
title: NSLocalizedString("jailbreak.title", value: "DEVICE SECURITY COMPROMISED", comment: ""),
message: NSLocalizedString(
"jailbreak.message",
value: "Any 'jailbreak' app can access Trust's keychain data and steal your bitcoin! Wipe this wallet immediately and restore on a secure device",
comment: ""
),
preferredStyle: UIAlertControllerStyle.alert
)
controller.addAction(UIAlertAction(title: NSLocalizedString("jailbreak.submit", value: "Got it", comment: ""), style: .default))
return controller
}()
init(
navigationController: UINavigationController,
jailbreakChecker: JailbreakChecker
) {
self.navigationController = navigationController
self.jailbreakChecker = jailbreakChecker
}
func start() {
if jailbreakChecker.isJailbroken() {
navigationController.present(alertViewController, animated: true, completion: nil)
}
}
}

@ -0,0 +1,22 @@
// Copyright SIX DAY LLC. All rights reserved.
import Foundation
class DeviceChecker: JailbreakChecker {
func isJailbroken() -> Bool {
if TARGET_IPHONE_SIMULATOR == 1 {
return false
}
let list: [String] = [
"/Applications/Cydia.app",
"/Library/MobileSubstrate/MobileSubstrate.dylib",
"/bin/bash",
"/usr/sbin /sshd",
"/etc/apt",
"/private/var/lib/apt/",
]
return !list.filter { FileManager.default.fileExists(atPath: $0) }.isEmpty
}
}

@ -0,0 +1,7 @@
// Copyright SIX DAY LLC. All rights reserved.
import Foundation
protocol JailbreakChecker {
func isJailbroken() -> Bool
}

@ -31,6 +31,8 @@ class InCoordinator: Coordinator {
func start() { func start() {
showTabBar(for: account) showTabBar(for: account)
checkDevice()
} }
func showTabBar(for account: Account) { func showTabBar(for account: Account) {
@ -107,6 +109,17 @@ class InCoordinator: Coordinator {
removeCoordinator(coordinator) removeCoordinator(coordinator)
showTabBar(for: account) showTabBar(for: account)
} }
func checkDevice() {
let deviceChecker = CheckDeviceCoordinator(
navigationController: navigationController,
jailbreakChecker: DeviceChecker()
)
deviceChecker.start()
addCoordinator(deviceChecker)
}
} }
extension InCoordinator: TransactionCoordinatorDelegate { extension InCoordinator: TransactionCoordinatorDelegate {

@ -0,0 +1,32 @@
// Copyright SIX DAY LLC. All rights reserved.
import XCTest
@testable import Trust
class CheckDeviceCoordinatorTests: XCTestCase {
func testStartPositive() {
let navigationController = FakeNavigationController()
let coordinator = CheckDeviceCoordinator(
navigationController: navigationController,
jailbreakChecker: FakeJailbreakChecker(jailbroken: true)
)
coordinator.start()
XCTAssertTrue(navigationController.presentedViewController is UIAlertController)
}
func testStartNegative() {
let navigationController = FakeNavigationController()
let coordinator = CheckDeviceCoordinator(
navigationController: navigationController,
jailbreakChecker: FakeJailbreakChecker(jailbroken: false)
)
coordinator.start()
XCTAssertFalse(navigationController.presentedViewController is UIAlertController)
}
}

@ -0,0 +1,16 @@
// Copyright SIX DAY LLC. All rights reserved.
import Foundation
@testable import Trust
class FakeJailbreakChecker: JailbreakChecker {
let jailbroken: Bool
init(jailbroken: Bool) {
self.jailbroken = jailbroken
}
func isJailbroken() -> Bool {
return jailbroken
}
}
Loading…
Cancel
Save