org.mailster.crypto
Class X509SecureSocketFactory

java.lang.Object
  extended by org.mailster.crypto.X509SecureSocketFactory
All Implemented Interfaces:
javax.net.ssl.TrustManager, javax.net.ssl.X509TrustManager

public class X509SecureSocketFactory
extends java.lang.Object
implements javax.net.ssl.X509TrustManager

---
Mailster (C) 2007-2009 De Oliveira Edouard

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

See  Mailster Web Site
---

X509SecureSocketFactory.java - A full featured SSL socket factory that uses X509v3 certificates.

Version:
$Revision: 1.6 $, $Date: 2009/02/19 01:22:00 $
Author:
Edouard De Oliveira

Nested Class Summary
static class X509SecureSocketFactory.SSLProtocol
           
 
Field Summary
private static X509SecureSocketFactory _instance
           
private  javax.net.ssl.SSLContext context
           
private  javax.net.ssl.KeyManagerFactory kmf
           
private  X509SecureSocketFactory.SSLProtocol selectedProtocol
           
private  java.security.KeyStore temporaryTrustedKS
           
private  javax.net.ssl.TrustManagerFactory tmf
           
private  javax.net.ssl.X509TrustManager tmpTrustManager
          Temporary trusted certificates are hold in this TrustManager.
private  UICertificateTrustCallBackHandler trustCallBackHandler
           
private  java.security.KeyStore trustedKS
           
private  javax.net.ssl.X509TrustManager trustManager
          The default X509TrustManager provided by the JVM.
 
Constructor Summary
private X509SecureSocketFactory(java.lang.String protocol)
           
 
Method Summary
 void checkClientTrusted(java.security.cert.X509Certificate[] chain, java.lang.String authType)
           
 void checkServerTrusted(java.security.cert.X509Certificate[] chain, java.lang.String authType)
           
 void checkUserDecision(java.security.cert.X509Certificate[] chain, java.lang.String authType, boolean isServerCheck, java.security.cert.CertificateException e)
           
 java.security.cert.X509Certificate[] getAcceptedIssuers()
           
private  java.lang.String getCertificateUniqueID(java.security.cert.X509Certificate x509)
           
 javax.net.ssl.SSLContext getContext()
           
static X509SecureSocketFactory getInstance()
           
static X509SecureSocketFactory getInstance(X509SecureSocketFactory.SSLProtocol protocol, UICertificateTrustCallBackHandler handler)
           
 UICertificateTrustCallBackHandler getTrustCallBackHandler()
           
private  javax.net.ssl.X509TrustManager initTrustManager(java.security.KeyStore ks)
           
static void reload()
           
 void setTrustCallBackHandler(UICertificateTrustCallBackHandler trustCallBackHandler)
           
private  javax.net.ssl.X509TrustManager updateAndCheckTrustManager(java.security.KeyStore ks, java.security.cert.X509Certificate[] chain, java.io.OutputStream out, char[] pwd, java.lang.String authType, boolean isServerCheck)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

tmf

private javax.net.ssl.TrustManagerFactory tmf

kmf

private javax.net.ssl.KeyManagerFactory kmf

context

private javax.net.ssl.SSLContext context

trustedKS

private java.security.KeyStore trustedKS

temporaryTrustedKS

private java.security.KeyStore temporaryTrustedKS

_instance

private static X509SecureSocketFactory _instance

selectedProtocol

private X509SecureSocketFactory.SSLProtocol selectedProtocol

trustCallBackHandler

private UICertificateTrustCallBackHandler trustCallBackHandler

trustManager

private javax.net.ssl.X509TrustManager trustManager
The default X509TrustManager provided by the JVM. We'll delegate decisions to it, and fall back to the logic in this class if the default X509TrustManager doesn't trust it.


tmpTrustManager

private javax.net.ssl.X509TrustManager tmpTrustManager
Temporary trusted certificates are hold in this TrustManager.

Constructor Detail

X509SecureSocketFactory

private X509SecureSocketFactory(java.lang.String protocol)
                         throws java.lang.Exception
Throws:
java.lang.Exception
Method Detail

getInstance

public static X509SecureSocketFactory getInstance(X509SecureSocketFactory.SSLProtocol protocol,
                                                  UICertificateTrustCallBackHandler handler)
                                           throws java.lang.Exception
Throws:
java.lang.Exception

getInstance

public static X509SecureSocketFactory getInstance()

reload

public static void reload()
                   throws java.lang.Exception
Throws:
java.lang.Exception

initTrustManager

private javax.net.ssl.X509TrustManager initTrustManager(java.security.KeyStore ks)
                                                 throws java.security.KeyStoreException
Throws:
java.security.KeyStoreException

getCertificateUniqueID

private java.lang.String getCertificateUniqueID(java.security.cert.X509Certificate x509)

updateAndCheckTrustManager

private javax.net.ssl.X509TrustManager updateAndCheckTrustManager(java.security.KeyStore ks,
                                                                  java.security.cert.X509Certificate[] chain,
                                                                  java.io.OutputStream out,
                                                                  char[] pwd,
                                                                  java.lang.String authType,
                                                                  boolean isServerCheck)
                                                           throws java.lang.Exception
Throws:
java.lang.Exception

checkClientTrusted

public void checkClientTrusted(java.security.cert.X509Certificate[] chain,
                               java.lang.String authType)
                        throws java.security.cert.CertificateException
Specified by:
checkClientTrusted in interface javax.net.ssl.X509TrustManager
Throws:
java.security.cert.CertificateException

checkServerTrusted

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

checkUserDecision

public void checkUserDecision(java.security.cert.X509Certificate[] chain,
                              java.lang.String authType,
                              boolean isServerCheck,
                              java.security.cert.CertificateException e)
                       throws java.security.cert.CertificateException
Throws:
java.security.cert.CertificateException

getAcceptedIssuers

public java.security.cert.X509Certificate[] getAcceptedIssuers()
Specified by:
getAcceptedIssuers in interface javax.net.ssl.X509TrustManager

getContext

public javax.net.ssl.SSLContext getContext()

getTrustCallBackHandler

public UICertificateTrustCallBackHandler getTrustCallBackHandler()

setTrustCallBackHandler

public void setTrustCallBackHandler(UICertificateTrustCallBackHandler trustCallBackHandler)