1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2024-11-22 03:52:06 +01:00

Move saslFeatureReceived check in connect()

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): <stream:stream xmlns='jabber:client' to='*server*' xmlns:stream='http://etherx.jabber.org/streams' version='1.0'>
D/SMACK﹕ SENT (12): <iq id='miS03-37' to='*server*' type='get'><query xmlns='jabber:iq:register'></query></iq>
D/SMACK﹕ RCV (12): <?xml version='1.0'?><stream:stream xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams' id='4280133582' from='*server*' version='1.0' xml:lang='en'><stream:features><starttls xmlns='urn:ietf:params:xml:ns:xmpp-tls'/><mechanisms xmlns='urn:ietf:params:xml:ns:xmpp-sasl'><mechanism>PLAIN</mechanism><mechanism >DIGEST-MD5</mechanism><mechanism>SCRAM-SHA-1</mechanism></mechanisms><c xmlns='http://jabber.org/protocol/caps' hash='sha-1' node='http://www.process-one.net/en/ejabberd/' ver='a4WL1hRFRX38OouQz3okC+ayK2o='/><register xmlns='http://jabber.org/features/iq-register'/></stream:features>
D/SMACK﹕ SENT (12): <starttls xmlns='urn:ietf:params:xml:ns:xmpp-tls'></starttls>
D/SMACK﹕ RCV (12): <iq from='*server*' id='miS03-37' type='result'><query xmlns='jabber:iq:register'><instructions>Choose a username and password to register with this server</instructions><username></username><password/></query></iq>
D/SMACK﹕ SENT (12): <iq id='miS03-39' to='*server*' type='set'><query xmlns='jabber:iq:register'><password>s0r73pgojeopmssjaairu6kcmk3v4l</password>< username>nqcjloj4v6uk52bug16hrrhspfanlr</username></query></iq>
D/SMACK﹕ RCV (12): <proceed xmlns='urn:ietf:params:xml:ns:xmpp-tls'/>
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.<init>(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)
This commit is contained in:
Florian Schmaus 2014-09-29 16:41:56 +02:00
parent 7521ef951a
commit a942863ffe
2 changed files with 10 additions and 9 deletions

View file

@ -200,6 +200,10 @@ public class XMPPBOSHConnection extends AbstractXMPPConnection {
+ getHost() + ":" + getPort() + "."; + getHost() + ":" + getPort() + ".";
throw new SmackException(errorMessage); throw new SmackException(errorMessage);
} }
// Wait with SASL auth until the SASL mechanisms have been received
saslFeatureReceived.checkIfSuccessOrWaitOrThrow();
callConnectionConnectedListener(); callConnectionConnectedListener();
} }
@ -244,9 +248,6 @@ public class XMPPBOSHConnection extends AbstractXMPPConnection {
throw new AlreadyLoggedInException(); throw new AlreadyLoggedInException();
} }
// Wait with SASL auth until the SASL mechanisms have been received
saslFeatureReceived.checkIfSuccessOrWaitOrThrow();
// Do partial version of nameprep on the username. // Do partial version of nameprep on the username.
username = username.toLowerCase(Locale.US).trim(); username = username.toLowerCase(Locale.US).trim();

View file

@ -360,9 +360,6 @@ public class XMPPTCPConnection extends AbstractXMPPConnection {
throw new AlreadyLoggedInException(); throw new AlreadyLoggedInException();
} }
// Wait with SASL auth until the SASL mechanisms have been received
saslFeatureReceived.checkIfSuccessOrWaitOrThrow();
// Do partial version of nameprep on the username. // Do partial version of nameprep on the username.
if (username != null) { if (username != null) {
username = username.toLowerCase(Locale.US).trim(); username = username.toLowerCase(Locale.US).trim();
@ -634,9 +631,6 @@ public class XMPPTCPConnection extends AbstractXMPPConnection {
// get an opening stream packet back from server // get an opening stream packet back from server
packetReader.init(); packetReader.init();
// Make note of the fact that we're now connected.
connected = true;
if (isFirstInitialization) { if (isFirstInitialization) {
// Notify listeners that a new connection has been established // Notify listeners that a new connection has been established
for (ConnectionCreationListener listener : getConnectionCreationListeners()) { for (ConnectionCreationListener listener : getConnectionCreationListeners()) {
@ -856,6 +850,12 @@ public class XMPPTCPConnection extends AbstractXMPPConnection {
} }
// Establishes the connection, readers and writers // Establishes the connection, readers and writers
connectUsingConfiguration(config); 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(); callConnectionConnectedListener();
// Automatically makes the login if the user was previously connected successfully // Automatically makes the login if the user was previously connected successfully