diff --git a/LeadKitAdditions/CommonCrypto/CommonCrypto.h b/LeadKitAdditions/CommonCrypto/CommonCrypto.h new file mode 100644 index 0000000..def2316 --- /dev/null +++ b/LeadKitAdditions/CommonCrypto/CommonCrypto.h @@ -0,0 +1,19 @@ +// +// CommonCrypto.h +// CommonCrypto +// +// Created by Alexey Gerasimov on 25/04/2017. +// Copyright © 2017 TouchInstinct. All rights reserved. +// + +#import + +//! Project version number for CommonCrypto. +FOUNDATION_EXPORT double CommonCryptoVersionNumber; + +//! Project version string for CommonCrypto. +FOUNDATION_EXPORT const unsigned char CommonCryptoVersionString[]; + +// In this header, you should import all the public headers of your framework using statements like #import + + diff --git a/LeadKitAdditions/CommonCrypto/CommonCrypto.xcconfig b/LeadKitAdditions/CommonCrypto/CommonCrypto.xcconfig new file mode 100644 index 0000000..080c4d8 --- /dev/null +++ b/LeadKitAdditions/CommonCrypto/CommonCrypto.xcconfig @@ -0,0 +1,10 @@ +// +// CommonCrypto.xcconfig +// Chat +// +// Created by Alexey Gerasimov on 17/08/16. +// Copyright © 2016 Touch Instinct. All rights reserved. +// + +MODULEMAP_FILE[sdk=iphoneos*] = $(SRCROOT)/CommonCrypto/iphoneos.modulemap +MODULEMAP_FILE[sdk=iphonesimulator*] = $(SRCROOT)/CommonCrypto/iphonesimulator.modulemap \ No newline at end of file diff --git a/LeadKitAdditions/CommonCrypto/Info.plist b/LeadKitAdditions/CommonCrypto/Info.plist new file mode 100644 index 0000000..fbe1e6b --- /dev/null +++ b/LeadKitAdditions/CommonCrypto/Info.plist @@ -0,0 +1,24 @@ + + + + + CFBundleDevelopmentRegion + en + CFBundleExecutable + $(EXECUTABLE_NAME) + CFBundleIdentifier + $(PRODUCT_BUNDLE_IDENTIFIER) + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + $(PRODUCT_NAME) + CFBundlePackageType + FMWK + CFBundleShortVersionString + 1.0 + CFBundleVersion + $(CURRENT_PROJECT_VERSION) + NSPrincipalClass + + + diff --git a/LeadKitAdditions/CommonCrypto/iphoneos.modulemap b/LeadKitAdditions/CommonCrypto/iphoneos.modulemap new file mode 100755 index 0000000..125b772 --- /dev/null +++ b/LeadKitAdditions/CommonCrypto/iphoneos.modulemap @@ -0,0 +1,4 @@ +module CommonCrypto [system] { + header "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/usr/include/CommonCrypto/CommonCrypto.h" + export * +} diff --git a/LeadKitAdditions/CommonCrypto/iphonesimulator.modulemap b/LeadKitAdditions/CommonCrypto/iphonesimulator.modulemap new file mode 100755 index 0000000..835d686 --- /dev/null +++ b/LeadKitAdditions/CommonCrypto/iphonesimulator.modulemap @@ -0,0 +1,4 @@ +module CommonCrypto [system] { + header "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/usr/include/CommonCrypto/CommonCrypto.h" + export * +} diff --git a/LeadKitAdditions/LeadKitAdditions.xcodeproj/project.pbxproj b/LeadKitAdditions/LeadKitAdditions.xcodeproj/project.pbxproj index c0835e2..e6bbb41 100644 --- a/LeadKitAdditions/LeadKitAdditions.xcodeproj/project.pbxproj +++ b/LeadKitAdditions/LeadKitAdditions.xcodeproj/project.pbxproj @@ -19,6 +19,8 @@ EF05EDC21EAF706200CAE7B6 /* DefaultNetworkService.swift in Sources */ = {isa = PBXBuildFile; fileRef = EF05EDBF1EAF706200CAE7B6 /* DefaultNetworkService.swift */; }; EF05EDC61EAF70EB00CAE7B6 /* TouchIDService.swift in Sources */ = {isa = PBXBuildFile; fileRef = EF05EDC51EAF70EB00CAE7B6 /* TouchIDService.swift */; }; EF05EDC81EAF91D500CAE7B6 /* BasePassCodeService.swift in Sources */ = {isa = PBXBuildFile; fileRef = EF05EDC71EAF91D500CAE7B6 /* BasePassCodeService.swift */; }; + EF05EDD21EAF9CF100CAE7B6 /* CommonCrypto.h in Headers */ = {isa = PBXBuildFile; fileRef = EF05EDD01EAF9CF100CAE7B6 /* CommonCrypto.h */; settings = {ATTRIBUTES = (Public, ); }; }; + EF05EDDA1EAF9D4A00CAE7B6 /* CommonCrypto.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = EF05EDCE1EAF9CF100CAE7B6 /* CommonCrypto.framework */; settings = {ATTRIBUTES = (Weak, ); }; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ @@ -38,6 +40,12 @@ EF05EDBF1EAF706200CAE7B6 /* DefaultNetworkService.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DefaultNetworkService.swift; sourceTree = ""; }; EF05EDC51EAF70EB00CAE7B6 /* TouchIDService.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TouchIDService.swift; sourceTree = ""; }; EF05EDC71EAF91D500CAE7B6 /* BasePassCodeService.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BasePassCodeService.swift; sourceTree = ""; }; + EF05EDCE1EAF9CF100CAE7B6 /* CommonCrypto.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = CommonCrypto.framework; sourceTree = BUILT_PRODUCTS_DIR; }; + EF05EDD01EAF9CF100CAE7B6 /* CommonCrypto.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CommonCrypto.h; sourceTree = ""; }; + EF05EDD11EAF9CF100CAE7B6 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + EF05EDD61EAF9D2900CAE7B6 /* CommonCrypto.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = CommonCrypto.xcconfig; sourceTree = ""; }; + EF05EDD71EAF9D2900CAE7B6 /* iphoneos.modulemap */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = "sourcecode.module-map"; path = iphoneos.modulemap; sourceTree = ""; }; + EF05EDD81EAF9D2900CAE7B6 /* iphonesimulator.modulemap */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = "sourcecode.module-map"; path = iphonesimulator.modulemap; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -45,10 +53,18 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( + EF05EDDA1EAF9D4A00CAE7B6 /* CommonCrypto.framework in Frameworks */, 7A94B4A5956B82BE1CEBA873 /* Pods_LeadKitAdditions.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; + EF05EDCA1EAF9CF100CAE7B6 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ @@ -64,6 +80,7 @@ isa = PBXGroup; children = ( CAE698E51E968820000394B0 /* LeadKitAdditions */, + EF05EDCF1EAF9CF100CAE7B6 /* CommonCrypto */, CAE698E41E968820000394B0 /* Products */, F8A65FEC7C0EB4B93746E50F /* Pods */, A3117951840B8B7D2E7A8A80 /* Frameworks */, @@ -74,6 +91,7 @@ isa = PBXGroup; children = ( CAE698E31E968820000394B0 /* LeadKitAdditions.framework */, + EF05EDCE1EAF9CF100CAE7B6 /* CommonCrypto.framework */, ); name = Products; sourceTree = ""; @@ -129,6 +147,18 @@ path = Enums; sourceTree = ""; }; + EF05EDCF1EAF9CF100CAE7B6 /* CommonCrypto */ = { + isa = PBXGroup; + children = ( + EF05EDD01EAF9CF100CAE7B6 /* CommonCrypto.h */, + EF05EDD61EAF9D2900CAE7B6 /* CommonCrypto.xcconfig */, + EF05EDD11EAF9CF100CAE7B6 /* Info.plist */, + EF05EDD71EAF9D2900CAE7B6 /* iphoneos.modulemap */, + EF05EDD81EAF9D2900CAE7B6 /* iphonesimulator.modulemap */, + ); + path = CommonCrypto; + sourceTree = ""; + }; F8A65FEC7C0EB4B93746E50F /* Pods */ = { isa = PBXGroup; children = ( @@ -149,6 +179,14 @@ ); runOnlyForDeploymentPostprocessing = 0; }; + EF05EDCB1EAF9CF100CAE7B6 /* Headers */ = { + isa = PBXHeadersBuildPhase; + buildActionMask = 2147483647; + files = ( + EF05EDD21EAF9CF100CAE7B6 /* CommonCrypto.h in Headers */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; /* End PBXHeadersBuildPhase section */ /* Begin PBXNativeTarget section */ @@ -174,6 +212,24 @@ productReference = CAE698E31E968820000394B0 /* LeadKitAdditions.framework */; productType = "com.apple.product-type.framework"; }; + EF05EDCD1EAF9CF100CAE7B6 /* CommonCrypto */ = { + isa = PBXNativeTarget; + buildConfigurationList = EF05EDD31EAF9CF100CAE7B6 /* Build configuration list for PBXNativeTarget "CommonCrypto" */; + buildPhases = ( + EF05EDC91EAF9CF100CAE7B6 /* Sources */, + EF05EDCA1EAF9CF100CAE7B6 /* Frameworks */, + EF05EDCB1EAF9CF100CAE7B6 /* Headers */, + EF05EDCC1EAF9CF100CAE7B6 /* Resources */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = CommonCrypto; + productName = CommonCrypto; + productReference = EF05EDCE1EAF9CF100CAE7B6 /* CommonCrypto.framework */; + productType = "com.apple.product-type.framework"; + }; /* End PBXNativeTarget section */ /* Begin PBXProject section */ @@ -188,6 +244,10 @@ LastSwiftMigration = 0830; ProvisioningStyle = Manual; }; + EF05EDCD1EAF9CF100CAE7B6 = { + CreatedOnToolsVersion = 8.3.1; + ProvisioningStyle = Manual; + }; }; }; buildConfigurationList = CAE698DD1E968820000394B0 /* Build configuration list for PBXProject "LeadKitAdditions" */; @@ -203,6 +263,7 @@ projectRoot = ""; targets = ( CAE698E21E968820000394B0 /* LeadKitAdditions */, + EF05EDCD1EAF9CF100CAE7B6 /* CommonCrypto */, ); }; /* End PBXProject section */ @@ -215,6 +276,13 @@ ); runOnlyForDeploymentPostprocessing = 0; }; + EF05EDCC1EAF9CF100CAE7B6 /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; /* End PBXResourcesBuildPhase section */ /* Begin PBXShellScriptBuildPhase section */ @@ -296,6 +364,13 @@ ); runOnlyForDeploymentPostprocessing = 0; }; + EF05EDC91EAF9CF100CAE7B6 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; /* End PBXSourcesBuildPhase section */ /* Begin XCBuildConfiguration section */ @@ -449,6 +524,52 @@ }; name = Release; }; + EF05EDD41EAF9CF100CAE7B6 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + CODE_SIGN_IDENTITY = ""; + DEFINES_MODULE = YES; + DEVELOPMENT_TEAM = ""; + DYLIB_COMPATIBILITY_VERSION = 1; + DYLIB_CURRENT_VERSION = 1; + DYLIB_INSTALL_NAME_BASE = "@rpath"; + INFOPLIST_FILE = CommonCrypto/Info.plist; + INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; + IPHONEOS_DEPLOYMENT_TARGET = 9.0; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + "MODULEMAP_FILE[sdk=iphoneos*]" = /Users/alexeygerasimov/Documents/dev/LeadKitAdditions/LeadKitAdditions/CommonCrypto/iphoneos.modulemap; + "MODULEMAP_FILE[sdk=iphonesimulator*]" = /Users/alexeygerasimov/Documents/dev/LeadKitAdditions/LeadKitAdditions/CommonCrypto/iphonesimulator.modulemap; + PRODUCT_BUNDLE_IDENTIFIER = com.touchin.CommonCrypto; + PRODUCT_NAME = "$(TARGET_NAME)"; + PROVISIONING_PROFILE_SPECIFIER = ""; + SKIP_INSTALL = YES; + SWIFT_VERSION = 3.0; + }; + name = Debug; + }; + EF05EDD51EAF9CF100CAE7B6 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + CODE_SIGN_IDENTITY = ""; + DEFINES_MODULE = YES; + DEVELOPMENT_TEAM = ""; + DYLIB_COMPATIBILITY_VERSION = 1; + DYLIB_CURRENT_VERSION = 1; + DYLIB_INSTALL_NAME_BASE = "@rpath"; + INFOPLIST_FILE = CommonCrypto/Info.plist; + INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; + IPHONEOS_DEPLOYMENT_TARGET = 9.0; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + "MODULEMAP_FILE[sdk=iphoneos*]" = /Users/alexeygerasimov/Documents/dev/LeadKitAdditions/LeadKitAdditions/CommonCrypto/iphoneos.modulemap; + "MODULEMAP_FILE[sdk=iphonesimulator*]" = /Users/alexeygerasimov/Documents/dev/LeadKitAdditions/LeadKitAdditions/CommonCrypto/iphonesimulator.modulemap; + PRODUCT_BUNDLE_IDENTIFIER = com.touchin.CommonCrypto; + PRODUCT_NAME = "$(TARGET_NAME)"; + PROVISIONING_PROFILE_SPECIFIER = ""; + SKIP_INSTALL = YES; + SWIFT_VERSION = 3.0; + }; + name = Release; + }; /* End XCBuildConfiguration section */ /* Begin XCConfigurationList section */ @@ -470,6 +591,14 @@ defaultConfigurationIsVisible = 0; defaultConfigurationName = Release; }; + EF05EDD31EAF9CF100CAE7B6 /* Build configuration list for PBXNativeTarget "CommonCrypto" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + EF05EDD41EAF9CF100CAE7B6 /* Debug */, + EF05EDD51EAF9CF100CAE7B6 /* Release */, + ); + defaultConfigurationIsVisible = 0; + }; /* End XCConfigurationList section */ }; rootObject = CAE698DA1E968820000394B0 /* Project object */; diff --git a/LeadKitAdditions/LeadKitAdditions/Services/BasePassCodeService.swift b/LeadKitAdditions/LeadKitAdditions/Services/BasePassCodeService.swift index 6bec7f9..f80b71d 100644 --- a/LeadKitAdditions/LeadKitAdditions/Services/BasePassCodeService.swift +++ b/LeadKitAdditions/LeadKitAdditions/Services/BasePassCodeService.swift @@ -22,6 +22,7 @@ import KeychainAccess import CocoaLumberjack +import CommonCrypto open class BasePassCodeService { @@ -76,11 +77,15 @@ extension BasePassCodeService { } public func save(passCode: String?) { - keychain[Keys.passCodeHash] = passCode?.hashMD5 + if let passCode = passCode { + keychain[Keys.passCodeHash] = sha256(passCode) + } else { + keychain[Keys.passCodeHash] = nil + } } public func check(passCode: String) -> Bool { - return passCode.hashMD5 == passCodeHash + return sha256(passCode) == passCodeHash } public func reset() { @@ -90,10 +95,24 @@ extension BasePassCodeService { } -private extension String { +private extension BasePassCodeService { - var hashMD5: String? { - return self + func sha256(_ str: String) -> String? { + guard let data = str.data(using: String.Encoding.utf8), let shaData = sha256(data) else { + return nil + } + + let rc = shaData.base64EncodedString(options: []) + return rc + } + + func sha256(_ data: Data) -> Data? { + guard let res = NSMutableData(length: Int(CC_SHA256_DIGEST_LENGTH)) else { + return nil + } + + CC_SHA256((data as NSData).bytes, CC_LONG(data.count), res.mutableBytes.assumingMemoryBound(to: UInt8.self)) + return res as Data } }