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 x5c validation #63

Open
tanguilp opened this issue Jan 10, 2019 · 3 comments
Open

Support x5c validation #63

tanguilp opened this issue Jan 10, 2019 · 3 comments

Comments

@tanguilp
Copy link

My understanding is that with the x5c (and jwk) header parameters there's no need to specify a key when verifying. That would be a verify/1 function in JWS module.

Specification: https://tools.ietf.org/html/rfc7515#section-4.1.6

I've seen it in the wild, for example FIDO2 metadata are published in such JWTs (https://fidoalliance.org/specs/fido-v2.0-id-20180227/fido-metadata-service-v2.0-id-20180227.html#metadata-toc-object-processing-rules).

@tanguilp
Copy link
Author

Actually if you are willing to give me some guidelines I'd be willing to try to implement it and propose a patch.

@potatosalad potatosalad added this to To do in jose 2.0.x Jul 30, 2019
@potatosalad potatosalad added this to To do in jose 1.11.x Jan 8, 2020
@sjmadsen
Copy link

Another instance in the wild: the JWTs delivered by Apple's App Store Server Notifications v2 utilize a certificate chain in the x5c header parameter.

@behe
Copy link
Contributor

behe commented Feb 14, 2022

If somebody else finds this issue when trying to validate App Store Server Notifications v2, this is how this can be done:

# Extract certificates from the x5c field in the header
%{"x5c" => x5c} =
  jws
  |> JOSE.JWS.peek_protected()
  |> Jason.decode!()

# Base64 decode and reverse them to the format expected by the verify function
cert_chain =
  Enum.map(x5c, &Base.decode64!/1)
  |> Enum.reverse()

# Verify certificate chain and extract the public key
%Req.Response{body: trusted_cert} =
  Req.get!("https://www.apple.com/certificateauthority/AppleRootCA-G3.cer")

{:ok, {{_key_oid_name, public_key_type, public_key_params}, _policy_tree}} =
  :public_key.pkix_path_validation(trusted_cert, cert_chain, [])

public _key = {public_key_type, public_key_params}

# Convert the public key into a JSON Web Key
jwk = JOSE.JWK.from_key(public_key)
# Verify the signature of the JWS
{true, payload, _jose_jws_protected_details} = JOSE.JWS.verify(jwk, jws)

@potatosalad potatosalad added this to the jose 1.12.0 milestone Sep 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: To do
Status: To do
jose 1.11.x
  
To do
jose 2.0.x
  
To do
Development

No branches or pull requests

4 participants