Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 34 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,33 @@ jobs:
- name: Clippy
run: cargo clippy --workspace --all-targets --all-features -- -D warnings

- name: Check production crypto dependencies
run: |
packages=(
reqsign-core
reqsign-aliyun-oss
reqsign-aws-core
reqsign-aws-v4
reqsign-aws-v4a
reqsign-azure-storage
reqsign-google
reqsign-huaweicloud-obs
reqsign-openstack-keystone
reqsign-oracle
reqsign-tencent-cos
reqsign-volcengine-tos
)
# Query each root separately so the facade's default-crypto graph is
# 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 --package "$package" --all-features --target all --edges normal --prefix none \
| grep -Eq '^(sha1|sha2|hmac|rsa|p256|aes-gcm) v'; then
echo "production cryptographic dependency found in $package"
exit 1
fi
done

licenses:
runs-on: ubuntu-latest
timeout-minutes: 10
Expand Down Expand Up @@ -98,11 +125,12 @@ jobs:
- name: Check
run: |
rustup target add wasm32-unknown-unknown
cargo check -p reqsign-core --target wasm32-unknown-unknown
cargo check --package reqsign-core --target wasm32-unknown-unknown
cargo check --package reqsign-crypto-rustcrypto --target wasm32-unknown-unknown
cargo check -p reqsign-aws-core --target wasm32-unknown-unknown
cargo check -p reqsign-aws-v4a --target wasm32-unknown-unknown
cargo build --manifest-path reqsign/Cargo.toml --target wasm32-unknown-unknown --no-default-features --features=aws,aws-v4a,azure,aliyun,tencent
cargo build --manifest-path reqsign/Cargo.toml --target wasm32-unknown-unknown --no-default-features --features=default-context,aws,aws-v4a,azure,aliyun,tencent
cargo build --manifest-path reqsign/Cargo.toml --target wasm32-unknown-unknown --no-default-features --features=default-context,default-crypto,aws,aws-v4a,azure,aliyun,tencent

unit:
runs-on: ubuntu-latest
Expand All @@ -117,6 +145,10 @@ jobs:
env:
RUST_LOG: DEBUG
RUST_BACKTRACE: full
- name: Facade crypto feature tests
run: |
cargo test --package reqsign --all-features --test crypto --test default_signer
cargo test --package reqsign --no-default-features --features default-context --test crypto_without_default_crypto
- name: Doc Test
run: cargo +nightly test --doc --all-features --workspace
env:
Expand Down
63 changes: 63 additions & 0 deletions .github/workflows/crypto_boring.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

name: Crypto Boring

on:
push:
branches:
- main
paths:
- "Cargo.toml"
- "rust-toolchain.toml"
- "core/**"
- "crypto/boring/**"
- "crypto/rustcrypto/**"
- "services/aws-core/**"
- "services/aws-v4/**"
- ".github/workflows/crypto_boring.yml"
pull_request:
branches:
- main
paths:
- "Cargo.toml"
- "rust-toolchain.toml"
- "core/**"
- "crypto/boring/**"
- "crypto/rustcrypto/**"
- "services/aws-core/**"
- "services/aws-v4/**"
- ".github/workflows/crypto_boring.yml"

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}-${{ github.event_name }}
cancel-in-progress: true

permissions: {}

jobs:
test:
runs-on: ubuntu-latest
timeout-minutes: 60
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- name: Clippy
run: cargo clippy --manifest-path crypto/boring/Cargo.toml --all-targets -- -D warnings
- name: Test
run: cargo test --manifest-path crypto/boring/Cargo.toml
13 changes: 13 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,17 @@ For security-sensitive changes, follow [SECURITY.md](SECURITY.md) and
[THREAT_MODEL.md](THREAT_MODEL.md) as the source of truth for Reqsign's
security boundary and its relationship to OpenDAL and other host applications.

### Crypto Provider

All signing cryptography goes through a `reqsign_core::crypto::CryptoProvider`
resolved by `Context` (explicit binding, then the process-wide registration).
`reqsign-core` and every `services/*` crate carry no production cryptographic
implementation. `reqsign-core` exposes no public JWT module or feature; Azure
and Google own their private RS256 JWS formatting. Follow
[docs/crypto-provider.md](docs/crypto-provider.md) as the source of truth for
the provider contract, resolution and installation ownership, error semantics,
and the official RustCrypto/BoringSSL implementations.

### Default Credential Provider

All future refactors and API reviews around `DefaultCredentialProvider` must
Expand Down Expand Up @@ -76,6 +87,8 @@ this supported subset.

- Service crates and core share a lockstep major version (`3.0.0`).
- `reqsign-http-send-reqwest` has its own major (`4.0.0`).
- `reqsign-crypto-rustcrypto` and `reqsign-crypto-boring` each have independent
version lines, starting at `1.0.0`.
- The facade `reqsign` crate follows an independent scheme (`0.20.0`).
- Release is triggered by pushing a `v*.*.*` tag; `cargo publish --workspace`
publishes everything.
Expand Down
5 changes: 4 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
# under the License.

[workspace]
members = ["core", "context/*", "services/*", "reqsign"]
members = ["core", "context/*", "crypto/rustcrypto", "services/*", "reqsign"]
exclude = ["crypto/boring"]
resolver = "3"

[workspace.package]
Expand All @@ -34,6 +35,7 @@ reqsign-aws-v4a = { version = "3.2.0", path = "services/aws-v4a" }
reqsign-azure-storage = { version = "3.3.2", path = "services/azure-storage" }
reqsign-command-execute-tokio = { version = "3.0.9", path = "context/command-execute-tokio" }
reqsign-core = { version = "3.3.4", path = "core" }
reqsign-crypto-rustcrypto = { version = "1.0.0", path = "crypto/rustcrypto" }
reqsign-file-read-tokio = { version = "3.0.9", path = "context/file-read-tokio" }
reqsign-google = { version = "3.4.0", path = "services/google" }
reqsign-http-send-reqwest = { version = "4.0.9", path = "context/http-send-reqwest" }
Expand All @@ -54,6 +56,7 @@ dotenvy = "0.15"
env_logger = "0.11"
form_urlencoded = "1"
futures = "0.3"
getrandom = "0.3"
hex = "0.4"
hmac = "0.13"
http = "1"
Expand Down
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ use reqsign::{aws, default_context};

#[tokio::main]
async fn main() -> Result<()> {
// Create a default runtime context (HTTP client, file reader, OS env, command execution)
// Create a default runtime context (HTTP client, file reader, OS env, command execution).
// It binds RustCrypto when no process-wide provider is installed.
let ctx = default_context();
// Create a default signer for S3 in us-east-1 using the supplied context
let signer = aws::default_signer(ctx, "s3", "us-east-1");
Expand Down Expand Up @@ -55,15 +56,17 @@ For more control over the components, you can manually assemble the signer:

```rust
use anyhow::Result;
use reqsign::{Context, Signer};
use reqsign::{Context, RustCryptoProvider, Signer};
use reqsign_aws_v4::{DefaultCredentialProvider, RequestSigner};
use reqsign_file_read_tokio::TokioFileRead;
use reqsign_http_send_reqwest::ReqwestHttpSend;

#[tokio::main]
async fn main() -> Result<()> {
// Build your own context with specific implementations
// Build your own context with specific implementations.
// A bare Context starts unbound, so bind the provider explicitly.
let ctx = Context::new()
.with_crypto(RustCryptoProvider::new())
.with_file_read(TokioFileRead)
.with_http_send(ReqwestHttpSend::default())
.with_env(reqsign::OsEnv);
Expand Down
9 changes: 0 additions & 9 deletions core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,26 +29,17 @@ rust-version.workspace = true

[features]
default = []
jwt = ["dep:rsa", "dep:serde", "dep:serde_json"]

[dependencies]
anyhow = { workspace = true }
asyncband = { workspace = true }
base64 = { workspace = true }
bytes = { workspace = true }
hex = { workspace = true }
hmac = { workspace = true }
http = { workspace = true }
jiff = { workspace = true }
log = { workspace = true }
percent-encoding = { workspace = true }
sha1 = { workspace = true }
sha2 = { workspace = true }

# Optional dependencies
rsa = { workspace = true, optional = true }
serde = { workspace = true, optional = true }
serde_json = { workspace = true, optional = true }

[target.'cfg(target_os = "windows")'.dependencies]
windows-sys = { version = "0.61.0", features = [
Expand Down
48 changes: 48 additions & 0 deletions core/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
// specific language governing permissions and limitations
// under the License.

use crate::crypto::{self, CryptoProvider};
use crate::{BoxedFuture, Error, MaybeSend, Result};
use bytes::Bytes;
use std::collections::HashMap;
Expand All @@ -31,6 +32,15 @@ use std::sync::Arc;
/// reqsign provides NO default implementations. Users MAY configure components they need.
/// Any unconfigured component will use a no-op implementation that returns errors or empty values when called.
///
/// ## Cryptographic provider
///
/// Crypto operations resolve through the context. Resolution prefers a provider
/// bound with [`Context::with_crypto`], then the process-wide provider installed
/// with [`crate::crypto::install_default`]. A bare `Context::new()` has no
/// explicit binding and returns [`crate::ErrorKind::ConfigInvalid`] when crypto
/// is first needed without a process-wide provider. Creating or cloning a
/// context never installs or freezes a global provider.
///
/// ## Example
///
/// ```
Expand All @@ -46,6 +56,7 @@ pub struct Context {
http: Arc<dyn HttpSendDyn>,
env: Arc<dyn Env>,
cmd: Arc<dyn CommandExecuteDyn>,
crypto: Option<Arc<dyn CryptoProvider>>,
}

impl Debug for Context {
Expand All @@ -55,6 +66,7 @@ impl Debug for Context {
.field("http", &self.http)
.field("env", &self.env)
.field("cmd", &self.cmd)
.field("crypto", &self.crypto)
.finish()
}
}
Expand Down Expand Up @@ -87,6 +99,7 @@ impl Context {
http: Arc::new(NoopHttpSend),
env: Arc::new(NoopEnv),
cmd: Arc::new(NoopCommandExecute),
crypto: None,
}
}

Expand Down Expand Up @@ -114,6 +127,41 @@ impl Context {
self
}

/// Bind a cryptographic provider to this context.
///
/// An explicitly bound provider has the highest priority for every crypto
/// operation performed through this context. It does not affect the
/// process-wide provider or other contexts.
pub fn with_crypto(mut self, provider: impl CryptoProvider) -> Self {
self.crypto = Some(Arc::new(provider));
self
}

/// Resolve the cryptographic provider for this context.
///
/// Resolution order is:
///
/// 1. the provider bound with [`Context::with_crypto`];
/// 2. the process-wide provider installed with
/// [`crate::crypto::install_default`].
///
/// If neither is available this returns [`crate::ErrorKind::ConfigInvalid`]
/// at the point of use. Resolution never installs or freezes a provider.
/// An unbound context observes the current process-wide registration; a
/// context that already has an explicit binding keeps it.
pub fn crypto_provider(&self) -> Result<&dyn CryptoProvider> {
if let Some(provider) = &self.crypto {
return Ok(provider.as_ref());
}
if let Some(provider) = crypto::get_default() {
return Ok(provider.as_ref());
}

Err(Error::config_invalid(
"no CryptoProvider is available; bind one with Context::with_crypto or install a process-wide default",
))
}

/// Read the file content entirely in `Vec<u8>`.
#[inline]
pub async fn file_read(&self, path: &str) -> Result<Vec<u8>> {
Expand Down
Loading
Loading