Repository navigation
feat(auth)!: sign, verify, and generate keys on rind #7570
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
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
caae20f
feat(auth)!: sign, verify, and generate keys on rind
kixelated 312aee3
bench(auth): sign and verify per key family
kixelated 8a50988
Merge origin/main; rind 0.1.2 and the mesh module on rind
kixelated dacd465
chore(quest): claim quest/m2/rind/auth.md
kixelated 0133425
Merge branch 'worktree-agent-aa40a2958d356c1e7' into quest/m2/rind/auth
kixelated 5c3fb88
chore(quest): moq-auth on rind is done
kixelated 41aa3e1
Merge origin/main; refuse an unsupported CPU as Error::UnsupportedCpu…
kixelated 7f49b06
Merge remote-tracking branch 'origin/main' into quest/m2/rind/auth
kixelated 40e9f4f
Merge origin/main; keep kio's async feature on moq-auth
kixelated eb9afcc
Merge origin/main; keep both moq-auth benches and main's kio features
kixelated 4d2fe26
fix(auth): build the jwt bench for CodSpeed, sync the workspace-hack,…
kixelated c8c1c79
Merge remote-tracking branch 'origin/main' into quest/m2/rind/auth
kixelated 8b2f760
Merge branch 'base' into pr-7570
77fd681
fix(ci): register the auth jwt benchmark in Nightly
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 was deleted.
Oops, something went wrong.
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,30 @@ | ||
| //! Signing and verifying one token with each key family, through the public API. | ||
| //! | ||
| //! Run with `cargo bench -p moq-auth --bench jwt`. | ||
|
|
||
| use std::hint::black_box; | ||
|
|
||
| use criterion::{Criterion, criterion_group, criterion_main}; | ||
| use moq_auth::{Algorithm, Claims, Key}; | ||
|
|
||
| fn bench_jwt(c: &mut Criterion) { | ||
| let claims = Claims::default() | ||
| .with_root("room") | ||
| .with_publish(["alice/**".parse::<moq_auth::Pattern>().unwrap()]); | ||
|
|
||
| let mut group = c.benchmark_group("jwt"); | ||
| for algorithm in [Algorithm::HS256, Algorithm::ES256, Algorithm::EdDSA, Algorithm::RS256] { | ||
| let key = Key::generate(algorithm, None).unwrap(); | ||
| let token = key.sign(&claims).unwrap(); | ||
| group.bench_function(format!("sign_{algorithm}"), |b| { | ||
| b.iter(|| key.sign(black_box(&claims)).unwrap()) | ||
| }); | ||
| group.bench_function(format!("verify_{algorithm}"), |b| { | ||
| b.iter(|| key.verify(black_box(&token)).unwrap()) | ||
| }); | ||
| } | ||
| group.finish(); | ||
| } | ||
|
|
||
| criterion_group!(benches, bench_jwt); | ||
| criterion_main!(benches); | ||
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,40 @@ | ||
| /// Refuse a CPU that rind can't run on, naming the missing feature, and make rind | ||
| /// jsonwebtoken's provider unless the process installed its own first. | ||
| /// | ||
| /// rind panics on such a CPU instead, so every key runs this before its first operation. | ||
| pub(crate) fn init() -> crate::Result<()> { | ||
| rind::cpu::check().map_err(crate::Error::unsupported_cpu)?; | ||
| // An error means the process already picked a provider, which it is entitled to. | ||
| let _ = rind_jsonwebtoken::DEFAULT_PROVIDER.install_default(); | ||
| Ok(()) | ||
| } | ||
|
|
||
| /// TLS on rind with the platform's roots, for an HTTP client given no config of its own. | ||
| /// | ||
| /// reqwest has no crypto provider of its own and builds a TLS config for every scheme, so | ||
| /// each client hands it one. | ||
| #[cfg(feature = "client")] | ||
| pub(crate) fn tls() -> crate::Result<rustls::ClientConfig> { | ||
| use rustls_platform_verifier::BuilderVerifierExt; | ||
| let provider = rind_rustls::default_provider().map_err(crate::Error::unsupported_cpu)?; | ||
| Ok( | ||
| rustls::ClientConfig::builder_with_provider(std::sync::Arc::new(provider)) | ||
| .with_safe_default_protocol_versions() | ||
| .map_err(crate::Error::crypto)? | ||
| .with_platform_verifier() | ||
| .map_err(crate::Error::crypto)? | ||
| .with_no_client_auth(), | ||
| ) | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| /// The dev-dependencies turn on jsonwebtoken's aws-lc backend, so signing alone can't show | ||
| /// that rind is the provider. | ||
| #[test] | ||
| fn installs_rind_when_none_is_installed() { | ||
| super::init().unwrap(); | ||
| let installed = rind_jsonwebtoken::DEFAULT_PROVIDER.install_default().unwrap_err(); | ||
| assert!(std::ptr::eq(installed, &rind_jsonwebtoken::DEFAULT_PROVIDER)); | ||
| } | ||
| } |
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
Oops, something went wrong.
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.
This invocation fails:
moq-auth's published release is its own dev-dependency, socargo bench -p moq-auth --bench jwterrors withspecification `moq-auth` is ambiguous— the exact reasonrs/justfilenow builds this bench fromrs/moq-auth. Use the form the nightly script uses (cargo bench --manifest-path rs/moq-auth/Cargo.toml --bench jwt, seesh/gh/nightly.sh:133) or runcargo bench --bench jwtfrom this directory. The PR body's Measurements line quotes the same ambiguous command.