Skip to content

Commit ffd64dc

Browse files
authored
Merge pull request #9 from fingerprintjs/ios12-support
iOS 12 support
2 parents efbbb5f + 7137c96 commit ffd64dc

File tree

9 files changed

+98
-22
lines changed

9 files changed

+98
-22
lines changed

FingerprintJS.podspec

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
Pod::Spec.new do |spec|
22
# Name and version
33
spec.name = 'FingerprintJS'
4-
spec.version = '1.1.1'
4+
spec.version = '1.1.2'
55

66
# License
77
spec.license = { type: 'MIT', file: 'LICENSE' }
88

99
# Contact information
1010
spec.homepage = 'https://fingerprint.com/'
1111
spec.authors = {
12-
'Fingerprint': 'fingerprintkit@fingerprint.com',
12+
'Fingerprint': 'ios@fingerprint.com',
1313
'Petr Palata': '[email protected]'
1414
}
1515

@@ -28,8 +28,8 @@ Pod::Spec.new do |spec|
2828

2929
# Build (source files, deployment target)
3030
spec.source_files = 'Sources/FingerprintJS/**/*.{swift,h,m}'
31-
spec.ios.deployment_target = '13.0'
32-
spec.tvos.deployment_target = '13.0'
31+
spec.ios.deployment_target = '12.0'
32+
spec.tvos.deployment_target = '12.0'
3333
spec.swift_versions = ['5.3', '5.4', '5.5', '5.6']
3434

3535
# Tests

Package.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import PackageDescription
55

66
let package = Package(
77
name: "FingerprintJS",
8-
platforms: [.iOS(.v13), .tvOS(.v13)],
8+
platforms: [.iOS(.v12), .tvOS(.v12)],
99
products: [
1010
.library(
1111
name: "FingerprintJS",

Sources/FingerprintJS.xcodeproj/project.pbxproj

+14-8
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
6A23866328042DFB002D09F3 /* DocumentsDirectoryAttributesProvidingMock.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6A23866228042DFB002D09F3 /* DocumentsDirectoryAttributesProvidingMock.swift */; };
1313
6A3BB827280588FD00D2EBB9 /* OSInfoHarvesterTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6A3BB826280588FD00D2EBB9 /* OSInfoHarvesterTests.swift */; };
1414
6A3BB82928058B4900D2EBB9 /* IdentifierHarvesterTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6A3BB82828058B4900D2EBB9 /* IdentifierHarvesterTests.swift */; };
15+
6A44A31928CF8FAF0026DCD8 /* SHA256HashingFunctionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6A44A31828CF8FAF0026DCD8 /* SHA256HashingFunctionTests.swift */; };
1516
6A7D016527FB31A30037E190 /* DiskSpaceInfo.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6A7D016427FB31A30037E190 /* DiskSpaceInfo.swift */; };
1617
6A82A18327D65DB4007C023F /* FingerprintJS.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6A82A17A27D65DB4007C023F /* FingerprintJS.framework */; };
1718
6A82A18927D65DB4007C023F /* FingerprintJS.h in Headers */ = {isa = PBXBuildFile; fileRef = 6A82A17D27D65DB4007C023F /* FingerprintJS.h */; settings = {ATTRIBUTES = (Public, ); }; };
@@ -63,6 +64,7 @@
6364
6A23866228042DFB002D09F3 /* DocumentsDirectoryAttributesProvidingMock.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DocumentsDirectoryAttributesProvidingMock.swift; sourceTree = "<group>"; };
6465
6A3BB826280588FD00D2EBB9 /* OSInfoHarvesterTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OSInfoHarvesterTests.swift; sourceTree = "<group>"; };
6566
6A3BB82828058B4900D2EBB9 /* IdentifierHarvesterTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IdentifierHarvesterTests.swift; sourceTree = "<group>"; };
67+
6A44A31828CF8FAF0026DCD8 /* SHA256HashingFunctionTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SHA256HashingFunctionTests.swift; sourceTree = "<group>"; };
6668
6A7D016427FB31A30037E190 /* DiskSpaceInfo.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DiskSpaceInfo.swift; sourceTree = "<group>"; };
6769
6A82A17A27D65DB4007C023F /* FingerprintJS.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = FingerprintJS.framework; sourceTree = BUILT_PRODUCTS_DIR; };
6870
6A82A17D27D65DB4007C023F /* FingerprintJS.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = FingerprintJS.h; sourceTree = "<group>"; };
@@ -259,6 +261,7 @@
259261
6AC362AC280013F300C4768A /* Tests */ = {
260262
isa = PBXGroup;
261263
children = (
264+
6A44A31828CF8FAF0026DCD8 /* SHA256HashingFunctionTests.swift */,
262265
6AB7146027EB612D004BBCF3 /* FingerprintTreeCalculatorTests.swift */,
263266
6AC362AA280013E200C4768A /* HardwareInfoHarvesterTests.swift */,
264267
6A3BB826280588FD00D2EBB9 /* OSInfoHarvesterTests.swift */,
@@ -458,6 +461,7 @@
458461
6A23866328042DFB002D09F3 /* DocumentsDirectoryAttributesProvidingMock.swift in Sources */,
459462
6AB7146127EB612D004BBCF3 /* FingerprintTreeCalculatorTests.swift in Sources */,
460463
6AC362B428042BB900C4768A /* ScreenSizeProviding.swift in Sources */,
464+
6A44A31928CF8FAF0026DCD8 /* SHA256HashingFunctionTests.swift in Sources */,
461465
6AC362B628042C1500C4768A /* CPUInfoProvidingMock.swift in Sources */,
462466
);
463467
runOnlyForDeploymentPostprocessing = 0;
@@ -525,13 +529,14 @@
525529
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
526530
GCC_WARN_UNUSED_FUNCTION = YES;
527531
GCC_WARN_UNUSED_VARIABLE = YES;
528-
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
532+
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
529533
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
530534
MTL_FAST_MATH = YES;
531535
ONLY_ACTIVE_ARCH = YES;
532536
SDKROOT = iphoneos;
533537
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
534538
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
539+
TARGETED_DEVICE_FAMILY = "1,2,3";
535540
VERSIONING_SYSTEM = "apple-generic";
536541
VERSION_INFO_PREFIX = "";
537542
};
@@ -583,12 +588,13 @@
583588
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
584589
GCC_WARN_UNUSED_FUNCTION = YES;
585590
GCC_WARN_UNUSED_VARIABLE = YES;
586-
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
591+
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
587592
MTL_ENABLE_DEBUG_INFO = NO;
588593
MTL_FAST_MATH = YES;
589594
SDKROOT = iphoneos;
590595
SWIFT_COMPILATION_MODE = wholemodule;
591596
SWIFT_OPTIMIZATION_LEVEL = "-O";
597+
TARGETED_DEVICE_FAMILY = "1,2,3";
592598
VALIDATE_PRODUCT = YES;
593599
VERSIONING_SYSTEM = "apple-generic";
594600
VERSION_INFO_PREFIX = "";
@@ -608,7 +614,7 @@
608614
GENERATE_INFOPLIST_FILE = YES;
609615
INFOPLIST_KEY_NSHumanReadableCopyright = "";
610616
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
611-
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
617+
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
612618
LD_RUNPATH_SEARCH_PATHS = (
613619
"$(inherited)",
614620
"@executable_path/Frameworks",
@@ -622,7 +628,7 @@
622628
SWIFT_EMIT_LOC_STRINGS = YES;
623629
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
624630
SWIFT_VERSION = 5.0;
625-
TARGETED_DEVICE_FAMILY = "1,2";
631+
TARGETED_DEVICE_FAMILY = "1,2,3";
626632
};
627633
name = Debug;
628634
};
@@ -639,7 +645,7 @@
639645
GENERATE_INFOPLIST_FILE = YES;
640646
INFOPLIST_KEY_NSHumanReadableCopyright = "";
641647
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
642-
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
648+
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
643649
LD_RUNPATH_SEARCH_PATHS = (
644650
"$(inherited)",
645651
"@executable_path/Frameworks",
@@ -652,7 +658,7 @@
652658
SUPPORTS_MACCATALYST = NO;
653659
SWIFT_EMIT_LOC_STRINGS = YES;
654660
SWIFT_VERSION = 5.0;
655-
TARGETED_DEVICE_FAMILY = "1,2";
661+
TARGETED_DEVICE_FAMILY = "1,2,3";
656662
};
657663
name = Release;
658664
};
@@ -668,7 +674,7 @@
668674
PRODUCT_NAME = "$(TARGET_NAME)";
669675
SWIFT_EMIT_LOC_STRINGS = NO;
670676
SWIFT_VERSION = 5.0;
671-
TARGETED_DEVICE_FAMILY = "1,2";
677+
TARGETED_DEVICE_FAMILY = "1,2,3";
672678
};
673679
name = Debug;
674680
};
@@ -684,7 +690,7 @@
684690
PRODUCT_NAME = "$(TARGET_NAME)";
685691
SWIFT_EMIT_LOC_STRINGS = NO;
686692
SWIFT_VERSION = 5.0;
687-
TARGETED_DEVICE_FAMILY = "1,2";
693+
TARGETED_DEVICE_FAMILY = "1,2,3";
688694
};
689695
name = Release;
690696
};

Sources/FingerprintJS/Hashing/Digest+StringOutput.swift

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import CryptoKit
99
import Foundation
1010

11+
@available(iOS 13.0, tvOS 13.0, *)
1112
extension Digest {
1213
var bytes: [UInt8] { Array(makeIterator()) }
1314
var data: Data { Data(bytes) }

Sources/FingerprintJS/Hashing/SHA256FingerprintFunction.swift

+21
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,33 @@
55
// Created by Petr Palata on 10.03.2022.
66
//
77

8+
import CommonCrypto
89
import CryptoKit
910
import Foundation
1011

1112
class SHA256HashingFunction: FingerprintFunction {
1213
public func fingerprint(data: Data) -> String {
14+
if #available(iOS 13.0, tvOS 13.0, *) {
15+
return computeSHA256CryptoKit(data)
16+
} else {
17+
return computeSHA256CommonCrypto(data)
18+
}
19+
}
20+
21+
@available(iOS 13.0, tvOS 13.0, *)
22+
func computeSHA256CryptoKit(_ data: Data) -> String {
1323
let digest = SHA256.hash(data: data)
1424
return digest.hexStr
1525
}
26+
27+
func computeSHA256CommonCrypto(_ data: Data) -> String {
28+
var hash = [UInt8](repeating: 0, count: Int(CC_SHA256_DIGEST_LENGTH))
29+
data.withUnsafeBytes {
30+
_ = CC_SHA256($0.baseAddress, CC_LONG(data.count), &hash)
31+
}
32+
let digest = Data(hash)
33+
return digest.map {
34+
String(format: "%02hhx", $0)
35+
}.joined()
36+
}
1637
}

Sources/FingerprintJS/Library/DeviceInfoProvider.swift

+13-8
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@ import Foundation
1010
public protocol DeviceInfoProviding {
1111
/// Gathers and returns all information about the device
1212
/// - Returns: `DeviceInfo` object that contains typed representation of device information values
13+
@available(iOS 13.0, tvOS 13.0, *)
1314
func getDeviceInfo() async -> DeviceInfo
14-
15+
1516
/// Gathers all information about the device and reports it through the completion block
1617
/// - Parameter completion: Completion block reporting the `DeviceInfo` object
1718
func getDeviceInfo(_ completion: @escaping (DeviceInfo) -> Void)
@@ -43,8 +44,17 @@ public class DeviceInfoProvider {
4344

4445
extension DeviceInfoProvider: DeviceInfoProviding {
4546

47+
@available(iOS 13.0, tvOS 13.0, *)
4648
public func getDeviceInfo() async -> DeviceInfo {
47-
return DeviceInfo(
49+
return await withCheckedContinuation { continuation in
50+
self.getDeviceInfo { deviceInfo in
51+
continuation.resume(returning: deviceInfo)
52+
}
53+
}
54+
}
55+
56+
public func getDeviceInfo(_ completion: @escaping (DeviceInfo) -> Void) {
57+
let deviceInfo = DeviceInfo(
4858
vendorIdentifier: identifierHarvester.vendorIdentifier,
4959
diskSpace: hardwareInfoHarvester.diskSpaceInfo,
5060
screenResolution: hardwareInfoHarvester.displayResolution,
@@ -59,12 +69,7 @@ extension DeviceInfoProvider: DeviceInfoProviding {
5969
osRelease: osInfoHarvester.osRelease,
6070
kernelVersion: osInfoHarvester.kernelVersion
6171
)
62-
}
6372

64-
public func getDeviceInfo(_ completion: @escaping (DeviceInfo) -> Void) {
65-
Task.init {
66-
let deviceInfo = await getDeviceInfo()
67-
completion(deviceInfo)
68-
}
73+
completion(deviceInfo)
6974
}
7075
}

Sources/FingerprintJS/Library/Fingerprinter.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ extension Fingerprinter {
7474
}
7575

7676
// MARK: - Public Interface: Async/Await (iOS 13+)
77-
@available(iOS 13, macOS 11, *)
77+
@available(iOS 13.0, tvOS 13.0, *)
7878
extension Fingerprinter {
7979
/// Retrieves a stable device identifier that is tied to the current device/application combination
8080
/// - Returns: Device identifier `String` value or `nil` if an error occurs

Sources/FingerprintJSTests/Mocks/MockHashingFunction.swift

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
// Created by Petr Palata on 23.03.2022.
66
//
77
import Foundation
8+
89
@testable import FingerprintJS
910

1011
class MockFingerprintFunction: FingerprintFunction {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
//
2+
// SHA256HashingFunctionTests.swift
3+
//
4+
//
5+
// Created by Petr Palata on 12.09.2022.
6+
//
7+
8+
import XCTest
9+
10+
@testable import FingerprintJS
11+
12+
class SHA256HashingFunctionTests: XCTestCase {
13+
private var sut: SHA256HashingFunction!
14+
15+
override func setUpWithError() throws {
16+
sut = SHA256HashingFunction()
17+
}
18+
19+
override func tearDownWithError() throws {
20+
sut = nil
21+
}
22+
23+
@available(iOS 13.0, tvOS 13.0, *)
24+
func testComputesSameHashForBothHashingVersions() {
25+
if #available(iOS 13.0, tvOS 13.0, *) {
26+
let data = Data(base64Encoded: "dGhpcyBpcyBmaW5nZXJwcmludA==")!
27+
28+
let sha256cryptoKit = sut.computeSHA256CryptoKit(data)
29+
let sha256commonCrypto = sut.computeSHA256CommonCrypto(data)
30+
31+
XCTAssertEqual(sha256cryptoKit, sha256commonCrypto)
32+
}
33+
}
34+
35+
func testFingerprintComputesCorrectHashFunction() {
36+
let data = Data(base64Encoded: "dGhpcyBpcyBmaW5nZXJwcmludA==")!
37+
38+
let fingerprint = sut.fingerprint(data: data)
39+
40+
XCTAssertEqual(fingerprint, "d7ffc906ba87c045110c78f34aad06f5259788d7f535b84cf0dd4cdcbf08a436")
41+
}
42+
}

0 commit comments

Comments
 (0)