Class TlsOptions

java.lang.Object
com.jsgalactic.axiom.lifecycle.TlsOptions

public final class TlsOptions extends Object
TLS settings of one HTTP listener, passed with ListenerOptions.Builder.tls(TlsOptions). A listener with TLS options speaks HTTPS and nothing else on its port; a client that sends plain text is disconnected.

Key material comes from exactly one source: a PEM certificate chain file and an unencrypted PKCS#8 PEM private key file (pem(Path, Path)), or an SSLContext supplier (TlsOptions.Builder.sslContext(Supplier)) for keys that live in a keystore, a hardware module or a secret manager. Material is validated when the listener starts, so a missing file, a malformed PEM, a key that does not match the certificate or an expired certificate stops startup with a TlsConfigurationException and never prints key content. The files are read once at startup and again by Server.reloadTls() or the optional polling (see TlsOptions.Builder.reloadInterval(Duration)); a reload swaps the material for new connections atomically and leaves open connections alone. A reload that fails keeps the previous material.

Protocols and ciphers. TLS 1.2 is the default minimum and TLS 1.3 is used whenever the client supports it. Only forward-secret authenticated-encryption suites are enabled by default (see DEFAULT_CIPHER_SUITES). The listener advertises ALPN http/1.1 only.

Client certificates are not requested by default. TlsOptions.Builder.requireClientCertificates(Path) turns on mutual TLS: a client without a certificate issued by one of the trusted certificates is refused during the handshake.

Instances are immutable and may be shared by several listeners.

  • Field Details

    • DEFAULT_CIPHER_SUITES

      public static final List<String> DEFAULT_CIPHER_SUITES
      The cipher suites enabled by default: TLS 1.3 suites and, for TLS 1.2, ECDHE key exchange with AES-GCM or ChaCha20-Poly1305. Suites the JVM does not support are skipped.
  • Method Details

    • pem

      public static TlsOptions pem(Path certificateChain, Path privateKey)
      Options that serve a PEM certificate chain and private key with every other setting at its default.
      Parameters:
      certificateChain - PEM file holding the server certificate first, then its issuers
      privateKey - PEM file holding the matching unencrypted PKCS#8 private key
      Returns:
      the options
      Throws:
      NullPointerException - if a path is null
    • builder

      public static TlsOptions.Builder builder()
      Starts a builder with every setting at its default and no key material.
      Returns:
      a new builder
    • toBuilder

      public TlsOptions.Builder toBuilder()
      Starts a builder holding these options' values.
      Returns:
      a new builder
    • certificateChain

      public Optional<Path> certificateChain()
      Returns:
      the PEM certificate chain file, or empty when an SSL context supplier is used
    • privateKey

      public Optional<Path> privateKey()
      Returns:
      the PEM private key file, or empty when an SSL context supplier is used
    • sslContext

      public Optional<Supplier<SSLContext>> sslContext()
      Returns:
      the SSL context supplier, or empty when PEM files are used
    • minimumProtocol

      public TlsOptions.Protocol minimumProtocol()
      Returns:
      the oldest TLS version a client may use
    • cipherSuites

      public List<String> cipherSuites()
      Returns:
      the enabled cipher suites in preference order
    • clientAuth

      public TlsOptions.ClientAuth clientAuth()
      Returns:
      whether clients must present a certificate
    • clientTrust

      public Optional<Path> clientTrust()
      Returns:
      the PEM file of certificates that client certificates must chain to, if any
    • reloadInterval

      public Optional<Duration> reloadInterval()
      Returns:
      how often the key files are checked for changes, or empty when they are not polled
    • clock

      public Clock clock()
      Returns:
      the clock that decides whether a certificate is valid
    • toString

      public String toString()
      Describes the options without file names or key material.
      Overrides:
      toString in class Object