Package io.github.mahmoudimus.quic.tls
Class TlsConfig.Builder
java.lang.Object
io.github.mahmoudimus.quic.tls.TlsConfig.Builder
- Enclosing class:
TlsConfig
Builds a
TlsConfig. Builders are not thread-safe.-
Method Summary
Modifier and TypeMethodDescriptionalpnProtocols(String... protocols) The application protocols (ALPN).alpnSelector(Function<ClientHelloInfo, String> selector) Server: picks the application protocol from the client's offer, instead of thepreference list.build()Builds the configuration.certificate(CertifiedKey key) Server: one certificate for every connection.certificate(List<X509Certificate> chain, PrivateKey privateKey) Server: one certificate for every connection.certificateSelector(Function<ClientHelloInfo, CertifiedKey> selector) Server: picks the certificate for each ClientHello, typically by its server name.cipherSuites(CipherSuite... suites) The cipher suites to offer (client) or accept (server), most preferred first.clientAuth(ClientAuth clientAuth) Server: whether to ask the client for a certificate.Client: the certificate to present if the server asks for one.clientTrustManager(X509TrustManager trustManager) Server: the trust manager that validates client certificates.clock(InstantSource clock) The wall clock ticket ages and lifetimes are measured with.earlyData(boolean enabled) Turns 0-RTT on or off (off by default).earlyDataPolicy(EarlyDataPolicy policy) Server: decides whether to accept 0-RTT data the protocol allows.groups(NamedGroup... groups) The key exchange groups, most preferred first.maxHandshakeMessageSize(int bytes) The largest handshake message body accepted from the peer; a longer one fails withCRYPTO_BUFFER_EXCEEDED.secureRandom(SecureRandom random) The source of randomness for hello randoms, key shares and signatures.serverName(String serverName) Client: the server's host name or IP address.sessionTickets(Ticketer ticketer) Server: the ticketer that seals session tickets, which turns on NewSessionTicket and PSK resumption.signatureSchemes(SignatureScheme... schemes) The signature schemes allowed for CertificateVerify, most preferred first.ticketsPerConnection(int count) Server: how many tickets to send after each handshake.trustAllCertificates(boolean trustAll) Client: accept any server certificate without validating its chain or name.trustManager(X509TrustManager trustManager) Client: the trust manager that validates the server's chain.verifyHostname(boolean verify) Client: whether the server's certificate must be valid for the server name, as HTTPS endpoint identification checks.
-
Method Details
-
cipherSuites
The cipher suites to offer (client) or accept (server), most preferred first. A server picks the first of its suites the client offers.- Parameters:
suites- one or more suites- Returns:
- this builder
-
groups
The key exchange groups, most preferred first. A client sends a key share for the first and lists them all insupported_groups; a server takes the first of its groups the client sent a key share for, or else asks for the first of its groups the client supports with a HelloRetryRequest.- Parameters:
groups- one or more groups- Returns:
- this builder
-
signatureSchemes
The signature schemes allowed for CertificateVerify, most preferred first. Thersa_pkcs1schemes cannot be used here; a client always advertises them as well, for the signatures in certificate chains.- Parameters:
schemes- one or more schemes- Returns:
- this builder
- Throws:
IllegalArgumentException- if a scheme cannot sign a TLS 1.3 CertificateVerify
-
secureRandom
The source of randomness for hello randoms, key shares and signatures.- Parameters:
random- the random source- Returns:
- this builder
-
maxHandshakeMessageSize
The largest handshake message body accepted from the peer; a longer one fails withCRYPTO_BUFFER_EXCEEDED. This bounds what a session buffers per encryption level.- Parameters:
bytes- the limit, at least 4096 (RFC 9001 section 4.1.3)- Returns:
- this builder
-
alpnProtocols
The application protocols (ALPN). A client offers them in this order; a server without anALPN selectorpicks the first of them the client offered. QUIC requires ALPN, so a handshake without a common protocol fails withno_application_protocol. Characters map one to one onto bytes (ISO-8859-1).- Parameters:
protocols- the protocol names, such as"h3"- Returns:
- this builder
-
serverName
Client: the server's host name or IP address. A host name is sent as SNI; either is what the server's certificate is checked against.- Parameters:
serverName- the host name or IP literal- Returns:
- this builder
-
trustManager
Client: the trust manager that validates the server's chain. The default is the JDK's default trust manager.- Parameters:
trustManager- the trust manager- Returns:
- this builder
-
trustAllCertificates
Client: accept any server certificate without validating its chain or name. The CertificateVerify signature is still checked. For tests only.- Parameters:
trustAll- true to skip certificate validation- Returns:
- this builder
-
verifyHostname
Client: whether the server's certificate must be valid for the server name, as HTTPS endpoint identification checks. On by default.- Parameters:
verify- false to skip the host name check- Returns:
- this builder
-
clientCertificate
Client: the certificate to present if the server asks for one. Without one, the client answers a CertificateRequest with an empty Certificate.- Parameters:
key- the chain and key- Returns:
- this builder
-
certificate
Server: one certificate for every connection.- Parameters:
key- the chain and key- Returns:
- this builder
-
certificate
Server: one certificate for every connection.- Parameters:
chain- the certificates, end-entity firstprivateKey- the end-entity certificate's private key- Returns:
- this builder
-
certificateSelector
Server: picks the certificate for each ClientHello, typically by its server name. It runs on the thread that feeds the session its handshake data. Returning null fails the handshake withunrecognized_nameif the client sent a name,handshake_failureotherwise.- Parameters:
selector- the selector- Returns:
- this builder
-
alpnSelector
Server: picks the application protocol from the client's offer, instead of thepreference list. Returning null, or a protocol the client did not offer, fails the handshake withno_application_protocol.- Parameters:
selector- the selector- Returns:
- this builder
-
clientAuth
Server: whether to ask the client for a certificate.- Parameters:
clientAuth- the policy- Returns:
- this builder
-
clientTrustManager
Server: the trust manager that validates client certificates. The default is the JDK's default trust manager.- Parameters:
trustManager- the trust manager- Returns:
- this builder
-
clock
The wall clock ticket ages and lifetimes are measured with.- Parameters:
clock- the clock- Returns:
- this builder
-
earlyData
Turns 0-RTT on or off (off by default). A client then offers early data when its ticket allows it; a server issues tickets that allow early data and accepts it when thepolicydoes. 0-RTT data can be replayed; seeEarlyDataPolicy.- Parameters:
enabled- whether to use 0-RTT- Returns:
- this builder
-
sessionTickets
Server: the ticketer that seals session tickets, which turns on NewSessionTicket and PSK resumption. Servers that share a ticketer accept each other's tickets. Not used withclient authentication.- Parameters:
ticketer- the ticketer, or null to issue no tickets (the default)- Returns:
- this builder
-
ticketsPerConnection
Server: how many tickets to send after each handshake. Clients use each ticket once, so more tickets allow more resumed connections before the next full handshake.- Parameters:
count- 0 to 16; 2 by default- Returns:
- this builder
-
earlyDataPolicy
Server: decides whether to accept 0-RTT data the protocol allows. The default, withearlyDataon, isEarlyDataPolicy.antiReplay(); compose an application veto with it rather than replacing it.- Parameters:
policy- the policy- Returns:
- this builder
-
build
Builds the configuration.- Returns:
- the immutable configuration
-