EMMA Coverage Report (generated Tue Feb 12 22:23:49 ICT 2008)
[all classes][org.apache.commons.httpclient.contrib.ssl]

COVERAGE SUMMARY FOR SOURCE FILE [EasyX509TrustManager.java]

nameclass, %method, %block, %line, %
EasyX509TrustManager.java0%   (0/1)0%   (0/5)0%   (0/94)0%   (0/23)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class EasyX509TrustManager0%   (0/1)0%   (0/5)0%   (0/94)0%   (0/23)
<static initializer> 0%   (0/1)0%   (0/4)0%   (0/1)
EasyX509TrustManager (KeyStore): void 0%   (0/1)0%   (0/29)0%   (0/9)
checkClientTrusted (X509Certificate [], String): void 0%   (0/1)0%   (0/6)0%   (0/2)
checkServerTrusted (X509Certificate [], String): void 0%   (0/1)0%   (0/51)0%   (0/10)
getAcceptedIssuers (): X509Certificate [] 0%   (0/1)0%   (0/4)0%   (0/1)

1/*
2 * ====================================================================
3 *
4 *  Copyright 2002-2004 The Apache Software Foundation
5 *
6 *  Licensed under the Apache License, Version 2.0 (the "License");
7 *  you may not use this file except in compliance with the License.
8 *  You may obtain a copy of the License at
9 *
10 *      http://www.apache.org/licenses/LICENSE-2.0
11 *
12 *  Unless required by applicable law or agreed to in writing, software
13 *  distributed under the License is distributed on an "AS IS" BASIS,
14 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 *  See the License for the specific language governing permissions and
16 *  limitations under the License.
17 * ====================================================================
18 *
19 * This software consists of voluntary contributions made by many
20 * individuals on behalf of the Apache Software Foundation.  For more
21 * information on the Apache Software Foundation, please see
22 * <http://www.apache.org/>.
23 *
24 */
25 
26package org.apache.commons.httpclient.contrib.ssl;
27 
28import java.security.KeyStore;
29import java.security.KeyStoreException;
30import java.security.NoSuchAlgorithmException;
31import java.security.cert.CertificateException;
32import java.security.cert.X509Certificate;
33 
34import javax.net.ssl.TrustManagerFactory;
35import javax.net.ssl.TrustManager;
36import javax.net.ssl.X509TrustManager;
37import org.apache.commons.logging.Log; 
38import org.apache.commons.logging.LogFactory;
39 
40/**
41 * <p>
42 * EasyX509TrustManager unlike default {@link X509TrustManager} accepts 
43 * self-signed certificates. 
44 * </p>
45 * <p>
46 * This trust manager SHOULD NOT be used for productive systems 
47 * due to security reasons, unless it is a concious decision and 
48 * you are perfectly aware of security implications of accepting 
49 * self-signed certificates
50 * </p>
51 * 
52 * @author <a href="mailto:adrian.sutton@ephox.com">Adrian Sutton</a>
53 * @author <a href="mailto:oleg@ural.ru">Oleg Kalnichevski</a>
54 * 
55 * <p>
56 * DISCLAIMER: HttpClient developers DO NOT actively support this component.
57 * The component is provided as a reference material, which may be inappropriate
58 * for use without additional customization.
59 * </p>
60 */
61 
62public class EasyX509TrustManager implements X509TrustManager
63{
64    private X509TrustManager standardTrustManager = null;
65 
66    /** Log object for this class. */
67    private static final Log LOG = LogFactory.getLog(EasyX509TrustManager.class);
68 
69    /**
70     * Constructor for EasyX509TrustManager.
71     */
72    public EasyX509TrustManager(KeyStore keystore) throws NoSuchAlgorithmException, KeyStoreException {
73        super();
74        TrustManagerFactory factory = TrustManagerFactory.getInstance("SunX509");
75        factory.init(keystore);
76        TrustManager[] trustmanagers = factory.getTrustManagers();
77        if (trustmanagers.length == 0) {
78            throw new NoSuchAlgorithmException("SunX509 trust manager not supported");
79        }
80        this.standardTrustManager = (X509TrustManager)trustmanagers[0];
81    }
82 
83    /**
84     * @see javax.net.ssl.X509TrustManager#checkClientTrusted(X509Certificate[],String)
85     */
86        public void checkClientTrusted(X509Certificate[] chain, String authType)
87                throws CertificateException
88        {
89                this.standardTrustManager.checkClientTrusted(chain, authType);
90        }
91 
92    /**
93     * @see javax.net.ssl.X509TrustManager#checkServerTrusted(X509Certificate[],String)
94     */
95        public void checkServerTrusted(X509Certificate[] chain, String authType)
96                throws CertificateException {
97        if ((chain != null) && LOG.isDebugEnabled()) {
98            LOG.debug("Server certificate chain:");
99            for (int i = 0; i < chain.length; i++) {
100                LOG.debug("X509Certificate[" + i + "]=" + chain[i]);
101            }
102        }
103        if ((chain != null) && (chain.length == 1)) {
104            X509Certificate certificate = chain[0];
105            certificate.checkValidity(); 
106        } else {
107            this.standardTrustManager.checkServerTrusted(chain, authType);
108        }
109    }
110 
111    /**
112     * @see javax.net.ssl.X509TrustManager#getAcceptedIssuers()
113     */
114    public X509Certificate[] getAcceptedIssuers() {
115        return this.standardTrustManager.getAcceptedIssuers();
116    }
117}

[all classes][org.apache.commons.httpclient.contrib.ssl]
EMMA 2.0.5312 (C) Vladimir Roubtsov