1
0
mirror of https://github.com/moparisthebest/Yaaic synced 2024-08-13 16:53:50 -04:00

PircBot Patch: Use org.yaaic.ssl.NaiveTrustManager for SSL connections

This commit is contained in:
Sebastian Kaspari 2010-04-14 00:49:15 +02:00
parent 3871d38f14
commit 3200d6403b

View File

@ -29,7 +29,12 @@ import java.util.Enumeration;
import java.util.Hashtable;
import java.util.StringTokenizer;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSocket;
import javax.net.ssl.SSLSocketFactory;
import javax.net.ssl.X509TrustManager;
import org.yaaic.ssl.NaiveTrustManager;
/**
* PircBot is a Java framework for writing IRC bots quickly and easily.
@ -149,7 +154,19 @@ public abstract class PircBot implements ReplyConstants {
// XXX: PircBot Patch for SSL
Socket socket;
if (_useSSL) {
socket = SSLSocketFactory.getDefault().createSocket(hostname, port);
try {
SSLContext context = SSLContext.getInstance("TLS");
context.init(null, new X509TrustManager[] { new NaiveTrustManager() }, null);
SSLSocketFactory factory = context.getSocketFactory();
SSLSocket ssocket = (SSLSocket) factory.createSocket(hostname, port);
ssocket.startHandshake();
socket = ssocket;
}
catch(Exception e)
{
// XXX: It's not really an IOException :)
throw new IOException("Cannot open SSL socket");
}
} else {
socket = new Socket(hostname, port);
}