服务商获取权限失败的话retry,更换了首页的背景图

This commit is contained in:
DDIsFriend
2023-11-21 13:47:33 +08:00
parent cfd5d93c71
commit 11d838906f
28 changed files with 921 additions and 372 deletions

View File

@@ -1,5 +1,5 @@
//
// ServerTrustPolicy.swift
// ServerTrustEvaluation.swift
//
// Copyright (c) 2014-2016 Alamofire Software Foundation (http://alamofire.org/)
//
@@ -48,7 +48,7 @@ open class ServerTrustManager {
self.evaluators = evaluators
}
#if !(os(Linux) || os(Windows))
#if canImport(Security)
/// Returns the `ServerTrustEvaluating` value for the given host, if one is set.
///
/// By default, this method will return the policy that perfectly matches the given host. Subclasses could override
@@ -75,8 +75,8 @@ open class ServerTrustManager {
/// A protocol describing the API used to evaluate server trusts.
public protocol ServerTrustEvaluating {
#if os(Linux) || os(Windows)
// Implement this once Linux/Windows has API for evaluating server trusts.
#if !canImport(Security)
// Implement this once other platforms have API for evaluating server trusts.
#else
/// Evaluates the given `SecTrust` value for the given `host`.
///
@@ -91,7 +91,7 @@ public protocol ServerTrustEvaluating {
// MARK: - Server Trust Evaluators
#if !(os(Linux) || os(Windows))
#if canImport(Security)
/// An evaluator which uses the default server trust evaluation while allowing you to control whether to validate the
/// host provided by the challenge. Applications are encouraged to always validate the host in production environments
/// to guarantee the validity of the server's certificate chain.
@@ -181,6 +181,15 @@ public final class RevocationTrustEvaluator: ServerTrustEvaluating {
try trust.af.performValidation(forHost: host)
}
#if swift(>=5.9)
if #available(iOS 12, macOS 10.14, tvOS 12, watchOS 5, visionOS 1, *) {
try trust.af.evaluate(afterApplying: SecPolicy.af.revocation(options: options))
} else {
try trust.af.validate(policy: SecPolicy.af.revocation(options: options)) { status, result in
AFError.serverTrustEvaluationFailed(reason: .revocationCheckFailed(output: .init(host, trust, status, result), options: options))
}
}
#else
if #available(iOS 12, macOS 10.14, tvOS 12, watchOS 5, *) {
try trust.af.evaluate(afterApplying: SecPolicy.af.revocation(options: options))
} else {
@@ -188,6 +197,7 @@ public final class RevocationTrustEvaluator: ServerTrustEvaluating {
AFError.serverTrustEvaluationFailed(reason: .revocationCheckFailed(output: .init(host, trust, status, result), options: options))
}
}
#endif
}
}
@@ -355,10 +365,8 @@ public final class PublicKeysTrustEvaluator: ServerTrustEvaluating {
let pinnedKeysInServerKeys: Bool = {
for serverPublicKey in trust.af.publicKeys {
for pinnedPublicKey in keys {
if serverPublicKey == pinnedPublicKey {
return true
}
if keys.contains(serverPublicKey) {
return true
}
}
return false
@@ -449,7 +457,7 @@ public final class DisabledTrustEvaluator: ServerTrustEvaluating {
// MARK: - Extensions
extension Array where Element == ServerTrustEvaluating {
#if os(Linux) || os(Windows)
#if os(Linux) || os(Windows) || os(Android)
// Add this same convenience method for Linux/Windows.
#else
/// Evaluates the given `SecTrust` value for the given `host`.
@@ -598,7 +606,15 @@ extension AlamofireExtension where ExtendedType == SecTrust {
/// The `SecCertificate`s contained in `self`.
public var certificates: [SecCertificate] {
#if swift(>=5.5.1) // Xcode 13.1 / 2021 SDKs.
#if swift(>=5.9)
if #available(iOS 15, macOS 12, tvOS 15, watchOS 8, visionOS 1, *) {
return (SecTrustCopyCertificateChain(type) as? [SecCertificate]) ?? []
} else {
return (0..<SecTrustGetCertificateCount(type)).compactMap { index in
SecTrustGetCertificateAtIndex(type, index)
}
}
#elseif swift(>=5.5.1) // Xcode 13.1 / 2021 SDKs.
if #available(iOS 15, macOS 12, tvOS 15, watchOS 8, *) {
return (SecTrustCopyCertificateChain(type) as? [SecCertificate]) ?? []
} else {
@@ -623,6 +639,15 @@ extension AlamofireExtension where ExtendedType == SecTrust {
/// - Parameter host: The hostname, used only in the error output if validation fails.
/// - Throws: An `AFError.serverTrustEvaluationFailed` instance with a `.defaultEvaluationFailed` reason.
public func performDefaultValidation(forHost host: String) throws {
#if swift(>=5.9)
if #available(iOS 12, macOS 10.14, tvOS 12, watchOS 5, visionOS 1, *) {
try evaluate(afterApplying: SecPolicy.af.default)
} else {
try validate(policy: SecPolicy.af.default) { status, result in
AFError.serverTrustEvaluationFailed(reason: .defaultEvaluationFailed(output: .init(host, type, status, result)))
}
}
#else
if #available(iOS 12, macOS 10.14, tvOS 12, watchOS 5, *) {
try evaluate(afterApplying: SecPolicy.af.default)
} else {
@@ -630,6 +655,7 @@ extension AlamofireExtension where ExtendedType == SecTrust {
AFError.serverTrustEvaluationFailed(reason: .defaultEvaluationFailed(output: .init(host, type, status, result)))
}
}
#endif
}
/// Validates `self` after applying `SecPolicy.af.hostname(host)`, which performs the default validation as well as
@@ -638,6 +664,15 @@ extension AlamofireExtension where ExtendedType == SecTrust {
/// - Parameter host: The hostname to use in the validation.
/// - Throws: An `AFError.serverTrustEvaluationFailed` instance with a `.defaultEvaluationFailed` reason.
public func performValidation(forHost host: String) throws {
#if swift(>=5.9)
if #available(iOS 12, macOS 10.14, tvOS 12, watchOS 5, visionOS 1, *) {
try evaluate(afterApplying: SecPolicy.af.hostname(host))
} else {
try validate(policy: SecPolicy.af.hostname(host)) { status, result in
AFError.serverTrustEvaluationFailed(reason: .hostValidationFailed(output: .init(host, type, status, result)))
}
}
#else
if #available(iOS 12, macOS 10.14, tvOS 12, watchOS 5, *) {
try evaluate(afterApplying: SecPolicy.af.hostname(host))
} else {
@@ -645,6 +680,7 @@ extension AlamofireExtension where ExtendedType == SecTrust {
AFError.serverTrustEvaluationFailed(reason: .hostValidationFailed(output: .init(host, type, status, result)))
}
}
#endif
}
}
@@ -704,11 +740,19 @@ extension AlamofireExtension where ExtendedType == SecCertificate {
guard let createdTrust = trust, trustCreationStatus == errSecSuccess else { return nil }
#if swift(>=5.9)
if #available(iOS 14, macOS 11, tvOS 14, watchOS 7, visionOS 1, *) {
return SecTrustCopyKey(createdTrust)
} else {
return SecTrustCopyPublicKey(createdTrust)
}
#else
if #available(iOS 14, macOS 11, tvOS 14, watchOS 7, *) {
return SecTrustCopyKey(createdTrust)
} else {
return SecTrustCopyPublicKey(createdTrust)
}
#endif
}
}