Skip to content

Commit 51b248d

Browse files
authored
[5.10] Revert "Update swift-certificates to 1.0.1, swift-crypto to 3.0.0 (#6949)" (#6988)
1 parent f71e373 commit 51b248d

File tree

6 files changed

+81
-49
lines changed

6 files changed

+81
-49
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: "3.0.0")),
739+
.package(url: "https://github.com/apple/swift-crypto.git", .upToNextMinor(from: "2.5.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: "1.0.1")),
742+
.package(url: "https://github.com/apple/swift-certificates.git", .upToNextMinor(from: "0.6.0")),
743743
]
744744
} else {
745745
package.dependencies += [

Sources/PackageCollectionsSigning/CertificatePolicy.swift

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

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

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-
)
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+
)
419418

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)
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
429424
}
425+
return Array(responseBody)
430426
}
431427
}
432428

Sources/PackageCollectionsSigning/X509Extensions.swift

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,29 @@ extension DistinguishedName {
5959
private func stringAttribute(oid: ASN1ObjectIdentifier) -> String? {
6060
for relativeDistinguishedName in self {
6161
for attribute in relativeDistinguishedName where attribute.type == oid {
62-
return attribute.value.description
62+
if let stringValue = attribute.stringValue {
63+
return stringValue
64+
}
6365
}
6466
}
6567
return nil
6668
}
6769
}
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: 17 additions & 21 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,31 +158,27 @@ struct _OCSPVerifierPolicy: VerifierPolicy {
158158
private struct _OCSPRequester: OCSPRequester {
159159
let httpClient: HTTPClient
160160

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

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-
)
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+
)
175174

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)
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
185180
}
181+
return Array(responseBody)
186182
}
187183
}
188184

Sources/PackageSigning/X509Extensions.swift

Lines changed: 22 additions & 2 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 else {
33+
guard status == errSecSuccess, let secCertificate = secCertificate else {
3434
throw StringError("failed to get certificate from SecIdentity: status \(status)")
3535
}
3636
self = try Certificate(secCertificate: secCertificate)
@@ -60,13 +60,33 @@ extension DistinguishedName {
6060
private func stringAttribute(oid: ASN1ObjectIdentifier) -> String? {
6161
for relativeDistinguishedName in self {
6262
for attribute in relativeDistinguishedName where attribute.type == oid {
63-
return attribute.value.description
63+
if let stringValue = attribute.stringValue {
64+
return stringValue
65+
}
6466
}
6567
}
6668
return nil
6769
}
6870
}
6971

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+
7090
// MARK: - Certificate cache
7191

7292
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 GeneralizedTime(validationTime - .days(1)),
521-
nextUpdate: try GeneralizedTime(validationTime + .days(1))
520+
thisUpdate: try .init(validationTime - .days(1)),
521+
nextUpdate: try .init(validationTime + .days(1))
522522
)],
523523
privateKey: intermediatePrivateKey,
524524
responseExtensions: { nonce }
@@ -1150,7 +1150,7 @@ enum OCSPTestHelper {
11501150
}
11511151
if isCodeSigning {
11521152
Critical(
1153-
try ExtendedKeyUsage([ExtendedKeyUsage.Usage.codeSigning])
1153+
ExtendedKeyUsage([ExtendedKeyUsage.Usage.codeSigning])
11541154
)
11551155
}
11561156
if let ocspServer {

0 commit comments

Comments
 (0)