Skip to content
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

Support for compressed tokens #347

Open
inferiorhumanorgans opened this issue Nov 30, 2023 · 7 comments
Open

Support for compressed tokens #347

inferiorhumanorgans opened this issue Nov 30, 2023 · 7 comments

Comments

@inferiorhumanorgans
Copy link

I'm working on a crate to decode SMART Health Cards. Per their spec, these are their requirements:

  • JWS Header
    • header includes alg: "ES256"
    • header includes zip: "DEF"
    • header includes kid equal to the base64url-encoded (see section 5 of RFC4648) SHA-256 JWK Thumbprint of the key (see RFC7638)
  • JWS Payload
    • payload is minified (i.e., all optional whitespace is stripped)
    • payload is compressed with the DEFLATE (see RFC1951) algorithm before being signed (note, this should be "raw" DEFLATE compression, omitting any zlib or gz headers)

Previously I've hacked up a copy of 8-beta2, but before I work on bringing this up to date with the current version of jsonwebtoken, is this something you'd entertain a PR for or is it out of scope for the crate?

@Keats
Copy link
Owner

Keats commented Dec 1, 2023

Definitely out of scope

@inferiorhumanorgans
Copy link
Author

The problem I've run into is that the Header struct doesn't allow access to arbitrary headers (e.g. JWS §4.2, JWE § 4.1) and only allows access to a subset of the defined headers. In this case I'm after the zip header (JWS § 4.1.3) which would allow inflating compressed JWE objects as a external trait.

@Keats
Copy link
Owner

Keats commented Dec 1, 2023

We could dump all other fields not part of the spec in a hashmap? I'd take a PR for that if that's not a breaking change.

@inferiorhumanorgans
Copy link
Author

Sure, however I think there are only two registered headers not covered by the struct: crit (JWS § 4.1.11) and zip (JWE § 4.1.3) so it would come down to whether it's worth potential allocation or if it's worth carrying around a couple extra fields for the most common cases.

@Keats
Copy link
Owner

Keats commented Dec 1, 2023

I think we want to add crit at least since it's part of JWS. zip is simple and can be deserialize to an enum {Deflate, Other(String)} if we wanted and enc should be an enum as well

@inferiorhumanorgans
Copy link
Author

Sounds great.

@Keats
Copy link
Owner

Keats commented Dec 4, 2023

It would have to come from a PR though, and that's a breaking change

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants