KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > drftpd > plugins > SiteBotSSL


1 /*
2  * This file is part of DrFTPD, Distributed FTP Daemon.
3  *
4  * DrFTPD is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * DrFTPD is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with DrFTPD; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  */

18 package org.drftpd.plugins;
19
20 import java.io.IOException JavaDoc;
21 import java.security.GeneralSecurityException JavaDoc;
22 import java.security.cert.CertificateException JavaDoc;
23 import java.security.cert.X509Certificate JavaDoc;
24 import java.util.Properties JavaDoc;
25
26 import javax.net.ssl.SSLContext;
27 import javax.net.ssl.TrustManager;
28 import javax.net.ssl.X509TrustManager;
29
30 import net.sf.drftpd.FatalException;
31
32 import org.apache.log4j.Logger;
33
34 /**
35  * @author mog
36  * @version $Id: SiteBotSSL.java,v 1.3 2004/04/23 01:55:03 mog Exp $
37  */

38 public class SiteBotSSL extends SiteBot {
39     private static final Logger logger = Logger.getLogger(SiteBot.class);
40     private boolean _useSSL;
41     protected void reload(Properties JavaDoc ircCfg) throws IOException JavaDoc {
42         _useSSL = ircCfg.getProperty("irc.ssl", "false").equals("true");
43         logger.debug("useSSL: "+_useSSL);
44         super.reload(ircCfg);
45     }
46
47     public SiteBotSSL() throws IOException JavaDoc {
48         super();
49     }
50
51     public void connect() throws IOException JavaDoc {
52         logger.debug("In connect()");
53         if (_useSSL) {
54             try {
55                 SSLContext ctx = SSLContext.getInstance("TLS");
56                 //KeyManagerFactory kmf = KeyManagerFactory.getInstance("JSSE");
57
//ctx.init(kmf.getKeyManagers(), null, null);
58
TrustManager tms[] =
59                     { new X509TrustManager() {
60                         public void checkClientTrusted(
61                             X509Certificate JavaDoc[] arg0,
62                             String JavaDoc arg1)
63                         throws CertificateException JavaDoc {
64                         }
65
66                         public void checkServerTrusted(
67                             X509Certificate JavaDoc[] arg0,
68                             String JavaDoc arg1)
69                             throws CertificateException JavaDoc {
70                         }
71                         public X509Certificate JavaDoc[] getAcceptedIssuers() {
72                             return null;
73                         }
74                     }
75                 };
76
77                 ctx.init(null, tms, null);
78                 _conn.connect(
79                     ctx.getSocketFactory().createSocket(_server, _port),
80                     _server);
81                 return;
82             } catch (GeneralSecurityException JavaDoc e) {
83                 throw new FatalException(e);
84             }
85         } else {
86             super.connect();
87         }
88     }
89
90 }
91
Popular Tags