broadcast-auth
Shared multi-scheme authentication for RTSP and HTTP clients and
servers: one [Credentials] model — Basic, Digest, Bearer —
one client-side challenge->response helper, and one server-side
challenge+verify type (Verifier, plus a reverse-proxy Forwarded
scheme), so every credentialed client and server in the workspace
(rtsp-runtime; multimux's HTTP input adapters and its shared
output-auth gate) answers/issues a WWW-Authenticate challenge through the
same code instead of re-implementing auth per client or per origin.
Why
Auth is not transport-specific. RTSP (RFC 2326 §14/§16 reuses HTTP's Basic and
Digest verbatim), TS-over-HTTP, HLS-pull, and any other credentialed origin all
face the same handful of schemes. Before this crate, rtsp-runtime carried its
own Credentials/Authenticator pair wrapping http-auth; this crate pulls
that logic out so it can be shared, and adds Bearer (RFC 6750), which
http-auth does not cover (Bearer needs no challenge-response round-trip at
all).
Schemes
- Basic (RFC 7617) / Digest (RFC 7616) — challenge parsing and the
Digest response hash are delegated to the mature
http-authcrate.Authenticatorkeeps the negotiated state alive across a session so Digest'snc(nonce count) advances correctly on every subsequent request. - Bearer (RFC 6750) — no challenge needed; the
Authorizationvalue is alwaysBearer <token>. - Forwarded (server-side only) — trusts that a fronting reverse proxy
has already authenticated the caller and forwards the authenticated
username in a configured header (conventionally
X-Forwarded-User); noCredentials/challenge-response round-trip at all. Safe only behind a trusted reverse proxy that strips any client-supplied copy of that header before forwarding — seeVerifier::forwarded's doc comment.
Credentials::new(user, pass) doesn't commit to Basic or Digest: the
responder answers whichever scheme the server's challenge actually advertises
(http-auth's challenge parser decides the wire scheme from the challenge
text, not from the Credentials variant).
Client and server
- Client (
respond/Authenticator): given aWWW-Authenticatechallenge received from a server, compute theAuthorizationvalue to answer it — see Usage below. - Server (
server::Verifier): given a configuredCredentials+ realm,Verifier::challenge()renders theWWW-Authenticatevalue for a401andVerifier::verify(&RequestContext)checks an incoming request. Basic/Bearer compare in constant time; Digest recomputes the response hash (RFC 7616 §3.4.1) and also checks the client's claimeduriagainst the actual request URI. This is the production verifier behindmultimux's shared output-auth gate. RequestContextcarries the method/URI/body (needed to compute or verify a response) plus, for server-side use, every request header (headers, looked up case-insensitively viaRequestContext::header) and the transport peer address (peer_addr) — what lets aVerifierscheme see beyondAuthorization(the mechanismVerifier::forwardedneeds). Both default to empty/NoneviaRequestContext::new, so a client-side 2-arg call site is unaffected.
Usage
use ;
// Negotiate once from the server's 401 WWW-Authenticate value...
let mut auth = from_challenge?;
// ...then answer every subsequent request with the same Authenticator so
// Digest's nc advances (RFC 7616 §3.3):
let value = auth.authorization?;
assert!;
# Ok::
Bearer skips the challenge entirely:
use Credentials;
let creds = bearer;
A one-shot helper (respond) is available for callers that don't need to keep
an Authenticator around for more than one request.
Scope
In: the Credentials model, challenge parsing (via http-auth) + response
computation for Basic/Digest, Bearer's stateless header value, a stateful
Authenticator for session reuse.
Out: transport IO (sockets, header framing) — that's each client's own job
(rtsp-runtime's session engine, multimux's HTTP adapters). Out: credential
storage/config parsing — callers build Credentials from URL userinfo or
their own config.
Consumers
rtsp-runtime— re-exportsbroadcast_auth::Credentialsasrtsp_runtime::Credentialsand delegates itsAuthenticatorto this crate (RFC 2326 §14).ll-hls-runtime—client::tokio_client::TokioClientauthenticates via this crate'sCredentials/Authenticator(Basic/Digest/Bearer).multimux— client-side: itsTsHttp/HlsPull/Rtspinput adapters (source::http_auth) answer upstream challenges via this crate'sAuthenticator. Server-side:Config::output_auth's shared output-auth gate (every/{stream}/…route, across every configured route) is built on this crate'sserver::Verifier, including theForwardedscheme for a reverse-proxy deployment.