mirror of
https://github.com/apple/swift-certificates
synced 2026-11-22 04:20:39 +00:00
Merge branch 'main' into dn-set-of
This commit is contained in:
14 files changed
+45
-16
No files matched your search
@@ -14,6 +14,7 @@
|
||||
|
||||
@preconcurrency import Crypto
|
||||
@preconcurrency import _CryptoExtras
|
||||
import Foundation
|
||||
|
||||
extension Certificate {
|
||||
/// A private key that can be used with a certificate.
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
import SwiftASN1
|
||||
@preconcurrency import Crypto
|
||||
@preconcurrency import _CryptoExtras
|
||||
import Foundation
|
||||
|
||||
extension Certificate {
|
||||
/// A public key that can be used with a certificate.
|
||||
|
||||
@@ -12,6 +12,8 @@
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
import SwiftASN1
|
||||
|
||||
/// Set the Common Name (CN) of a ``DistinguishedName``.
|
||||
///
|
||||
/// This type is used in ``DistinguishedNameBuilder`` contexts.
|
||||
|
||||
@@ -12,6 +12,8 @@
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
import SwiftASN1
|
||||
|
||||
/// Set the Country Name (C) of a ``DistinguishedName``.
|
||||
///
|
||||
/// This type is used in ``DistinguishedNameBuilder`` contexts.
|
||||
|
||||
@@ -12,6 +12,8 @@
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
import SwiftASN1
|
||||
|
||||
/// Set the Locality Name (L) of a ``DistinguishedName``.
|
||||
///
|
||||
/// This type is used in ``DistinguishedNameBuilder`` contexts.
|
||||
|
||||
@@ -12,6 +12,8 @@
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
import SwiftASN1
|
||||
|
||||
/// Set the Organization Name (O) of a ``DistinguishedName``.
|
||||
///
|
||||
/// This type is used in ``DistinguishedNameBuilder`` contexts.
|
||||
|
||||
@@ -12,6 +12,8 @@
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
import SwiftASN1
|
||||
|
||||
/// Set the Organizational Unit Name (OU) of a ``DistinguishedName``.
|
||||
///
|
||||
/// This type is used in ``DistinguishedNameBuilder`` contexts.
|
||||
|
||||
@@ -12,6 +12,8 @@
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
import SwiftASN1
|
||||
|
||||
/// Set the State or Province Name (ST) of a ``DistinguishedName``.
|
||||
///
|
||||
/// This type is used in ``DistinguishedNameBuilder`` contexts.
|
||||
|
||||
@@ -12,6 +12,8 @@
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
import SwiftASN1
|
||||
|
||||
/// Set the Street Address (STREET) of a ``DistinguishedName``.
|
||||
///
|
||||
/// This type is used in ``DistinguishedNameBuilder`` contexts.
|
||||
|
||||
@@ -14,9 +14,13 @@
|
||||
|
||||
import SwiftASN1
|
||||
import Crypto
|
||||
import protocol Foundation.DataProtocol
|
||||
import struct Foundation.Date
|
||||
import typealias Foundation.TimeInterval
|
||||
#if canImport(Darwin)
|
||||
import Foundation
|
||||
#else
|
||||
// swift-corelibs-foundation hasn't marked anything Sendable yet https://github.com/apple/swift-corelibs-foundation/issues/4687
|
||||
@preconcurrency import Foundation
|
||||
#endif
|
||||
|
||||
|
||||
public protocol OCSPRequester: Sendable {
|
||||
/// Called with an OCSP Request.
|
||||
@@ -77,7 +81,7 @@ enum OCSPRequestHashAlgorithm {
|
||||
}
|
||||
}
|
||||
|
||||
public struct OCSPVerifierPolicy<Requester: OCSPRequester>: VerifierPolicy {
|
||||
public struct OCSPVerifierPolicy<Requester: OCSPRequester>: VerifierPolicy, Sendable {
|
||||
|
||||
private var requester: Requester
|
||||
private var requestHashAlgorithm: OCSPRequestHashAlgorithm
|
||||
@@ -303,7 +307,7 @@ extension OCSPSingleResponse {
|
||||
/// - maxDuration: max execution duration in seconds of `operation`
|
||||
/// - operation: the task to start and cancel after `maxDuration` seconds
|
||||
/// - Returns: the result of `operation`
|
||||
private func withTimeout<Result>(
|
||||
private func withTimeout<Result: Sendable>(
|
||||
_ maxDuration: TimeInterval,
|
||||
operation: @escaping @Sendable () async -> Result
|
||||
) async -> Result {
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
import SwiftASN1
|
||||
@preconcurrency import Crypto
|
||||
@preconcurrency import _CryptoExtras
|
||||
import Foundation
|
||||
|
||||
extension Certificate {
|
||||
/// An abstract representation of the cryptographic signature on a certificate.
|
||||
|
||||
@@ -16,7 +16,7 @@ public protocol VerifierPolicy {
|
||||
mutating func chainMeetsPolicyRequirements(chain: UnverifiedCertificateChain) async -> PolicyEvaluationResult
|
||||
}
|
||||
|
||||
public enum PolicyEvaluationResult {
|
||||
public enum PolicyEvaluationResult: Sendable {
|
||||
case meetsPolicy
|
||||
case failsToMeetPolicy(reason: String)
|
||||
}
|
||||
|
||||
@@ -159,7 +159,7 @@ final class DistinguishedNameTests: XCTestCase {
|
||||
StateOrProvinceName("DigiLand")
|
||||
}
|
||||
|
||||
for name in ["foo", "bar", "baz"].filter { $0 == "baz" } {
|
||||
for name in ["foo", "bar", "baz"].filter({ $0 == "baz" }) {
|
||||
CommonName(name)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,7 +16,11 @@ import XCTest
|
||||
import Crypto
|
||||
import SwiftASN1
|
||||
@testable import X509
|
||||
#if canImport(Darwin)
|
||||
import Foundation
|
||||
#else
|
||||
@preconcurrency import Foundation
|
||||
#endif
|
||||
|
||||
actor TestRequester: OCSPRequester {
|
||||
private let queryClosure: @Sendable (OCSPRequest, String) async throws -> OCSPResponse
|
||||
@@ -171,6 +175,7 @@ final class OCSPVerifierPolicyTests: XCTestCase {
|
||||
}
|
||||
|
||||
func testSingleCertWithOCSP() async {
|
||||
let now = self.now
|
||||
await self.assertChainMeetsPolicy(
|
||||
chain: Self.chainWithSingleCertWithOCSP,
|
||||
requester: .noThrow { request, uri -> OCSPResponse in
|
||||
@@ -182,14 +187,15 @@ final class OCSPVerifierPolicyTests: XCTestCase {
|
||||
return .successful(.signed(responses: [OCSPSingleResponse(
|
||||
certID: singleRequest.certID,
|
||||
certStatus: .good,
|
||||
thisUpdate: try .init(self.now - .days(1)),
|
||||
nextUpdate: try .init(self.now + .days(1))
|
||||
thisUpdate: try .init(now - .days(1)),
|
||||
nextUpdate: try .init(now + .days(1))
|
||||
)], responseExtensions: { nonce }))
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
func testWrongNonce() async {
|
||||
let now = self.now
|
||||
await self.assertChainFailsToMeetPolicy(
|
||||
chain: Self.chainWithSingleCertWithOCSP,
|
||||
requester: .noThrow { request, uri -> OCSPResponse in
|
||||
@@ -201,14 +207,15 @@ final class OCSPVerifierPolicyTests: XCTestCase {
|
||||
return .successful(.signed(responses: [OCSPSingleResponse(
|
||||
certID: singleRequest.certID,
|
||||
certStatus: .good,
|
||||
thisUpdate: try .init(self.now - .days(1)),
|
||||
nextUpdate: try .init(self.now + .days(1))
|
||||
thisUpdate: try .init(now - .days(1)),
|
||||
nextUpdate: try .init(now + .days(1))
|
||||
)], responseExtensions: { OCSPNonce() }))
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
func testRevokedCert() async {
|
||||
let now = self.now
|
||||
await self.assertChainFailsToMeetPolicy(
|
||||
chain: Self.chainWithSingleCertWithOCSP,
|
||||
requester: .noThrow { request, uri -> OCSPResponse in
|
||||
@@ -220,17 +227,18 @@ final class OCSPVerifierPolicyTests: XCTestCase {
|
||||
return .successful(.signed(responses: [OCSPSingleResponse(
|
||||
certID: singleRequest.certID,
|
||||
certStatus: .revoked(.init(
|
||||
revocationTime: try .init(self.now),
|
||||
revocationTime: try .init(now),
|
||||
revocationReason: .unspecified
|
||||
)),
|
||||
thisUpdate: try .init(self.now - .days(1)),
|
||||
nextUpdate: try .init(self.now + .days(1))
|
||||
thisUpdate: try .init(now - .days(1)),
|
||||
nextUpdate: try .init(now + .days(1))
|
||||
)], responseExtensions: { nonce }))
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
func testResponseDoesNotIncludeResponseForRequestedCert() async {
|
||||
let now = self.now
|
||||
await self.assertChainFailsToMeetPolicy(
|
||||
chain: Self.chainWithSingleCertWithOCSP,
|
||||
requester: .noThrow { request, uri -> OCSPResponse in
|
||||
@@ -246,8 +254,8 @@ final class OCSPVerifierPolicyTests: XCTestCase {
|
||||
serialNumber: .init()
|
||||
),
|
||||
certStatus: .good,
|
||||
thisUpdate: try .init(self.now - .days(1)),
|
||||
nextUpdate: try .init(self.now + .days(1))
|
||||
thisUpdate: try .init(now - .days(1)),
|
||||
nextUpdate: try .init(now + .days(1))
|
||||
)], responseExtensions: { nonce }))
|
||||
}
|
||||
)
|
||||
|
||||
Reference in new issue
Block a user