errbot icon indicating copy to clipboard operation
errbot copied to clipboard

Cannot connect to TLS 1.2

Open johnnybubonic opened this issue 8 years ago • 17 comments

I am...

  • [x] Reporting a bug
  • [ ] Suggesting a new feature
  • [ ] Requesting help with running my bot
  • [ ] Requesting help writing plugins
  • [ ] Here about something else

I am running...

  • Errbot version: 5.2.0
  • OS version: CentOS 7.4.1708
  • Python version: 3.6.4
  • Using a virtual environment: no

Issue description

The server (ejabberd 18.04) is set to require STARTTLS, and will only accept TLSv1.1 and TLS1.2. Not only is it seemingly impossible to specify these (additionally, it should be possible to specify a list of client ciphers to try in preferential order), but I further get CERT: Invalid certificate trust chain. - even if I use XMPP_CA_CERT_FILE = None.

Steps to reproduce

See above.

johnnybubonic avatar May 30 '18 22:05 johnnybubonic

More information:

after modifying line 874 in ~/.local/lib/python3.6/site-packages/sleekxmpp/xmlstream/xmlstream.py per this comment

from:

        except (Socket.error, ssl.SSLError):
            log.error('CERT: Invalid certificate trust chain.')

to:

        except (Socket.error, ssl.SSLError) as serr:
            log.error('CERT: Invalid certificate trust chain.')
            error_msg = "Could not connect to %s:%s. Socket Error #%s: %s"
            self.event('socket_error', serr, direct=True)
            log.error(error_msg, self.address[0], self.address[1],
                                 serr.errno, serr.strerror)

I get the following error output:

22:20:26 INFO     sleekxmpp.xmlstream.xmlst Negotiating TLS
22:20:26 INFO     sleekxmpp.xmlstream.xmlst Using SSL version: TLSv1
22:20:26 ERROR    sleekxmpp.xmlstream.xmlst CERT: Invalid certificate trust chain.
22:20:26 ERROR    sleekxmpp.xmlstream.xmlst Could not connect to [REDACTED]:5222. Socket Error #8: EOF occurred in violation of protocol (_ssl.c:777)

And, per the config:

[bot@[REDACTED] ~]$ egrep -E '^XMPP_CA_CERT_FILE' config.py
XMPP_CA_CERT_FILE = None

So it would seem that SleekXMPP doesn't support TLS1.2? Perhaps https://github.com/poezio/slixmpp would be an acceptable alternative? (Differences)

For what it's worth:

[bot@[REDACTED] ~]$ openssl version OpenSSL 1.0.2k-fips 26 Jan 2017

johnnybubonic avatar May 30 '18 22:05 johnnybubonic

Johny, are you still seeing this? I put in a workaround into XMPP, haven't checked if this was fixed upstream since then

nulfox avatar Jun 28 '18 12:06 nulfox

hello-

yes, i can't check at the moment as i'm on holiday but i'll check in a few days

johnnybubonic avatar Jun 29 '18 13:06 johnnybubonic

Any updated on this?

sijis avatar Aug 07 '18 18:08 sijis

ah shoot, apologies- still need to test. i'll see if i can get that tested this weekend; it's in my calendar

johnnybubonic avatar Aug 10 '18 10:08 johnnybubonic

okay, i have some time to test. how am i testing this? pypi still has 5.2.0.

any quick instructions on how i can test from my virtualenv?

johnnybubonic avatar Aug 10 '18 23:08 johnnybubonic

You can try this

# python3 -m venv venv

$ source venv/bin/activate

#you should now be in a virtualenv

$ git clone https://github.com/errbotio/errbot

$ cd errbot

$ pip install .

# now copy your errbot config.py and start the bot

$ errbot

At the end, you should have the latest version of errbot (potentially unreleased) installed within a virtualenv.

sijis avatar Aug 11 '18 01:08 sijis

hrm. had to manually install some other modules (sleekxmpp, parsedatetime, pytz - pytz, i'm pretty sure, was for a plugin) into the venv with pip.

18:43:45 INFO     sleekxmpp.xmlstream.xmlst Negotiating TLS
18:43:45 INFO     sleekxmpp.xmlstream.xmlst Using SSL version: TLSv1
18:43:45 ERROR    sleekxmpp.xmlstream.xmlst CERT: Invalid certificate trust chain.
18:43:45 INFO     errbot.core               Disconnect callback, deactivating all the plugins.
18:43:45 ERROR    sleekxmpp.xmlstream.xmlst Can not read from closed socket.
18:43:51 INFO     sleekxmpp.xmlstream.xmlst Negotiating TLS
18:43:51 INFO     sleekxmpp.xmlstream.xmlst Using SSL version: TLSv1
18:43:51 ERROR    sleekxmpp.xmlstream.xmlst CERT: Invalid certificate trust chain.
18:43:51 INFO     errbot.core               Disconnect callback, deactivating all the plugins.
18:43:51 ERROR    sleekxmpp.xmlstream.xmlst Can not read from closed socket.
18:43:52 INFO     errbot.core               Disconnect callback, deactivating all the plugins.

that's with XMPP_CA_CERT_FILE = None.

when i leave it undefined in config.py, i get:

18:46:08 INFO     sleekxmpp.xmlstream.xmlst Negotiating TLS
18:46:08 INFO     sleekxmpp.xmlstream.xmlst Using SSL version: TLSv1
18:46:08 ERROR    sleekxmpp.xmlstream.xmlst Socket Error #2: No such file or directory
18:46:08 INFO     sleekxmpp.xmlstream.xmlst Waiting for </stream:stream> from server
18:46:12 INFO     errbot.core               Disconnect callback, deactivating all the plugins.

johnnybubonic avatar Aug 14 '18 18:08 johnnybubonic

Any updates on this?

patrick7 avatar Jul 09 '19 07:07 patrick7

None. There are a few new releases of errbot, which you should try, but I don't think it will address anything you are seeing.

My guess is that it's something on the sleekxmpp side and how we call it. You can try using an older version of sleekxmpp and see if there is any progress.

sijis avatar Jul 12 '19 01:07 sijis

Hi Everyone, I came across this issue when searching for SleekXMPP TLSv1.2 support and my solution was to patch SleekXMPP in my Dockerfile:

COPY requirements.txt ./
RUN pip install --no-cache-dir -r requirements.txt && \
    PY_VER=$(python -V | grep -m 1 -o [0-9]\.[0-9]) && \
    echo "Patching SleekXMPP for TLSv1_2 support over Python ${PY_VER}.X" && \
    sed -i 's/PROTOCOL_TLSv1/PROTOCOL_TLSv1_2/' /usr/local/lib/python${PY_VER}/site-packages/sleekxmpp/xmlstream/xmlstream.py

I hope you can get a hint how to implement this in your project, too.

immanuelfodor avatar Aug 20 '19 07:08 immanuelfodor

It turns out, there is no need to patch the lib, the desired TLS protocol can be set on the XMPP object before connecting, see here: https://github.com/fritzy/SleekXMPP/blob/ab5b056194411f53bd07f64ca18d25b5df4b4386/examples/send_client.py#L129

import ssl

# ...

xmpp.ssl_version = ssl.PROTOCOL_TLSv1_2

So in your project, it should be set around here on self.client (init or connect func):

  • https://github.com/errbotio/errbot/blob/master/errbot/backends/xmpp.py#L311
  • https://github.com/errbotio/errbot/blob/master/errbot/backends/xmpp.py#L333

immanuelfodor avatar Aug 20 '19 11:08 immanuelfodor

Interesting findings. What version are you using for sleekxmpp?

sijis avatar Aug 20 '19 18:08 sijis

Nothing special, the latest that comes wit pip, 1.3.3. Here is my requirements.txt and the project where I needed to set up TLSv1.2, it works fine: https://github.com/immanuelfodor/xmpp-muc-message-gateway

immanuelfodor avatar Aug 21 '19 02:08 immanuelfodor

I've created PR #1377 based on the feedback from @immanuelfodor. I do not have access to any xmpp service so I cannot truly check the changes included.

I would appreciate if anyone could try out the changes in that PR and see if it addresses any of the issues.

sijis avatar Aug 23 '19 03:08 sijis

FYI, PR #1377 was merged.

selurvedu avatar Dec 16 '19 15:12 selurvedu

Closing. Reopen if there is still a problem.

sijis avatar Dec 16 '19 17:12 sijis