Package biopb.tensor

Class TlsTrusts

java.lang.Object
biopb.tensor.TlsTrusts

public final class TlsTrusts extends Object
Resolve the TlsTrust for a grpc+tls:// location.

The Java twin of Python's biopb.tensor._tls. A server on a private LAN typically presents a self-signed or private-CA certificate that the JDK's default trust store does not know, so the caller says how to trust it, in one of three modes:

  • caPem -- trust exactly these PEM bytes (a private CA, or the server's own leaf). Never touches the network and never consults the pin store.
  • expectedFingerprint -- fetch the presented leaf and require its SHA-256 to equal this, on every resolve: a wrong certificate is refused on the first connect, which trust-on-first-use cannot do. Also bypasses the pin store.
  • neither -- trust on first use, the SSH host-key model: the first certificate seen for a host:port is pinned in the TlsPinStore and used as the anchor; a different one later is a TlsPinMismatchException. Protects against an attacker who arrives after pinning, not one already in the path at first connect.

Trust and hostname verification are separate checks. An anchor supplies the first; the JDK still matches the dialed name against the certificate's SANs, so a certificate that pins fine still fails every handshake if the server never listed the name clients dial. When the anchor is the certificate the server presents, that second check is redundant -- the presented certificate must be the pinned one, so there is no "different but validly-issued certificate" for a name check to exclude -- and a name the certificate does list is substituted as the overrideHostname. A CA anchor keeps the name check, which is load-bearing there. The substitution never disables verification: the chain is still checked against the anchor.

One thing a plain FlightClient cannot give you: an expired anchor fails every handshake with no reason the caller can read. TlsCertExpiredException is raised here instead, where the answer is known.

  • Method Summary

    Modifier and Type
    Method
    Description
    static TlsTrust
    anchored(byte[] anchorPem)
    A trust that carries anchorPem to a consumer to resolve for itself, as a SerializedTensor.tls_anchor does.
    static TlsTrust
    concrete(org.apache.arrow.flight.Location location, TlsTrust trust)
    trust as something a client can use for location.
    static String
    fingerprint(byte[] pem)
    SHA-256 of a certificate's DER body, lowercase hex: the id a fingerprint names.
    static boolean
    isTlsLocation(org.apache.arrow.flight.Location location)
    Whether location is a grpc+tls:// address, so trust applies.
    static TlsTrust
    resolve(org.apache.arrow.flight.Location location, byte[] caPem, String expectedFingerprint, TlsPinStore pins)
    Resolve the trust for location.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • resolve

      public static TlsTrust resolve(org.apache.arrow.flight.Location location, byte[] caPem, String expectedFingerprint, TlsPinStore pins) throws IOException
      Resolve the trust for location.
      Parameters:
      location - the server; a non-TLS location needs no trust and gets TlsTrust.NONE with no network
      caPem - trust exactly these PEM bytes; wins over the other modes
      expectedFingerprint - SHA-256 of the server's certificate DER, hex (colon-grouped or bare, any case)
      pins - where trust-on-first-use remembers pins; needed only when neither caPem nor expectedFingerprint is given
      Throws:
      TlsPinMismatchException - the server presents a certificate that contradicts the pin or the configured fingerprint
      TlsCertExpiredException - the anchor has expired
      IllegalArgumentException - trust on first use was asked for with no pins
      IOException - the server could not be reached to read its certificate
    • anchored

      public static TlsTrust anchored(byte[] anchorPem)
      A trust that carries anchorPem to a consumer to resolve for itself, as a SerializedTensor.tls_anchor does. No network here, so the sender never has to reach the address the consumer will dial. Null or empty (the sender trusted the system store) is the system store again.
    • concrete

      public static TlsTrust concrete(org.apache.arrow.flight.Location location, TlsTrust trust)
      trust as something a client can use for location.

      An anchored(byte[]) trust is the sender's decision about which certificate; the name check is this process's, because it depends on the name dialed here. When the anchor is the leaf the server presents, a name the certificate does not list is rescued with an override; a CA anchor keeps the SAN check. A probe that cannot run leaves no override, so a working connection never breaks here.

    • isTlsLocation

      public static boolean isTlsLocation(org.apache.arrow.flight.Location location)
      Whether location is a grpc+tls:// address, so trust applies.
    • fingerprint

      public static String fingerprint(byte[] pem)
      SHA-256 of a certificate's DER body, lowercase hex: the id a fingerprint names.