wjhk.jupload2.upload
Class InteractiveTrustManager

java.lang.Object
  extended by wjhk.jupload2.upload.InteractiveTrustManager
All Implemented Interfaces:
TrustManager, X509TrustManager, CallbackHandler

public class InteractiveTrustManager
extends Object
implements X509TrustManager, CallbackHandler

An implementation of X509TrustManager which can operate in different modes. If mode is NONE, then any server certificate is accepted and no certificate-based client authentication is performed. If mode is SERVER, then server certificates are verified and if verification is unsuccessful, a dialog is presented to the user, which allows accepting a certificate temporarily or permanently. If mode is CLIENT, then certificate-based client authentication is performed. Finally, there is a mode STRICT, which combines both SERVER and CLIENT modes.

Author:
felfert

Field Summary
static int CLIENT
          Mode for using client certificates.
static int NONE
          Mode for accepting any certificate.
static int SERVER
          Mode for verifying server certificate chains.
static int STRICT
          Mode for performing both client authentication and server cert verification.
 
Constructor Summary
InteractiveTrustManager(UploadPolicy p, String hostname, String passwd)
          Create a new instance.
 
Method Summary
 void checkClientTrusted(X509Certificate[] arg0, String arg1)
          As this class is used on the client side only, The implementation of this method does nothing.
 void checkServerTrusted(X509Certificate[] chain, String authType)
           
 X509Certificate[] getAcceptedIssuers()
           
 KeyManager[] getKeyManagers()
          Retrieve key managers.
 X509TrustManager[] getTrustManagers()
          Retrieve trust managers.
 void handle(Callback[] callbacks)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NONE

public static final int NONE
Mode for accepting any certificate.

See Also:
Constant Field Values

SERVER

public static final int SERVER
Mode for verifying server certificate chains.

See Also:
Constant Field Values

CLIENT

public static final int CLIENT
Mode for using client certificates.

See Also:
Constant Field Values

STRICT

public static final int STRICT
Mode for performing both client authentication and server cert verification.

See Also:
Constant Field Values
Constructor Detail

InteractiveTrustManager

public InteractiveTrustManager(UploadPolicy p,
                               String hostname,
                               String passwd)
                        throws NoSuchAlgorithmException,
                               KeyStoreException,
                               CertificateException,
                               IllegalArgumentException,
                               UnrecoverableKeyException
Create a new instance.

Parameters:
p - The UploadPolicy to use for this instance.
hostname -
passwd - An optional password for the truststore.
Throws:
NoSuchAlgorithmException
KeyStoreException
CertificateException
IllegalArgumentException
UnrecoverableKeyException
Method Detail

handle

public void handle(Callback[] callbacks)
            throws UnsupportedCallbackException
Specified by:
handle in interface CallbackHandler
Throws:
UnsupportedCallbackException
See Also:
CallbackHandler.handle(javax.security.auth.callback.Callback[])

getKeyManagers

public KeyManager[] getKeyManagers()
Retrieve key managers.

Returns:
The current array of key managers.

getTrustManagers

public X509TrustManager[] getTrustManagers()
Retrieve trust managers.

Returns:
The current array of trust managers

checkClientTrusted

public void checkClientTrusted(X509Certificate[] arg0,
                               String arg1)
As this class is used on the client side only, The implementation of this method does nothing.

Specified by:
checkClientTrusted in interface X509TrustManager
See Also:
X509TrustManager.checkClientTrusted(java.security.cert.X509Certificate[], java.lang.String)

checkServerTrusted

public void checkServerTrusted(X509Certificate[] chain,
                               String authType)
                        throws CertificateException
Specified by:
checkServerTrusted in interface X509TrustManager
Throws:
CertificateException
See Also:
X509TrustManager.checkServerTrusted(java.security.cert.X509Certificate[], java.lang.String)

getAcceptedIssuers

public X509Certificate[] getAcceptedIssuers()
Specified by:
getAcceptedIssuers in interface X509TrustManager
See Also:
X509TrustManager.getAcceptedIssuers()