Package com.jsgalactic.axiom.lifecycle
Class TlsOptions.Builder
java.lang.Object
com.jsgalactic.axiom.lifecycle.TlsOptions.Builder
- Enclosing class:
TlsOptions
Collects settings before
build(). Not thread-safe; the built options are immutable.-
Method Summary
Modifier and TypeMethodDescriptionbuild()Builds immutable options.certificateChain(Path file) Sets the PEM file holding the server certificate followed by its intermediate issuers.cipherSuites(List<String> suites) Replaces the enabled cipher suites, in preference order.Sets the clock that decides whether certificates are expired or not yet valid.minimumProtocol(TlsOptions.Protocol protocol) Sets the oldest TLS version a client may negotiate.privateKey(Path file) Sets the PEM file holding the private key of the server certificate.reloadInterval(Duration interval) Checks the key files for changes at this interval and reloads them when one changed, asServer.reloadTls()does.Turns on mutual TLS for anSSL contextwhose trust managers decide which client certificates are accepted.requireClientCertificates(Path trustedCertificates) Turns on mutual TLS for PEM key material: clients must present a certificate that chains to one of the certificates in the file, or the handshake fails.sslContext(Supplier<SSLContext> supplier) Takes the key material from anSSLContext, an alternative to the PEM files.
-
Method Details
-
certificateChain
Sets the PEM file holding the server certificate followed by its intermediate issuers.- Parameters:
file- the certificate chain file- Returns:
- this builder
-
privateKey
Sets the PEM file holding the private key of the server certificate. The key must be unencrypted PKCS#8 (BEGIN PRIVATE KEY) with an RSA, EC or Ed25519 key.- Parameters:
file- the private key file- Returns:
- this builder
-
sslContext
Takes the key material from anSSLContext, an alternative to the PEM files. The supplier is called at startup and on each reload, and may return a new context each time. The listener applies its own protocol, cipher suite, ALPN and client authentication settings to every connection; the context supplies the keys and, withrequireClientCertificates(), the trust anchors.- Parameters:
supplier- produces the context; must not return null- Returns:
- this builder
-
minimumProtocol
Sets the oldest TLS version a client may negotiate. The default is TLS 1.2, which is also the oldest version this API allows.- Parameters:
protocol- the minimum version- Returns:
- this builder
-
cipherSuites
Replaces the enabled cipher suites, in preference order. Names are JSSE standard names. Suites the JVM does not support are skipped, and at least one must remain.- Parameters:
suites- one or more suite names- Returns:
- this builder
- Throws:
IllegalArgumentException- if empty or a name is blank
-
requireClientCertificates
Turns on mutual TLS for PEM key material: clients must present a certificate that chains to one of the certificates in the file, or the handshake fails.- Parameters:
trustedCertificates- PEM file of the trusted client certificates or issuing authorities- Returns:
- this builder
-
requireClientCertificates
Turns on mutual TLS for anSSL contextwhose trust managers decide which client certificates are accepted.- Returns:
- this builder
-
reloadInterval
Checks the key files for changes at this interval and reloads them when one changed, asServer.reloadTls()does. A reload that fails is logged and counted, keeps the previous material, and is tried again at the next check. Off by default. It applies to PEM files only.- Parameters:
interval- 1 second to one day- Returns:
- this builder
- Throws:
IllegalArgumentException- if out of range
-
clock
Sets the clock that decides whether certificates are expired or not yet valid. Tests inject a fixed clock; the default is the system UTC clock.- Parameters:
clock- the clock- Returns:
- this builder
-
build
Builds immutable options.- Returns:
- the options
- Throws:
IllegalStateException- if the key material is not exactly one of PEM files (both a chain and a key) or an SSL context supplier, if a client trust file is combined with an SSL context, or if polling is combined with an SSL context
-