public class SSLEepGetextends EepGet
HTTPS only, no retries, no min and max size options, no timeout option As of 0.9.45, supports redirect to https (redirect to http will still fail). Fails on bad certs (must have a valid cert chain) Self-signed certs or CAs not in the JVM key store must be loaded to be trusted.

Since 0.8.2, loads additional trusted CA certs from $I2P/certificates/ssl/ and ~/.i2p/certificates/ssl/

Since 0.9.33, HTTP proxies (CONNECT) supported. Proxy auth not supported.

  • Field Details

    • _saveCerts

      private int _saveCerts
      If true, save cert chain on cert error.
    • _bypassVerification

      private boolean _bypassVerification
      If true, don't do hostname verification.
    • _commandLine

      private boolean _commandLine
      True if called from main(), used for logging.
    • _sslContext

      private final SSLContext _sslContext
      May be null if init failed.
    • _stm

      May be null if init failed.
    • _proxyType

      private final SSLEepGet.ProxyType _proxyType
      The type of proxy used for the connection.
    • _forceDoH

      private int _forceDoH
      Zero to ask the config, one off, two on, three on with IPv6.
    • CERT_DIR

      private static final String CERT_DIR
      Directory holding the saved SSL certificates.
      See Also:
    • PROP_USE_DNS_OVER_HTTPS

      private static final String PROP_USE_DNS_OVER_HTTPS
      Config key for DNS over HTTPS lookups.
      See Also:
    • DEFAULT_USE_DNS_OVER_HTTPS

      private static final boolean DEFAULT_USE_DNS_OVER_HTTPS
      Whether DNS over HTTPS is used unless configured.
      See Also:
  • Constructor Details

    • SSLEepGet

      public SSLEepGet(I2PAppContext ctx, OutputStream outputStream, String url)
      A new SSLEepGet with a new SSLState.
      Parameters:
      ctx - the router context supplying config, logging, and the cert directories
      outputStream - stream to write the response body to; takes precedence over outputFile
      url - the https URL to fetch; redirects back to http are not followed
    • SSLEepGet

      public SSLEepGet(I2PAppContext ctx, OutputStream outputStream, String url, SSLEepGet.SSLState state)
      Create an SSLEepGet that writes to a stream, using an existing SSL state.
      Parameters:
      ctx - the router context supplying config, logging, and the cert directories
      outputStream - stream to write the response body to; takes precedence over outputFile
      url - the https URL to fetch; redirects back to http are not followed
      state - an SSLState retrieved from a previous SSLEepGet with getSSLState(), or null. This makes repeated fetches from the same host MUCH faster, and prevents repeated key store loads even for different hosts.
    • SSLEepGet

      public SSLEepGet(I2PAppContext ctx, OutputStream outputStream, String url, long maxSize, SSLEepGet.SSLState state)
      Create an SSLEepGet that writes to a stream, using an existing SSL state, limited to a maximum response size.
      Parameters:
      ctx - the router context supplying config, logging, and the cert directories
      outputStream - stream to write the response body to; takes precedence over outputFile
      url - the https URL to fetch; redirects back to http are not followed
      maxSize - The maximum size of the response
      state - an SSLState retrieved from a previous SSLEepGet with getSSLState(), or null. This makes repeated fetches from the same host MUCH faster, and prevents repeated key store loads even for different hosts.
    • SSLEepGet

      public SSLEepGet(I2PAppContext ctx, String outputFile, String url)
      A new SSLEepGet with a new SSLState.
      Parameters:
      ctx - the router context supplying config, logging, and the cert directories
      outputFile - path of the file to write the response body to; takes precedence over outputStream
      url - the https URL to fetch; redirects back to http are not followed
    • SSLEepGet

      public SSLEepGet(I2PAppContext ctx, String outputFile, String url, SSLEepGet.SSLState state)
      Create an SSLEepGet that writes to a file, using an existing SSL state.
      Parameters:
      ctx - the router context supplying config, logging, and the cert directories
      outputFile - path of the file to write the response body to; takes precedence over outputStream
      url - the https URL to fetch; redirects back to http are not followed
      state - an SSLState retrieved from a previous SSLEepGet with getSSLState(), or null. This makes repeated fetches from the same host MUCH faster, and prevents repeated key store loads even for different hosts.
    • SSLEepGet

      public SSLEepGet(I2PAppContext ctx, SSLEepGet.ProxyType type, String proxyHost, int proxyPort, OutputStream outputStream, String url)
      Use a proxy.
      Parameters:
      ctx - the router context supplying config, logging, and the cert directories
      type - proxy scheme used to reach the origin, or NONE for a direct connection
      proxyHost - Must be valid hostname or literal IPv4/v6. If type is INTERNAL, set to "localhost".
      proxyPort - Must be valid, -1 disallowed, no default. If type is INTERNAL, set to 4444.
      outputStream - stream to write the response body to; takes precedence over outputFile
      url - the https URL to fetch; redirects back to http are not followed
    • SSLEepGet

      public SSLEepGet(I2PAppContext ctx, SSLEepGet.ProxyType type, String proxyHost, int proxyPort, OutputStream outputStream, String url, SSLEepGet.SSLState state)
      Use a proxy.
      Parameters:
      ctx - the router context supplying config, logging, and the cert directories
      type - proxy scheme used to reach the origin, or NONE for a direct connection
      proxyHost - Must be valid hostname or literal IPv4/v6. If type is INTERNAL, set to "localhost".
      proxyPort - Must be valid, -1 disallowed, no default. If type is INTERNAL, set to 4444.
      outputStream - stream to write the response body to; takes precedence over outputFile
      url - the https URL to fetch; redirects back to http are not followed
      state - an SSLState retrieved from a previous SSLEepGet with getSSLState(), or null. This makes repeated fetches from the same host MUCH faster, and prevents repeated key store loads even for different hosts.
    • SSLEepGet

      public SSLEepGet(I2PAppContext ctx, SSLEepGet.ProxyType type, String proxyHost, int proxyPort, String outputFile, String url)
      Use a proxy.
      Parameters:
      ctx - the router context supplying config, logging, and the cert directories
      type - proxy scheme used to reach the origin, or NONE for a direct connection
      proxyHost - Must be valid hostname or literal IPv4/v6. If type is INTERNAL, set to "localhost".
      proxyPort - Must be valid, -1 disallowed, no default. If type is INTERNAL, set to 4444.
      outputFile - path of the file to write the response body to; takes precedence over outputStream
      url - the https URL to fetch; redirects back to http are not followed
    • SSLEepGet

      public SSLEepGet(I2PAppContext ctx, SSLEepGet.ProxyType type, String proxyHost, int proxyPort, String outputFile, String url, SSLEepGet.SSLState state)
      Use a proxy.
      Parameters:
      ctx - the router context supplying config, logging, and the cert directories
      type - proxy scheme used to reach the origin, or NONE for a direct connection
      proxyHost - Must be valid hostname or literal IPv4/v6. If type is INTERNAL, set to "localhost".
      proxyPort - Must be valid, -1 disallowed, no default. If type is INTERNAL, set to 4444.
      outputFile - path of the file to write the response body to; takes precedence over outputStream
      url - the https URL to fetch; redirects back to http are not followed
      state - an SSLState retrieved from a previous SSLEepGet with getSSLState(), or null. This makes repeated fetches from the same host MUCH faster, and prevents repeated key store loads even for different hosts.
    • SSLEepGet

      private SSLEepGet(I2PAppContext ctx, String outputFile, OutputStream outputStream, String url, long maxSize, SSLEepGet.SSLState state)
      Output file and output stream: one null, one non-null.
      Parameters:
      ctx - the application context, may be null
      outputFile - the file to write the content to, or null to use the stream
      outputStream - the stream to write the content to, or null to use the file
      url - the https URL to fetch
      maxSize - the maximum content size in bytes, -1 for unlimited
      state - an SSLState retrieved from a previous SSLEepGet with getSSLState(), or null. This makes repeated fetches from the same host MUCH faster, and prevents repeated key store loads even for different hosts.
  • Method Details

    • initSSLContext

      private SSLContext initSSLContext()
      Loads certs from location of javax.net.ssl.keyStore property, else from $JAVA_HOME/lib/security/jssacacerts, else from $JAVA_HOME/lib/security/cacerts.

      Then adds certs found in the $I2P/certificates/ssl/ directory and in the ~/.i2p/certificates/ssl/ directory.

      Returns:
      null on failure
    • saveCerts

      private static void saveCerts(String host, SSLEepGet.SavingTrustManager stm)
      Modified from http://blogs.sun.com/andreas/resource/InstallCert.java
      Parameters:
      host - the server host name, used to name the saved .crt files
      stm - the trust manager holding the captured server certificate chain
    • getSSLState

      public SSLEepGet.SSLState getSSLState()
      Pass this back to the next SSLEepGet constructor for faster fetches. This may be called either after the constructor or after the fetch.
      Returns:
      the SSL state
    • forceDNSOverHTTPS

      public void forceDNSOverHTTPS(boolean on)
      Override the config setting, force DNSoverHTTPS on or off Call before the fetch.
      Parameters:
      on - true to force DoH on, false to force it off, overriding eepget.useDNSOverHTTPS
    • forceDNSOverHTTPS

      public void forceDNSOverHTTPS(boolean on, boolean forceIPv6)
      Override the config setting, force DNSoverHTTPS on or off Call before the fetch.
      Parameters:
      on - true to force DoH on, false to force it off, overriding eepget.useDNSOverHTTPS
      forceIPv6 - use IPv6 for BOTH the connection to the DoH server AND for the queried address. on must be true.
    • doFetch

      protected void doFetch(SocketTimeout timeout) throws IOException
      Fetch the resource over SSL.
      Overrides:
      doFetch in class EepGet
      Parameters:
      timeout - may be null
      Throws:
      IOException - on IO error
    • sendRequest

      protected void sendRequest(SocketTimeout timeout) throws IOException
      Send the HTTP request over SSL.
      Overrides:
      sendRequest in class EepGet
      Parameters:
      timeout - may be null
      Throws:
      IOException - on IO error
    • httpProxyConnect

      private void httpProxyConnect(String host, int port) throws IOException
      Connect to a HTTP proxy. Proxy address must be in _proxyHost and _proxyPort. Side effects: Sets _proxy, _proxyIn, _proxyOut, and other globals via readHeaders().
      Parameters:
      host - what the proxy should connect to
      port - what the proxy should connect to
      Throws:
      IOException - if connecting to the proxy fails
    • internalHttpProxyConnect

      private void internalHttpProxyConnect(String host, int port) throws IOException
      Connect to a HTTP proxy. Proxy address must be in _proxyHost and _proxyPort. Side effects: Sets _proxy, _proxyIn, _proxyOut, and other globals via readHeaders().
      Parameters:
      host - what the proxy should connect to
      port - what the proxy should connect to, probably 4444
      Throws:
      IOException - if connecting to the proxy fails
    • httpProxyConnect

      private void httpProxyConnect(Socket proxy, String host, int port) throws IOException
      Connect to a HTTP proxy. Proxy address must be in _proxyHost and _proxyPort. Side effects: Sets _proxyIn, _proxyOut, and other globals via readHeaders().
      Parameters:
      proxy - the connected proxy socket to send the CONNECT request over
      host - what the proxy should connect to
      port - what the proxy should connect to
      Throws:
      IOException - if the proxy header read times out or the proxy response is not 200
    • socksProxyConnect

      private void socksProxyConnect(boolean isSocks5, String host, int port) throws IOException
      Connect to a SOCKS proxy. Proxy address must be in _proxyHost and _proxyPort. Side effects: Sets _proxy, _proxyIn, _proxyOut, and other globals via readHeaders().
      Parameters:
      isSocks5 - true to use SOCKS 5, false for SOCKS 4
      host - what the proxy should connect to
      port - what the proxy should connect to
      Throws:
      IOException - if connecting to the proxy fails, or credentials are set while using SOCKS 4