Skip to content

Commit

Permalink
Merge pull request #9 from fingerprintjs/ios12-support
Browse files Browse the repository at this point in the history
iOS 12 support
  • Loading branch information
petrpalata authored Sep 12, 2022
2 parents efbbb5f + 7137c96 commit ffd64dc
Show file tree
Hide file tree
Showing 9 changed files with 98 additions and 22 deletions.
8 changes: 4 additions & 4 deletions FingerprintJS.podspec
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
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' }

# Contact information
spec.homepage = 'https://fingerprint.com/'
spec.authors = {
'Fingerprint': 'fingerprintkit@fingerprint.com',
'Fingerprint': 'ios@fingerprint.com',
'Petr Palata': '[email protected]'
}

Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
22 changes: 14 additions & 8 deletions Sources/FingerprintJS.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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, ); }; };
Expand Down Expand Up @@ -63,6 +64,7 @@
6A23866228042DFB002D09F3 /* DocumentsDirectoryAttributesProvidingMock.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DocumentsDirectoryAttributesProvidingMock.swift; sourceTree = "<group>"; };
6A3BB826280588FD00D2EBB9 /* OSInfoHarvesterTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OSInfoHarvesterTests.swift; sourceTree = "<group>"; };
6A3BB82828058B4900D2EBB9 /* IdentifierHarvesterTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IdentifierHarvesterTests.swift; sourceTree = "<group>"; };
6A44A31828CF8FAF0026DCD8 /* SHA256HashingFunctionTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SHA256HashingFunctionTests.swift; sourceTree = "<group>"; };
6A7D016427FB31A30037E190 /* DiskSpaceInfo.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DiskSpaceInfo.swift; sourceTree = "<group>"; };
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 = "<group>"; };
Expand Down Expand Up @@ -259,6 +261,7 @@
6AC362AC280013F300C4768A /* Tests */ = {
isa = PBXGroup;
children = (
6A44A31828CF8FAF0026DCD8 /* SHA256HashingFunctionTests.swift */,
6AB7146027EB612D004BBCF3 /* FingerprintTreeCalculatorTests.swift */,
6AC362AA280013E200C4768A /* HardwareInfoHarvesterTests.swift */,
6A3BB826280588FD00D2EBB9 /* OSInfoHarvesterTests.swift */,
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -525,13 +529,14 @@
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;
SDKROOT = iphoneos;
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
TARGETED_DEVICE_FAMILY = "1,2,3";
VERSIONING_SYSTEM = "apple-generic";
VERSION_INFO_PREFIX = "";
};
Expand Down Expand Up @@ -583,12 +588,13 @@
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;
SWIFT_COMPILATION_MODE = wholemodule;
SWIFT_OPTIMIZATION_LEVEL = "-O";
TARGETED_DEVICE_FAMILY = "1,2,3";
VALIDATE_PRODUCT = YES;
VERSIONING_SYSTEM = "apple-generic";
VERSION_INFO_PREFIX = "";
Expand All @@ -608,7 +614,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",
Expand All @@ -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;
};
Expand All @@ -639,7 +645,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",
Expand All @@ -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;
};
Expand All @@ -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;
};
Expand All @@ -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;
};
Expand Down
1 change: 1 addition & 0 deletions Sources/FingerprintJS/Hashing/Digest+StringOutput.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import CryptoKit
import Foundation

@available(iOS 13.0, tvOS 13.0, *)
extension Digest {
var bytes: [UInt8] { Array(makeIterator()) }
var data: Data { Data(bytes) }
Expand Down
21 changes: 21 additions & 0 deletions Sources/FingerprintJS/Hashing/SHA256FingerprintFunction.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,33 @@
// Created by Petr Palata on 10.03.2022.
//

import CommonCrypto
import CryptoKit
import Foundation

class SHA256HashingFunction: FingerprintFunction {
public func fingerprint(data: Data) -> String {
if #available(iOS 13.0, tvOS 13.0, *) {
return computeSHA256CryptoKit(data)
} else {
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()
}
}
21 changes: 13 additions & 8 deletions Sources/FingerprintJS/Library/DeviceInfoProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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.0, tvOS 13.0, *)
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)
Expand Down Expand Up @@ -43,8 +44,17 @@ public class DeviceInfoProvider {

extension DeviceInfoProvider: DeviceInfoProviding {

@available(iOS 13.0, tvOS 13.0, *)
public func getDeviceInfo() async -> DeviceInfo {
return DeviceInfo(
return await withCheckedContinuation { continuation in
self.getDeviceInfo { deviceInfo in
continuation.resume(returning: deviceInfo)
}
}
}

public func getDeviceInfo(_ completion: @escaping (DeviceInfo) -> Void) {
let deviceInfo = DeviceInfo(
vendorIdentifier: identifierHarvester.vendorIdentifier,
diskSpace: hardwareInfoHarvester.diskSpaceInfo,
screenResolution: hardwareInfoHarvester.displayResolution,
Expand All @@ -59,12 +69,7 @@ extension DeviceInfoProvider: DeviceInfoProviding {
osRelease: osInfoHarvester.osRelease,
kernelVersion: osInfoHarvester.kernelVersion
)
}

public func getDeviceInfo(_ completion: @escaping (DeviceInfo) -> Void) {
Task.init {
let deviceInfo = await getDeviceInfo()
completion(deviceInfo)
}
completion(deviceInfo)
}
}
2 changes: 1 addition & 1 deletion Sources/FingerprintJS/Library/Fingerprinter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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, *)
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
Expand Down
1 change: 1 addition & 0 deletions Sources/FingerprintJSTests/Mocks/MockHashingFunction.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
// Created by Petr Palata on 23.03.2022.
//
import Foundation

@testable import FingerprintJS

class MockFingerprintFunction: FingerprintFunction {
Expand Down
42 changes: 42 additions & 0 deletions Sources/FingerprintJSTests/Tests/SHA256HashingFunctionTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
//
// 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() {
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")
}
}

0 comments on commit ffd64dc

Please sign in to comment.