Expand description
§coqui-peer-tls
Mutual-TLS identity between peers, with no RPC layer. Each side has a self-issued
certificate and tells the other only its fingerprint; you get back an authenticated, encrypted
byte stream and the verified peer. This is the TLS method of
coqui-peer, which holds the peer id, the trust store
and the sans-IO handshake trait; this crate adds X.509 and rustls. See the
documentation.
Status: alpha.
0.0.0-alpha.1is a pre-release: the API may change in any release before 1.0.
§Features
- Certificate ids: a certificate’s id is
coqui-peer’sPeerId, the SHA-256 of the certificate, writtensha256:<hex>; SHA-384, SHA-512 and SHA-1 pins can be read. - Trust you choose: pinned fingerprints, a CA with subject and SAN globs, both, or any certificate whose key the peer proves; a client can verify a server by the web PKI, with a CA bundle or the operating system’s verifier, alone or beside pins.
- Pairing: an untrusted peer that proves its key is recorded as waiting in the trust store, and an operator accepts it by fingerprint; or two devices pair by an invitation, a PIN or a device flow on a connection of their own, bound to it by the TLS exporter.
- Key rotation: a peer announces its successor certificate; store-backed pins promote it once proven and retire the old one after a window you choose.
- Policy:
intermediateby default (TLS 1.2 and 1.3), withmodern(TLS 1.3 only) andlegacypresets; settings looser than the default are reported as data, never refused. A policy can carry an access control list, applied by address at theClientHelloand by fingerprint before the trust store. - Your own stack: the rustls verifiers as values, configurations around a verifier of your own, per-connection configurations for quinn, and the identity’s chain and key.
- Streams: blocking
dialandacceptover anyRead + Write, async ones over tokio; the sans-IOcoqui-peermethod for message transports. - Server TLS: the server proves itself by certificate and the client authenticates inside
the channel (browsers over
wss://and WebTransport); short-lived identities for WebTransport’sserverCertificateHashes. - Nothing installs a process-wide crypto provider, and nothing reads a file or the environment unless you give it a path.
§Installation
cargo add coqui-peer-tls@0.0.0-alpha.1| Feature | Adds | Needed for | Default |
|---|---|---|---|
generate | rcgen, time | Identity::generate, generate_valid_for, generate_with, open_or_create | off |
fields | x509-parser | CertificateFields: a certificate’s names, SANs (UPN included), serial and validity, as a map to pick identities from | off |
ca | fields, globset | Trust::Ca, Trust::PinnedOrCa, CaPolicy | off |
tokio | tokio, tokio-rustls, coqui-peer/tokio | module asynch: async dial, accept, pairing and rotation | off |
pin | coqui-peer/pin | PIN pairing | off |
serde | serde, coqui-peer/serde, coqui-net-acl/serde | reading and writing a Policy and PeerId as text | off |
acl | coqui-net-acl | an access control list inside a Policy | off |
platform-roots | rustls-platform-verifier | Roots::platform: servers verified by the operating system | off |
aws-lc | rustls’s aws-lc-rs provider (AWS-LC, built from C) | crypto = "aws-lc": ML-KEM key exchange, ML-DSA, the cnsa-2.0 profile | off |
fips | aws-lc and rustls’s fips (AWS-LC’s FIPS module) | the fips-140-3-validated profile; global, see Development | off |
Rust 1.89 or later. A default build depends on coqui-peer, rustls (0.23.27 or later, ring
provider) and rustls-webpki, which rustls already uses.
§Quick start
Dial a peer you pinned, with an identity read from a file:
use std::sync::Arc;
use coqui_peer_tls::{Identity, Pins, Trust, client_config, dial};
let me = Identity::read("identity.pem".as_ref())?.expect("an identity file");
let trust = Trust::Pinned(Pins::fixed([
"sha256:630dcd2966c4336691125448bbb25b4ff412a49c732db2c8abc1b8581bd710dd".parse()?,
]));
let config = client_config(&me, &trust, &[b"my-protocol/1"])?; // default: TLS 1.2 and 1.3
let socket = std::net::TcpStream::connect("192.0.2.7:7000")?;
let (stream, peer) = dial(Arc::new(config), socket)?;
println!("connected to {}", peer.fingerprint);Dial a server with a CA-issued certificate, verified by the web PKI for its name:
use std::sync::Arc;
use coqui_peer_tls::{Roots, Trust, client_config_without_identity, dial_named};
use rustls::pki_types::ServerName;
let trust = Trust::Roots(Roots::bundle_file("/etc/ssl/certs/ca-certificates.crt"));
let config = client_config_without_identity(&trust, &[b"my-protocol/1"])?;
let name = ServerName::try_from("example.com")?.to_owned();
let socket = std::net::TcpStream::connect("example.com:443")?;
let (stream, server) = dial_named(Arc::new(config), name, socket)?;Roots are a different trust model from pins: any server one of the roots issued a certificate for the dialled name is trusted. The chain, the dates and the name are always checked.
§API overview
| Module | Purpose |
|---|---|
coqui_peer_tls | Identity, PeerIdentity; Trust, Pins, CaPolicy, Roots and their verifiers; Policy; the configuration builders, Built, and ServerConfigs / ConnectionConfig for a configuration per connection; dial, accept and their variants; Tls and TlsHandshake; pairing over TLS; rotation; PeerError, Refusal; re-exports of coqui-peer’s ids, store and Weakening. |
coqui_peer_tls::asynch | Async dial, accept, pairing and rotation over tokio (tokio). |
coqui_peer_tls::pair | coqui-peer’s pairing exchange, re-exported. |
coqui_peer_tls::acl | coqui-net-acl, re-exported (acl). |
§Profiles and policy
Policy::default() is intermediate and works as it is. Policy::modern(), intermediate()
and legacy() are plain values; start from one and change any public field. weakened() lists
every setting looser than the default, as data; client_config_with and server_config_with
return that list beside the configuration. Nothing is printed.
| Field | modern | intermediate (default) | legacy |
|---|---|---|---|
tls_versions | 1.3 | 1.2, 1.3 | 1.2, 1.3 |
cipher_suites, kx_groups | all the provider has | same | same |
pin_digests | sha256, sha384, sha512 | same | plus sha1 |
check_validity | true | true | true |
allow_chain_when_pinned | false | false | false |
allow_resumption | false | false | false |
require_ems | true | true | false |
waiting (per_source / total / rerecord) | 16 / 1000 / 60 s | same | same |
acl | none | none | none |
Allowing TLS 1.2 costs nothing between peers that speak 1.3: they negotiate 1.3, and TLS 1.3’s
downgrade protection keeps an attacker from forcing 1.2; every 1.2 suite offered is ECDHE with
an AEAD cipher, and the extended master secret is required. modern refuses peers that speak
only 1.2; choose it to keep client certificates from passive observers (TLS 1.2 sends them
unencrypted) when such peers exist. legacy adds SHA-1 pins and TLS 1.2 without the extended
master secret; a peer that cannot take a TLS 1.3 ClientHello at all is served by
tls_versions = ["1.2"].
§Cipher profiles
Apart from the versions, a policy lists the algorithm profiles it allows
(cipher_profiles, default ["mozilla"]) and the provider that runs them (crypto, ring or,
with the aws-lc feature, aws-lc). What is offered is the union of the allowed profiles in
the order of the first listed, narrowed to the versions, the provider and any cipher_suites /
kx_groups list; a version left with no suite is dropped. Each profile is named for exactly
what it claims:
| Profile | What it is |
|---|---|
mozilla | Mozilla’s server-side TLS guideline 6.0, intermediate. The default. |
fips-140-3-compliant | FIPS 140-3 approved algorithm selection; not a validated module. |
fips-140-2-compliant | The same without the ML-KEM groups, which only a 140-3 module can have approved; not a validated module. Every FIPS 140-2 certificate is on the CMVP Historical List since September 2026. |
fips-140-3-validated | AWS-LC’s FIPS module; validated only as its CMVP certificate and tested operating environments state. Needs the fips feature; a configuration rustls does not report FIPS is refused. |
cnsa-1.0 | CNSSP 15 / RFC 9151 as far as rustls goes: AES-256-GCM, P-384, SHA-384. |
cnsa-2.0 | CNSA 2.0 (ML-KEM-1024, ML-DSA-87, AES-256) in the shape of draft-becker-cnsa2-tls-profile-05; needs crypto = "aws-lc". |
The CNSA profiles need an identity of your own (P-384 or RSA 3072+, or ML-DSA-87): generated identities are P-256. The crate’s API header lists every algorithm and what each profile does not meet.
Session resumption is off in every preset: rustls does not check the peer’s certificate again on a resumed session, so a peer removed from the trust store could reconnect on a session it held. TLS 1.0, 1.1 and non-AEAD suites cannot be offered; MD5 pins are never accepted.
use coqui_peer_tls::{Digest, Identity, Policy, Trust, server_config_with};
let identity = Identity::read("identity.pem".as_ref())?.expect("an identity file");
let mut policy = Policy::default();
policy.pin_digests.push(Digest::Sha1);
policy.waiting.per_source = 4;
let built = server_config_with(&identity, &Trust::AnyWithKeyProof, &[b"my-protocol/1"], &policy)?;
for weaker in &built.weakened {
eprintln!("{} = {} (default: {})", weaker.setting, weaker.value, weaker.strict);
}With the serde feature a Policy also reads and writes a versioned text form (version 1),
in the format you choose:
policy_version = 1
profile = "intermediate" # a built-in preset to start from
tls_versions = ["1.2", "1.3"]
cipher_profiles = ["mozilla"] # allowed algorithm profiles
crypto = "ring" # or "aws-lc", with the `aws-lc` feature
pin_digests = ["sha256", "sha384", "sha512"]
allow_resumption = false
require_ems = true
waiting_per_source = 16
waiting_total = 1000
waiting_rerecord_secs = 60
[acl] # optional, with the `acl` feature; see coqui-net-acl
default = "deny"
[[acl.rule]]
action = "permit"
source = "10.9.0.0/16"
destination = "10.6.20.5"Every key is optional; absent keys keep the preset. Committed examples for every preset are in
the repository’s tests/vectors/policy/.
§Access control
A policy’s access control list (feature acl) is applied by every server configuration built
under it: by address when the ClientHello arrives, before any certificate is sent, and by the
client certificate’s fingerprint before the trust store is consulted, so a denied client is
never recorded as waiting. Fingerprint rules may be written in any spelling a PeerId parses.
The refusals are Refusal::AddressDenied, PeerDenied and AddressUnknown. For quinn,
ServerConfigs builds a configuration per connection from its addresses, sharing one session
cache, and keeps the refusal its handshake ended with (ConnectionConfig::refusal), since
quinn reports only the alert; Trust::client_cert_verifier_for is the verifier alone, and
Policy::admits_address decides before the handshake. Under optional client authentication a
rule naming a fingerprint never admits a client.
§Limits
- A waiting entry is recorded only after the peer proves it holds the certificate’s key. Each
entry stores the address the handshake came from, and the per-source caps
(
waiting.per_source,waiting.rerecord) apply per IPv4 address or per IPv6 /64. - Not provided: a handshake probe, a helper for reading and writing one connection from two threads, and QUIC datagrams.
§Development
ALL=generate,ca,tokio,pin,serde,acl,platform-roots,fields,aws-lc # every feature but fips
cargo fmt --all --check
cargo clippy --all-targets --features $ALL -- -D warnings
cargo +1.89 clippy --all-targets --features $ALL -- -D warnings
cargo test --features $ALL
RUSTDOCFLAGS="-D warnings" cargo doc --no-deps --features $ALL
cargo +nightly-2026-09-21 public-api --features $ALL -sss --color never | diff -u tools/public-api.txt -
cargo test --features fips # needs CMake and Goaws-lc builds AWS-LC from C (a C compiler; clang on Windows ARM64). fips builds AWS-LC’s
FIPS module (aws-lc-fips-sys: CMake and Go, and on Windows bindgen with libclang, NASM and
Ninja) and has global effect: rustls’s fips feature changes defaults for every crate in the
build. If bindgen fails with ParseQuote is not implemented for syn::File, cargo paired bindgen
0.73 with prettyplease 0.3; cargo update -p prettyplease --precise 0.2.37 fixes the lockfile.
The fips feature adds no item to the API, so the snapshot is taken without it.
§Releasing
This project follows Semantic Versioning and keeps a
CHANGELOG.md.
Pushing a tag matching v* runs the release workflow: the tests and a strict documentation
build gate a GitHub release, marked as a pre-release when the version has a - suffix. The
crate is published to crates.io with cargo publish by a maintainer, after coqui-net-acl and
coqui-peer.
§License
MPL-2.0; see LICENSE.
Re-exports§
pub use coqui_net_acl as acl;acl
Modules§
- asynch
tokio - Async dial and accept over
tokio-rustls, for anyAsyncRead + AsyncWritestream. - pair
- Pairing: how a joiner and a responder come to accept each other’s keys, over any channel.
Structs§
- Built
- A built configuration and the settings of its
Policythat are looser than the default policy’s, so a host can surface them. Nothing is printed by this crate. - CaPolicy
ca - A CA trust policy: certificates signed by the CAs in a PEM file whose subject and subject alternative names match optional globs.
- Certificate
Fields fields - The identifying fields of a certificate (feature
fields). - Clock
- The wall clock a
TrustStoreor a pairing desk reads for expiry and retirement times. - Connection
Config - The server configuration of one connection, and the refusal its handshake ended with.
- Identity
- This side’s certificate and its private key, with the intermediates that issued the certificate when it has any.
- Invitation
- A one-time pairing secret: whoever presents it may pair, until it expires or its uses run out.
- Invitation
Options - How
TrustStore::invitemakes an invitation. - KeyMaterial
- The public key material a method gives the trust store for one peer, with the name of the method that understands it.
- Name
fields - A distinguished name: its text as x509-parser displays it (
CN=a, O=b) and its attributes in certificate order, each(short name, value). - Pair
Config - The TLS side of pairing: the device’s own
Policyand the ALPN that marks a pairing connection. Nothing here sets a TLS version or suite; the policy does. - Pair
Dial - A joiner’s pairing connection, past the point where it has something to show (or done).
- Peer
Client Verifier - Verifies the certificate a client presents to a listening server.
- PeerId
- Who a peer is: the hash of its public key or certificate, the whole of what one peer is told of another.
- Peer
Identity - A verified peer: the certificate the other side proved it holds the key of.
- Peer
Server Verifier - Verifies the certificate a server presents to a dialing client.
- Pins
- A set of pinned certificate fingerprints: fixed, or the accepted peers of a
TrustStore. - Policy
- What a TLS configuration and a trust decision are allowed to do.
- Random
- A source of cryptographically secure random bytes: invitation secrets, user codes and pairing slots are drawn from it.
- Roots
- The certificate authorities a client verifies a server against: the chain up to one of them, every certificate’s validity dates and the server name the client dialled.
- Rotation
Options - How an accepted peer’s key is replaced by its successor.
- Server
Configs - The server configurations of one listener whose connections reach rustls without this crate’s accept helpers, such as quinn, which runs the verifier on threads of its own and takes a configuration per incoming connection.
- Tls
- The TLS method: client and server configurations, each optional, that start handshakes.
- TlsHandshake
- One TLS handshake, driven by the caller: rustls’s own sans-IO connection.
- Trust
Store - Persistent trust: peers an operator accepted, peers that were turned away and wait to be accepted (pairing), open invitations, and announced successor keys.
- Waiting
Entry - A peer waiting for acceptance.
- Waiting
Limits - Bounds on the waiting queue.
- Weakening
- A setting looser than its strict value, as plain data for the caller to show or log.
Enums§
- Cipher
Profile - A named set of algorithms a
Policyallows: cipher suites, key-exchange groups and signature schemes, each profile exactly what its name claims. - Crypto
- The crypto provider a policy’s configurations run on.
- Digest
- The algorithm a
PeerIdis made with: the<alg>of its<alg>:<hash>text. - Peer
Error - Sanitized failures while loading, storing or using a peer identity. No message holds key
material; only
CaFilenames a path, the file it could not use. - Refusal
- Why this side refused a peer: its certificate, or its addresses under a policy’s access control list.
- Responder
Trust - How a joiner checks the responder’s certificate on the pairing connection.
- Rotation
Event - A change of a peer’s key, for the caller to report as it chooses.
- San
fields - A subject alternative name.
- TlsVersion
- A TLS protocol version. rustls offers 1.2 and 1.3 only: SSL 3, TLS 1.0 and 1.1 cannot be offered by this crate, and asking for them is an error, never ignored.
- Trust
- Whom to trust.
Constants§
- CLIENT_
AUTH_ SETTING - The
Weakening::settinga server configuration without client authentication reports. - EXPORTER_
LABEL - The label of the TLS exporter (RFC 8446 section 7.5, RFC 5705) that binds a pairing exchange to its connection; 32 bytes with an empty context.
- METHOD
- The method name under which certificates are kept in a
TrustStore. - PAIR_
ALPN - The default ALPN of a pairing connection.
- POLICY_
VERSION - The version of the serialized form of
Policy(policy_version). - SERVER_
NAME - The server name
dialandTlsHandshake::clientsend, and the subjectAltName of generated identities. Pinned trust is by fingerprint, so the name carries no meaning there;Rootscheck the name, so dial a server they verify withdial_named.
Traits§
- Peer
Addr - A stream that can name the remote address it is connected to.
- Read
Timeout - A blocking transport whose reads can be bounded in time, as the
_untilloops need to end at their deadline. - Trust
Store Ext - Certificate-shaped access to a
TrustStore. - Write
Timeout - A blocking transport whose writes can be bounded in time, as the
_untilloops need when the peer stops reading.
Functions§
- accept
- Accepts a peer over
io, completing the handshake before returning. - accept_
at accept_fromwith the local address the connection arrived at as well, which a policy’s access control list reads for rules that name a destination or a port.- accept_
from acceptfor a stream that is not aTcpStream, with the address it came from given.- announce
- Announces
successoras the next identity of this side, over a connection the current identity authenticated: one framedRotationmessage. What follows on the connection is the caller’s protocol. - certificate_
key - A DER-encoded certificate as the trust store’s key material: method
tls, PEM labelCERTIFICATE. - client_
config - A client configuration under the default policy (TLS 1.2 and 1.3) that presents
identityand verifies the server bytrust: pinned, byRootsfor the name dialled (dial_named), pinned or roots, or any certificate with key proof. - client_
config_ with - A client configuration under
policy. Session resumption is off unlessPolicy::allow_resumptionis set, which then keeps rustls’s default session cache. - client_
config_ with_ verifier - A client configuration under
policythat verifies the server withverifier, a verifier of the host’s own (one of this crate’s wrapped, for example). It presentsidentityand its intermediates, or no certificate forNone, and handles versions, suites, groups, the extended master secret, ALPN and resumption asclient_config_withdoes. - client_
config_ without_ identity - A client configuration under the default policy that presents no certificate, for a
server built with
server_config_without_client_auth. The server is verified bytrustexactly as inclient_config; this side proves itself, if at all, inside the encrypted channel. A server that requires a client certificate refuses it. - client_
config_ without_ identity_ with client_config_without_identityunderpolicy, with the same handling of versions, suites, groups and resumption asclient_config_with.- crypto_
provider - rustls’s ring provider with its defaults. The configurations built here take the provider a
Policyselects (Policy::crypto_provider); nothing in this crate installs a process-wide default. - default_
server_ name SERVER_NAMEas the name rustls takes, for a host that dials with a connector of its own (rustls, tokio-rustls, quinn) and trusts by pins.- dial
- Dials a peer over
io, completing the handshake before returning. - dial_
named dialsendingnameas the server name: the host the client dialled, for a server verified byRoots, which check that its certificate is for that name (a DNS name, or an IP address the certificate names). Pinned trust ignores the name.- pair_
accept - Accepts a pairing connection over
streamasidentityand runs the responder’s side to its end: redeeming an invitation fromstore, taking PINs and decisions fromdesk(this call blocks while the operator decides), and accepting the joiner’s certificate instore. The address ofstreamis the source the desk throttles by. - pair_
accept_ from pair_acceptfor a stream that is not a TCP stream, with the address it came from given.- pair_
client_ config - The client configuration of a pairing connection for
pairing: an invitation pins the inviter; otherwiseresponderdecides. - pair_
dial - Dials a pairing connection over
streamasidentityand runspairinguntil there is something toshow, or to its end;PairDial::finishcompletes it. - pair_
server_ config - The server configuration of a pairing connection:
identity, any client certificate whose key is proven,config’s ALPN and policy. A server on one port serves it to clients that offer the pairing ALPN (asynch::accept_with) and its own configuration to the rest. - random
- A
Randomdrawing from the TLS provider’s secure random source, for aPairingDeskand invitations. - receive_
announcement - Reads an
announcement fromsender(the verified peer of this connection) and records it instoreas the pending successor ofsender’s certificate. Returns the successor’s id. The next handshake that proves it promotes it, unless the store’s rotation options require approval. - server_
config - A server configuration under the default policy that presents
identityand requires a client certificate trusted bytrust. Session resumption is off: every connection verifies the client’s certificate. - server_
config_ with - A server configuration under
policy, shared by every connection it accepts. Session resumption is off unlessPolicy::allow_resumptionis set, which then keeps rustls’s default session cache and TLS 1.3 tickets. - server_
config_ with_ verifier - A server configuration under
policythat verifies clients withverifier, a verifier of the host’s own (one of this crate’s wrapped, for example). It presentsidentityand its intermediates, and handles versions, suites, groups, the extended master secret, ALPN, resumption and the access control list asserver_config_withdoes. - server_
config_ without_ client_ auth - A server configuration under the default policy that presents
identityand asks for no client certificate: the server proves itself, the client does not at the TLS layer. - server_
config_ without_ client_ auth_ with server_config_without_client_authunderpolicy, with the same handling of versions, suites, groups, ALPN and resumption asserver_config_with.- with_
addresses with_sourcewith the local address the connection arrived at as well, which a policy’s access control list needs for rules that name a destination or a port.- with_
source - Runs
workwithsourceas the address the verifiers record waiting entries under, and decide a policy’s access control list by, with no local address.