English
tls
TLS the way sing-box 1.14.4 builds it from options (common/tls): clients for outbounds and downloads, servers for inbounds, the root store. rustls with ring; our own TLS 1.3 (ours-tls13) where rustls does not fit: uTLS fingerprints, REALITY, fragmentation, kTLS.
| Crate | ours-mod-tls, modules/system/tls |
| Binary feature | the module is always in the list; tls → ours-mod-tls/implementation, unstable-ktls → ours-mod-tls/unstable-ktls; hysteria, hysteria2, tuic, dns-quic, dns-h3, transport-xhttp → ours-mod-tls/quic |
| Crate features | implementation (rustls, ring, ours-tls13/implementation, …), unstable-ktls (+ ours-tls13/unstable-ktls), quic (ours-quic: QUIC TLS; turns on implementation) |
requires
Nothing. The module is required by everyone who builds TLS or takes the root store: http, anytls, shadowtls, trojan, vless, hysteria, hysteria2, tuic, router (remote rule-sets), group (probes), dns (DoT/DoH/DoQ), adblock, subscriptions, mixed, transport, transport-xhttp, and shadowsocks with v2ray-plugin.
provides
Provide::Unit(Store)— oneCertificatesstore per instance (OnceLock).buildprepares new roots (prepare) and publishes the TLS factory over the store,ours_tls_options::Tls(Tls::of(services)): HTTP download clients andavailable(), whichours-http,router,group,adblockandsubscriptionstake, and clients and servers over streams (client,client_sealedfor ShadowTLS v3,server,browser), whichhttp,mixed,anytls,trojan,vless,shadowtlsand thev2ray-pluginofshadowsockstake — none of them names this module. With thequicfeature it also publishes QUIC TLS over the same store,ours_quic::tls::Factory, which the QUIC protocols, the QUIC transport anddnstake. The store itself is not in the services.commitreplaces the roots and turns on file watching;closestops the watching. A failed reload does not touch the roots.Provide::Point("tls"),Provide::Block { block: "tls", key: "inbound" | "outbound" }— the entities'tlsblock, decoded byours_tls_options::block: presence enables TLS, the server name issni,reality,utls,echare their own nested blocks;reality.handshake.serverishost:port(split_address, without a port — an error). Fields that make sense only together are blocks (GROUPED):fragment: {packet, record, fallback_delay},ktls: {tx, rx},spoof: {sni, method}, on the serverclient_auth: {mode, certificate, certificate_path, public_key_sha256};loweredspreads them into flat sing-box option names, and rejects the same names in the config with a hint (`kernel_tx` is `ktls.tx`).Provide::Section { key: "certificate" }— the roots section, one component.
Syntax: the tls block, certificate.
Dependencies
ours-tls13 (our own TLS 1.3, REALITY, uTLS, kTLS — through ours-ktls-sys), ours-net-sys (watching files), ours-api, ours-codec, ours-json, rustls, tokio-rustls, ring, x25519-dalek, arc-swap, base64 (REALITY keys, base64url).
Design
src/lib.rs— the shared parts:TcpTls(Own— TLS 1.3 of our own stream, in the process or in the kernel;Other— older versions through rustls), kTLS warnings as in sing-box, versions/cipher suites/curves in Go's terms, PEM.src/client.rs—Client(std_client.go): the rustls andtls13(uTLS/REALITY) engines.with_compatibility— the protocol reports whether kTLS benefits it;http/http_pool— download clients;quic(alpn)— the rustls configuration for QUIC protocols (uTLS, REALITY, fragmentation, kTLS are rejected there);with_session_id— our own session ID in the ClientHello (uTLS only).ClientStream::into_kernelhands over a stream the relay can splice.src/server.rs—Server(std_server.go), the REALITY server, rereading the certificate, the key and the CA when the files change.src/roots.rs—Certificates: the roots clients verify servers by; files and directories are reread when they change.src/module.rs—MODULEand theStoreunit;src/certificate.rs— the section's options.src/contract.rs— the contract's traits:TlsClientforClient,TlsServerforServer,ours_tls_options::TlsFactoryforCertificates. Over TCP, TLS 1.3 of our own stream comes back asStream::Spliced(KernelStream), anything older asStream::Boxed;trojanandvlesstakeours_tls13::KernelStreamout of the stream once per connection (Vision, kTLS).src/quic.rs(quic+implementation) —ours_quic::tls::QuicTlsforCertificates: the configurations ofClient::quic/quic_chromeandServer::quicasClientTls/ServerTls.src/disabled.rs— a build withoutimplementation: the types are kept, the handshake fails before sockets are opened, the streams are uninhabited types (the splice interface remains).
kTLS
With unstable-ktls, the TLS 1.3 keys are handed to the kernel after the handshake (ktls.tx/ktls.rx, in the options kernel_tx/kernel_rx), and the relay moves data as over an ordinary socket. Without the feature, kernel_* are rejected when the client or the server is built ("kTLS is not built in"). Protocols with Vision (VLESS) enable kTLS for a direction when Vision finishes padding.
Tests
modules/system/tls/tests/: handshake.rs (clients and servers from sing-box options through a pipe), ktls.rs (kTLS on loopback, KeyUpdate, record_size_limit, warnings; needs the tls kernel module), reality.rs; unit tests in roots.rs, disabled.rs. The block's tests are in crates/tls-options/src/block.rs.