1 29 30 package org.apache.commons.httpclient.contrib.ssl; 31 32 import java.security.cert.X509Certificate ; 33 34 import javax.net.ssl.X509TrustManager; 35 import java.security.cert.CertificateException ; 36 import org.apache.commons.logging.Log; 37 import org.apache.commons.logging.LogFactory; 38 39 53 54 public class AuthSSLX509TrustManager implements X509TrustManager 55 { 56 private X509TrustManager defaultTrustManager = null; 57 58 59 private static final Log LOG = LogFactory.getLog(AuthSSLX509TrustManager.class); 60 61 64 public AuthSSLX509TrustManager(final X509TrustManager defaultTrustManager) { 65 super(); 66 if (defaultTrustManager == null) { 67 throw new IllegalArgumentException ("Trust manager may not be null"); 68 } 69 this.defaultTrustManager = defaultTrustManager; 70 } 71 72 75 public void checkClientTrusted(X509Certificate [] certificates,String authType) throws CertificateException { 76 if (LOG.isInfoEnabled() && certificates != null) { 77 for (int c = 0; c < certificates.length; c++) { 78 X509Certificate cert = certificates[c]; 79 LOG.info(" Client certificate " + (c + 1) + ":"); 80 LOG.info(" Subject DN: " + cert.getSubjectDN()); 81 LOG.info(" Signature Algorithm: " + cert.getSigAlgName()); 82 LOG.info(" Valid from: " + cert.getNotBefore() ); 83 LOG.info(" Valid until: " + cert.getNotAfter()); 84 LOG.info(" Issuer: " + cert.getIssuerDN()); 85 } 86 } 87 defaultTrustManager.checkClientTrusted(certificates,authType); 88 } 89 90 93 public void checkServerTrusted(X509Certificate [] certificates,String authType) throws CertificateException { 94 if (LOG.isInfoEnabled() && certificates != null) { 95 for (int c = 0; c < certificates.length; c++) { 96 X509Certificate cert = certificates[c]; 97 LOG.info(" Server certificate " + (c + 1) + ":"); 98 LOG.info(" Subject DN: " + cert.getSubjectDN()); 99 LOG.info(" Signature Algorithm: " + cert.getSigAlgName()); 100 LOG.info(" Valid from: " + cert.getNotBefore() ); 101 LOG.info(" Valid until: " + cert.getNotAfter()); 102 LOG.info(" Issuer: " + cert.getIssuerDN()); 103 } 104 } 105 defaultTrustManager.checkServerTrusted(certificates,authType); 106 } 107 108 111 public X509Certificate [] getAcceptedIssuers() { 112 return this.defaultTrustManager.getAcceptedIssuers(); 113 } 114 } | Popular Tags |