-
Notifications
You must be signed in to change notification settings - Fork 115
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add parsed JWK header parameter #240
Add parsed JWK header parameter #240
Conversation
TODO: jwk parameter parsing TODO: tests
Hi @johanfylling 👋 Good find! That indeed looks like a mismatch between implementation and spec. We'll have a look at you pull request soon and will get back to you with some feedback. |
Hi @johanfylling! Sorry for the delay. Your implementation looks pretty solid. Our next steps on this pull request would be to get the tests fully up and running again. Also I think we could speed up the release of this if we'd keep around the old Since that way we wouldn't introduce any breaking API changes, we could release this much faster as a minor version bump and wouldn't have to wait for the next major release. Moreover, it would make it much easier for you to fix the tests as the old tests should just run ok again and you would only have to add one or two test cases that cover the new parsed JWK parameter. Let me know what you think! |
…alization keeping the old behaviour of the 'jwk' parameter.
I have updated the pull request to now have two parameters that both read/write to the 'jwk' header param. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes this would definitely be an acceptable solution. The duplication is a bit unfortunate but this is our fault and we'll clean that up once we get a chance to redo the header implementation.
If you have time to add some more test that hit both the JWE and JWS implementation - that would be greatly appreciated.
JOSESwift/Sources/JWEHeader.swift
Outdated
@@ -143,8 +143,8 @@ extension JWEHeader: CommonHeaderParameterSpace { | |||
return URL(string: parameter) | |||
} | |||
} | |||
|
|||
/// The JSON Web key corresponding to the key used to encrypt the JWE. | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
JOSESwift/Sources/JWEHeader.swift
Outdated
@@ -154,6 +154,36 @@ extension JWEHeader: CommonHeaderParameterSpace { | |||
} | |||
} | |||
|
|||
/// The JSON Web key corresponding to the key used to encrypt the JWE, as a JWK.. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/// The JSON Web key corresponding to the key used to encrypt the JWE, as a JWK.. | |
/// The JSON Web key corresponding to the key used to encrypt the JWE, as a JWK. |
JOSESwift/Sources/JWEHeader.swift
Outdated
guard let keyTypeString = jwkParameters[JWKParameter.keyType.rawValue], | ||
let keyType = JWKKeyType(rawValue: keyTypeString) else { | ||
return nil | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
guard let keyTypeString = jwkParameters[JWKParameter.keyType.rawValue], | |
let keyType = JWKKeyType(rawValue: keyTypeString) else { | |
return nil | |
} | |
guard | |
let keyTypeString = jwkParameters[JWKParameter.keyType.rawValue], | |
let keyType = JWKKeyType(rawValue: keyTypeString) | |
else { | |
return nil | |
} |
JOSESwift/Sources/JWSHeader.swift
Outdated
@@ -103,8 +103,8 @@ extension JWSHeader: CommonHeaderParameterSpace { | |||
return URL(string: parameter) | |||
} | |||
} | |||
|
|||
/// The JSON Web key corresponding to the key used to digitally sign the JWS. | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
JOSESwift/Sources/JWSHeader.swift
Outdated
guard let keyTypeString = jwkParameters[JWKParameter.keyType.rawValue], | ||
let keyType = JWKKeyType(rawValue: keyTypeString) else { | ||
return nil | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
guard let keyTypeString = jwkParameters[JWKParameter.keyType.rawValue], | |
let keyType = JWKKeyType(rawValue: keyTypeString) else { | |
return nil | |
} | |
guard | |
let keyTypeString = jwkParameters[JWKParameter.keyType.rawValue], | |
let keyType = JWKKeyType(rawValue: keyTypeString) | |
else { | |
return nil | |
} |
I've added tests for JWE- and JWS headers. The two failing tests were already failing on the tag (2.2.1) I branched off from. |
Marking this PR ready for review now. |
I'll let you know once this is released @johanfylling. Thanks for the contribution! |
Thank you very much for your input @daniel-mohemian and for accepting our proposal! |
Hey @johanfylling 👋 Your contribution is now live as 2.3.0. |
Awesome! Thank you very much for a speedy release. |
The JWS and JWE specifications dictate that the 'jwk' header parameter should be represented as a JWK (https://tools.ietf.org/html/rfc7515#section-4.1.3 & https://tools.ietf.org/html/rfc7516#section-4.1.5). The JWK representation is a JSON dictionary, and not a string, as currently implemented by JOSESwift.
This pull request is a suggested solution. It is also a work in progress, as the implementation of the 'jwk' header getters is sub-optimal and a better approach may be more desirable.
This pull request also does not provide test coverage, and short-circuits some tests in benefit of successful compilation.