mirror of
https://codeberg.org/Mercury-IM/Smack
synced 2024-11-16 20:22:05 +01:00
Allow to perform SASL authentication over plain connections. SMACK-83
git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/trunk@2784 b35dd754-fafc-0310-a699-88a17e54d16e
This commit is contained in:
parent
b94d041bba
commit
391e7269e6
1 changed files with 31 additions and 13 deletions
|
@ -288,16 +288,14 @@ class PacketReader {
|
||||||
// Get the connection id.
|
// Get the connection id.
|
||||||
for (int i=0; i<parser.getAttributeCount(); i++) {
|
for (int i=0; i<parser.getAttributeCount(); i++) {
|
||||||
if (parser.getAttributeName(i).equals("id")) {
|
if (parser.getAttributeName(i).equals("id")) {
|
||||||
if (("1.0".equals(parser.getAttributeValue("", "version")) &&
|
// Save the connectionID
|
||||||
connection.isUsingTLS()) || (!"1.0".equals(
|
|
||||||
parser.getAttributeValue("", "version")))) {
|
|
||||||
// Save the connectionID and notify that we've gotten it.
|
|
||||||
// Only notify if TLS has been secured or if the server
|
|
||||||
// does not support TLS
|
|
||||||
synchronized(connectionIDLock) {
|
|
||||||
connectionID = parser.getAttributeValue(i);
|
connectionID = parser.getAttributeValue(i);
|
||||||
connectionIDLock.notifyAll();
|
if (!"1.0".equals(parser.getAttributeValue("", "version"))) {
|
||||||
}
|
// Notify that a stream has been opened if the
|
||||||
|
// server is not XMPP 1.0 compliant otherwise make the
|
||||||
|
// notification after TLS has been negotiated or if TLS
|
||||||
|
// is not supported
|
||||||
|
releaseConnectionIDLock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (parser.getAttributeName(i).equals("from")) {
|
else if (parser.getAttributeName(i).equals("from")) {
|
||||||
|
@ -352,6 +350,21 @@ class PacketReader {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Releases the connection ID lock so that the thread that was waiting can resume. The
|
||||||
|
* lock will be released when one of the following three conditions is met:<p>
|
||||||
|
*
|
||||||
|
* 1) An opening stream was sent from a non XMPP 1.0 compliant server
|
||||||
|
* 2) Stream features were received from an XMPP 1.0 compliant server that does not support TLS
|
||||||
|
* 3) TLS negotiation was successful
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private void releaseConnectionIDLock() {
|
||||||
|
synchronized(connectionIDLock) {
|
||||||
|
connectionIDLock.notifyAll();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Processes a packet after it's been fully parsed by looping through the installed
|
* Processes a packet after it's been fully parsed by looping through the installed
|
||||||
* packet collectors and listeners and letting them examine the packet to see if
|
* packet collectors and listeners and letting them examine the packet to see if
|
||||||
|
@ -390,17 +403,19 @@ class PacketReader {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void parseFeatures(XmlPullParser parser) throws Exception {
|
private void parseFeatures(XmlPullParser parser) throws Exception {
|
||||||
|
boolean startTLSReceived = false;
|
||||||
boolean done = false;
|
boolean done = false;
|
||||||
while (!done) {
|
while (!done) {
|
||||||
int eventType = parser.next();
|
int eventType = parser.next();
|
||||||
|
|
||||||
if (eventType == XmlPullParser.START_TAG) {
|
if (eventType == XmlPullParser.START_TAG) {
|
||||||
if (parser.getName().equals("starttls")) {
|
if (parser.getName().equals("starttls")) {
|
||||||
|
startTLSReceived = true;
|
||||||
// Confirm the server that we want to use TLS
|
// Confirm the server that we want to use TLS
|
||||||
connection.startTLSReceived();
|
connection.startTLSReceived();
|
||||||
}
|
}
|
||||||
else if (parser.getName().equals("mechanisms") && connection.isUsingTLS()) {
|
else if (parser.getName().equals("mechanisms")) {
|
||||||
// The server is reporting available SASL mechanism. Store this information
|
// The server is reporting available SASL mechanisms. Store this information
|
||||||
// which will be used later while logging (i.e. authenticating) into
|
// which will be used later while logging (i.e. authenticating) into
|
||||||
// the server
|
// the server
|
||||||
connection.getSASLAuthentication()
|
connection.getSASLAuthentication()
|
||||||
|
@ -421,6 +436,9 @@ class PacketReader {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (!startTLSReceived) {
|
||||||
|
releaseConnectionIDLock();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue