forked from pocmo/Yaaic
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(Authentication) Implementation of authentication via SASL on connect
- Loading branch information
Showing
3 changed files
with
56 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,6 +39,7 @@ General Public License (GPL) and the www.jibble.org Commercial License. | |
import javax.net.ssl.X509TrustManager; | ||
|
||
import org.yaaic.ssl.NaiveTrustManager; | ||
import org.yaaic.tools.Base64; | ||
|
||
/** | ||
* PircBot is a Java framework for writing IRC bots quickly and easily. | ||
|
@@ -200,6 +201,33 @@ public final synchronized void connect(String hostname, int port, String passwor | |
OutputThread.sendRawLine(this, bwriter, "PASS " + password); | ||
} | ||
String nick = this.getName(); | ||
|
||
|
||
if (saslUsername != null) { | ||
OutputThread.sendRawLine(this, bwriter, "CAP LS"); | ||
OutputThread.sendRawLine(this, bwriter, "CAP REQ : sasl multi-prefix"); | ||
OutputThread.sendRawLine(this, bwriter, "CAP END"); | ||
|
||
OutputThread.sendRawLine(this, bwriter, "AUTHENTICATE PLAIN"); | ||
|
||
String authString = saslUsername + "\0" + saslUsername + "\0" + saslPassword; | ||
|
||
String authStringEncoded = Base64.encodeBytes(authString.getBytes()); | ||
|
||
while (authStringEncoded.length() >= 400) { | ||
String toSend = authStringEncoded.substring(0, 400); | ||
authString = authStringEncoded.substring(400); | ||
|
||
OutputThread.sendRawLine(this, bwriter, "AUTHENTICATE " + toSend); | ||
} | ||
|
||
if (authStringEncoded.length() > 0) { | ||
OutputThread.sendRawLine(this, bwriter, "AUTHENTICATE " + authStringEncoded); | ||
} else { | ||
OutputThread.sendRawLine(this, bwriter, "AUTHENTICATE +"); | ||
} | ||
} | ||
|
||
OutputThread.sendRawLine(this, bwriter, "NICK " + nick); | ||
OutputThread.sendRawLine(this, bwriter, "USER " + this.getLogin() + " 8 * :" + this.getVersion()); | ||
|
||
|
@@ -257,9 +285,8 @@ public final synchronized void reconnect() throws IOException, IrcException, Nic | |
connect(getServer(), getPort(), getPassword()); | ||
} | ||
|
||
|
||
/** | ||
* Set wether SSL should be used to connect to the server | ||
* Set wether SSL should be used to connect to the server. | ||
* | ||
* @author Sebastian Kaspari <[email protected]> | ||
*/ | ||
|
@@ -268,6 +295,20 @@ public void setUseSSL(boolean useSSL) | |
_useSSL = useSSL; | ||
} | ||
|
||
/** | ||
* Set credentials for SASL authentication. | ||
* | ||
* @param username | ||
* @param password | ||
* | ||
* @author Sebastian Kaspari <[email protected]> | ||
*/ | ||
public void setSaslCredentials(String username, String password) | ||
{ | ||
this.saslUsername = username; | ||
this.saslPassword = password; | ||
} | ||
|
||
|
||
/** | ||
* This method disconnects from the server cleanly by calling the | ||
|
@@ -3106,6 +3147,10 @@ else if (userMode == VOICE_REMOVE) { | |
private final Queue _outQueue = new Queue(); | ||
private long _messageDelay = 1000; | ||
|
||
// SASL | ||
private String saslUsername; | ||
private String saslPassword; | ||
|
||
// A Hashtable of channels that points to a selfreferential Hashtable of | ||
// User objects (used to remember which users are in which channels). | ||
private Hashtable<String, Hashtable<User, User>> _channels = new Hashtable<String, Hashtable<User, User>>(); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters