Class KeyStoreSslContextSource

java.lang.Object
org.microproxy.tls.KeyStoreSslContextSource
All Implemented Interfaces:
SslContextSource

public class KeyStoreSslContextSource extends Object implements SslContextSource
An SslContextSource for the proxy's own TLS listener, presenting the certificate of a key store entry (PKCS#12 or JKS): the HTTPS and HTTP/2 listener (withSslContextSource), and, through getKeyMaterial(java.lang.String), the HTTP/3 listener of a reverse proxy. Peer certificates are checked against the JDK's default trust store, which matters only with client authentication.

 MicroProxy.bootstrap()
         .withReverseProxy("https://backend.internal")
         .withSslContextSource(new KeyStoreSslContextSource(Path.of("site.p12"), "secret".toCharArray()))
         .withHttp3(true)
         .start();
 
  • Constructor Details

    • KeyStoreSslContextSource

      public KeyStoreSslContextSource(Path keyStore, char[] password) throws IOException
      Presents the first key entry of a key store file, whose type (PKCS#12 or JKS) is detected.
      Parameters:
      keyStore - the key store file
      password - the key store's password, which is also the entry's
      Throws:
      IOException - if the file cannot be read, or holds no usable key entry
    • KeyStoreSslContextSource

      public KeyStoreSslContextSource(KeyStore keyStore, String alias, char[] password) throws IOException
      Presents a key store entry.
      Parameters:
      keyStore - the loaded key store
      alias - the key entry's alias, or null for the first key entry
      password - the entry's password
      Throws:
      IOException - if the key store has no such key entry, or it cannot be read
  • Method Details

    • getSslContext

      public SSLContext getSslContext()
      Description copied from interface: SslContextSource
      Returns the TLS context for this connection.
      Specified by:
      getSslContext in interface SslContextSource
      Returns:
      the TLS context for this connection
    • getKeyMaterial

      public KeyMaterial getKeyMaterial(String serverName)
      The entry's chain and key, whatever name the client asks for.
      Specified by:
      getKeyMaterial in interface SslContextSource
      Parameters:
      serverName - the server name the client asked for (SNI), or null if it sent none
      Returns:
      the chain and key to present, or null if this source has none