Documentation
¶
Overview ¶
Package testserver provides hermetic servers for testing the TLS prober without touching the network: real crypto/tls servers whose versions, suites and groups are configurable, and a scripted raw-TCP server for replies the standard library cannot produce (SSLv2/SSLv3, garbage, stalls).
Test and demo support only: nothing in the shipped cipherhorizon binary imports it (cmd/demo-targets, a development tool, does).
Index ¶
- Variables
- func Alert(desc byte) []byte
- func AnswerAnyTLS13() func([]byte) []byte
- func Certificates(t testing.TB) (ec, rsaC tls.Certificate)
- func Legacy(version uint16, order []uint16, clientPref bool) func([]byte) []byte
- func LoadCertificates() (ec, rsaC tls.Certificate, err error)
- func MLDSACertificate(t testing.TB) tls.Certificate
- func ServerHello(version, suite uint16) []byte
- type CertKind
- type Config
- type Server
Constants ¶
This section is empty.
Variables ¶
var CertValidity = 24 * time.Hour
CertValidity is how long the test certificates are valid. Tests keep the short default (their expiry findings depend on it); the demo targets set a realistic one before the first server starts.
Functions ¶
func AnswerAnyTLS13 ¶
AnswerAnyTLS13 answers every ClientHello with a TLS 1.3 ServerHello (TLS_AES_128_GCM_SHA256, an X25519 share), whatever it offered: a server that does not choose its certificate by the client's signature_algorithms. It cannot complete a handshake.
func Certificates ¶
func Certificates(t testing.TB) (ec, rsaC tls.Certificate)
Certificates returns the test ECDSA and RSA certificates (self-signed).
func Legacy ¶
Legacy speaks exactly one protocol version. order is the server's preference; clientPref makes it pick the first acceptable suite in the CLIENT's order instead.
func LoadCertificates ¶
func LoadCertificates() (ec, rsaC tls.Certificate, err error)
LoadCertificates returns the ECDSA and RSA certificates (self-signed).
func MLDSACertificate ¶
func MLDSACertificate(t testing.TB) tls.Certificate
MLDSACertificate returns the test ML-DSA-65 certificate (self-signed).
func ServerHello ¶
ServerHello is a ServerHello plus ServerHelloDone record choosing suite.
Types ¶
type CertKind ¶
type CertKind int
CertKind selects which certificates a server presents.
const ( CertECDSA CertKind = iota // one ECDSA P-256 certificate CertRSA // one RSA-2048 certificate CertBoth // both; the suite chosen decides which is used // CertMLDSA is one ML-DSA-65 certificate (FIPS 204), usable only in TLS 1.3. CertMLDSA // CertECDSAAndMLDSA is an ECDSA P-256 and an ML-DSA-65 certificate; the client's // signature_algorithms decide which is used, the ECDSA one when both would do. CertECDSAAndMLDSA )
The certificate kinds.
type Config ¶
type Config struct {
MinVersion, MaxVersion uint16
Suites []uint16 // TLS 1.2 and earlier; TLS 1.3 suites are fixed by Go
Curves []tls.CurveID
Cert CertKind
ALPN []string
// ClientAuth configures whether the server asks for (or requires) a client
// certificate. Zero value (tls.NoClientCert) asks for none.
ClientAuth tls.ClientAuthType
// HTTPResponse, when set, makes the server read one request after the TLS
// handshake completes and write back this function's result (nil closes
// without answering), mirroring StartScript. Used to test the optional
// post-handshake HTTP check.
HTTPResponse func(request []byte) []byte
// Chain, when set, replaces Cert: the server presents exactly these
// certificates (with any OCSPStaple and SignedCertificateTimestamps they carry).
Chain []tls.Certificate
// NoSNI, when set, is presented to clients that send no server_name.
NoSNI *tls.Certificate
// Addr is the listen address; empty means 127.0.0.1:0. Restarting a server on
// the same address with a different Config simulates an endpoint being changed.
Addr string
// StartTLS, when set (smtp, imap, pop3, ftp, xmpp, ldap, postgres), makes every connection
// begin in that protocol's plain text and switch to TLS when asked. RefuseStartTLS makes the
// server say no instead.
StartTLS string
RefuseStartTLS bool
// SelectCertFirst makes the server choose its certificate from the first ClientHello and
// refuse with an alert when none fits the offered signature_algorithms, before any
// HelloRetryRequest. OpenSSL works this way; Go's server sends a HelloRetryRequest first.
SelectCertFirst bool
}
Config configures a TLS server. Zero values mean crypto/tls defaults.
type Server ¶
type Server struct {
Host string
Port int
Addr string // host:port
// contains filtered or unexported fields
}
Server is a running test server.
func Listen ¶
Listen is Start for programs that are not tests (the demo targets). The caller closes the server.
func ListenScript ¶
ListenScript is StartScript for programs that are not tests. The caller closes the server.
func Start ¶
Start runs a TLS server on 127.0.0.1 until the test ends. Each connection is handshaken and closed.
func StartScript ¶
StartScript runs a raw TCP server that reads one chunk from the client and answers with reply(chunk), then closes. A nil reply closes without answering; stall keeps the connection open and silent until the client gives up.