Skip to content
Merged
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
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion quest/m1/rind/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,5 +65,4 @@ The epic's own work, once every child has merged:

## Required

- [One typed unsupported-CPU error](/quest/m1/rind/cpu-error.md) - moq-auth, moq-hls and moq-crypto e2ee carry `moq_crypto::provider::UnsupportedCpu` and drop their own CPU-check helpers
- [moq-rtc on rind](/quest/m1/rind/rtc.md) - str0m and dimpl run DTLS, SRTP, and STUN on rind
49 changes: 0 additions & 49 deletions quest/m1/rind/cpu-error.md

This file was deleted.

1 change: 0 additions & 1 deletion quest/m2/recut-held.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,5 @@ padding probes in [lite07-finalize](/quest/m2/lite07-finalize.md).

## Required

- [rind CPU error](/quest/m1/rind/cpu-error.md) - claim held rind
- [Release on leave](/quest/m1/stream-credit/release-on-leave.md) - claim held stream-credit
- [Probe padding](/quest/m2/probe/padding.md) - claim held probe
5 changes: 2 additions & 3 deletions rs/moq-auth/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ async = ["kio/async"]
client = [
"async",
"dep:reqwest",
"dep:rind-rustls",
"moq-crypto/provider",
"dep:rustls",
"dep:rustls-platform-verifier",
"dep:tokio",
Expand All @@ -34,15 +34,14 @@ axum = { workspace = true, optional = true }
base64 = { workspace = true }
jsonwebtoken = { workspace = true }
kio = { workspace = true, features = ["serde"] }
moq-crypto = { workspace = true, features = ["serde"] }
moq-crypto = { workspace = true, features = ["serde", "cpu"] }
moq-pattern = { workspace = true, features = ["serde"] }
pkcs1 = { workspace = true, features = ["std"] }
pkcs8 = { workspace = true }
rand = { workspace = true, optional = true }
reqwest = { workspace = true, features = ["rustls-no-provider", "json"], optional = true }
rind = { workspace = true }
rind-jsonwebtoken = { workspace = true }
rind-rustls = { workspace = true, optional = true }
rustls = { version = "0.23", default-features = false, optional = true }
rustls-platform-verifier = { version = "0.7", optional = true }
serde = { workspace = true }
Expand Down
4 changes: 4 additions & 0 deletions rs/moq-auth/MIGRATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ How to update your code for each breaking change, newest first.

## Unreleased

### Shared unsupported CPU error

`Error::UnsupportedCpu` now carries `moq_crypto::cpu::UnsupportedCpu` instead of a `String`. Use its `Display` implementation for the missing feature message. Core builds still need no rustls.

### `Peer` carries the certificate chain

`Peer` gains `chain`: the SHA-256 of the leaf and of each certificate it provably
Expand Down
18 changes: 8 additions & 10 deletions rs/moq-auth/src/crypto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
///
/// 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)?;
moq_crypto::cpu::check()?;
// An error means the process already picked a provider, which it is entitled to.
let _ = rind_jsonwebtoken::DEFAULT_PROVIDER.install_default();
Ok(())
Expand All @@ -16,15 +16,13 @@ pub(crate) fn init() -> crate::Result<()> {
#[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(),
)
let provider = moq_crypto::provider::provider()?;
Ok(rustls::ClientConfig::builder_with_provider(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)]
Expand Down
9 changes: 2 additions & 7 deletions rs/moq-auth/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,8 @@ pub enum Error {
MeshState(String),

/// This CPU lacks a feature the crate's cryptography requires, named in rind's message.
#[error("unsupported CPU: {0}")]
UnsupportedCpu(String),
#[error(transparent)]
UnsupportedCpu(#[from] moq_crypto::cpu::UnsupportedCpu),
}

// Dependency errors are flattened to their message so their crates stay out of this crate's
Expand Down Expand Up @@ -243,11 +243,6 @@ impl Error {
pub(crate) fn crypto(err: impl std::error::Error) -> Self {
Self::Crypto(message(err))
}

/// Carries rind's message rather than its type, so rind stays out of this crate's API.
pub(crate) fn unsupported_cpu(err: rind::cpu::MissingFeature) -> Self {
Self::UnsupportedCpu(err.to_string())
}
}

#[cfg(feature = "client")]
Expand Down
9 changes: 5 additions & 4 deletions rs/moq-crypto/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@ default = ["sign", "e2ee"]
# Per-frame signing: `sign::SecretKey` and the signed broadcast wrappers.
sign = ["dep:bytes", "dep:kio", "dep:moq-net", "dep:rind", "dep:zeroize"]
# End-to-end encryption: the `e2ee` module.
e2ee = ["dep:base64", "dep:bytes", "dep:kio", "dep:moq-net", "dep:rind", "dep:uuid", "dep:zeroize"]
# rind's rustls provider and CPU check, with the `UnsupportedCpu` error the transport crates
# share. Needs neither `moq-net` nor the other features, so moq-quic and moq-tokio can use it.
provider = ["dep:rind", "dep:rind-rustls", "dep:rustls"]
e2ee = ["cpu", "dep:base64", "dep:bytes", "dep:kio", "dep:moq-net", "dep:rind", "dep:uuid", "dep:zeroize"]
# CPU support and its shared error need only rind.
cpu = ["dep:rind"]
# The rustls provider adds TLS without needing `moq-net`.
provider = ["cpu", "dep:rind-rustls", "dep:rustls"]
# `sign::PublicKey` serializes as its canonical z-base-32 text.
serde = ["dep:serde"]
# Generated async wrappers for the `sign` and `e2ee` poll methods. Enable where you `.await` them.
Expand Down
4 changes: 4 additions & 0 deletions rs/moq-crypto/MIGRATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ How to update your code for each breaking change, newest first.

## Unreleased

### Shared unsupported CPU error

`e2ee::Error::Unsupported(String)` is now `UnsupportedCpu(cpu::UnsupportedCpu)`. The shared `UnsupportedCpu` type and `check()` move from `provider` to `cpu`, enabled by the new `cpu` feature and by `e2ee` and `provider`. `cpu` needs only rind; `provider` adds rustls.

### Async wrappers are opt-in

Enable the `async` Cargo feature to keep awaiting `read_frame`, `recv_group`, `recv`,
Expand Down
18 changes: 9 additions & 9 deletions rs/moq-crypto/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,32 @@ Cryptography for [Media over QUIC](https://moq.dev): the `sign` module signs eve
relays cannot forge it, and the `e2ee` module encrypts groups, datagrams, and track names so
relays cannot read them. Both wrap `moq-net` and check timestamps with its
`track::Info::rescale`, so a frame either half accepts is one `moq-net` accepts. The `provider`
module is the [rind](https://github.com/moq-dev/rind) rustls provider and CPU check that the
MoQ transport crates share.
module is the [rind](https://github.com/moq-dev/rind) rustls provider; `cpu` holds the CPU
check and error that the MoQ crates share.

## Features

`sign` and `e2ee`, both default, enable the two modules. With default features off, the crate is
only `sign::PublicKey`, the endpoint ID, with its canonical z-base-32 text: it builds without
`moq-net` or rind, for crates such as `moq-auth` that name endpoints but sign nothing.
`serde` adds the key's string serialization. `provider`, off by default, enables the `provider`
module; it depends only on rind and rustls, never on `moq-net`, so the transport crates can
use it without a dependency cycle.
`moq-net` or rind, for crates that only name endpoints.
`serde` adds the key's string serialization. `cpu`, enabled by `e2ee` and `provider`, adds
only rind. `provider`, off by default, adds the rustls integration without `moq-net`, so
transport crates can use it without a dependency cycle.

## Provider

MoQ runs all of its cryptography on rind. Its primitives panic on a CPU missing a feature rind
requires, so the `provider` module refuses such a CPU up front. Today that is NEON on aarch64;
requires, so the `cpu` module refuses such a CPU up front. Today that is NEON on aarch64;
every `x86_64` CPU and armv7 are supported, and a CPU without AES or other crypto extensions
runs rind's slower paths rather than being refused:

- `provider::check()` returns `UnsupportedCpu`, naming the missing feature.
- `cpu::check()` returns `cpu::UnsupportedCpu`, naming the missing feature.
- `provider::provider()` returns rind's rustls `CryptoProvider`, or that error. It ignores the
process default, so TLS works whether or not one was installed.
- `provider::install_default()` installs rind as rustls' process default for libraries such as
reqwest that read it, leaving a provider the process already installed in place.

moq-quic, moq-tokio, qmux, and moq-uring report the same `UnsupportedCpu`, and
moq-auth, moq-hls, e2ee, moq-rtmp, and the transports report the same `cpu::UnsupportedCpu`, and
`moq_tokio::crypto` re-exports this module's API.

## Signing
Expand Down
13 changes: 13 additions & 0 deletions rs/moq-crypto/src/cpu.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//! CPU support for rind cryptography, without a TLS dependency.

/// This CPU lacks a feature that rind requires, named in the message.
#[derive(Clone, Copy, Debug, PartialEq, Eq, thiserror::Error)]
#[error("unsupported CPU: {0}")]
pub struct UnsupportedCpu(pub(crate) rind::cpu::MissingFeature);

/// Refuse a CPU that rind cannot run on, naming the missing feature.
///
/// Call this before using rind's primitives directly; the rustls provider checks it too.
pub fn check() -> Result<(), UnsupportedCpu> {
rind::cpu::check().map_err(UnsupportedCpu)
}
10 changes: 5 additions & 5 deletions rs/moq-crypto/src/e2ee/credential.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use rind::hkdf;
use zeroize::{Zeroize, ZeroizeOnDrop};

use crate::e2ee::Epoch;
use crate::e2ee::error::{Error, Result};
use crate::e2ee::error::Result;
use crate::e2ee::generation;
use crate::e2ee::limits::{PATH_LABEL, PATH_LEN, PROFILE, SECRET_LEN, check_bytes, check_u53};

Expand Down Expand Up @@ -54,10 +54,10 @@ impl Credential {
///
/// # Errors
///
/// [`Error::Unsupported`] if this CPU lacks a feature the crypto needs.
/// [`Error::Identity`] if `context` exceeds 65535 bytes or `kid` exceeds `2^53-1`.
/// [`Error::UnsupportedCpu`](crate::e2ee::Error::UnsupportedCpu) if this CPU lacks a feature the crypto needs.
/// [`Error::Identity`](crate::e2ee::Error::Identity) if `context` exceeds 65535 bytes or `kid` exceeds `2^53-1`.
pub fn new(config: Config) -> Result<Self> {
rind::cpu::check().map_err(|missing| Error::Unsupported(missing.to_string()))?;
crate::cpu::check()?;
check_bytes(config.context.len())?;
check_u53(config.kid)?;
let secret = Secret(config.secret);
Expand All @@ -84,7 +84,7 @@ impl Credential {
///
/// # Errors
///
/// [`Error::Identity`] if `semantic` exceeds 65535 bytes.
/// [`Error::Identity`](crate::e2ee::Error::Identity) if `semantic` exceeds 65535 bytes.
pub fn path(&self, semantic: &str) -> Result<moq_net::Path> {
let material: [u8; PATH_LEN] = self.expand(&self.path_info(semantic)?);
// A fixed-length encoding, far under the path limit.
Expand Down
6 changes: 3 additions & 3 deletions rs/moq-crypto/src/e2ee/error.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/// Typed failures from [draft-lcurley-moq-e2ee](https://datatracker.ietf.org/doc/draft-lcurley-moq-e2ee/).
///
/// Display is the profile code. Secrets, keys, and plaintext never appear here.
/// Display is the profile code or the CPU refusal. Secrets, keys, and plaintext never appear here.
#[derive(thiserror::Error, Debug, Clone)]
#[non_exhaustive]
pub enum Error {
Expand All @@ -25,8 +25,8 @@ pub enum Error {
Authentication,

/// This CPU lacks an instruction set extension the crypto requires; the message names it.
#[error("unsupported: {0}")]
Unsupported(String),
#[error(transparent)]
UnsupportedCpu(#[from] crate::cpu::UnsupportedCpu),

/// The underlying MoQ track failed.
#[error(transparent)]
Expand Down
9 changes: 6 additions & 3 deletions rs/moq-crypto/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,22 @@
//! forging it. [`e2ee`] encrypts groups, datagrams, and track names so a relay forwards
//! ciphertext it cannot read. Both wrap `moq-net` and check a frame's timestamp with
//! `moq_net::track::Info::rescale`, so neither accepts a frame the net track would refuse.
//! [`provider`] is rind's rustls provider and CPU check, with the [`provider::UnsupportedCpu`]
//! [`provider`] is rind's rustls provider; [`cpu`] holds the CPU check and [`cpu::UnsupportedCpu`]
//! error that moq-quic, moq-tokio, and the other transport crates report.
//!
//! The `sign` and `e2ee` features, both default, gate those halves; `provider`, off by default,
//! gates the provider and needs no `moq-net`. Without any of them the crate holds only
//! [`sign::PublicKey`], the endpoint ID, and its canonical z-base-32 text, with no `moq-net`
//! gates the rustls provider and enables `cpu`, which needs only rind. Without any of these
//! features the crate holds only [`sign::PublicKey`], the endpoint ID, and its canonical
//! z-base-32 text, with no `moq-net`
//! or crypto backend; `serde` adds its string serialization.
//!
//! The `poll_*` methods are always available. Enable the `async` feature for their generated
//! async wrappers (such as `read_frame` and `recv_group`); it is off by default.

#![warn(missing_docs)]

#[cfg(feature = "cpu")]
pub mod cpu;
#[cfg(feature = "e2ee")]
pub mod e2ee;
#[cfg(feature = "provider")]
Expand Down
23 changes: 6 additions & 17 deletions rs/moq-crypto/src/provider.rs
Original file line number Diff line number Diff line change
@@ -1,27 +1,16 @@
//! rind, MoQ's one cryptography provider: the CPU check and its rustls provider.
//! rind's rustls cryptography provider.
//!
//! rind's primitives panic on a CPU missing a feature they require, so each entry point
//! here refuses such a CPU with [`UnsupportedCpu`] instead. The transport crates report
//! this one type, and rind stays out of their public APIs.
//! here refuses such a CPU with [`crate::cpu::UnsupportedCpu`] instead. The [`crate::cpu`]
//! module owns the shared error reported by transport crates, keeping rind out of their APIs.

use std::sync::{Arc, OnceLock};

use crate::cpu::UnsupportedCpu;

/// A shared rustls crypto provider.
pub type Provider = Arc<rustls::crypto::CryptoProvider>;

/// This CPU lacks a feature that rind requires, named in the message.
#[derive(Clone, Copy, Debug, PartialEq, Eq, thiserror::Error)]
#[error("unsupported CPU: {0}")]
pub struct UnsupportedCpu(rind::cpu::MissingFeature);

/// Refuse a CPU that rind cannot run on, naming the missing feature.
///
/// Call this before using rind's primitives directly; [`provider`] and
/// [`install_default`] run it themselves.
pub fn check() -> Result<(), UnsupportedCpu> {
rind::cpu::check().map_err(UnsupportedCpu)
}

/// Return rind's rustls provider, refusing a CPU missing a required feature.
///
/// The process default is not consulted, so TLS works whether or not one was installed.
Expand Down Expand Up @@ -51,7 +40,7 @@ mod tests {
// The test hosts run rind, so the provider builds and every call returns the same one.
let first = provider().unwrap();
assert!(Arc::ptr_eq(&first, &provider().unwrap()));
check().unwrap();
crate::cpu::check().unwrap();
install_default().unwrap();
// A second install keeps the first provider and still succeeds.
install_default().unwrap();
Expand Down
Loading
Loading