-
Notifications
You must be signed in to change notification settings - Fork 322
Feat: Implement ES256K support for secp256k1 signed JWTs #461
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
Open
ThisIsMissEm
wants to merge
3
commits into
Keats:master
Choose a base branch
from
ThisIsMissEm:feat/implement-secp256k1-ES256K
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| use jsonwebtoken::jwk::Jwk; | ||
| use jsonwebtoken::{DecodingKey, Validation, decode, decode_header}; | ||
| use std::collections::HashMap; | ||
|
|
||
| // These were generated from Node.js using the @atproto/crypto library: | ||
| const TOKEN: &str = "eyJ0eXAiOiJhdCtqd3QiLCJhbGciOiJFUzI1NksifQ.eyJzY29wZSI6ImNvbS5hdHByb3RvLmFjY2VzcyIsInN1YiI6ImRpZDpleGFtcGxlOmFsaWNlIiwiaWF0IjoxNzYyODA5ODk4LCJhdWQiOiJkaWQ6d2ViOmJza3kubmV0d29yayJ9.krVCmWVQ2lTdXzi7Gcu0vv-szONeYj7kSpevjGiGBJcJnY5NgweIhNEzsnqoi6ni9VONgIrYfCj6T7LhJr9isg"; | ||
| const JWK: &str = r#"{ "kty": "EC", "x": "elgF6kwpkD00J9SPmoXBtaueneZf-77LnzrGrB7Ic7A", "y": "BTKRlhfwemkSQdB560lxw-Sg4GNH1gjkXXrryU-7jNM", "crv": "secp256k1" }"#; | ||
|
|
||
| fn main() -> Result<(), Box<dyn std::error::Error>> { | ||
| let jwk: Jwk = serde_json::from_str(JWK).unwrap(); | ||
| let header = decode_header(TOKEN).unwrap(); | ||
|
|
||
| println!("Header Algorithm: {:#?}", header.alg); | ||
|
|
||
| let validation = { | ||
| let mut validation = Validation::new(header.alg); | ||
| validation.set_audience(&["did:web:bsky.network"]); | ||
| validation.set_required_spec_claims(&["sub", "scope"]); | ||
| validation.validate_exp = false; | ||
| validation | ||
| }; | ||
|
|
||
| let decoded_token = decode::<HashMap<String, serde_json::Value>>( | ||
| TOKEN, | ||
| &DecodingKey::from_jwk(&jwk).unwrap(), | ||
| &validation, | ||
| )?; | ||
|
|
||
| println!("{:#?}", decoded_token); | ||
|
|
||
| Ok(()) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| -----BEGIN PRIVATE KEY----- | ||
| MIGEAgEAMBAGByqGSM49AgEGBSuBBAAKBG0wawIBAQQgmSIP8ezE7unJ624FYvIx | ||
| jCGK7n5abnzqVKjG9p63MO2hRANCAATd1slq/xOfdan3Oq9gMjCi7x25M7ubpM1H | ||
| tVBdj/NyNR9LHW9g6MI94yPvm2c3/fVczqL4lxuhJLGLWQGPYwjG | ||
| -----END PRIVATE KEY----- |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| { | ||
| "kty": "EC", | ||
| "x": "3dbJav8Tn3Wp9zqvYDIwou8duTO7m6TNR7VQXY_zcjU", | ||
| "y": "H0sdb2Dowj3jI--bZzf99VzOoviXG6EksYtZAY9jCMY", | ||
| "crv": "secp256k1", | ||
| "d": "mSIP8ezE7unJ624FYvIxjCGK7n5abnzqVKjG9p63MO0" | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| -----BEGIN PUBLIC KEY----- | ||
| MFYwEAYHKoZIzj0CAQYFK4EEAAoDQgAE3dbJav8Tn3Wp9zqvYDIwou8duTO7m6TN | ||
| R7VQXY/zcjUfSx1vYOjCPeMj75tnN/31XM6i+JcboSSxi1kBj2MIxg== | ||
| -----END PUBLIC KEY----- |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
should this be gated by rust_crypto feature since it's only available there? As well as all JWK operations?
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.
I'm not sure how to make this rust_crypto gated (that's a little beyond my current knowledge of rust)
would it be something like wrapping in: };
#[cfg(feature = "rust_crypto")]?