5

I'm stuck with this problem and I can not solve it.

Code:

 ConnectionConfiguration config = new ConnectionConfiguration(host, port);
        config.setDebuggerEnabled(true);
        config.setSASLAuthenticationEnabled(true);
        config.setSecurityMode(ConnectionConfiguration.SecurityMode.enabled);

        XMPPConnection connection = new XMPPConnection(config);
try{
            connection.connect();
            connection.login(login, password);
            //auth.authenticate(login, password, host);
        }
        catch (XMPPException exc){
            exc.printStackTrace();
        }

full stack trace:

/Library/Java/JavaVirtualMachines/1.6.0_35-b10-428.jdk/Contents/Home/bin/java -Didea.launcher.port=7544 "-Didea.launcher.bin.path=/Applications/IntelliJ IDEA 11 CE.app/bin" -Dfile.encoding=UTF-8 -classpath "/Library/Java/JavaVirtualMachines/1.6.0_35-b10-428.jdk/Contents/Home/lib/deploy.jar:/Library/Java/JavaVirtualMachines/1.6.0_35-b10-428.jdk/Contents/Home/lib/dt.jar:/Library/Java/JavaVirtualMachines/1.6.0_35-b10-428.jdk/Contents/Home/lib/javaws.jar:/Library/Java/JavaVirtualMachines/1.6.0_35-b10-428.jdk/Contents/Home/lib/jce.jar:/Library/Java/JavaVirtualMachines/1.6.0_35-b10-428.jdk/Contents/Home/lib/jconsole.jar:/Library/Java/JavaVirtualMachines/1.6.0_35-b10-428.jdk/Contents/Home/lib/management-agent.jar:/Library/Java/JavaVirtualMachines/1.6.0_35-b10-428.jdk/Contents/Home/lib/plugin.jar:/Library/Java/JavaVirtualMachines/1.6.0_35-b10-428.jdk/Contents/Home/lib/sa-jdi.jar:/Library/Java/JavaVirtualMachines/1.6.0_35-b10-428.jdk/Contents/Classes/charsets.jar:/Library/Java/JavaVirtualMachines/1.6.0_35-b10-428.jdk/Contents/Classes/classes.jar:/Library/Java/JavaVirtualMachines/1.6.0_35-b10-428.jdk/Contents/Classes/jsse.jar:/Library/Java/JavaVirtualMachines/1.6.0_35-b10-428.jdk/Contents/Classes/ui.jar:/Library/Java/JavaVirtualMachines/1.6.0_35-b10-428.jdk/Contents/Home/lib/ext/apple_provider.jar:/Library/Java/JavaVirtualMachines/1.6.0_35-b10-428.jdk/Contents/Home/lib/ext/dnsns.jar:/Library/Java/JavaVirtualMachines/1.6.0_35-b10-428.jdk/Contents/Home/lib/ext/localedata.jar:/Library/Java/JavaVirtualMachines/1.6.0_35-b10-428.jdk/Contents/Home/lib/ext/sunjce_provider.jar:/Library/Java/JavaVirtualMachines/1.6.0_35-b10-428.jdk/Contents/Home/lib/ext/sunpkcs11.jar:/Users/dmitry/IdeaProjects/smacker/target/classes:/Users/dmitry/IdeaProjects/smacker/lib/smack-3.2.1.jar:/Users/dmitry/IdeaProjects/smacker/lib/smackx-3.2.1.jar:/Applications/IntelliJ IDEA 11 CE.app/lib/idea_rt.jar" com.intellij.rt.execution.application.AppMain Main
Connection failed. No response from server.: 
    at org.jivesoftware.smack.PacketReader.startup(PacketReader.java:119)
    at org.jivesoftware.smack.XMPPConnection.initConnection(XMPPConnection.java:568)
    at org.jivesoftware.smack.XMPPConnection.connectUsingConfiguration(XMPPConnection.java:527)
    at org.jivesoftware.smack.XMPPConnection.connect(XMPPConnection.java:953)
    at SessionsHandler.openSession(SessionsHandler.java:62)
    at Main.main(Main.java:16)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)

Smack debug output:

in:

<stream:stream to="xmpp.odnoklassniki.ru" xmlns="jabber:client" xmlns:stream="http://etherx.jabber.org/streams" version="1.0">
<starttls xmlns="urn:ietf:params:xml:ns:xmpp-tls"/>
<stream:stream to="odnoklassniki.ru" xmlns="jabber:client" xmlns:stream="http://etherx.jabber.org/streams" version="1.0">
</stream:stream>

out:

<?xml version="1.0"?><stream:stream xmlns="jabber:client" xmlns:stream="http://etherx.jabber.org/streams" from="odnoklassniki.ru" 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>X-ODKL-API</mechanism><mechanism>X-ODKL-BLOWFISH</mechanism><mechanism>PLAIN</mechanism></mechanisms><auth xmlns='http://jabber.org/features/iq-auth'/></stream:features>
<proceed xmlns='urn:ietf:params:xml:ns:xmpp-tls'/>
<?xml version="1.0"?><stream:stream xmlns="jabber:client" xmlns:stream="http://etherx.jabber.org/streams" from="odnoklassniki.ru" version="1.0" xml:lang="en">
<stream:features><mechanisms xmlns='urn:ietf:params:xml:ns:xmpp-sasl'><mechanism>X-ODKL-API</mechanism><mechanism>X-ODKL-BLOWFISH</mechanism><mechanism>PLAIN</mechanism></mechanisms><auth xmlns='http://jabber.org/features/iq-auth'/></stream:features>

telnet:

dmitry@pro:~$ telnet xmpp.odnoklassniki.ru 5222
Trying 217.20.145.69...
Connected to xmpp.odnoklassniki.ru.
Escape character is '^]'.
Flow
  • 23,572
  • 15
  • 99
  • 156
Dmitry Zagorulkin
  • 8,370
  • 4
  • 37
  • 60
  • Unfortunately the logging information you sent does not help a lot. Do you probably have exception stack trace? – AlexR Nov 08 '12 at 14:13

4 Answers4

8

The Smack library (3.2.2) expecting @id attribute in the second (after starttls) "stream:stream" packet.

This attribute is optional and xmpp.odnoklassnki.ru doesn't send it:

<stream:stream to="odnoklassniki.ru" xmlns="jabber:client" xmlns:stream="http://etherx.jabber.org/streams" version="1.0">

There are two options to solve this:

  • Either to patch PacketReader to assign some kind of "fake" ID to connections without @id attribute in stream:stream packet
  • or ask admins / developers of xmpp.odnoklassniki.ru to add (fake or real) ID attribute to stream:stream packet

This is a part "patched" of PacketReader:parsePackets() method. Please, note new connectionIdReceived variable and correspondent "if" condition:

// We found an opening stream. Record information about it, then notify
// the connectionID lock so that the packet reader startup can finish.
else if (parser.getName().equals("stream")) {
    // Ensure the correct jabber:client namespace is being used.
    if ("jabber:client".equals(parser.getNamespace(null))) {
        // Get the connection id.
        boolean connectionIdReceived = false;
        for (int i=0; i<parser.getAttributeCount(); i++) {
            if (parser.getAttributeName(i).equals("id")) {
                // Save the connectionID
                connectionID = parser.getAttributeValue(i);
                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();
                }
                connectionIdReceived = true;
            }
            else if (parser.getAttributeName(i).equals("from")) {
                // Use the server name that the server says that it is.
                connection.config.setServiceName(parser.getAttributeValue(i));
            }
        }
        if (!connectionIdReceived) {
            connectionID = "<unspecified>";
            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();
            }
        }
    }
}
vlsergey
  • 254
  • 1
  • 10
  • [As per RFC 6120 the `id` attribute is mandatory, not optional](http://xmpp.org/rfcs/rfc6120.html#streams-attr-id). You should contact the server developers/admins about the broken implementation. – Flow Dec 10 '12 at 20:26
  • @Flow , according to [RFC 3920](http://xmpp.org/rfcs/rfc3920.html#streams) (yes, obsoleted one, but still wildly used) it is optional: "The 'id' attribute SHOULD be used only in the XML stream header from the receiving entity to the initiating entity". Seems like a difference between old and new specification. – vlsergey Dec 13 '12 at 07:08
3

I see a couple of possibilities:

  • The cert you're getting from the server is not being accepted by your library because of trust chain or the *-name that the server is offering:

Subject: C=RU, L=Moscow, O=Odnoklassniki Ltd, CN=*.odnoklassniki.ru

  • In "secure" mode, your library doesn't like any of the auth mechanisms that are offered by that server, since there are only two non-standard mechanisms (X-ODKL-API, X-ODKL-BLOWFISH) and two less-secure mechanisms (PLAIN, http://jabber.org/features/iq-auth).

If I had to guess it would be the second. That's not an error condition that most client library authors are unlikely to run into. Turn off the security modes, and try again.

Joe Hildebrand
  • 10,354
  • 2
  • 38
  • 48
  • 2
    `config.setSASLAuthenticationEnabled(false); config.setSecurityMode(ConnectionConfiguration.SecurityMode.disabled);` - same error – Dmitry Zagorulkin Nov 12 '12 at 06:22
  • When i am trying same configuration with `adium` it is connected when `do strict certificate checks` option is setted. Could you give me something information. what does it mean? How i can get this certificate from the server. thank you! – Dmitry Zagorulkin Nov 12 '12 at 07:31
  • Getting the same error and doing same as @DmitryZagorulkin – Waqas Jan 30 '17 at 11:21
3

you XMPP domain seems to be wrong, this can be also the problem. And you also send both stream headers to different domains:

header 1 to xmpp.odnoklassniki.ru:

<stream:stream to="xmpp.odnoklassniki.ru" xmlns="jabber:client" xmlns:stream="http://etherx.jabber.org/streams" version="1.0">

header 2 to odnoklassniki.ru:

<stream:stream to="odnoklassniki.ru" xmlns="jabber:client" xmlns:stream="http://etherx.jabber.org/streams" version="1.0">

The server always replies with .... from="odnoklassniki.ru" .... So odnoklassniki.ru should be your correct XMPP domain.

Alex
  • 4,066
  • 2
  • 19
  • 21
  • good day. but if i type the `xmpp.odnoklassniki.ru:5222` in other client. it's working fine. Adium for instance. more info here:http://security.stackexchange.com/questions/23972/how-to-create-trusted-chain-of-certificates-if-i-have-the-last-certificate – Dmitry Zagorulkin Nov 16 '12 at 06:51
  • When Adium is able to connect then this does not mean that you are using the correct xmpp domain. Your server is probably very fault tolerant, and it offers only the weak PLAIN and old legacy auth mechanisms where the xmpp domain doesn't matter for authentication. – Alex Nov 16 '12 at 12:14
  • What do you think smack is able to connect to this server? what kind of configuration i should to do? – Dmitry Zagorulkin Nov 16 '12 at 12:26
1

try this...

it worked for me...try giving the resource name also...i face same problem gioving resource name solved it

 ConnectionConfiguration config;
config = new ConnectionConfiguration(ip, port, "Smack");
config.setSASLAuthenticationEnabled(false);
config.setReconnectionAllowed(true);
config.setCompressionEnabled(false);
config.setDebuggerEnabled(true);
connection = new XMPPConnection(config);
connection.connect();
if (connection.isConnected()) {
    connection.login(loginName, password);
}
Complicated
  • 117
  • 2
  • 16