1 18 package org.drftpd.plugins; 19 20 import java.io.IOException ; 21 import java.security.GeneralSecurityException ; 22 import java.security.cert.CertificateException ; 23 import java.security.cert.X509Certificate ; 24 import java.util.Properties ; 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 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 ircCfg) throws IOException { 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 { 48 super(); 49 } 50 51 public void connect() throws IOException { 52 logger.debug("In connect()"); 53 if (_useSSL) { 54 try { 55 SSLContext ctx = SSLContext.getInstance("TLS"); 56 TrustManager tms[] = 59 { new X509TrustManager() { 60 public void checkClientTrusted( 61 X509Certificate [] arg0, 62 String arg1) 63 throws CertificateException { 64 } 65 66 public void checkServerTrusted( 67 X509Certificate [] arg0, 68 String arg1) 69 throws CertificateException { 70 } 71 public X509Certificate [] 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 e) { 83 throw new FatalException(e); 84 } 85 } else { 86 super.connect(); 87 } 88 } 89 90 } 91
| Popular Tags
|