org.schwering.irc.lib
Class SSLIRCConnection

java.lang.Object
  extended byjava.lang.Thread
      extended byorg.schwering.irc.lib.IRCConnection
          extended byorg.schwering.irc.lib.SSLIRCConnection
All Implemented Interfaces:
java.lang.Runnable

Deprecated. This class has been replaced with org.schwering.irc.lib.ssl.SSLDefaultTrustManager.

public class SSLIRCConnection
extends IRCConnection

The SSL extension of the IRCConnection class.

Note that this class is deprecated. The SSL supporting classes moved to org.schwering.irc.lib.ssl since IRClib 1.10.

The IRC server you want to connect to must accept SSL connections. Otherwise you cannot connect to it with an instance of SSLIRCConnection. IRC servers which accept SSL connections are really very rare, because SSL means a high load for the server.

The following sample code tries to establish an IRC connection to an IRC server which must support SSL. Differences to the code which demonstrates the use of of the IRCConnection class are printed in bold font:


 /* 
  * The following code of a class which imports org.schwering.irc.lib.*
  * prepares an SSL IRC connection and then tries to establish the 
  * connection. The server is "irc.somenetwork.com", the ports are 
  * the default SSL port (443) and the port used on most SSL IRC servers
  * (994). No password is used (null). The nickname is "Foo" and 
  * the realname is "Mr. Foobar". The username "foobar".
  * Because of setDaemon(true), the JVM exits even if this thread is 
  * running.
  * By setting an instance of SSLDefaultTrustManager as TrustManager
  * (which is also done implicitely by the SSLIRCConnection class if no
  * TrustManager is set until the connect method is invoked), the
  * X509Certificate is accepted automatically. Of course, you can write
  * your own TrustManager. For example, you could write a class which
  * extends SSLDefaultTrustManager and overrides its checkServerTrusted
  * method. In the new checkServerTrusted method, you could ask the user
  * to accept or reject the certificate.
  * An instance of the class MyListener which must implement 
  * IRCActionListener is set as event-listener for the connection. 
  * The connection is told to parse out mIRC color codes and to enable
  * automatic PING? PONG! replies.
  */
 SSLIRCConnection conn = new SSLIRCConnection(
                               "irc.somenetwork.com", 
                               new int[] { 443, 994 },  
                               null, 
                               "Foo", 
                               "Mr. Foobar", 
                               "foo@bar.com" 
                             ); 
 
 conn.addIRCEventListener(new MyListener()); 
 conn.addTrustManager(new SSLDefaultTrustManager());
 conn.setDaemon(true);
 conn.setColors(false); 
 conn.setPong(true); 
   
 try {
   conn.connect(); // Try to connect!!! Don't forget this!!!
 } catch (IOException ioexc) {
   ioexc.printStackTrace(); 
 }
 

The serverpassword isn't needed in most cases. You can give null or "" instead as done in this example.

TrustManagers can be added and removed until the connect method is invoked. If no TrustManagers are set until then, an SSLDefaultTrustManager is set automatically. It accepts all X509 certificates.

Version:
1.33
Author:
Christoph Schwering <schwering@gmail.com>
See Also:
IRCConnection, SSLDefaultTrustManager, TrustManager

Field Summary
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
SSLIRCConnection(java.lang.String host, int[] ports, java.lang.String pass, java.lang.String nick, java.lang.String username, java.lang.String realname)
          Deprecated. Creates a new IRC connection with secure sockets (SSL).
SSLIRCConnection(java.lang.String host, int portMin, int portMax, java.lang.String pass, java.lang.String nick, java.lang.String username, java.lang.String realname)
          Deprecated. Creates a new IRC connection with secure sockets (SSL).
 
Method Summary
 void addTrustManager(com.sun.net.ssl.TrustManager trustManager)
          Deprecated. Adds a new TrustManager.
 void connect()
          Deprecated. Establish a connection to the server.
 com.sun.net.ssl.TrustManager[] getTrustManagers()
          Deprecated. Returns the set TrustManagers.
 boolean removeTrustManager(com.sun.net.ssl.TrustManager trustManager)
          Deprecated. Removes one TrustManager.
 
Methods inherited from class org.schwering.irc.lib.IRCConnection
addIRCEventListener, close, doAway, doAway, doInvite, doIson, doJoin, doJoin, doKick, doKick, doList, doList, doMode, doMode, doNames, doNames, doNick, doNotice, doPart, doPart, doPong, doPrivmsg, doQuit, doQuit, doTopic, doTopic, doUserhost, doWho, doWhois, doWhowas, getColors, getEncoding, getHost, getNick, getPassword, getPong, getPort, getPorts, getRealname, getTimeout, getUsername, isConnected, removeIRCEventListener, run, send, setColors, setEncoding, setPong, setTimeout, toString
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getContextClassLoader, getName, getPriority, getThreadGroup, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setName, setPriority, sleep, sleep, start, stop, stop, suspend, yield
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

SSLIRCConnection

public SSLIRCConnection(java.lang.String host,
                        int[] ports,
                        java.lang.String pass,
                        java.lang.String nick,
                        java.lang.String username,
                        java.lang.String realname)
Deprecated. 
Creates a new IRC connection with secure sockets (SSL).
The difference to the other constructor is, that it transmits the ports in an int[]. Thus, also ports like 994, 6000 and 6697 can be selected.

The constructor prepares a new IRC connection with secure sockets which can be really started by invoking the connect method. Before invoking it, you should set the IRCEventListener, optionally the TrustManager, if you don't want to use the SSLDefaultTrustManager which accepts the X509 certificate automatically, and other settings.
Note that you do not need to set a password to connect to the large public IRC networks like QuakeNet, EFNet etc. To use no password in your IRC connection, use "" or null for the password argument in the constructor.

Parameters:
host - The hostname of the server we want to connect to.
ports - The portrange to which we want to connect.
pass - The password of the IRC server. If your server isn't secured by a password (that's normal), use null or "".
nick - The nickname for the connection. Is used to register the connection.
username - The username. Is used to register the connection.
realname - The realname. Is used to register the connection.
Throws:
java.lang.IllegalArgumentException - If the host or ports is null or ports' length is 0.
See Also:
connect()

SSLIRCConnection

public SSLIRCConnection(java.lang.String host,
                        int portMin,
                        int portMax,
                        java.lang.String pass,
                        java.lang.String nick,
                        java.lang.String username,
                        java.lang.String realname)
Deprecated. 
Creates a new IRC connection with secure sockets (SSL).
The difference to the other constructor is, that it transmits the ports as two ints. Thus, only a portrange from port x to port y like from port 6000 to 6010 can be selected.

The constructor prepares a new IRC connection with secure sockets which can be really started by invoking the connect method. Before invoking it, you should set the IRCEventListener, optionally the TrustManager, if you don't want to use the SSLDefaultTrustManager which accepts the X509 certificate automatically, and other settings.
Note that you do not need to set a password to connect to the large public IRC networks like QuakeNet, EFNet etc. To use no password in your IRC connection, use "" or null for the password argument in the constructor.

Parameters:
host - The hostname of the server we want to connect to.
portMin - The beginning of the port range we are going to connect to.
portMax - The ending of the port range we are going to connect to.
pass - The password of the IRC server. If your server isn't secured by a password (that's normal), use null or "".
nick - The nickname for the connection. Is used to register the connection.
username - The username. Is used to register the connection.
realname - The realname. Is used to register the connection.
Throws:
java.lang.IllegalArgumentException - If the host is null.
See Also:
connect()
Method Detail

connect

public void connect()
             throws java.io.IOException
Deprecated. 
Establish a connection to the server.
This method must be invoked to start a connection; the constructor doesn't do that!
It tries all set ports until one is open. If all ports fail it throws an IOException. If anything SSL related fails (for example conflicts with the algorithms or during the handshaking), a SSLException is thrown.
You can invoke connect only one time.

Overrides:
connect in class IRCConnection
Throws:
java.io.IOException - If an I/O error occurs.
javax.net.ssl.SSLException - If anything with the secure sockets fails.
java.net.SocketException - If the connect method was already invoked.
See Also:
IRCConnection.isConnected(), IRCConnection.doQuit(), IRCConnection.doQuit(String), IRCConnection.close()

addTrustManager

public void addTrustManager(com.sun.net.ssl.TrustManager trustManager)
Deprecated. 
Adds a new TrustManager.
Please remind that we're talking here about com.sun.net.ssl.TrustManagers of the JSSE API and not the javax.net.ssl.TrustManagers of the Java 1.4 API!

Parameters:
trustManager - The TrustManager object which is to add.
See Also:
removeTrustManager(TrustManager), getTrustManagers()

removeTrustManager

public boolean removeTrustManager(com.sun.net.ssl.TrustManager trustManager)
Deprecated. 
Removes one TrustManager.
Please remind that we're talking here about com.sun.net.ssl.TrustManagers of the JSSE API and not the javax.net.ssl.TrustManagers of the Java 1.4 API!

Parameters:
trustManager - The TrustManager object which is to remove.
Returns:
true if a TrustManager was removed.
See Also:
addTrustManager(TrustManager), getTrustManagers()

getTrustManagers

public com.sun.net.ssl.TrustManager[] getTrustManagers()
Deprecated. 
Returns the set TrustManagers. The default TrustManager is an instance of SSLDefaultTrustManager, which is set when you invoke the connect method without having set another TrustManager.
Please remind that we're talking here about com.sun.net.ssl.TrustManagers of the JSSE API and not the javax.net.ssl.TrustManagers of the Java 1.4 API!

Returns:
The set TrustManagers.
See Also:
addTrustManager(TrustManager), removeTrustManager(TrustManager)