|
|
@@ -204,13 +204,22 @@ class ServerTrustPolicyTestCase: BaseTestCase {
|
|
|
|
|
|
func trustIsValid(trust: SecTrust) -> Bool {
|
|
|
var isValid = false
|
|
|
-
|
|
|
+ #if swift (>=2.3)
|
|
|
+ var result = SecTrustResultType(rawValue: SecTrustResultType.Invalid.rawValue)
|
|
|
+ let status = SecTrustEvaluate(trust, &result!)
|
|
|
+ #else
|
|
|
var result = SecTrustResultType(kSecTrustResultInvalid)
|
|
|
let status = SecTrustEvaluate(trust, &result)
|
|
|
+ #endif
|
|
|
|
|
|
if status == errSecSuccess {
|
|
|
+ #if swift (>=2.3)
|
|
|
+ let unspecified = SecTrustResultType(rawValue: SecTrustResultType.Unspecified.rawValue)
|
|
|
+ let proceed = SecTrustResultType(rawValue: SecTrustResultType.Proceed.rawValue)
|
|
|
+ #else
|
|
|
let unspecified = SecTrustResultType(kSecTrustResultUnspecified)
|
|
|
let proceed = SecTrustResultType(kSecTrustResultProceed)
|
|
|
+ #endif
|
|
|
|
|
|
isValid = result == unspecified || result == proceed
|
|
|
}
|
|
|
@@ -233,7 +242,11 @@ class ServerTrustPolicyExplorationBasicX509PolicyValidationTestCase: ServerTrust
|
|
|
setRootCertificateAsLoneAnchorCertificateForTrust(trust)
|
|
|
|
|
|
// When
|
|
|
+ #if swift (>=2.3)
|
|
|
+ let policies = [SecPolicyCreateBasicX509()!]
|
|
|
+ #else
|
|
|
let policies = [SecPolicyCreateBasicX509()]
|
|
|
+ #endif
|
|
|
SecTrustSetPolicies(trust, policies)
|
|
|
|
|
|
// Then
|
|
|
@@ -246,7 +259,11 @@ class ServerTrustPolicyExplorationBasicX509PolicyValidationTestCase: ServerTrust
|
|
|
setRootCertificateAsLoneAnchorCertificateForTrust(trust)
|
|
|
|
|
|
// When
|
|
|
+ #if swift (>=2.3)
|
|
|
+ let policies = [SecPolicyCreateBasicX509()!]
|
|
|
+ #else
|
|
|
let policies = [SecPolicyCreateBasicX509()]
|
|
|
+ #endif
|
|
|
SecTrustSetPolicies(trust, policies)
|
|
|
|
|
|
// Then
|
|
|
@@ -259,7 +276,11 @@ class ServerTrustPolicyExplorationBasicX509PolicyValidationTestCase: ServerTrust
|
|
|
setRootCertificateAsLoneAnchorCertificateForTrust(trust)
|
|
|
|
|
|
// When
|
|
|
+ #if swift (>=2.3)
|
|
|
+ let policies = [SecPolicyCreateBasicX509()!]
|
|
|
+ #else
|
|
|
let policies = [SecPolicyCreateBasicX509()]
|
|
|
+ #endif
|
|
|
SecTrustSetPolicies(trust, policies)
|
|
|
|
|
|
// Then
|
|
|
@@ -272,7 +293,11 @@ class ServerTrustPolicyExplorationBasicX509PolicyValidationTestCase: ServerTrust
|
|
|
setRootCertificateAsLoneAnchorCertificateForTrust(trust)
|
|
|
|
|
|
// When
|
|
|
+ #if swift (>=2.3)
|
|
|
+ let policies = [SecPolicyCreateBasicX509()!]
|
|
|
+ #else
|
|
|
let policies = [SecPolicyCreateBasicX509()]
|
|
|
+ #endif
|
|
|
SecTrustSetPolicies(trust, policies)
|
|
|
|
|
|
// Then
|
|
|
@@ -294,7 +319,11 @@ class ServerTrustPolicyExplorationSSLPolicyValidationTestCase: ServerTrustPolicy
|
|
|
setRootCertificateAsLoneAnchorCertificateForTrust(trust)
|
|
|
|
|
|
// When
|
|
|
+ #if swift(>=2.3)
|
|
|
+ let policies = [SecPolicyCreateSSL(true, "test.alamofire.org")!]
|
|
|
+ #else
|
|
|
let policies = [SecPolicyCreateSSL(true, "test.alamofire.org")]
|
|
|
+ #endif
|
|
|
SecTrustSetPolicies(trust, policies)
|
|
|
|
|
|
// Then
|
|
|
@@ -307,7 +336,11 @@ class ServerTrustPolicyExplorationSSLPolicyValidationTestCase: ServerTrustPolicy
|
|
|
setRootCertificateAsLoneAnchorCertificateForTrust(trust)
|
|
|
|
|
|
// When
|
|
|
+ #if swift(>=2.3)
|
|
|
+ let policies = [SecPolicyCreateSSL(true, "test.alamofire.org")!]
|
|
|
+ #else
|
|
|
let policies = [SecPolicyCreateSSL(true, "test.alamofire.org")]
|
|
|
+ #endif
|
|
|
SecTrustSetPolicies(trust, policies)
|
|
|
|
|
|
// Then
|
|
|
@@ -320,7 +353,11 @@ class ServerTrustPolicyExplorationSSLPolicyValidationTestCase: ServerTrustPolicy
|
|
|
setRootCertificateAsLoneAnchorCertificateForTrust(trust)
|
|
|
|
|
|
// When
|
|
|
+ #if swift(>=2.3)
|
|
|
+ let policies = [SecPolicyCreateSSL(true, "test.alamofire.org")!]
|
|
|
+ #else
|
|
|
let policies = [SecPolicyCreateSSL(true, "test.alamofire.org")]
|
|
|
+ #endif
|
|
|
SecTrustSetPolicies(trust, policies)
|
|
|
|
|
|
// Then
|
|
|
@@ -333,7 +370,11 @@ class ServerTrustPolicyExplorationSSLPolicyValidationTestCase: ServerTrustPolicy
|
|
|
setRootCertificateAsLoneAnchorCertificateForTrust(trust)
|
|
|
|
|
|
// When
|
|
|
+ #if swift(>=2.3)
|
|
|
+ let policies = [SecPolicyCreateSSL(true, "test.alamofire.org")!]
|
|
|
+ #else
|
|
|
let policies = [SecPolicyCreateSSL(true, "test.alamofire.org")]
|
|
|
+ #endif
|
|
|
SecTrustSetPolicies(trust, policies)
|
|
|
|
|
|
// Then
|
|
|
@@ -346,7 +387,11 @@ class ServerTrustPolicyExplorationSSLPolicyValidationTestCase: ServerTrustPolicy
|
|
|
setRootCertificateAsLoneAnchorCertificateForTrust(trust)
|
|
|
|
|
|
// When
|
|
|
+ #if swift(>=2.3)
|
|
|
+ let policies = [SecPolicyCreateSSL(true, "test.alamofire.org")!]
|
|
|
+ #else
|
|
|
let policies = [SecPolicyCreateSSL(true, "test.alamofire.org")]
|
|
|
+ #endif
|
|
|
SecTrustSetPolicies(trust, policies)
|
|
|
|
|
|
// Then
|
|
|
@@ -359,7 +404,11 @@ class ServerTrustPolicyExplorationSSLPolicyValidationTestCase: ServerTrustPolicy
|
|
|
setRootCertificateAsLoneAnchorCertificateForTrust(trust)
|
|
|
|
|
|
// When
|
|
|
+ #if swift(>=2.3)
|
|
|
+ let policies = [SecPolicyCreateSSL(true, "test.alamofire.org")!]
|
|
|
+ #else
|
|
|
let policies = [SecPolicyCreateSSL(true, "test.alamofire.org")]
|
|
|
+ #endif
|
|
|
SecTrustSetPolicies(trust, policies)
|
|
|
|
|
|
// Then
|
|
|
@@ -372,11 +421,19 @@ class ServerTrustPolicyExplorationSSLPolicyValidationTestCase: ServerTrustPolicy
|
|
|
setRootCertificateAsLoneAnchorCertificateForTrust(trust)
|
|
|
|
|
|
// When
|
|
|
+ #if swift(>=2.3)
|
|
|
+ let policies = [
|
|
|
+ SecPolicyCreateSSL(true, "test.alamofire.org")!,
|
|
|
+ SecPolicyCreateSSL(true, "blog.alamofire.org")!,
|
|
|
+ SecPolicyCreateSSL(true, "www.alamofire.org")!
|
|
|
+ ]
|
|
|
+ #else
|
|
|
let policies = [
|
|
|
SecPolicyCreateSSL(true, "test.alamofire.org"),
|
|
|
SecPolicyCreateSSL(true, "blog.alamofire.org"),
|
|
|
SecPolicyCreateSSL(true, "www.alamofire.org")
|
|
|
]
|
|
|
+ #endif
|
|
|
SecTrustSetPolicies(trust, policies)
|
|
|
|
|
|
// Then
|
|
|
@@ -389,7 +446,11 @@ class ServerTrustPolicyExplorationSSLPolicyValidationTestCase: ServerTrustPolicy
|
|
|
setRootCertificateAsLoneAnchorCertificateForTrust(trust)
|
|
|
|
|
|
// When
|
|
|
+ #if swift(>=2.3)
|
|
|
+ let policies = [SecPolicyCreateSSL(true, nil)!]
|
|
|
+ #else
|
|
|
let policies = [SecPolicyCreateSSL(true, nil)]
|
|
|
+ #endif
|
|
|
SecTrustSetPolicies(trust, policies)
|
|
|
|
|
|
// Then
|
|
|
@@ -402,7 +463,11 @@ class ServerTrustPolicyExplorationSSLPolicyValidationTestCase: ServerTrustPolicy
|
|
|
setRootCertificateAsLoneAnchorCertificateForTrust(trust)
|
|
|
|
|
|
// When
|
|
|
+ #if swift(>=2.3)
|
|
|
+ let policies = [SecPolicyCreateSSL(true, "test.alamofire.org")!]
|
|
|
+ #else
|
|
|
let policies = [SecPolicyCreateSSL(true, "test.alamofire.org")]
|
|
|
+ #endif
|
|
|
SecTrustSetPolicies(trust, policies)
|
|
|
|
|
|
// Then
|