Repository navigation
Conversation
Move all signing cryptography out of reqsign-core and the service crates behind a process-wide CryptoProvider. Core installs one provider at most once, never falls back to a bundled implementation, and returns ConfigInvalid when no provider is installed. Hash, HMAC, and JWT helpers now propagate failures; the rsa-typed JWT entry point is removed. Migrate every signing call site, including AWS SSO/SigV4a, Azure client certificate and SAS, Google service account and client-side CAB, Oracle, Aliyun, Huawei, Tencent, and Volcengine. On-wire formats and existing caller contracts are preserved. Add reqsign-crypto-rustcrypto as a workspace member with native support for all operations and the existing WASM subset, and add the excluded, native-only reqsign-crypto-boring crate with a dedicated Linux CI job. The reqsign facade re-exports RustCryptoProvider behind default-crypto but never installs it implicitly. Document the contract, ownership and migration in docs/crypto-provider.md.
SHA-1 cache keys now come from reqsign_core::hash, so aws-core no longer uses the hex crate directly.
State that installation must precede credential loading that uses crypto, and explain how generic credential chains surface Ok(None) while selected identities such as AWS SSO propagate the underlying error. Clarify that installation is at-most-once rather than idempotent, note Google service-account invalid key behavior, and check every optional dependency path per root in the production crypto graph gate.
Add explicit Context::with_crypto bindings and context fallbacks. Crypto resolution now prefers an explicit binding, then the process-wide install, then the fallback, and otherwise fails with ConfigInvalid at the point of use. Contexts never install or freeze the global slot, so a provider installed after a context was created still takes precedence over its fallback. The facade's default_context supplies RustCrypto as a fallback when default-crypto is enabled, making default signers and examples work without startup boilerplate while preserving explicit and global overrides. Bare Context::new() still has no provider. Thread the selected provider through signing, credential, and granting paths and through standalone hash, JWT PEM, and Azure service SAS entry points. Update tests to bind providers locally, add resolution-priority and facade feature coverage, update caller documentation, and classify reqsign-crypto-rustcrypto as an internal website crate so the provider catalog validator accepts the new workspace member.
Keep one explicit Context binding and resolve it before the process-wide default. When default-crypto is enabled, default_context binds RustCrypto only if the global slot is empty at construction; otherwise it leaves the context unbound. This avoids a third resolution layer while keeping default signers and examples free of install boilerplate. Update docs, caller-facing notes, and isolated tests for install-before- construction, OnceLock non-occupation, feature-off behavior, and explicit provider priority.
State that a bare Context has no explicit binding, not that a global provider is absent from the process.
Bring in the SSO AssumeRole provider chain and shared SigV4 signing options from #954, plus the latest CI and website dependency updates. Port the new shared signing path and role-chain tests to the two-layer Context CryptoProvider resolution: pass the resolved provider through sign_request_parts, generated signing keys, STS request construction, and the role-chain fixtures. Preserve #954's profile selection, explicit Single/Double canonicalization, S3 Express routing, and credential-chain error behavior.
Start reqsign-crypto-rustcrypto and reqsign-crypto-boring on independent 1.0.0 lines. Update the workspace dependency, Boring's RustCrypto dev dependency, and the versioning documentation while keeping core, service, and facade versions unchanged.
Remove the public reqsign_core::jwt module and jwt feature, along with core's optional serde/serde_json dependencies and the JWT-only test support/dev dependencies. Azure now formats its client-certificate RS256 assertion privately, and Google shares one private crate-local JWT helper between request signing and service-account token exchange. Both keep the existing headers, claims, unpadded JWS encoding, PKCS#8/PKCS#1 support, and provider error semantics. Google's base64 dependency is now always available, while the former optional-feature wiring is removed. Port the JWT contract tests to the service helpers and update the design/caller documentation.
| # not unified into the roots. --all-features covers every optional | ||
| # path; --target all also covers target-specific dependencies. | ||
| for package in "${packages[@]}"; do | ||
| if cargo tree -p "$package" --all-features --target all --edges normal --prefix none \ |
There was a problem hiding this comment.
| if cargo tree -p "$package" --all-features --target all --edges normal --prefix none \ | |
| if cargo tree --package "$package" --all-features --target all --edges normal --prefix none \ |
| cargo check -p reqsign-core --target wasm32-unknown-unknown | ||
| cargo check -p reqsign-crypto-rustcrypto --target wasm32-unknown-unknown |
There was a problem hiding this comment.
| cargo check -p reqsign-core --target wasm32-unknown-unknown | |
| cargo check -p reqsign-crypto-rustcrypto --target wasm32-unknown-unknown | |
| cargo check --package reqsign-core --target wasm32-unknown-unknown | |
| cargo check --package reqsign-crypto-rustcrypto --target wasm32-unknown-unknown |
| RUST_BACKTRACE: full | ||
| - name: Facade crypto feature tests | ||
| run: | | ||
| cargo test -p reqsign --all-features --test crypto --test default_signer |
There was a problem hiding this comment.
| cargo test -p reqsign --all-features --test crypto --test default_signer | |
| cargo test --package reqsign --all-features --test crypto --test default_signer |
Apply the review suggestions for the per-root dependency gate, core and RustCrypto WASM checks, and the facade crypto feature tests.
Bring in the Context ownership and credential-cache isolation contract, the caller-supplied Context for every facade default_signer, and the latest service versions and documentation. Resolve the facade README overlap by keeping the new default_signer signature and documenting the conditional RustCrypto binding. Bind an explicit test provider in the service-only context test and update the default-signer integration test for the caller-context API. Reconcile Boring's workspace path dependencies with the versions now on the branch, and preserve the two-layer CryptoProvider design, private service JWT helpers, backend versions, and dependency boundaries.
Document that the provider exposes the focused digest, HMAC, signature, encryption, and random-generation operations Reqsign needs, and that one provider serves all operations at runtime.
erickguan
left a comment
There was a problem hiding this comment.
Just some minor comments worth ironing out.
I feel some jwt.rs can also be generic but I am not going to be in your way.
A question about design for my learning: why don't we require core instead of extracting a trait only lib when reverse dependencies? i.e. why do you allow crypto lib refer to reqsign_core?
| - name: Facade crypto feature tests | ||
| run: | | ||
| cargo test --package reqsign --all-features --test crypto --test default_signer | ||
| cargo test -p reqsign --no-default-features --features default-context --test crypto_without_default_crypto |
There was a problem hiding this comment.
| cargo test -p reqsign --no-default-features --features default-context --test crypto_without_default_crypto | |
| cargo test --package reqsign --no-default-features --features default-context --test crypto_without_default_crypto |
| use support::TestProvider; | ||
|
|
||
| #[test] | ||
| fn concurrent_installation_elects_exactly_one_provider() { |
There was a problem hiding this comment.
We probably don't need timing related test where most likely one instance works.
| use reqsign_crypto_rustcrypto::RustCryptoProvider; | ||
|
|
||
| #[test] | ||
| fn hashes_match_published_vectors_with_expected_widths() { |
There was a problem hiding this comment.
Try no to pin hashes because we don't test its values. Length and perhaps character range checks are more than enough.
| } | ||
|
|
||
| #[test] | ||
| fn hashes_match_published_vectors() { |
There was a problem hiding this comment.
Same reason, not to test hash values.
Use --package in the facade crypto CI command, drop the redundant threaded install stress test, and keep deterministic install assertions. Compare hash helpers with provider raw bytes instead of pinned digests, and verify the RustCrypto adapter against direct primitives.
|
Thanks for the review, @erickguan. Addressed the four inline comments in 970c07a:
On the design question: Review: #970 (review) |
Problem
Reqsign currently bundles cryptographic implementations into
reqsign-coreand several service crates. Applications cannot choose a single crypto stack, and the publicjwtAPI exposesrsa::RsaPrivateKeyin its surface. This is the breaking-change implementation of the approved CryptoProvider design, withContext-owned provider selection and a facade default that works without startup boilerplate.Final behavior
reqsign-coreand everyservices/*crate carry zero production dependencies onsha1,sha2,hmac,rsa,p256, oraes-gcm. Crypto operations resolve throughContextin this order:Context::with_crypto(provider)(explicit, highest priority);reqsign_core::crypto::install_default(provider)registration;ErrorKind::ConfigInvalidat the point of use.Context::new()starts unbound. Creating, using, or cloning a context never installs or freezes the process-wide slot. An explicitly bound context keeps its provider; an unbound context observes the current global registration. Distinct contexts can use independent providers.The
reqsignfacade addsdefault-crypto(included indefault). When enabled,default_context()checks the process-wide registration at construction: it bindsRustCryptoProvideronly when the slot is empty, and leaves the context unbound when a global provider is already installed. It never writes the global slot. Per-servicedefault_signer(...)and examples therefore work without startup boilerplate. Applications choosing a global provider install it before constructing facade contexts; contexts already bound to RustCrypto keep that binding, and an explicitwith_cryptobinding always wins. Withoutdefault-crypto,default_context()has no implicit binding. Middleware such as OpenDAL must not install a global provider.Standalone crypto entry points take an explicit provider:
hash::*and Azure'sServiceSharedAccessSignature::token. Callers with a context passctx.crypto_provider()?. Pure base64 encoders/decoders stay unchanged. The publicreqsign_core::jwtmodule andjwtfeature are removed; Azure client-certificate and Google service-account flows format RS256 JWS in private service helpers using the selected provider.Error semantics remain: missing/unsupported provider operation is non-retryable
ConfigInvalid; malformed key material isCredentialInvalid; backend failures areUnexpected.Two provider crates ship:
reqsign-crypto-rustcrypto(crypto/rustcrypto) is a workspace member and implements all eight operations natively; onwasm32-unknown-unknownit provides SHA-1, SHA-256, HMAC-SHA-1/256, and P-256 ECDSA, reporting RSA/AES-GCM/random as unsupported.reqsign-crypto-boring(crypto/boring) is excluded from the main workspace, native-only, independently versioned, and verified by a focused Linux workflow. It implements all eight operations through safe, stateless BoringSSL APIs and forwards an optionalfipsfeature.The authoritative contract, resolution and ownership rules, migration guidance, error boundaries, and provider manifests are in
docs/crypto-provider.md.Migration
default_context()/default_signer(...)without installing anything.RustCryptoProvider::install_default()once before constructing facade contexts.reqsign-coreusers bind a provider withContext::new().with_crypto(provider), or install a global provider, before signing.Result; service JWT formatting remains private.Ok(None)behavior, expiry/auth semantics, crate versions, and workspace isolation are preserved.Signer::signthen reportsCredentialInvalidwith the request unchanged. AWS SSO-style selected identities propagate their errors. This is documented rather than changed.#941 alignment
This PR leaves #941 and its
rsa 0.10bump untouched. RSA remains encapsulated inreqsign-crypto-rustcryptowith the existingrsa 0.9.2requirement and MSRV. After this review, #941 can update only that provider crate; no public Reqsign API change is needed.Validation
On the current head:
cargo test --workspace --all-features --no-fail-fastand doc tests pass, including Google CAB tests with their feature enabled.cargo clippy --workspace --all-targets --all-features -- -D warnings,cargo fmt, andhawkeye checkpass.default-cryptopresent and absent. With the global slot empty,default_context()binds RustCrypto, works, does not occupyOnceLock, and can still install a global provider afterward; that existing context keeps RustCrypto, while a newdefault_context()uses the global provider. Explicit bindings still win. Feature-off and bare missing-provider behavior are covered.cargo tree -p <each core/service crate> --all-features --target all --edges normalconfirms zero production crypto implementation dependencies; CI enforces this per root to avoid workspace feature unification.reqsign-core(all features),reqsign-crypto-rustcrypto, and the facade withdefault-context,default-crypto;cargo check -p reqsign --examples --all-featurespasses.pnpm install --frozen-lockfile,pnpm run validate-providers(10 providers, 7 internal crates, workspace fully claimed),pnpm build, and the third-party runtime asset check pass.reqsign-crypto-rustcryptois classified as an internal crate; excluded Boring is not in the workspace list.cargo publish -p reqsign-core --dry-runpackages successfully. A full workspace publish dry-run cannot verify dependent crates against the new unpublished core API before release; release packaging remains part of the normal release process.Base:
724d6c7; currentmainis2d5daad, whose only delta is Azure CI retry scripts. The new crypto backends start on independent1.0.0version lines; existing core, service, and facade versions are unchanged. The PR is ready for Xuanwo and community review and is intentionally not merged by the maintenance loop.