From 2efa730f3ca1aa1affb66ab4e60887de37b4331f Mon Sep 17 00:00:00 2001 From: Dimitri Bouniol Date: Mon, 18 Nov 2024 01:25:14 -0800 Subject: [PATCH 1/2] Fixed mistakes constructing a valid JWK from public key data --- Sources/AcmeSwift/APIs/AcmeSwift+Orders.swift | 8 ++++---- Sources/AcmeSwift/Helpers/AcmeRequestBody.swift | 8 ++++---- Sources/AcmeSwift/Models/AcmeError.swift | 2 -- 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/Sources/AcmeSwift/APIs/AcmeSwift+Orders.swift b/Sources/AcmeSwift/APIs/AcmeSwift+Orders.swift index 25073ea..66ef159 100644 --- a/Sources/AcmeSwift/APIs/AcmeSwift+Orders.swift +++ b/Sources/AcmeSwift/APIs/AcmeSwift+Orders.swift @@ -334,9 +334,9 @@ extension AcmeSwift { let jwk = JWK.ecdsa( nil, identifier: nil, - x: publicKey.prefix(upTo: publicKey.count/2).base64EncodedString(), - y: publicKey.suffix(from: publicKey.count/2).base64EncodedString(), - curve: nil + x: publicKey.prefix(publicKey.count/2).toBase64UrlString(), + y: publicKey.suffix(publicKey.count/2).toBase64UrlString(), + curve: .p256 ) let encoder = JSONEncoder() encoder.outputFormatting = .sortedKeys @@ -347,6 +347,6 @@ extension AcmeSwift { extension SHA256Digest { var base64URLString: String { - Data(self).base64EncodedString().base64ToBase64Url() + Data(self).toBase64UrlString() } } diff --git a/Sources/AcmeSwift/Helpers/AcmeRequestBody.swift b/Sources/AcmeSwift/Helpers/AcmeRequestBody.swift index 2489231..11b10b3 100644 --- a/Sources/AcmeSwift/Helpers/AcmeRequestBody.swift +++ b/Sources/AcmeSwift/Helpers/AcmeRequestBody.swift @@ -65,12 +65,12 @@ struct AcmeRequestBody: Encodable { self.protected = .init( alg: .es256, - jwk: accountURL == nil ? JWTKit.JWK.ecdsa( + jwk: accountURL == nil ? JWK.ecdsa( nil, identifier: nil, - x: publicKey.prefix(upTo: publicKey.count/2).base64EncodedString(), - y: publicKey.suffix(from: publicKey.count/2).base64EncodedString(), - curve: nil + x: publicKey.prefix(publicKey.count/2).toBase64UrlString(), + y: publicKey.suffix(publicKey.count/2).toBase64UrlString(), + curve: .p256 ) : nil, kid: accountURL, nonce: nonce, diff --git a/Sources/AcmeSwift/Models/AcmeError.swift b/Sources/AcmeSwift/Models/AcmeError.swift index 53c6de7..2fd43a3 100644 --- a/Sources/AcmeSwift/Models/AcmeError.swift +++ b/Sources/AcmeSwift/Models/AcmeError.swift @@ -17,8 +17,6 @@ public enum AcmeError: Error, Sendable { /// No nonce (anti-replay) value was returned by the endpoint case noNonceReturned - case jwsEncodeError(String) - case dataCorrupted(String) case errorCode(UInt, String) From 15e88fc4b5ff5e6e28166ebee034ad911fdd1a51 Mon Sep 17 00:00:00 2001 From: Dimitri Bouniol Date: Mon, 18 Nov 2024 01:25:40 -0800 Subject: [PATCH 2/2] Fixed a swift non-mutated variable warning --- Tests/AcmeSwiftTests/AccountTests.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/AcmeSwiftTests/AccountTests.swift b/Tests/AcmeSwiftTests/AccountTests.swift index 25b8df2..93484e2 100644 --- a/Tests/AcmeSwiftTests/AccountTests.swift +++ b/Tests/AcmeSwiftTests/AccountTests.swift @@ -13,7 +13,7 @@ final class AccountTests: XCTestCase { self.logger = Logger.init(label: "acme-swift-tests") self.logger.logLevel = .trace - var config = HTTPClient.Configuration(certificateVerification: .fullVerification, backgroundActivityLogger: self.logger) + let config = HTTPClient.Configuration(certificateVerification: .fullVerification, backgroundActivityLogger: self.logger) self.http = HTTPClient( eventLoopGroupProvider: .singleton, configuration: config