Class VariableX509TrustManager

java.lang.Object
net.sourceforge.jnlp.security.VariableX509TrustManager

public final class VariableX509TrustManager extends Object
This class implements an X509 Trust Manager. The certificates it trusts are "variable", in the sense that it can dynamically, and temporarily support different certificates that are not in the keystore.
  • Field Details

  • Constructor Details

    • VariableX509TrustManager

      public VariableX509TrustManager()
      Constructor initializes the system, user and custom stores
  • Method Details

    • main

      public static void main(String[] args)
    • loadManagers

      private void loadManagers(List<KeyStore> keyStores, List<X509TrustManager> managers)
    • getTrustManagerFactory

      private TrustManagerFactory getTrustManagerFactory(KeyStore keyStore)
    • checkTrustClient

      public void checkTrustClient(X509Certificate[] chain, String authType, String hostName) throws CertificateException
      Check if client is trusted (no support for custom here, only system/user)
      Parameters:
      chain - certificate chain
      authType - type of authentication
      hostName - hostname
      Throws:
      CertificateException - if certificate is wrong
    • checkTrustServer

      public void checkTrustServer(X509Certificate[] chain, String authType, String hostName, SSLSocket socket, SSLEngine engine) throws CertificateException
      Check if the server is trusted.

      First, existing stores are checked to see if the certificate is trusted. Next, if the certificate is not explicitly trusted by the user, a host name check is performed. The user is them prompted as needed.

      Parameters:
      chain - The cert chain
      authType - The auth type algorithm
      hostName - The expected hostName that the server should have
      socket - The SSLSocket in use (may be null)
      engine - The SSLEngine in use (may be null)
      Throws:
      CertificateException - if certificate is wrong
    • checkAllManagers

      private void checkAllManagers(X509Certificate[] chain, String authType, Socket socket, SSLEngine engine) throws CertificateException
      Check system, user and custom trust manager.

      This method is intended to work with both, JRE6 and JRE7. If socket and engine are null, it assumes that the call is for JRE6 (i.e. not javax.net.ssl.X509ExtendedTrustManager which is Java 7 specific). If either of those are not null, it will assume that the caTrustManagers are javax.net.ssl.X509ExtendedTrustManager instances and will invoke their check methods.

      Parameters:
      chain - The certificate chain
      authType - The authentication type
      socket - the SSLSocket being used for the connection
      engine - the SSLEngine being used for the connection
      Throws:
      CertificateException
    • isExplicitlyTrusted

      private boolean isExplicitlyTrusted(X509Certificate[] chain, String authType)
      Return if the user explicitly trusted this i.e. in userTrustManager or temporarilyTrusted
    • getAcceptedIssuers

      protected X509Certificate[] getAcceptedIssuers()
    • temporarilyUntrust

      private void temporarilyUntrust(Certificate c)
      Temporarily untrust the given cert - do not ask the user to trust this certificate again
      Parameters:
      c - The certificate to trust
    • isTemporarilyUntrusted

      private boolean isTemporarilyUntrusted(Certificate c)
      Was this certificate explicitly untrusted by user?
      Parameters:
      c - the certificate
      Returns:
      true if the user was presented with this certificate and chose not to trust it
    • temporarilyTrust

      private void temporarilyTrust(Certificate c)
      Temporarily trust the given cert (runtime)
      Parameters:
      c - The certificate to trust
    • askUser

      private boolean askUser(X509Certificate[] chain, boolean isTrusted, boolean hostMatched, String hostName)
      Ask user if the certificate should be trusted
      Parameters:
      chain - The certificate chain
      Returns:
      user's response
    • getInstance

      public static VariableX509TrustManager getInstance()
      Return an instance of this singleton
      Returns:
      The instance