Index: EasyX509TrustManager.java =================================================================== RCS file: /home/cvspublic/jakarta-commons/httpclient/src/contrib/org/apache/commons/httpclient/contrib/ssl/EasyX509TrustManager.java,v retrieving revision 1.4 diff -u -r1.4 EasyX509TrustManager.java --- EasyX509TrustManager.java 10 Jun 2004 18:25:24 -0000 1.4 +++ EasyX509TrustManager.java 13 Oct 2005 10:38:55 -0000 @@ -31,10 +31,11 @@ import java.security.cert.CertificateException; import java.security.cert.X509Certificate; -import com.sun.net.ssl.TrustManagerFactory; -import com.sun.net.ssl.TrustManager; -import com.sun.net.ssl.X509TrustManager; -import org.apache.commons.logging.Log; +import javax.net.ssl.TrustManager; +import javax.net.ssl.TrustManagerFactory; +import javax.net.ssl.X509TrustManager; + +import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; /** @@ -51,6 +52,7 @@ * * @author Adrian Sutton * @author Oleg Kalnichevski + * @author Patrick Reinhart * *
* DISCLAIMER: HttpClient developers DO NOT actively support this component. @@ -68,29 +70,33 @@ /** * Constructor for EasyX509TrustManager. + * @param keystore to initialize the default trust manager factory with + * @throws NoSuchAlgorithmException + * @throws KeyStoreException */ public EasyX509TrustManager(KeyStore keystore) throws NoSuchAlgorithmException, KeyStoreException { super(); - TrustManagerFactory factory = TrustManagerFactory.getInstance("SunX509"); + String algorithm = TrustManagerFactory.getDefaultAlgorithm(); + TrustManagerFactory factory = TrustManagerFactory.getInstance(algorithm); factory.init(keystore); TrustManager[] trustmanagers = factory.getTrustManagers(); if (trustmanagers.length == 0) { - throw new NoSuchAlgorithmException("SunX509 trust manager not supported"); + throw new NoSuchAlgorithmException("'" + algorithm + "' trust manager not supported"); } this.standardTrustManager = (X509TrustManager)trustmanagers[0]; } /** - * @see com.sun.net.ssl.X509TrustManager#isClientTrusted(X509Certificate[]) + * @see X509TrustManager#checkClientTrusted(X509Certificate[], String) */ - public boolean isClientTrusted(X509Certificate[] certificates) { - return this.standardTrustManager.isClientTrusted(certificates); + public void checkClientTrusted(X509Certificate[] certificates, String authType) throws CertificateException { + standardTrustManager.checkClientTrusted(certificates, authType); } /** - * @see com.sun.net.ssl.X509TrustManager#isServerTrusted(X509Certificate[]) + * @see X509TrustManager#checkServerTrusted(X509Certificate[], String) */ - public boolean isServerTrusted(X509Certificate[] certificates) { + public void checkServerTrusted(X509Certificate[] certificates, String authType) throws CertificateException { if ((certificates != null) && LOG.isDebugEnabled()) { LOG.debug("Server certificate chain:"); for (int i = 0; i < certificates.length; i++) { @@ -100,20 +106,18 @@ if ((certificates != null) && (certificates.length == 1)) { X509Certificate certificate = certificates[0]; try { - certificate.checkValidity(); - } - catch (CertificateException e) { + certificate.checkValidity(); + } catch (CertificateException e) { LOG.error(e.toString()); - return false; + throw e; } - return true; } else { - return this.standardTrustManager.isServerTrusted(certificates); + standardTrustManager.checkServerTrusted(certificates, authType); } } /** - * @see com.sun.net.ssl.X509TrustManager#getAcceptedIssuers() + * @see X509TrustManager#getAcceptedIssuers() */ public X509Certificate[] getAcceptedIssuers() { return this.standardTrustManager.getAcceptedIssuers();