Skip to content

Commit 9f3bef5

Browse files
committed
[5.10] Bring back "Update swift-certificates to 1.0.1, swift-crypto to 3.0.0 (#6949)"
This reverts commit 4a022ba.
1 parent 51b248d commit 9f3bef5

File tree

6 files changed

+49
-81
lines changed

6 files changed

+49
-81
lines changed

Package.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -736,10 +736,10 @@ if ProcessInfo.processInfo.environment["SWIFTCI_USE_LOCAL_DEPS"] == nil {
736736
// dependency version changes here with those projects.
737737
.package(url: "https://github.com/apple/swift-argument-parser.git", .upToNextMinor(from: "1.2.2")),
738738
.package(url: "https://github.com/apple/swift-driver.git", branch: relatedDependenciesBranch),
739-
.package(url: "https://github.com/apple/swift-crypto.git", .upToNextMinor(from: "2.5.0")),
739+
.package(url: "https://github.com/apple/swift-crypto.git", .upToNextMinor(from: "3.0.0")),
740740
.package(url: "https://github.com/apple/swift-system.git", .upToNextMinor(from: "1.1.1")),
741741
.package(url: "https://github.com/apple/swift-collections.git", .upToNextMinor(from: "1.0.1")),
742-
.package(url: "https://github.com/apple/swift-certificates.git", .upToNextMinor(from: "0.6.0")),
742+
.package(url: "https://github.com/apple/swift-certificates.git", .upToNextMinor(from: "1.0.1")),
743743
]
744744
} else {
745745
package.dependencies += [

Sources/PackageCollectionsSigning/CertificatePolicy.swift

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -402,27 +402,31 @@ struct _OCSPVerifierPolicy: VerifierPolicy {
402402
private struct _OCSPRequester: OCSPRequester {
403403
let httpClient: HTTPClient
404404

405-
func query(request: [UInt8], uri: String) async throws -> [UInt8] {
405+
func query(request: [UInt8], uri: String) async -> OCSPRequesterQueryResult {
406406
guard let url = URL(string: uri), let host = url.host else {
407-
throw SwiftOCSPRequesterError.invalidURL(uri)
407+
return .terminalError(SwiftOCSPRequesterError.invalidURL(uri))
408408
}
409409

410-
let response = try await self.httpClient.post(
411-
url,
412-
body: Data(request),
413-
headers: [
414-
"Content-Type": "application/ocsp-request",
415-
"Host": host,
416-
]
417-
)
410+
do {
411+
let response = try await self.httpClient.post(
412+
url,
413+
body: Data(request),
414+
headers: [
415+
"Content-Type": "application/ocsp-request",
416+
"Host": host,
417+
]
418+
)
418419

419-
guard response.statusCode == 200 else {
420-
throw SwiftOCSPRequesterError.invalidResponse(statusCode: response.statusCode)
421-
}
422-
guard let responseBody = response.body else {
423-
throw SwiftOCSPRequesterError.emptyResponse
420+
guard response.statusCode == 200 else {
421+
throw SwiftOCSPRequesterError.invalidResponse(statusCode: response.statusCode)
422+
}
423+
guard let responseBody = response.body else {
424+
throw SwiftOCSPRequesterError.emptyResponse
425+
}
426+
return .response(Array(responseBody))
427+
} catch {
428+
return .nonTerminalError(error)
424429
}
425-
return Array(responseBody)
426430
}
427431
}
428432

Sources/PackageCollectionsSigning/X509Extensions.swift

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -59,29 +59,9 @@ extension DistinguishedName {
5959
private func stringAttribute(oid: ASN1ObjectIdentifier) -> String? {
6060
for relativeDistinguishedName in self {
6161
for attribute in relativeDistinguishedName where attribute.type == oid {
62-
if let stringValue = attribute.stringValue {
63-
return stringValue
64-
}
62+
return attribute.value.description
6563
}
6664
}
6765
return nil
6866
}
6967
}
70-
71-
extension RelativeDistinguishedName.Attribute {
72-
fileprivate var stringValue: String? {
73-
let asn1StringBytes: ArraySlice<UInt8>?
74-
do {
75-
asn1StringBytes = try ASN1PrintableString(asn1Any: self.value).bytes
76-
} catch {
77-
asn1StringBytes = try? ASN1UTF8String(asn1Any: self.value).bytes
78-
}
79-
80-
guard let asn1StringBytes,
81-
let stringValue = String(bytes: asn1StringBytes, encoding: .utf8)
82-
else {
83-
return nil
84-
}
85-
return stringValue
86-
}
87-
}

Sources/PackageSigning/VerifierPolicies.swift

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ extension SignatureProviderProtocol {
2424
func buildPolicySet(configuration: VerifierConfiguration, httpClient: HTTPClient) -> some VerifierPolicy {
2525
_CodeSigningPolicy()
2626
_ADPCertificatePolicy()
27-
27+
2828
let now = Date()
2929
switch (configuration.certificateExpiration, configuration.certificateRevocation) {
3030
case (.enabled(let expiryValidationTime), .strict(let revocationValidationTime)):
@@ -158,27 +158,31 @@ struct _OCSPVerifierPolicy: VerifierPolicy {
158158
private struct _OCSPRequester: OCSPRequester {
159159
let httpClient: HTTPClient
160160

161-
func query(request: [UInt8], uri: String) async throws -> [UInt8] {
161+
func query(request: [UInt8], uri: String) async -> OCSPRequesterQueryResult {
162162
guard let url = URL(string: uri), let host = url.host else {
163-
throw SwiftOCSPRequesterError.invalidURL(uri)
163+
return .terminalError(SwiftOCSPRequesterError.invalidURL(uri))
164164
}
165165

166-
let response = try await self.httpClient.post(
167-
url,
168-
body: Data(request),
169-
headers: [
170-
"Content-Type": "application/ocsp-request",
171-
"Host": host,
172-
]
173-
)
166+
do {
167+
let response = try await self.httpClient.post(
168+
url,
169+
body: Data(request),
170+
headers: [
171+
"Content-Type": "application/ocsp-request",
172+
"Host": host,
173+
]
174+
)
174175

175-
guard response.statusCode == 200 else {
176-
throw SwiftOCSPRequesterError.invalidResponse(statusCode: response.statusCode)
177-
}
178-
guard let responseBody = response.body else {
179-
throw SwiftOCSPRequesterError.emptyResponse
176+
guard response.statusCode == 200 else {
177+
throw SwiftOCSPRequesterError.invalidResponse(statusCode: response.statusCode)
178+
}
179+
guard let responseBody = response.body else {
180+
throw SwiftOCSPRequesterError.emptyResponse
181+
}
182+
return .response(Array(responseBody))
183+
} catch {
184+
return .nonTerminalError(error)
180185
}
181-
return Array(responseBody)
182186
}
183187
}
184188

Sources/PackageSigning/X509Extensions.swift

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ extension Certificate {
3030
init(secIdentity: SecIdentity) throws {
3131
var secCertificate: SecCertificate?
3232
let status = SecIdentityCopyCertificate(secIdentity, &secCertificate)
33-
guard status == errSecSuccess, let secCertificate = secCertificate else {
33+
guard status == errSecSuccess, let secCertificate else {
3434
throw StringError("failed to get certificate from SecIdentity: status \(status)")
3535
}
3636
self = try Certificate(secCertificate: secCertificate)
@@ -60,33 +60,13 @@ extension DistinguishedName {
6060
private func stringAttribute(oid: ASN1ObjectIdentifier) -> String? {
6161
for relativeDistinguishedName in self {
6262
for attribute in relativeDistinguishedName where attribute.type == oid {
63-
if let stringValue = attribute.stringValue {
64-
return stringValue
65-
}
63+
return attribute.value.description
6664
}
6765
}
6866
return nil
6967
}
7068
}
7169

72-
extension RelativeDistinguishedName.Attribute {
73-
fileprivate var stringValue: String? {
74-
let asn1StringBytes: ArraySlice<UInt8>?
75-
do {
76-
asn1StringBytes = try ASN1PrintableString(asn1Any: self.value).bytes
77-
} catch {
78-
asn1StringBytes = try? ASN1UTF8String(asn1Any: self.value).bytes
79-
}
80-
81-
guard let asn1StringBytes,
82-
let stringValue = String(bytes: asn1StringBytes, encoding: .utf8)
83-
else {
84-
return nil
85-
}
86-
return stringValue
87-
}
88-
}
89-
9070
// MARK: - Certificate cache
9171

9272
extension Certificate {

Tests/PackageSigningTests/SigningTests.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -517,8 +517,8 @@ final class SigningTests: XCTestCase {
517517
responses: [OCSPSingleResponse(
518518
certID: singleRequest.certID,
519519
certStatus: .unknown,
520-
thisUpdate: try .init(validationTime - .days(1)),
521-
nextUpdate: try .init(validationTime + .days(1))
520+
thisUpdate: try GeneralizedTime(validationTime - .days(1)),
521+
nextUpdate: try GeneralizedTime(validationTime + .days(1))
522522
)],
523523
privateKey: intermediatePrivateKey,
524524
responseExtensions: { nonce }
@@ -1150,7 +1150,7 @@ enum OCSPTestHelper {
11501150
}
11511151
if isCodeSigning {
11521152
Critical(
1153-
ExtendedKeyUsage([ExtendedKeyUsage.Usage.codeSigning])
1153+
try ExtendedKeyUsage([ExtendedKeyUsage.Usage.codeSigning])
11541154
)
11551155
}
11561156
if let ocspServer {

0 commit comments

Comments
 (0)