de.duenndns.ssl
Class MemorizingTrustManager

Package class diagram package MemorizingTrustManager
java.lang.Object
  extended by de.duenndns.ssl.MemorizingTrustManager
All Implemented Interfaces:
TrustManager, X509TrustManager

public class MemorizingTrustManager
extends Object
implements X509TrustManager

A X509 trust manager implementation which asks the user about invalid certificates and memorizes their decision.

The certificate validity is checked using the system default X509 TrustManager, creating a query Dialog if the check fails.

WARNING: This only works if a dedicated thread is used for opening sockets!


Field Summary
static String INTERCEPT_DECISION_INTENT
           
static String INTERCEPT_DECISION_INTENT_LAUNCH
           
 
Constructor Summary
MemorizingTrustManager(Context m)
          Creates an instance of the MemorizingTrustManager class.
 
Method Summary
 void bindDisplayActivity(Activity act)
          Binds an Activity to the MTM for displaying the query dialog.
 void checkCertTrusted(X509Certificate[] chain, String authType, boolean isServer)
           
 void checkClientTrusted(X509Certificate[] chain, String authType)
           
 void checkServerTrusted(X509Certificate[] chain, String authType)
           
 X509Certificate[] getAcceptedIssuers()
           
static X509TrustManager[] getInstanceList(Context c)
          Returns a X509TrustManager list containing a new instance of TrustManagerFactory.
static void interactResult(Intent i)
           
static void setKeyStoreFile(String dirname, String filename)
          Changes the path for the KeyStore file.
 void unbindDisplayActivity(Activity act)
          Removes an Activity from the MTM display stack.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

INTERCEPT_DECISION_INTENT

public static final String INTERCEPT_DECISION_INTENT
See Also:
Constant Field Values

INTERCEPT_DECISION_INTENT_LAUNCH

public static final String INTERCEPT_DECISION_INTENT_LAUNCH
See Also:
Constant Field Values
Constructor Detail

MemorizingTrustManager

public MemorizingTrustManager(Context m)
Creates an instance of the MemorizingTrustManager class. You need to supply the application context. This has to be one of: - Application - Activity - Service The context is used for file management, to display the dialog / notification and for obtaining translated strings.

Parameters:
m - Context for the application.
Method Detail

getInstanceList

public static X509TrustManager[] getInstanceList(Context c)
Returns a X509TrustManager list containing a new instance of TrustManagerFactory. This function is meant for convenience only. You can use it as follows to integrate TrustManagerFactory for HTTPS sockets:
     SSLContext sc = SSLContext.getInstance("TLS");
     sc.init(null, MemorizingTrustManager.getInstanceList(this),
         new java.security.SecureRandom());
     HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
 

Parameters:
c - Activity or Service to show the Dialog / Notification

bindDisplayActivity

public void bindDisplayActivity(Activity act)
Binds an Activity to the MTM for displaying the query dialog. This is useful if your connection is run from a service that is triggered by user interaction -- in such cases the activity is visible and the user tends to ignore the service notification. You should never have a hidden activity bound to MTM! Use this function in onResume() and @see unbindDisplayActivity in onPause().

Parameters:
act - Activity to be bound

unbindDisplayActivity

public void unbindDisplayActivity(Activity act)
Removes an Activity from the MTM display stack. Always call this function when the Activity added with

Parameters:
act - Activity to be unbound
See Also:
is hidden.

setKeyStoreFile

public static void setKeyStoreFile(String dirname,
                                   String filename)
Changes the path for the KeyStore file. The actual filename relative to the app's directory will be app_dirname/filename.

Parameters:
dirname - directory to store the KeyStore.
filename - file name for the KeyStore.

checkCertTrusted

public void checkCertTrusted(X509Certificate[] chain,
                             String authType,
                             boolean isServer)
                      throws CertificateException
Throws:
CertificateException

checkClientTrusted

public void checkClientTrusted(X509Certificate[] chain,
                               String authType)
                        throws CertificateException
Specified by:
checkClientTrusted in interface X509TrustManager
Throws:
CertificateException

checkServerTrusted

public void checkServerTrusted(X509Certificate[] chain,
                               String authType)
                        throws CertificateException
Specified by:
checkServerTrusted in interface X509TrustManager
Throws:
CertificateException

getAcceptedIssuers

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

interactResult

public static void interactResult(Intent i)


Copyright © 2009 Beem-project.com. All Rights Reserved.