Class VariableX509TrustManager
java.lang.Object
net.sourceforge.jnlp.security.VariableX509TrustManager
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 Summary
FieldsModifier and TypeFieldDescriptionprivate final List<X509TrustManager> private final List<X509TrustManager> private final List<X509TrustManager> private static VariableX509TrustManagerprivate static final Loggerstatic final Stringstatic final Stringprivate final List<Certificate> private final List<Certificate> -
Constructor Summary
ConstructorsConstructorDescriptionConstructor initializes the system, user and custom stores -
Method Summary
Modifier and TypeMethodDescriptionprivate booleanaskUser(X509Certificate[] chain, boolean isTrusted, boolean hostMatched, String hostName) Ask user if the certificate should be trustedprivate voidcheckAllManagers(X509Certificate[] chain, String authType, Socket socket, SSLEngine engine) Check system, user and custom trust manager.voidcheckTrustClient(X509Certificate[] chain, String authType, String hostName) Check if client is trusted (no support for custom here, only system/user)voidcheckTrustServer(X509Certificate[] chain, String authType, String hostName, SSLSocket socket, SSLEngine engine) Check if the server is trusted.protected X509Certificate[]static VariableX509TrustManagerReturn an instance of this singletonprivate TrustManagerFactorygetTrustManagerFactory(KeyStore keyStore) private booleanisExplicitlyTrusted(X509Certificate[] chain, String authType) Return if the user explicitly trusted this i.e.private booleanWas this certificate explicitly untrusted by user?private voidloadManagers(List<KeyStore> keyStores, List<X509TrustManager> managers) static voidprivate voidTemporarily trust the given cert (runtime)private voidTemporarily untrust the given cert - do not ask the user to trust this certificate again
-
Field Details
-
LOG
-
PKIX
- See Also:
-
SUN_JSSE
- See Also:
-
instance
-
temporarilyTrusted
-
temporarilyUntrusted
-
certTrustManagers
-
clientTrustManagers
-
caTrustManagers
-
-
Constructor Details
-
VariableX509TrustManager
public VariableX509TrustManager()Constructor initializes the system, user and custom stores
-
-
Method Details
-
main
-
loadManagers
-
getTrustManagerFactory
-
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 chainauthType- type of authenticationhostName- 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 chainauthType- The auth type algorithmhostName- The expected hostName that the server should havesocket- 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 chainauthType- The authentication typesocket- the SSLSocket being used for the connectionengine- the SSLEngine being used for the connection- Throws:
CertificateException
-
isExplicitlyTrusted
Return if the user explicitly trusted this i.e. in userTrustManager or temporarilyTrusted -
getAcceptedIssuers
-
temporarilyUntrust
Temporarily untrust the given cert - do not ask the user to trust this certificate again- Parameters:
c- The certificate to trust
-
isTemporarilyUntrusted
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
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
Return an instance of this singleton- Returns:
- The instance
-