Record Class TlsServerIdentity

java.lang.Object
java.lang.Record
org.microproxy.TlsServerIdentity
Record Components:
serverName - the host name sent as SNI, or null for the default; never an IP address (SNI carries host names only)
verificationHost - the host name or IP address the certificate must be valid for, or null for the server name

public record TlsServerIdentity(String serverName, String verificationHost) extends Record
Who the proxy expects at the other end of a TLS connection to a server, when that is not simply the request's host: the server name it sends in the ClientHello (SNI, RFC 6066 section 3) and the host name the server's certificate is verified against (HTTPS endpoint identification, RFC 9110 section 4.3.4). HttpFilters.proxyToServerTlsIdentity(java.lang.String) returns one for requests whose connection goes somewhere other than the name they are for: a reverse-proxy route or a chained setup that dials an IP address or an internal load balancer, while the service behind it presents a certificate for its public name.

A null component keeps the default: the server name is the request's host (or, for an intercepted CONNECT to an IP address, the server name the client sent), and the verification host is the server name. Setting the server name alone thus verifies the certificate against that name too; setting the verification host alone keeps the default SNI.

The identity is part of what keeps server connections apart: a connection made with one identity is never reused, pooled or coalesced (HTTP/2, RFC 9113 section 9.1.1) for a request with another.

  • Constructor Details

    • TlsServerIdentity

      public TlsServerIdentity(String serverName, String verificationHost)
      Checks and normalizes the names: lower case, without a trailing dot.
      Parameters:
      serverName - the host name sent as SNI, or null for the default
      verificationHost - the host the certificate must be valid for, or null for the server name
      Throws:
      IllegalArgumentException - if serverName is not a valid SNI host name, a component is blank, or both are null
  • Method Details

    • of

      public static TlsServerIdentity of(String serverName)
      An identity whose server name and verification host are both serverName.
      Parameters:
      serverName - the host name sent as SNI and that the certificate must be valid for
      Returns:
      the identity
    • of

      public static TlsServerIdentity of(String serverName, String verificationHost)
      An identity with the given server name and verification host.
      Parameters:
      serverName - the host name sent as SNI, or null for the default
      verificationHost - the host the certificate must be valid for, or null for the server name
      Returns:
      the identity
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with Objects::equals(Object,Object).
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • serverName

      public String serverName()
      Returns the value of the serverName record component.
      Returns:
      the value of the serverName record component
    • verificationHost

      public String verificationHost()
      Returns the value of the verificationHost record component.
      Returns:
      the value of the verificationHost record component