GithubHelp home page GithubHelp logo

Support x5c validation about erlang-jose HOT 3 OPEN

potatosalad avatar potatosalad commented on August 22, 2024 1
Support x5c validation

from erlang-jose.

Comments (3)

behe avatar behe commented on August 22, 2024 7

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)

from erlang-jose.

tanguilp avatar tanguilp commented on August 22, 2024

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

from erlang-jose.

sjmadsen avatar sjmadsen commented on August 22, 2024

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.

from erlang-jose.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.