Skip to content

Commit

Permalink
Fixed mistakes constructing a valid JWK from public key data
Browse files Browse the repository at this point in the history
  • Loading branch information
dimitribouniol committed Nov 18, 2024
1 parent b93d4df commit 2efa730
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 10 deletions.
8 changes: 4 additions & 4 deletions Sources/AcmeSwift/APIs/AcmeSwift+Orders.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -347,6 +347,6 @@ extension AcmeSwift {

extension SHA256Digest {
var base64URLString: String {
Data(self).base64EncodedString().base64ToBase64Url()
Data(self).toBase64UrlString()
}
}
8 changes: 4 additions & 4 deletions Sources/AcmeSwift/Helpers/AcmeRequestBody.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,12 @@ struct AcmeRequestBody<T: EndpointProtocol>: 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,
Expand Down
2 changes: 0 additions & 2 deletions Sources/AcmeSwift/Models/AcmeError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit 2efa730

Please sign in to comment.