From a942863ffe56fd1da93a8596a9bdcca8f0675741 Mon Sep 17 00:00:00 2001 From: Florian Schmaus Date: Mon, 29 Sep 2014 16:41:56 +0200 Subject: [PATCH] Move saslFeatureReceived check in connect() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit so that APIs that need a fully connected but not yet authenticated connection (e.g. AccountManager) can use the connection after connect() returns. Also move "connected = true" after saslFeatureReceived check, as if the check would throw, the boolean would still be 'true' resulting in an inconsistent state. Otherwise this could result in D/SMACK﹕ SENT (12): D/SMACK﹕ SENT (12): D/SMACK﹕ RCV (12): PLAINDIGEST-MD5SCRAM-SHA-1 D/SMACK﹕ SENT (12): D/SMACK﹕ RCV (12): Choose a username and password to register with this server D/SMACK﹕ SENT (12): s0r73pgojeopmssjaairu6kcmk3v4l< username>nqcjloj4v6uk52bug16hrrhspfanlr D/SMACK﹕ RCV (12): W/AbstractXMPPConnection﹕ Connection closed with error javax.net.ssl.SSLException: Connection closed by peer at com.android.org.conscrypt.NativeCrypto.SSL_do_handshake(Native Method) at com.android.org.conscrypt.OpenSSLSocketImpl.startHandshake(OpenSSLSocketImpl.ja va:405) at com.android.org.conscrypt.OpenSSLSocketImpl$SSLInputStream.(OpenSSLSocket Impl.java:661) at com.android.org.conscrypt.OpenSSLSocketImpl.getInputStream(OpenSSLSocketImpl.ja va:632) at org.jivesoftware.smack.tcp.XMPPTCPConnection.initReaderAndWriter(XMPPTCPConnect ion.java:661) at org.jivesoftware.smack.tcp.XMPPTCPConnection.proceedTLSReceived(XMPPTCPConnecti on.java:768) --- .../jivesoftware/smack/bosh/XMPPBOSHConnection.java | 7 ++++--- .../jivesoftware/smack/tcp/XMPPTCPConnection.java | 12 ++++++------ 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/smack-bosh/src/main/java/org/jivesoftware/smack/bosh/XMPPBOSHConnection.java b/smack-bosh/src/main/java/org/jivesoftware/smack/bosh/XMPPBOSHConnection.java index ad3d4868e..6539686fb 100644 --- a/smack-bosh/src/main/java/org/jivesoftware/smack/bosh/XMPPBOSHConnection.java +++ b/smack-bosh/src/main/java/org/jivesoftware/smack/bosh/XMPPBOSHConnection.java @@ -200,6 +200,10 @@ public class XMPPBOSHConnection extends AbstractXMPPConnection { + getHost() + ":" + getPort() + "."; throw new SmackException(errorMessage); } + + // Wait with SASL auth until the SASL mechanisms have been received + saslFeatureReceived.checkIfSuccessOrWaitOrThrow(); + callConnectionConnectedListener(); } @@ -244,9 +248,6 @@ public class XMPPBOSHConnection extends AbstractXMPPConnection { throw new AlreadyLoggedInException(); } - // Wait with SASL auth until the SASL mechanisms have been received - saslFeatureReceived.checkIfSuccessOrWaitOrThrow(); - // Do partial version of nameprep on the username. username = username.toLowerCase(Locale.US).trim(); diff --git a/smack-tcp/src/main/java/org/jivesoftware/smack/tcp/XMPPTCPConnection.java b/smack-tcp/src/main/java/org/jivesoftware/smack/tcp/XMPPTCPConnection.java index 32ab7ca69..b7e2afb66 100644 --- a/smack-tcp/src/main/java/org/jivesoftware/smack/tcp/XMPPTCPConnection.java +++ b/smack-tcp/src/main/java/org/jivesoftware/smack/tcp/XMPPTCPConnection.java @@ -360,9 +360,6 @@ public class XMPPTCPConnection extends AbstractXMPPConnection { throw new AlreadyLoggedInException(); } - // Wait with SASL auth until the SASL mechanisms have been received - saslFeatureReceived.checkIfSuccessOrWaitOrThrow(); - // Do partial version of nameprep on the username. if (username != null) { username = username.toLowerCase(Locale.US).trim(); @@ -634,9 +631,6 @@ public class XMPPTCPConnection extends AbstractXMPPConnection { // get an opening stream packet back from server packetReader.init(); - // Make note of the fact that we're now connected. - connected = true; - if (isFirstInitialization) { // Notify listeners that a new connection has been established for (ConnectionCreationListener listener : getConnectionCreationListeners()) { @@ -856,6 +850,12 @@ public class XMPPTCPConnection extends AbstractXMPPConnection { } // Establishes the connection, readers and writers connectUsingConfiguration(config); + + // Wait with SASL auth until the SASL mechanisms have been received + saslFeatureReceived.checkIfSuccessOrWaitOrThrow(); + + // Make note of the fact that we're now connected. + connected = true; callConnectionConnectedListener(); // Automatically makes the login if the user was previously connected successfully