From 47275de7d016b619303b72917c441933df3f5e2d Mon Sep 17 00:00:00 2001 From: Petr Palata Date: Sun, 11 Sep 2022 20:39:14 +0200 Subject: [PATCH 1/7] Lower deployment version to 12 and make necessary changes to support it --- Package.swift | 2 +- .../FingerprintJS.xcodeproj/project.pbxproj | 8 +++--- .../Hashing/Digest+StringOutput.swift | 1 + .../Hashing/SHA256FingerprintFunction.swift | 16 ++++++++++-- .../Library/DeviceInfoProvider.swift | 25 +++++++++++++++---- .../Mocks/MockHashingFunction.swift | 1 + 6 files changed, 41 insertions(+), 12 deletions(-) diff --git a/Package.swift b/Package.swift index 40b30f6..c063fad 100644 --- a/Package.swift +++ b/Package.swift @@ -5,7 +5,7 @@ import PackageDescription let package = Package( name: "FingerprintJS", - platforms: [.iOS(.v13), .tvOS(.v13)], + platforms: [.iOS(.v12), .tvOS(.v12)], products: [ .library( name: "FingerprintJS", diff --git a/Sources/FingerprintJS.xcodeproj/project.pbxproj b/Sources/FingerprintJS.xcodeproj/project.pbxproj index 78f4e65..ee5bd9d 100644 --- a/Sources/FingerprintJS.xcodeproj/project.pbxproj +++ b/Sources/FingerprintJS.xcodeproj/project.pbxproj @@ -525,7 +525,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 13.0; + IPHONEOS_DEPLOYMENT_TARGET = 12.0; MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; MTL_FAST_MATH = YES; ONLY_ACTIVE_ARCH = YES; @@ -583,7 +583,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 13.0; + IPHONEOS_DEPLOYMENT_TARGET = 12.0; MTL_ENABLE_DEBUG_INFO = NO; MTL_FAST_MATH = YES; SDKROOT = iphoneos; @@ -608,7 +608,7 @@ GENERATE_INFOPLIST_FILE = YES; INFOPLIST_KEY_NSHumanReadableCopyright = ""; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - IPHONEOS_DEPLOYMENT_TARGET = 13.0; + IPHONEOS_DEPLOYMENT_TARGET = 12.0; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", "@executable_path/Frameworks", @@ -639,7 +639,7 @@ GENERATE_INFOPLIST_FILE = YES; INFOPLIST_KEY_NSHumanReadableCopyright = ""; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - IPHONEOS_DEPLOYMENT_TARGET = 13.0; + IPHONEOS_DEPLOYMENT_TARGET = 12.0; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", "@executable_path/Frameworks", diff --git a/Sources/FingerprintJS/Hashing/Digest+StringOutput.swift b/Sources/FingerprintJS/Hashing/Digest+StringOutput.swift index 1ed7d91..858136c 100644 --- a/Sources/FingerprintJS/Hashing/Digest+StringOutput.swift +++ b/Sources/FingerprintJS/Hashing/Digest+StringOutput.swift @@ -8,6 +8,7 @@ import CryptoKit import Foundation +@available(iOS 13.0, tvOS 13, *) extension Digest { var bytes: [UInt8] { Array(makeIterator()) } var data: Data { Data(bytes) } diff --git a/Sources/FingerprintJS/Hashing/SHA256FingerprintFunction.swift b/Sources/FingerprintJS/Hashing/SHA256FingerprintFunction.swift index e632361..fedb4de 100644 --- a/Sources/FingerprintJS/Hashing/SHA256FingerprintFunction.swift +++ b/Sources/FingerprintJS/Hashing/SHA256FingerprintFunction.swift @@ -5,12 +5,24 @@ // Created by Petr Palata on 10.03.2022. // +import CommonCrypto import CryptoKit import Foundation class SHA256HashingFunction: FingerprintFunction { public func fingerprint(data: Data) -> String { - let digest = SHA256.hash(data: data) - return digest.hexStr + if #available(iOS 13, tvOS 13, *) { + let digest = SHA256.hash(data: data) + return digest.hexStr + } else { + var hash = [UInt8](repeating: 0, count: Int(CC_SHA256_DIGEST_LENGTH)) + data.withUnsafeBytes { + _ = CC_SHA256($0.baseAddress, CC_LONG(data.count), &hash) + } + let digest = Data(hash) + return digest.map { + String(format: "%02hhx", $0) + }.joined() + } } } diff --git a/Sources/FingerprintJS/Library/DeviceInfoProvider.swift b/Sources/FingerprintJS/Library/DeviceInfoProvider.swift index b702562..21c0b44 100644 --- a/Sources/FingerprintJS/Library/DeviceInfoProvider.swift +++ b/Sources/FingerprintJS/Library/DeviceInfoProvider.swift @@ -10,8 +10,9 @@ import Foundation public protocol DeviceInfoProviding { /// Gathers and returns all information about the device /// - Returns: `DeviceInfo` object that contains typed representation of device information values + @available(iOS 13, tvOS 13, *) func getDeviceInfo() async -> DeviceInfo - + /// Gathers all information about the device and reports it through the completion block /// - Parameter completion: Completion block reporting the `DeviceInfo` object func getDeviceInfo(_ completion: @escaping (DeviceInfo) -> Void) @@ -43,6 +44,7 @@ public class DeviceInfoProvider { extension DeviceInfoProvider: DeviceInfoProviding { + @available(iOS 13, tvOS 13, *) public func getDeviceInfo() async -> DeviceInfo { return DeviceInfo( vendorIdentifier: identifierHarvester.vendorIdentifier, @@ -62,9 +64,22 @@ extension DeviceInfoProvider: DeviceInfoProviding { } public func getDeviceInfo(_ completion: @escaping (DeviceInfo) -> Void) { - Task.init { - let deviceInfo = await getDeviceInfo() - completion(deviceInfo) - } + let deviceInfo = DeviceInfo( + vendorIdentifier: identifierHarvester.vendorIdentifier, + diskSpace: hardwareInfoHarvester.diskSpaceInfo, + screenResolution: hardwareInfoHarvester.displayResolution, + deviceType: hardwareInfoHarvester.deviceType, + deviceModel: hardwareInfoHarvester.deviceModel, + memorySize: hardwareInfoHarvester.memorySize, + physicalMemory: hardwareInfoHarvester.memorySize, + cpuCount: hardwareInfoHarvester.cpuCount, + osBuild: osInfoHarvester.osBuild, + osVersion: osInfoHarvester.osVersion, + osType: osInfoHarvester.osType, + osRelease: osInfoHarvester.osRelease, + kernelVersion: osInfoHarvester.kernelVersion + ) + + completion(deviceInfo) } } diff --git a/Sources/FingerprintJSTests/Mocks/MockHashingFunction.swift b/Sources/FingerprintJSTests/Mocks/MockHashingFunction.swift index b5a8c82..adee02b 100644 --- a/Sources/FingerprintJSTests/Mocks/MockHashingFunction.swift +++ b/Sources/FingerprintJSTests/Mocks/MockHashingFunction.swift @@ -5,6 +5,7 @@ // Created by Petr Palata on 23.03.2022. // import Foundation + @testable import FingerprintJS class MockFingerprintFunction: FingerprintFunction { From cf9ba149d51ab1f1e6eaaf72f90d2d65ae9a0766 Mon Sep 17 00:00:00 2001 From: Petr Palata Date: Sun, 11 Sep 2022 20:44:57 +0200 Subject: [PATCH 2/7] Restrict async APIs to tvOS 13.0 (wasn't restricted at all) --- Sources/FingerprintJS/Library/Fingerprinter.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/FingerprintJS/Library/Fingerprinter.swift b/Sources/FingerprintJS/Library/Fingerprinter.swift index 88b1757..8d223a4 100644 --- a/Sources/FingerprintJS/Library/Fingerprinter.swift +++ b/Sources/FingerprintJS/Library/Fingerprinter.swift @@ -74,7 +74,7 @@ extension Fingerprinter { } // MARK: - Public Interface: Async/Await (iOS 13+) -@available(iOS 13, macOS 11, *) +@available(iOS 13.0, tvOS 13.0, macOS 11.0, *) extension Fingerprinter { /// Retrieves a stable device identifier that is tied to the current device/application combination /// - Returns: Device identifier `String` value or `nil` if an error occurs From 6acee479d0ea1a239b4d2872ef1a18c8ac44e7a8 Mon Sep 17 00:00:00 2001 From: Petr Palata Date: Mon, 12 Sep 2022 14:33:19 +0200 Subject: [PATCH 3/7] Podspec version 1.1.2 --- FingerprintJS.podspec | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/FingerprintJS.podspec b/FingerprintJS.podspec index 4cfbc8e..eb0fdb0 100644 --- a/FingerprintJS.podspec +++ b/FingerprintJS.podspec @@ -1,7 +1,7 @@ Pod::Spec.new do |spec| # Name and version spec.name = 'FingerprintJS' - spec.version = '1.1.1' + spec.version = '1.1.2' # License spec.license = { type: 'MIT', file: 'LICENSE' } @@ -9,7 +9,7 @@ Pod::Spec.new do |spec| # Contact information spec.homepage = 'https://fingerprint.com/' spec.authors = { - 'Fingerprint': 'fingerprintkit@fingerprint.com', + 'Fingerprint': 'ios@fingerprint.com', 'Petr Palata': 'petr.palata@fingerprint.com' } @@ -28,8 +28,8 @@ Pod::Spec.new do |spec| # Build (source files, deployment target) spec.source_files = 'Sources/FingerprintJS/**/*.{swift,h,m}' - spec.ios.deployment_target = '13.0' - spec.tvos.deployment_target = '13.0' + spec.ios.deployment_target = '12.0' + spec.tvos.deployment_target = '12.0' spec.swift_versions = ['5.3', '5.4', '5.5', '5.6'] # Tests From 849c891d9a907c8f6cdd253f88759a4311e14363 Mon Sep 17 00:00:00 2001 From: Petr Palata Date: Mon, 12 Sep 2022 14:44:35 +0200 Subject: [PATCH 4/7] Refactor iOS 13 getDeviceInfo method to be a wrapper around the closure method --- .../Library/DeviceInfoProvider.swift | 20 +++++-------------- 1 file changed, 5 insertions(+), 15 deletions(-) diff --git a/Sources/FingerprintJS/Library/DeviceInfoProvider.swift b/Sources/FingerprintJS/Library/DeviceInfoProvider.swift index 21c0b44..3461deb 100644 --- a/Sources/FingerprintJS/Library/DeviceInfoProvider.swift +++ b/Sources/FingerprintJS/Library/DeviceInfoProvider.swift @@ -46,21 +46,11 @@ extension DeviceInfoProvider: DeviceInfoProviding { @available(iOS 13, tvOS 13, *) public func getDeviceInfo() async -> DeviceInfo { - return DeviceInfo( - vendorIdentifier: identifierHarvester.vendorIdentifier, - diskSpace: hardwareInfoHarvester.diskSpaceInfo, - screenResolution: hardwareInfoHarvester.displayResolution, - deviceType: hardwareInfoHarvester.deviceType, - deviceModel: hardwareInfoHarvester.deviceModel, - memorySize: hardwareInfoHarvester.memorySize, - physicalMemory: hardwareInfoHarvester.memorySize, - cpuCount: hardwareInfoHarvester.cpuCount, - osBuild: osInfoHarvester.osBuild, - osVersion: osInfoHarvester.osVersion, - osType: osInfoHarvester.osType, - osRelease: osInfoHarvester.osRelease, - kernelVersion: osInfoHarvester.kernelVersion - ) + return await withCheckedContinuation { continuation in + self.getDeviceInfo { deviceInfo in + continuation.resume(returning: deviceInfo) + } + } } public func getDeviceInfo(_ completion: @escaping (DeviceInfo) -> Void) { From dd2efe16c444ef38e99e47bff5337be8a4491dd4 Mon Sep 17 00:00:00 2001 From: Petr Palata Date: Mon, 12 Sep 2022 17:42:13 +0200 Subject: [PATCH 5/7] Fully specify the support iOS/tvOS versions in @available clauses --- Sources/FingerprintJS/Hashing/Digest+StringOutput.swift | 2 +- Sources/FingerprintJS/Library/DeviceInfoProvider.swift | 4 ++-- Sources/FingerprintJS/Library/Fingerprinter.swift | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Sources/FingerprintJS/Hashing/Digest+StringOutput.swift b/Sources/FingerprintJS/Hashing/Digest+StringOutput.swift index 858136c..71507cb 100644 --- a/Sources/FingerprintJS/Hashing/Digest+StringOutput.swift +++ b/Sources/FingerprintJS/Hashing/Digest+StringOutput.swift @@ -8,7 +8,7 @@ import CryptoKit import Foundation -@available(iOS 13.0, tvOS 13, *) +@available(iOS 13.0, tvOS 13.0, *) extension Digest { var bytes: [UInt8] { Array(makeIterator()) } var data: Data { Data(bytes) } diff --git a/Sources/FingerprintJS/Library/DeviceInfoProvider.swift b/Sources/FingerprintJS/Library/DeviceInfoProvider.swift index 3461deb..dce030c 100644 --- a/Sources/FingerprintJS/Library/DeviceInfoProvider.swift +++ b/Sources/FingerprintJS/Library/DeviceInfoProvider.swift @@ -10,7 +10,7 @@ import Foundation public protocol DeviceInfoProviding { /// Gathers and returns all information about the device /// - Returns: `DeviceInfo` object that contains typed representation of device information values - @available(iOS 13, tvOS 13, *) + @available(iOS 13.0, tvOS 13.0, *) func getDeviceInfo() async -> DeviceInfo /// Gathers all information about the device and reports it through the completion block @@ -44,7 +44,7 @@ public class DeviceInfoProvider { extension DeviceInfoProvider: DeviceInfoProviding { - @available(iOS 13, tvOS 13, *) + @available(iOS 13.0, tvOS 13.0, *) public func getDeviceInfo() async -> DeviceInfo { return await withCheckedContinuation { continuation in self.getDeviceInfo { deviceInfo in diff --git a/Sources/FingerprintJS/Library/Fingerprinter.swift b/Sources/FingerprintJS/Library/Fingerprinter.swift index 8d223a4..9b9659e 100644 --- a/Sources/FingerprintJS/Library/Fingerprinter.swift +++ b/Sources/FingerprintJS/Library/Fingerprinter.swift @@ -74,7 +74,7 @@ extension Fingerprinter { } // MARK: - Public Interface: Async/Await (iOS 13+) -@available(iOS 13.0, tvOS 13.0, macOS 11.0, *) +@available(iOS 13.0, tvOS 13.0, *) extension Fingerprinter { /// Retrieves a stable device identifier that is tied to the current device/application combination /// - Returns: Device identifier `String` value or `nil` if an error occurs From 958f1eefa4a98e447559fe640a37019a517b37b1 Mon Sep 17 00:00:00 2001 From: Petr Palata Date: Mon, 12 Sep 2022 17:54:07 +0200 Subject: [PATCH 6/7] Divide SHA256 into CryptoKit/CommonCrypto implementations and cover with a sanity test --- .../Hashing/SHA256FingerprintFunction.swift | 31 +++++++++------ .../Tests/SHA256HashingFunctionTests.swift | 39 +++++++++++++++++++ 2 files changed, 59 insertions(+), 11 deletions(-) create mode 100644 Sources/FingerprintJSTests/Tests/SHA256HashingFunctionTests.swift diff --git a/Sources/FingerprintJS/Hashing/SHA256FingerprintFunction.swift b/Sources/FingerprintJS/Hashing/SHA256FingerprintFunction.swift index fedb4de..ef66135 100644 --- a/Sources/FingerprintJS/Hashing/SHA256FingerprintFunction.swift +++ b/Sources/FingerprintJS/Hashing/SHA256FingerprintFunction.swift @@ -11,18 +11,27 @@ import Foundation class SHA256HashingFunction: FingerprintFunction { public func fingerprint(data: Data) -> String { - if #available(iOS 13, tvOS 13, *) { - let digest = SHA256.hash(data: data) - return digest.hexStr + if #available(iOS 13.0, tvOS 13.0, *) { + return computeSHA256CryptoKit(data) } else { - var hash = [UInt8](repeating: 0, count: Int(CC_SHA256_DIGEST_LENGTH)) - data.withUnsafeBytes { - _ = CC_SHA256($0.baseAddress, CC_LONG(data.count), &hash) - } - let digest = Data(hash) - return digest.map { - String(format: "%02hhx", $0) - }.joined() + return computeSHA256CommonCrypto(data) } } + + @available(iOS 13.0, tvOS 13.0, *) + func computeSHA256CryptoKit(_ data: Data) -> String { + let digest = SHA256.hash(data: data) + return digest.hexStr + } + + func computeSHA256CommonCrypto(_ data: Data) -> String { + var hash = [UInt8](repeating: 0, count: Int(CC_SHA256_DIGEST_LENGTH)) + data.withUnsafeBytes { + _ = CC_SHA256($0.baseAddress, CC_LONG(data.count), &hash) + } + let digest = Data(hash) + return digest.map { + String(format: "%02hhx", $0) + }.joined() + } } diff --git a/Sources/FingerprintJSTests/Tests/SHA256HashingFunctionTests.swift b/Sources/FingerprintJSTests/Tests/SHA256HashingFunctionTests.swift new file mode 100644 index 0000000..42ed87b --- /dev/null +++ b/Sources/FingerprintJSTests/Tests/SHA256HashingFunctionTests.swift @@ -0,0 +1,39 @@ +// +// SHA256HashingFunctionTests.swift +// +// +// Created by Petr Palata on 12.09.2022. +// + +import XCTest +@testable import FingerprintJS + +class SHA256HashingFunctionTests: XCTestCase { + private var sut: SHA256HashingFunction! + + override func setUpWithError() throws { + sut = SHA256HashingFunction() + } + + override func tearDownWithError() throws { + sut = nil + } + + @available(iOS 13.0, tvOS 13.0, *) + func testComputesSameHashForBothHashingVersions() { + let data = Data(base64Encoded: "dGhpcyBpcyBmaW5nZXJwcmludA==")! + + let sha256cryptoKit = sut.computeSHA256CryptoKit(data) + let sha256commonCrypto = sut.computeSHA256CommonCrypto(data) + + XCTAssertEqual(sha256cryptoKit, sha256commonCrypto) + } + + func testFingerprintComputesCorrectHashFunction() { + let data = Data(base64Encoded: "dGhpcyBpcyBmaW5nZXJwcmludA==")! + + let fingerprint = sut.fingerprint(data: data) + + XCTAssertEqual(fingerprint, "d7ffc906ba87c045110c78f34aad06f5259788d7f535b84cf0dd4cdcbf08a436") + } +} From 7137c9656a6041ddebf7a5ef851433244d9bfdd1 Mon Sep 17 00:00:00 2001 From: Petr Palata Date: Mon, 12 Sep 2022 18:33:00 +0200 Subject: [PATCH 7/7] Update .xcodeproj along with support for iOS 12 tests --- .../FingerprintJS.xcodeproj/project.pbxproj | 14 +++++++---- .../Hashing/SHA256FingerprintFunction.swift | 4 ++-- .../Tests/SHA256HashingFunctionTests.swift | 23 +++++++++++-------- 3 files changed, 25 insertions(+), 16 deletions(-) diff --git a/Sources/FingerprintJS.xcodeproj/project.pbxproj b/Sources/FingerprintJS.xcodeproj/project.pbxproj index ee5bd9d..b1d7087 100644 --- a/Sources/FingerprintJS.xcodeproj/project.pbxproj +++ b/Sources/FingerprintJS.xcodeproj/project.pbxproj @@ -12,6 +12,7 @@ 6A23866328042DFB002D09F3 /* DocumentsDirectoryAttributesProvidingMock.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6A23866228042DFB002D09F3 /* DocumentsDirectoryAttributesProvidingMock.swift */; }; 6A3BB827280588FD00D2EBB9 /* OSInfoHarvesterTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6A3BB826280588FD00D2EBB9 /* OSInfoHarvesterTests.swift */; }; 6A3BB82928058B4900D2EBB9 /* IdentifierHarvesterTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6A3BB82828058B4900D2EBB9 /* IdentifierHarvesterTests.swift */; }; + 6A44A31928CF8FAF0026DCD8 /* SHA256HashingFunctionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6A44A31828CF8FAF0026DCD8 /* SHA256HashingFunctionTests.swift */; }; 6A7D016527FB31A30037E190 /* DiskSpaceInfo.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6A7D016427FB31A30037E190 /* DiskSpaceInfo.swift */; }; 6A82A18327D65DB4007C023F /* FingerprintJS.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6A82A17A27D65DB4007C023F /* FingerprintJS.framework */; }; 6A82A18927D65DB4007C023F /* FingerprintJS.h in Headers */ = {isa = PBXBuildFile; fileRef = 6A82A17D27D65DB4007C023F /* FingerprintJS.h */; settings = {ATTRIBUTES = (Public, ); }; }; @@ -63,6 +64,7 @@ 6A23866228042DFB002D09F3 /* DocumentsDirectoryAttributesProvidingMock.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DocumentsDirectoryAttributesProvidingMock.swift; sourceTree = ""; }; 6A3BB826280588FD00D2EBB9 /* OSInfoHarvesterTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OSInfoHarvesterTests.swift; sourceTree = ""; }; 6A3BB82828058B4900D2EBB9 /* IdentifierHarvesterTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IdentifierHarvesterTests.swift; sourceTree = ""; }; + 6A44A31828CF8FAF0026DCD8 /* SHA256HashingFunctionTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SHA256HashingFunctionTests.swift; sourceTree = ""; }; 6A7D016427FB31A30037E190 /* DiskSpaceInfo.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DiskSpaceInfo.swift; sourceTree = ""; }; 6A82A17A27D65DB4007C023F /* FingerprintJS.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = FingerprintJS.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 6A82A17D27D65DB4007C023F /* FingerprintJS.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = FingerprintJS.h; sourceTree = ""; }; @@ -259,6 +261,7 @@ 6AC362AC280013F300C4768A /* Tests */ = { isa = PBXGroup; children = ( + 6A44A31828CF8FAF0026DCD8 /* SHA256HashingFunctionTests.swift */, 6AB7146027EB612D004BBCF3 /* FingerprintTreeCalculatorTests.swift */, 6AC362AA280013E200C4768A /* HardwareInfoHarvesterTests.swift */, 6A3BB826280588FD00D2EBB9 /* OSInfoHarvesterTests.swift */, @@ -458,6 +461,7 @@ 6A23866328042DFB002D09F3 /* DocumentsDirectoryAttributesProvidingMock.swift in Sources */, 6AB7146127EB612D004BBCF3 /* FingerprintTreeCalculatorTests.swift in Sources */, 6AC362B428042BB900C4768A /* ScreenSizeProviding.swift in Sources */, + 6A44A31928CF8FAF0026DCD8 /* SHA256HashingFunctionTests.swift in Sources */, 6AC362B628042C1500C4768A /* CPUInfoProvidingMock.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -532,6 +536,7 @@ SDKROOT = iphoneos; SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + TARGETED_DEVICE_FAMILY = "1,2,3"; VERSIONING_SYSTEM = "apple-generic"; VERSION_INFO_PREFIX = ""; }; @@ -589,6 +594,7 @@ SDKROOT = iphoneos; SWIFT_COMPILATION_MODE = wholemodule; SWIFT_OPTIMIZATION_LEVEL = "-O"; + TARGETED_DEVICE_FAMILY = "1,2,3"; VALIDATE_PRODUCT = YES; VERSIONING_SYSTEM = "apple-generic"; VERSION_INFO_PREFIX = ""; @@ -622,7 +628,7 @@ SWIFT_EMIT_LOC_STRINGS = YES; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; SWIFT_VERSION = 5.0; - TARGETED_DEVICE_FAMILY = "1,2"; + TARGETED_DEVICE_FAMILY = "1,2,3"; }; name = Debug; }; @@ -652,7 +658,7 @@ SUPPORTS_MACCATALYST = NO; SWIFT_EMIT_LOC_STRINGS = YES; SWIFT_VERSION = 5.0; - TARGETED_DEVICE_FAMILY = "1,2"; + TARGETED_DEVICE_FAMILY = "1,2,3"; }; name = Release; }; @@ -668,7 +674,7 @@ PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_EMIT_LOC_STRINGS = NO; SWIFT_VERSION = 5.0; - TARGETED_DEVICE_FAMILY = "1,2"; + TARGETED_DEVICE_FAMILY = "1,2,3"; }; name = Debug; }; @@ -684,7 +690,7 @@ PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_EMIT_LOC_STRINGS = NO; SWIFT_VERSION = 5.0; - TARGETED_DEVICE_FAMILY = "1,2"; + TARGETED_DEVICE_FAMILY = "1,2,3"; }; name = Release; }; diff --git a/Sources/FingerprintJS/Hashing/SHA256FingerprintFunction.swift b/Sources/FingerprintJS/Hashing/SHA256FingerprintFunction.swift index ef66135..fdbcacb 100644 --- a/Sources/FingerprintJS/Hashing/SHA256FingerprintFunction.swift +++ b/Sources/FingerprintJS/Hashing/SHA256FingerprintFunction.swift @@ -17,13 +17,13 @@ class SHA256HashingFunction: FingerprintFunction { return computeSHA256CommonCrypto(data) } } - + @available(iOS 13.0, tvOS 13.0, *) func computeSHA256CryptoKit(_ data: Data) -> String { let digest = SHA256.hash(data: data) return digest.hexStr } - + func computeSHA256CommonCrypto(_ data: Data) -> String { var hash = [UInt8](repeating: 0, count: Int(CC_SHA256_DIGEST_LENGTH)) data.withUnsafeBytes { diff --git a/Sources/FingerprintJSTests/Tests/SHA256HashingFunctionTests.swift b/Sources/FingerprintJSTests/Tests/SHA256HashingFunctionTests.swift index 42ed87b..8adda26 100644 --- a/Sources/FingerprintJSTests/Tests/SHA256HashingFunctionTests.swift +++ b/Sources/FingerprintJSTests/Tests/SHA256HashingFunctionTests.swift @@ -1,11 +1,12 @@ // // SHA256HashingFunctionTests.swift -// +// // // Created by Petr Palata on 12.09.2022. // import XCTest + @testable import FingerprintJS class SHA256HashingFunctionTests: XCTestCase { @@ -21,19 +22,21 @@ class SHA256HashingFunctionTests: XCTestCase { @available(iOS 13.0, tvOS 13.0, *) func testComputesSameHashForBothHashingVersions() { - let data = Data(base64Encoded: "dGhpcyBpcyBmaW5nZXJwcmludA==")! - - let sha256cryptoKit = sut.computeSHA256CryptoKit(data) - let sha256commonCrypto = sut.computeSHA256CommonCrypto(data) - - XCTAssertEqual(sha256cryptoKit, sha256commonCrypto) + if #available(iOS 13.0, tvOS 13.0, *) { + let data = Data(base64Encoded: "dGhpcyBpcyBmaW5nZXJwcmludA==")! + + let sha256cryptoKit = sut.computeSHA256CryptoKit(data) + let sha256commonCrypto = sut.computeSHA256CommonCrypto(data) + + XCTAssertEqual(sha256cryptoKit, sha256commonCrypto) + } } - + func testFingerprintComputesCorrectHashFunction() { let data = Data(base64Encoded: "dGhpcyBpcyBmaW5nZXJwcmludA==")! - + let fingerprint = sut.fingerprint(data: data) - + XCTAssertEqual(fingerprint, "d7ffc906ba87c045110c78f34aad06f5259788d7f535b84cf0dd4cdcbf08a436") } }