Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump min iOS version to 13 #257

Merged
merged 4 commits into from
Jan 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Alicerce.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Pod::Spec.new do |s|
s.module_name = 'Alicerce'
s.swift_version = '5.7'

s.ios.deployment_target = '11.0'
s.ios.deployment_target = '13.0'

s.subspec 'Core' do |ss|
ss.source_files = 'Sources/{Utils,Shared}/**/*.swift'
Expand Down Expand Up @@ -63,7 +63,7 @@ Pod::Spec.new do |s|
s.subspec 'Network' do |ss|
ss.source_files = 'Sources/Network/**/*.swift'
ss.dependency 'Alicerce/Core'
ss.frameworks = 'Security'
ss.frameworks = 'Security', 'CryptoKit'
end

s.subspec 'Observers' do |ss|
Expand Down
16 changes: 8 additions & 8 deletions Alicerce.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@
0AA061062273B5A00052B4A1 /* TestNIBTableHeaderFooterView.xib in Resources */ = {isa = PBXBuildFile; fileRef = F1D1F60622661EBA00CC46B3 /* TestNIBTableHeaderFooterView.xib */; };
0AA061072273B5A00052B4A1 /* TestNIBTableViewCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = F1D1F60122661D0300CC46B3 /* TestNIBTableViewCell.xib */; };
0AB34A062085385A001F2979 /* UnfairLockTestCase.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0AB34A052085385A001F2979 /* UnfairLockTestCase.swift */; };
0AB34A0820853873001F2979 /* PthreadLockTestCase.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0AB34A0720853873001F2979 /* PthreadLockTestCase.swift */; };
0AB34A0820853873001F2979 /* AllocatedUnfairLockTestCase.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0AB34A0720853873001F2979 /* AllocatedUnfairLockTestCase.swift */; };
0ABEC1E9284EADDF00043288 /* LogItemFormatComponent.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0ABEC1E8284EADDF00043288 /* LogItemFormatComponent.swift */; };
0ABEC1EB284EAE6400043288 /* Log+ItemFormat+GenericComponents.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0ABEC1EA284EAE6400043288 /* Log+ItemFormat+GenericComponents.swift */; };
0ABEC1EF284FDE3900043288 /* Log+ItemFormat+ItemComponents.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0ABEC1EE284FDE3900043288 /* Log+ItemFormat+ItemComponents.swift */; };
Expand Down Expand Up @@ -566,7 +566,7 @@
0AA4EBA6264598AE00616FB3 /* .github */ = {isa = PBXFileReference; lastKnownFileType = folder; path = .github; sourceTree = "<group>"; };
0AA4EBA72645E96900616FB3 /* Gemfile */ = {isa = PBXFileReference; lastKnownFileType = text; path = Gemfile; sourceTree = "<group>"; };
0AB34A052085385A001F2979 /* UnfairLockTestCase.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UnfairLockTestCase.swift; sourceTree = "<group>"; };
0AB34A0720853873001F2979 /* PthreadLockTestCase.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PthreadLockTestCase.swift; sourceTree = "<group>"; };
0AB34A0720853873001F2979 /* AllocatedUnfairLockTestCase.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AllocatedUnfairLockTestCase.swift; sourceTree = "<group>"; };
0ABEC1E8284EADDF00043288 /* LogItemFormatComponent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LogItemFormatComponent.swift; sourceTree = "<group>"; };
0ABEC1EA284EAE6400043288 /* Log+ItemFormat+GenericComponents.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Log+ItemFormat+GenericComponents.swift"; sourceTree = "<group>"; };
0ABEC1EE284FDE3900043288 /* Log+ItemFormat+ItemComponents.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Log+ItemFormat+ItemComponents.swift"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1022,15 +1022,15 @@
0A3C2D3B1EA7E1EE00EFB7D4 /* Utils */ = {
isa = PBXGroup;
children = (
0AB34A0720853873001F2979 /* AllocatedUnfairLockTestCase.swift */,
0A266F231ED37708009CD0D7 /* AssertDumpsEqualTestCase.swift */,
0ACEB2952080ED90000D95AD /* AtomicTestCase.swift */,
0A265E1C20EAEA8A00A55ED9 /* BoxTestCase.swift */,
9DEC00AC209A04D000F94353 /* BuilderCacheTestCase.swift */,
0ACEB2992080F0E5000D95AD /* LockTestCase.swift */,
0AB34A0720853873001F2979 /* PthreadLockTestCase.swift */,
0A3C2D3C1EA7E1EE00EFB7D4 /* ServiceLocatorTests.swift */,
0AB34A052085385A001F2979 /* UnfairLockTestCase.swift */,
0A265E1C20EAEA8A00A55ED9 /* BoxTestCase.swift */,
73C6051C20F3BD0E00D0B643 /* TokenTests.swift */,
0AB34A052085385A001F2979 /* UnfairLockTestCase.swift */,
);
path = Utils;
sourceTree = "<group>";
Expand Down Expand Up @@ -1853,7 +1853,7 @@
4838FE5823A951E9007311F0 /* TrailingConstrainableProxyTestCase.swift in Sources */,
0AFB0DCE20F8E81700A58515 /* MockAuthenticationChallengeHandler.swift in Sources */,
0AFB0DC720F8E77700A58515 /* MockURLSession.swift in Sources */,
0AB34A0820853873001F2979 /* PthreadLockTestCase.swift in Sources */,
0AB34A0820853873001F2979 /* AllocatedUnfairLockTestCase.swift in Sources */,
0A166EE22210B83100EC6686 /* CoreDataStack+ManagedObjectReflectableTestCase.swift in Sources */,
4838FE4F23A951C8007311F0 /* NSLayoutConstraint+TestHelpers.swift in Sources */,
0A3236E720D88ED400D225CB /* LoggerTestCase.swift in Sources */,
Expand Down Expand Up @@ -2587,7 +2587,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
ONLY_ACTIVE_ARCH = YES;
PRODUCT_NAME = "$(TARGET_NAME)";
SDKROOT = iphoneos;
Expand Down Expand Up @@ -2635,7 +2635,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
PRODUCT_NAME = "$(TARGET_NAME)";
SDKROOT = iphoneos;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
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: "Alicerce",
platforms: [
.iOS(.v11)
.iOS(.v13)
],
products: [
// single module product, mutually exclusive with *all* other products (which use sub-modules)!
Expand Down
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,13 @@ TODO

## Compatibility ✅

### `0.17.0` ... `master`
### `master`

- iOS 13.0+
- Xcode 14.0
- Swift 5.7

### `0.17.0`

- iOS 11.0+
- Xcode 14.0
Expand Down
1 change: 0 additions & 1 deletion Sources/AutoLayout/ConstrainableProxy.swift
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,6 @@ public extension EdgesConstrainableProxy {
}

@_disfavoredOverload
@available(iOS 11.0, *)
@discardableResult
func edges(
to anotherProxy: EdgesConstrainableProxy,
Expand Down
10 changes: 0 additions & 10 deletions Sources/AutoLayout/ViewProxy.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,8 @@ public final class ViewProxy: PositionConstrainableProxy, BaselineConstrainableP

public var layoutMarginsGuide: LayoutGuideProxy { view.layoutMarginsGuide.proxy(with: context) }

@available(iOS 11.0, *)
public var safeAreaLayoutGuide: LayoutGuideProxy { view.safeAreaLayoutGuide.proxy(with: context) }

public var safeArea: LayoutGuideProxy {

if #available(iOS 11.0, *) {
return safeAreaLayoutGuide
} else {
return layoutMarginsGuide
}
}

private let view: UIView

// MARK: - Lifecycle
Expand Down
7 changes: 2 additions & 5 deletions Sources/Extensions/Foundation/String.swift
Original file line number Diff line number Diff line change
Expand Up @@ -88,17 +88,14 @@ extension String {
while !scanner.isAtEnd {

// copy everything until finding a character to be replaced or skipped
var collector: NSString? = ""
if scanner.scanUpToCharacters(from: matchSet, into: &collector), let collector = collector {
final.append(collector as String)
}
if let collector = scanner.scanUpToCharacters(from: matchSet) { final.append(collector) }

// exit early if we're already at the end
guard !scanner.isAtEnd else { break }

// find and replace matching character if needed
replacementMap
.first { match, _ in scanner.scanString(String(match), into: nil) }
.first { match, _ in scanner.scanString(String(match)) != nil }
.flatMap { _, replacement in final.append(replacement) }
}

Expand Down
1 change: 0 additions & 1 deletion Sources/Extensions/UIKit/NSDirectionalEdgeInsets.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import UIKit

@available(iOS 11.0, *)
extension NSDirectionalEdgeInsets {

public var nonDirectional: UIEdgeInsets { .init(top: top, left: leading, bottom: bottom, right: trailing) }
Expand Down
10 changes: 5 additions & 5 deletions Sources/Extensions/UIKit/UIColor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ public extension UIColor {
let hex = hex.trimmingCharacters(in: .whitespacesAndNewlines)
.replacingOccurrences(of: "#", with: "")

var hexValue: UInt32 = 0
var hexValue: UInt64 = 0

guard Scanner(string: hex).scanHexInt32(&hexValue) else {
fatalError("😱 Cannot convert string into `UInt32`")
guard Scanner(string: hex).scanHexInt64(&hexValue) else {
fatalError("😱 Cannot convert string into `UInt64`")
}

let components: Components = {
Expand Down Expand Up @@ -55,15 +55,15 @@ public extension UIColor {

// MARK: - Private Methods

private static func components(fromHex6 hex: UInt32) -> Components {
private static func components(fromHex6 hex: UInt64) -> Components {
let red = CGFloat((hex & 0xFF0000) >> 16) / UIColor.divisor
let green = CGFloat((hex & 0x00FF00) >> 8) / UIColor.divisor
let blue = CGFloat(hex & 0x0000FF) / UIColor.divisor

return (red, green, blue, 1.0)
}

private static func components(fromHex8 hex: UInt32) -> Components {
private static func components(fromHex8 hex: UInt64) -> Components {

let alpha = CGFloat((hex & 0xFF000000) >> 24) / UIColor.divisor
let red = CGFloat((hex & 0x00FF0000) >> 16) / UIColor.divisor
Expand Down
1 change: 0 additions & 1 deletion Sources/Extensions/UIKit/UIEdgeInsets.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,5 @@ import UIKit

extension UIEdgeInsets {

@available(iOS 11.0, *)
public var directional: NSDirectionalEdgeInsets { .init(top: top, leading: left, bottom: bottom, trailing: right) }
}
16 changes: 7 additions & 9 deletions Sources/Network/Pinning/Data+SPKIHash.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Foundation
import CommonCrypto
import CryptoKit

// How to retrieve SPKI SHA256 Base64 encoded hashes:
//
Expand All @@ -16,18 +16,16 @@ import CommonCrypto

extension Data {

typealias CertificateSPKIBase64EncodedSHA256Hash = ServerTrustEvaluator.CertificateSPKIBase64EncodedSHA256Hash
public typealias CertificateSPKIBase64EncodedSHA256Hash =
ServerTrustEvaluator.CertificateSPKIBase64EncodedSHA256Hash

func spkiHash(for algorithm: PublicKeyAlgorithm) -> CertificateSPKIBase64EncodedSHA256Hash {
public func spkiHash(for algorithm: PublicKeyAlgorithm) -> CertificateSPKIBase64EncodedSHA256Hash {

// add missing ASN1 header for public keys to re-create the subject public key info (SPKI)
let spkiData = algorithm.asn1HeaderData + self

var spkiHash = [UInt8](repeating: 0, count: Int(CC_SHA256_DIGEST_LENGTH))
spkiData.withUnsafeBytes {
_ = CC_SHA256($0.baseAddress, CC_LONG(spkiData.count), &spkiHash)
}

return Data(spkiHash).base64EncodedString()
return spkiData.sha256().base64EncodedString()
}

func sha256() -> Data { Data(SHA256.hash(data: self)) }
}
12 changes: 1 addition & 11 deletions Sources/Network/Pinning/SecCertificate+PublicKey.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ extension SecCertificate {

public enum PublicKeyExtractionError: Swift.Error {
case createTrust(OSStatus?)
case trustEvaluation(OSStatus)
case copyPublicKey(SecTrust)
case copyPublicKeyExternalRepresentation(SecKey, CFError?)
case copyPublicKeyAttributes(SecKey)
Expand Down Expand Up @@ -40,7 +39,6 @@ extension SecCertificate {

// create an X509 trust for the certificate
var newTrust: SecTrust?
var result = SecTrustResultType.invalid
let policy = SecPolicyCreateBasicX509()

switch SecTrustCreateWithCertificates(self, policy, &newTrust) {
Expand All @@ -50,16 +48,8 @@ extension SecCertificate {

guard let trust = newTrust else { throw PublicKeyExtractionError.createTrust(nil) }

// validate the newly created certificate trust
switch SecTrustEvaluate(trust, &result) {
case errSecSuccess: break
case let error: throw PublicKeyExtractionError.trustEvaluation(error)
}

// get a public key reference from the certificate trust
guard let publicKey = SecTrustCopyPublicKey(trust) else {
throw PublicKeyExtractionError.copyPublicKey(trust)
}
guard let publicKey = SecTrustCopyPublicKey(trust) else { throw PublicKeyExtractionError.copyPublicKey(trust) }

return publicKey
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Foundation
import CommonCrypto
import CryptoKit

extension ServerTrustEvaluator {

Expand Down Expand Up @@ -34,7 +34,7 @@ extension ServerTrustEvaluator {
// validate pins
guard !pinnedHashes.isEmpty else { throw PinningPolicyValidationError.emptyPins }

let invalidPins = pinnedHashes.filter { Data(base64Encoded: $0)?.count ?? 0 != CC_SHA256_DIGEST_LENGTH }
let invalidPins = pinnedHashes.filter { Data(base64Encoded: $0)?.count ?? 0 != SHA256.Digest.byteCount }
guard invalidPins.isEmpty else { throw PinningPolicyValidationError.invalidPins(Set(invalidPins)) }

// validate backup pin enforcing
Expand Down
32 changes: 3 additions & 29 deletions Sources/Network/Pinning/ServerTrustEvaluator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,10 @@ public final class ServerTrustEvaluator {
let sslPolicy = SecPolicyCreateSSL(true, hostname as CFString)
SecTrustSetPolicies(trust, sslPolicy)

if #available(iOS 12.0, *) {
var trustError: CFError?
var trustError: CFError?

guard SecTrustEvaluateWithError(trust, &trustError) else {
throw PublicKeyPinVerificationError.evaluation(trustError)
}
} else {
try legacy_evaluateTrust(trust)
guard SecTrustEvaluateWithError(trust, &trustError) else {
throw PublicKeyPinVerificationError.evaluation(trustError)
}

let certificateChainLength = SecTrustGetCertificateCount(trust)
Expand All @@ -108,24 +104,6 @@ public final class ServerTrustEvaluator {
// at this point, we didn't find any matching SPKI hash in the chain
throw PublicKeyPinVerificationError.pinnedHashNotFound
}

@available(iOS, deprecated: 12.0, message: "Only required for `SecTrustEvaluate` check!")
func legacy_evaluateTrust(_ trust: SecTrust) throws {

var trustResult: SecTrustResultType = .invalid

switch SecTrustEvaluate(trust, &trustResult) {
case errSecSuccess: break
case let error: throw PublicKeyPinVerificationError.evaluationResult(trustResult, error)
}

switch trustResult {
case .unspecified, .proceed: break
default: throw PublicKeyPinVerificationError.sslValidation(trustResult,
SecTrustCopyResult(trust),
SecTrustCopyProperties(trust))
}
}
}

// MARK: - AuthenticationChallengeHandler
Expand Down Expand Up @@ -170,10 +148,6 @@ extension ServerTrustEvaluator {

public enum PublicKeyPinVerificationError: Swift.Error {
case evaluation(CFError?)
@available(iOS, deprecated: 12.0, message: "Only required for `SecTrustEvaluate` check!")
case evaluationResult(SecTrustResultType, OSStatus)
@available(iOS, deprecated: 12.0, message: "Only required for `SecTrustEvaluate` check!")
case sslValidation(SecTrustResultType, CFDictionary?, CFArray?)
case getCertificate(CFIndex)
case extractPublicKey(SecCertificate.PublicKeyExtractionError)
case pinnedHashNotFound
Expand Down
Loading