A new crate, crates/relay (lib `relay`, binary wanderbooks-relay), with no ledger-* dependency. Routes an assistant's TLS connection by the server name in its ClientHello down the line an app holds open, forwarding encrypted bytes only; the line is yamux over TLS 1.3 on 443, the app proving its key with an Ed25519 signature bound to the session's TLS exporter and a fresh nonce. One durable table (SQLite: name, key, created, blocked), four-word names from a curated list of 1454 words (42.0 bits), a PROXY v2 header with the caller's address, an authoritative DNS server that publishes an app's ACME DNS-01 value for its own name only, and a list of certificate authorities served as data. Every table, queue, buffer and time is bounded. New dependencies, each permissive and passing cargo deny: yamux 0.14 (Apache-2.0 OR MIT; the multiplexer), hickory-proto 0.26 (MIT OR Apache-2.0; DNS wire format, std only), rusqlite (already in the tree), rustls and tokio-rustls (already in the tree, ring provider), ring (Ed25519, already in the tree); dev only: rcgen 0.14 (MIT OR Apache-2.0), proptest, tempfile. Added to the kernel-only lint list (no Decimal in the crate). Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
52 lines
2.0 KiB
Rust
52 lines
2.0 KiB
Rust
//! TLS settings for the line, both ends.
|
|
//!
|
|
//! The line is TLS 1.3 only. The relay presents its own certificate for
|
|
//! its own host; the app checks it against the roots it is given. The app
|
|
//! proves itself not with a certificate but with the signature of
|
|
//! [`crate::proto`], bound to this session's exporter.
|
|
|
|
use std::path::Path;
|
|
use std::sync::Arc;
|
|
|
|
use rustls::pki_types::pem::PemObject;
|
|
use rustls::pki_types::{CertificateDer, PrivateKeyDer};
|
|
use rustls::{ClientConfig, RootCertStore, ServerConfig};
|
|
|
|
fn provider() -> Arc<rustls::crypto::CryptoProvider> {
|
|
Arc::new(rustls::crypto::ring::default_provider())
|
|
}
|
|
|
|
/// The relay's server settings from a chain and key.
|
|
pub fn server_config(
|
|
chain: Vec<CertificateDer<'static>>,
|
|
key: PrivateKeyDer<'static>,
|
|
) -> Result<Arc<ServerConfig>, rustls::Error> {
|
|
let mut cfg = ServerConfig::builder_with_provider(provider())
|
|
.with_protocol_versions(&[&rustls::version::TLS13])?
|
|
.with_no_client_auth()
|
|
.with_single_cert(chain, key)?;
|
|
// A line is long-lived and proven by signature: no tickets to hold.
|
|
cfg.send_tls13_tickets = 0;
|
|
Ok(Arc::new(cfg))
|
|
}
|
|
|
|
/// The relay's server settings from PEM files.
|
|
pub fn server_config_from_files(cert: &Path, key: &Path) -> Result<Arc<ServerConfig>, String> {
|
|
let chain = CertificateDer::pem_file_iter(cert)
|
|
.map_err(|e| format!("{}: {e}", cert.display()))?
|
|
.collect::<Result<Vec<_>, _>>()
|
|
.map_err(|e| format!("{}: {e}", cert.display()))?;
|
|
let key = PrivateKeyDer::from_pem_file(key).map_err(|e| format!("{}: {e}", key.display()))?;
|
|
server_config(chain, key).map_err(|e| e.to_string())
|
|
}
|
|
|
|
/// An app's client settings: TLS 1.3, checking the relay against `roots`.
|
|
pub fn client_config(roots: RootCertStore) -> Result<Arc<ClientConfig>, rustls::Error> {
|
|
Ok(Arc::new(
|
|
ClientConfig::builder_with_provider(provider())
|
|
.with_protocol_versions(&[&rustls::version::TLS13])?
|
|
.with_root_certificates(roots)
|
|
.with_no_client_auth(),
|
|
))
|
|
}
|