KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jivesoftware > messenger > net > SSLJiveTrustManager


1 /**
2  * $RCSfile: SSLJiveTrustManager.java,v $
3  * $Revision: 1.2 $
4  * $Date: 2004/10/25 23:41:59 $
5  *
6  * Copyright (C) 2004 Jive Software. All rights reserved.
7  *
8  * This software is published under the terms of the GNU Public License (GPL),
9  * a copy of which is included in this distribution.
10  */

11
12 package org.jivesoftware.messenger.net;
13
14 import org.jivesoftware.util.LocaleUtils;
15 import org.jivesoftware.util.Log;
16 import com.sun.net.ssl.X509TrustManager;
17 import java.security.cert.CertificateExpiredException JavaDoc;
18 import java.security.cert.CertificateNotYetValidException JavaDoc;
19 import java.security.cert.X509Certificate JavaDoc;
20
21 /**
22  * Trust manager which accepts certificates without any validation
23  * except date validation.
24  * <p/>
25  * A skeleton placeholder for developers wishing to implement their own custom
26  * trust manager. In future revisions we may expand the skeleton code if customers
27  * request assistance in creating custom trust managers.
28  * <p/>
29  * You only need a trust manager if your server will require clients
30  * to authenticated with the server (typically only the server authenticates
31  * with the client).
32  *
33  * @author Iain Shigeoka
34  */

35 public class SSLJiveTrustManager implements X509TrustManager {
36
37     public void checkClientTrusted(X509Certificate JavaDoc[] chain, String JavaDoc authType) {
38
39     }
40
41     public void checkServerTrusted(X509Certificate JavaDoc[] chain, String JavaDoc authType) {
42     }
43
44     public boolean isClientTrusted(X509Certificate JavaDoc[] x509Certificates) {
45         return true;
46     }
47
48     public boolean isServerTrusted(X509Certificate JavaDoc[] x509Certificates) {
49         boolean trusted = true;
50         try {
51             x509Certificates[0].checkValidity();
52         }
53         catch (CertificateExpiredException JavaDoc e) {
54             Log.error(LocaleUtils.getLocalizedString("admin.error"), e);
55             trusted = false;
56         }
57         catch (CertificateNotYetValidException JavaDoc e) {
58             Log.error(LocaleUtils.getLocalizedString("admin.error"), e);
59             trusted = false;
60         }
61         return trusted;
62     }
63
64     public X509Certificate JavaDoc[] getAcceptedIssuers() {
65         return new X509Certificate JavaDoc[0];
66     }
67 }
68
Popular Tags