Package net.sourceforge.jnlp.security
Class VariableX509TrustManager
- java.lang.Object
-
- net.sourceforge.jnlp.security.VariableX509TrustManager
-
public final class VariableX509TrustManager extends java.lang.ObjectThis 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
Fields Modifier and Type Field Description private java.util.List<javax.net.ssl.X509TrustManager>caTrustManagersprivate java.util.List<javax.net.ssl.X509TrustManager>certTrustManagersprivate java.util.List<javax.net.ssl.X509TrustManager>clientTrustManagersprivate static VariableX509TrustManagerinstanceprivate static LoggerLOGstatic java.lang.StringPKIXstatic java.lang.StringSUN_JSSEprivate java.util.List<java.security.cert.Certificate>temporarilyTrustedprivate java.util.List<java.security.cert.Certificate>temporarilyUntrusted
-
Constructor Summary
Constructors Constructor Description VariableX509TrustManager()Constructor initializes the system, user and custom stores
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private booleanaskUser(java.security.cert.X509Certificate[] chain, boolean isTrusted, boolean hostMatched, java.lang.String hostName)Ask user if the certificate should be trustedprivate voidcheckAllManagers(java.security.cert.X509Certificate[] chain, java.lang.String authType, java.net.Socket socket, javax.net.ssl.SSLEngine engine)Check system, user and custom trust manager.voidcheckTrustClient(java.security.cert.X509Certificate[] chain, java.lang.String authType, java.lang.String hostName)Check if client is trusted (no support for custom here, only system/user)voidcheckTrustServer(java.security.cert.X509Certificate[] chain, java.lang.String authType, java.lang.String hostName, javax.net.ssl.SSLSocket socket, javax.net.ssl.SSLEngine engine)Check if the server is trusted.protected java.security.cert.X509Certificate[]getAcceptedIssuers()static VariableX509TrustManagergetInstance()Return an instance of this singletonprivate javax.net.ssl.TrustManagerFactorygetTrustManagerFactory(java.security.KeyStore keyStore)private booleanisExplicitlyTrusted(java.security.cert.X509Certificate[] chain, java.lang.String authType)Return if the user explicitly trusted this i.e.private booleanisTemporarilyUntrusted(java.security.cert.Certificate c)Was this certificate explicitly untrusted by user?private voidloadManagers(java.util.List<java.security.KeyStore> keyStores, java.util.List<javax.net.ssl.X509TrustManager> managers)static voidmain(java.lang.String[] args)private voidtemporarilyTrust(java.security.cert.Certificate c)Temporarily trust the given cert (runtime)private voidtemporarilyUntrust(java.security.cert.Certificate c)Temporarily untrust the given cert - do not ask the user to trust this certificate again
-
-
-
Field Detail
-
LOG
private static final Logger LOG
-
PKIX
public static final java.lang.String PKIX
- See Also:
- Constant Field Values
-
SUN_JSSE
public static final java.lang.String SUN_JSSE
- See Also:
- Constant Field Values
-
instance
private static VariableX509TrustManager instance
-
temporarilyTrusted
private final java.util.List<java.security.cert.Certificate> temporarilyTrusted
-
temporarilyUntrusted
private final java.util.List<java.security.cert.Certificate> temporarilyUntrusted
-
certTrustManagers
private final java.util.List<javax.net.ssl.X509TrustManager> certTrustManagers
-
clientTrustManagers
private final java.util.List<javax.net.ssl.X509TrustManager> clientTrustManagers
-
caTrustManagers
private final java.util.List<javax.net.ssl.X509TrustManager> caTrustManagers
-
-
Method Detail
-
main
public static void main(java.lang.String[] args)
-
loadManagers
private void loadManagers(java.util.List<java.security.KeyStore> keyStores, java.util.List<javax.net.ssl.X509TrustManager> managers)
-
getTrustManagerFactory
private javax.net.ssl.TrustManagerFactory getTrustManagerFactory(java.security.KeyStore keyStore)
-
checkTrustClient
public void checkTrustClient(java.security.cert.X509Certificate[] chain, java.lang.String authType, java.lang.String hostName) throws java.security.cert.CertificateExceptionCheck if client is trusted (no support for custom here, only system/user)- Parameters:
chain- certificate chainauthType- type of authenticationhostName- hostname- Throws:
java.security.cert.CertificateException- if certificate is wrong
-
checkTrustServer
public void checkTrustServer(java.security.cert.X509Certificate[] chain, java.lang.String authType, java.lang.String hostName, javax.net.ssl.SSLSocket socket, javax.net.ssl.SSLEngine engine) throws java.security.cert.CertificateExceptionCheck 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:
java.security.cert.CertificateException- if certificate is wrong
-
checkAllManagers
private void checkAllManagers(java.security.cert.X509Certificate[] chain, java.lang.String authType, java.net.Socket socket, javax.net.ssl.SSLEngine engine) throws java.security.cert.CertificateExceptionCheck 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:
java.security.cert.CertificateException
-
isExplicitlyTrusted
private boolean isExplicitlyTrusted(java.security.cert.X509Certificate[] chain, java.lang.String authType)Return if the user explicitly trusted this i.e. in userTrustManager or temporarilyTrusted
-
getAcceptedIssuers
protected java.security.cert.X509Certificate[] getAcceptedIssuers()
-
temporarilyUntrust
private void temporarilyUntrust(java.security.cert.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(java.security.cert.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(java.security.cert.Certificate c)
Temporarily trust the given cert (runtime)- Parameters:
c- The certificate to trust
-
askUser
private boolean askUser(java.security.cert.X509Certificate[] chain, boolean isTrusted, boolean hostMatched, java.lang.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
-
-