Cannot connect to TLS 1.2
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.
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
Johny, are you still seeing this? I put in a workaround into XMPP, haven't checked if this was fixed upstream since then
hello-
yes, i can't check at the moment as i'm on holiday but i'll check in a few days
Any updated on this?
ah shoot, apologies- still need to test. i'll see if i can get that tested this weekend; it's in my calendar
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?
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.
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.
Any updates on this?
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.
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.
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
Interesting findings. What version are you using for sleekxmpp?
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
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.
FYI, PR #1377 was merged.
Closing. Reopen if there is still a problem.