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

adds support for W3C ES256K #462

Merged
merged 4 commits into from
Dec 19, 2022

Conversation

scrummitch
Copy link

Adds support for decoding JWTs using EcdsaSecp256k1Signature2019 which will become very popular due to Decentralised Identifiers becoming a W3C recommendation.

These signatures are used in Verifiable Credential issuance and presentations, see here https://identity.foundation/jwt-vc-presentation-profile.

Microsoft is using this method to sign their JWTs, see here https://learn.microsoft.com/en-us/azure/active-directory/verifiable-credentials/verifiable-credentials-standards#supported-algorithms

Please let me know if I've missed anything.

@scrummitch scrummitch changed the title adds support for W3C https://w3c-ccg.github.io/lds-ecdsa-secp256k1-2019/ adds support for W3C EcdsaSecp256k1VerificationKey2019 Oct 4, 2022
@OR13
Copy link

OR13 commented Oct 4, 2022

I recommend changing "EcdsaSecp256k1VerificationKey2019" to ES256K. In the context of JWT, only ES256K is needed to signal the alg and key type.

@scrummitch scrummitch changed the title adds support for W3C EcdsaSecp256k1VerificationKey2019 adds support for W3C ES256K Oct 4, 2022
Copy link
Collaborator

@bshaffer bshaffer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great!

One question I have is where you got the value for the EC curve (1.3.132.0.10). I searched for it online, and only found it referenced in a few websites like oid-info.com and oidref.com. It would be nice to see this value referenced from somewhere like IETF or other standards organization.

@scrummitch
Copy link
Author

This looks great!

One question I have is where you got the value for the EC curve (1.3.132.0.10). I searched for it online, and only found it referenced in a few websites like oid-info.com and oidref.com. It would be nice to see this value referenced from somewhere like IETF or other standards organization.

@bshaffer I used oid-info.com but its also in the source code for phpseclib here https://github.com/phpseclib/phpseclib/blob/master/phpseclib/Crypt/EC/Formats/Keys/Common.php#L120

@scrummitch
Copy link
Author

scrummitch commented Oct 5, 2022

@bshaffer Would like to get your opinion on swapping the order of the merge in JWT::encode(). For example to so typ can be blanked out. RFC 7519 says its not required https://www.rfc-editor.org/rfc/rfc7519#section-5.1

from

if (isset($head) && \is_array($head)) {
    $header = \array_merge($head, $header);
}

to

if (isset($head) && \is_array($head)) {
    $header = array_filter(\array_merge($header, $head));
}

@bshaffer
Copy link
Collaborator

bshaffer commented Oct 5, 2022

@bshaffer Would like to get your opinion on swapping the order of the merge in JWT::encode().

My initial thought is that this could change existing behavior, so unless it's a bug, I don't think we should allow it. Also, it's unrelated (AFAIK) to this PR, and so should be in a separate PR as a feat or fix.

What is the rational for blanking out typ?

@scrummitch
Copy link
Author

@bshaffer Would like to get your opinion on swapping the order of the merge in JWT::encode().

My initial thought is that this could change existing behavior, so unless it's a bug, I don't think we should allow it. Also, it's unrelated (AFAIK) to this PR, and so should be in a separate PR as a feat or fix.

What is the rational for blanking out typ?

Agreed it should be a separate PR so i'll raise that later when required

In the DIF .well-known DID configuration file the JWT used for proof requires typ to not exist in the header so i've been working backwards from that. https://identity.foundation/.well-known/resources/did-configuration/#json-web-token-proof-format

Maybe @OR13 knows why this is a requirement ?

@OR13
Copy link

OR13 commented Oct 5, 2022

That requirement regarding typ is getting removed, I'd ignore it.

Copy link
Collaborator

@bshaffer bshaffer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking pretty good! Just one more suggestion and this is good to go.

EDIT: Also, it looks like you still need to sign the Google CLA

src/JWT.php Outdated Show resolved Hide resolved
Updates in_array to enable strict mode

Co-authored-by: Brent Shaffer <betterbrent@google.com>
@scrummitch
Copy link
Author

@bshaffer thanks for the comment, ive updated that strict flag as per your suggestion.

You can see i've already accepted the CLA here:
image

@bshaffer bshaffer merged commit 213924f into firebase:main Dec 19, 2022
@scrummitch scrummitch deleted the features/secp256k1-ES256K branch December 20, 2022 05:42
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

Successfully merging this pull request may close these issues.

3 participants