xmppjs / xmpp.js

XMPP for JavaScript
ISC License
2.19k stars 372 forks source link

starttls should be ignorered when not using tcp #807

Closed DaveLomber closed 4 years ago

DaveLomber commented 4 years ago

We are trying to use the lib against Node 10.x

But getting the following error when trying to connect

[Chat] Connect with parameters  { userId: 35568, password: 'newUserAwesome' }
[Chat] status connecting wss://chat.connectycube.com:5291
[Chat] status connect 
[Chat] CONNECTING
[Chat] status opening 
[Chat] SENT: <open version="1.0" xmlns="urn:ietf:params:xml:ns:xmpp-framing" to="chat.connectycube.com"/>
[Chat] RECV: <open xmlns='urn:ietf:params:xml:ns:xmpp-framing' from='chat.connectycube.com' id='0ff4ce24-3d45-4202-bef2-6f00d980536c' version='1.0' xml:lang='en' />
[Chat] status open <open xmlns="urn:ietf:params:xml:ns:xmpp-framing" from="chat.connectycube.com" id="0ff4ce24-3d45-4202-bef2-6f00d980536c" version="1.0" xml:lang="en"/>
[Chat] RECV: <stream:features xmlns:stream="http://etherx.jabber.org/streams"><sm xmlns="urn:xmpp:sm:3"/><mechanisms xmlns="urn:ietf:params:xml:ns:xmpp-sasl"><mechanism>PLAIN</mechanism><mechanism>ANONYMOUS</mechanism></mechanisms><ver xmlns="urn:xmpp:features:rosterver"/><starttls xmlns="urn:ietf:params:xml:ns:xmpp-tls"/><compression xmlns="http://jabber.org/features/compress"><method>zlib</method></compression></stream:features>
[Chat] SENT: <starttls xmlns="urn:ietf:params:xml:ns:xmpp-tls"/>
[Chat] RECV: <proceed xmlns="urn:ietf:params:xml:ns:xmpp-tls"/>
[Chat] ERROR: TypeError: stream.pause is not a function

  Message:
    Unhandled promise rejection: TypeError: stream.pause is not a function
  Stack:
        at <Jasmine>
        at new JSStreamWrap (internal/wrap_js_stream.js:48:12)
        at new TLSSocket (_tls_wrap.js:316:12)
        at Object.connect (_tls_wrap.js:1123:16)
        at Promise (/Users/qwerty/workspace/myapp/node_modules/@xmpp/starttls/client.js:18:27)
        at <Jasmine>
        at proceed (/Users/qwerty/workspace/myapp/node_modules/@xmpp/starttls/client.js:14:10)
        at streamFeatures.use (/Users/qwerty/workspace/myapp/node_modules/@xmpp/starttls/client.js:41:11)
        at process._tickCallback (internal/process/next_tick.js:68:7)
DaveLomber commented 4 years ago

I commented these 2 lines:

https://github.com/xmppjs/xmpp.js/blob/master/packages/client/index.js#L48 https://github.com/xmppjs/xmpp.js/blob/master/packages/client/index.js#L68

and it started to work

DaveLomber commented 4 years ago

From my understanding, the lib should not send 'starttls' if we use wss as we already connect to secure port

DaveLomber commented 4 years ago

And I replaced

let XMPPClient = require('@xmpp/client');

with

let XMPPClient = require('@xmpp/client/react-native');

and it started to work for Node WSS, as RN file does not use 'starttls' as I see

So I need some output here, what's the right way, is there an issue with lib for Node WSS etc

sonnyp commented 4 years ago

What is your XMPP server? It shouldn't offer starttls on Websocket.

Is it prosody? In which case it was fixed in version 0.10 .

See https://issues.prosody.im/837

DaveLomber commented 4 years ago

We use Tigase

sonnyp commented 4 years ago

Okay so it's the same issue prosody had. Could you report the bug to Tigase and link it here?

Should be quite easy to workaround the issue in xmpp.js. See https://github.com/xmppjs/xmpp.js/blob/master/packages/starttls/client.js Something like:

function isUsingNodeSocket(entity) {
  // figure out a reliable way to find out if entity (client) transport is using a node.js net socket
  return true || false
}

module.exports = function({streamFeatures}) {
  return streamFeatures.use('starttls', NS, async (({entity}), next) => {
    // https://github.com/xmppjs/xmpp.js/issues/807
    if (!isUsingNodeSocket(entity)) {
      return next()
    }

    await starttls(entity)
    await proceed(entity)
    await entity.restart()
  })
}

I'd appreciate if you could give it a try. I'd be happy to help. Let me know.

Otherwise/Meanwhile, you could use @xmpp/client-core instead of @xmpp/client and exclude starttls. See https://github.com/xmppjs/xmpp.js/blob/master/packages/client/index.js for an example

DaveLomber commented 4 years ago

@sonnyp thank you for the detailed response I will check for Tigase

Meanwhile, the let XMPPClient = require('@xmpp/client/react-native'); way works currently for me, as it does not require 'starttls' at all. I will also check for @xmpp/client-core

sonnyp commented 4 years ago

fixed in https://github.com/xmppjs/xmpp.js/pull/809

@DaveLomber I opened an issue with the Tigase project https://github.com/tigase/tigase-server/issues/10

sonnyp commented 4 years ago

released in v0.9.2