Commit Graph

145 Commits

Author SHA1 Message Date
Val Lorentz
2902a85dbd
Fix STS parsing and handling of unchecked-TLS connections (#1524)
* ircutils: Fix incorrect log message on invalid STS policy

* STS: fix confusion over what a secure connection is

irclib computed 'secure_connection' when TLS is enabled and TLS certs
are checked; but ircutils used the value to parse STS policies, which
should only care about being TLS or not.

This commit fixes the incorrect parsing on unchecked-TLS, and triggers
a reconnect when a STS policy is encountered in this case, to force
TLS certs to be checked before storing the policy.

* Accept STS policies when reconnecting after getting it over cleartext

ircutils.parseStsPolicy() was passed self.driver.ssl which is the configured
value, even though the connection was forced to be TLS temporarily

* ci: Lower timeout

* Fix typo in test name

Co-authored-by: James Lu <james@overdrivenetworks.com>

---------

Co-authored-by: James Lu <james@overdrivenetworks.com>
2023-06-10 08:28:08 +02:00
Valentin Lorentz
add9306d30 Socket: Clear buffers on reconnect 2023-03-24 20:23:32 +01:00
Valentin Lorentz
4a620bf7f0 Socket: Use the right variable to initialize the reconnect delay 2022-06-16 22:35:08 +02:00
Valentin Lorentz
94d669ebec Make the minimum reconnect delay configurable 2022-05-28 13:53:05 +02:00
Valentin Lorentz
74f86654b1 Remove fallbacks for old Python versions. 2022-01-01 18:11:36 +01:00
Valentin Lorentz
baa8cda814 Fix bypassed cache invalidation checks, causing '@config reload' to be partially ignored
`registry.Value.__call__()` is a wrapper around access to
`registry.Value.value`, that checks if the value was set before the latest
call to `registry.open_registry`; and updates the `value` if needed.

When accessing `registry.Value.value` directly, this cache can't be
invalidated, causing the old value to still be used, until the next call
to `registry.Value.__call__()`.
2021-12-03 16:56:06 +01:00
Valentin Lorentz
63eb6672ea Revert generic 'The Limnoria Contributors' in copyright notices
This commit reverts db7ef3f025
(though it keeps the year updates)

After discussion with several people, it seems better to mention
copyright owners explicitly. eg. https://reuse.software/faq/#vcs-copyright
explains the issue of using VCSs to track copyright.

As db7ef3f025 only replaced mentions
of my name with 'The Limnoria Contributors', this commit only needs
to undo that + add one person who contributed to setup.py.
2021-10-17 09:57:55 +02:00
Valentin Lorentz
76bd1c89bf Socket: Gracefully handle invalid lines with UTF8ONLY
Just skip the line, instead of crashing the whole loop (which
contains the next lines from the same server too)
2021-09-13 18:45:49 +02:00
Valentin Lorentz
ee9f0dc1bf STS: When persisting STS keys, use the actual port instead of the one from the policy
'Servers MAY send this key to securely connected clients, but it will be ignored.'
-- https://ircv3.net/specs/extensions/sts\#the-port-key
2021-09-03 20:15:18 +02:00
Valentin Lorentz
d593f84a66 Socket: disable charset heuristics when the server advertizes UTF8ONLY. 2021-08-27 19:03:18 +02:00
Valentin Lorentz
db7ef3f025 all: Add generic 'The Limnoria Contributors' to copyright notices.
No need to bother with details (that are all outdated / out of sync
anyway), just look up the git history.
2021-08-01 21:54:49 +02:00
Valentin Lorentz
0f1011081e Socket: Fix cascading crash when Socket.run() crashes.
When a driver's run() method crashes, supybot.drivers.run() marks it
as dead and sets its 'irc' attribute to None.

This would be fine for "normal" independent drivers (like Socket used
to be), because this driver would never be called again.

But now that we use select(), some other thread may hold a reference
to this driver in a select() call frame, and call the dead driver's
'_read()' method when there is data to be read from the socket.

There is already a safeguard in '_read()' in the case the socket could
be read from, but this safeguard was missing from _handleSocketError.
This caused the "live" driver's select() to crash, which propagagated
to its run(), which caused the driver to be marked as dead, etc.

Eventually, all drivers could die, and we end up with the dreadful
"Schedule is the only remaining driver, why do we continue to live?"
in an infinite loop.
2021-07-14 23:55:31 +02:00
Tim Gates
649048443e
Fix a few simple typos (#1476)
Closes #1475
2021-06-21 01:07:50 +02:00
Valentin Lorentz
c8053dad54 Socket: Silence TLS warning for Tor hidden services.
They are already end-to-end encrypted and don't need TLS.
2021-06-12 21:03:15 +02:00
Valentin Lorentz
aaca81c5b9 drivers: Fix log message when the STS policy uses the same port as configured. 2021-06-02 16:51:09 +02:00
Valentin Lorentz
711db72ad0 Socket: Fix crash non-TLS connections when using a SOCKS proxy 2021-05-27 01:08:33 +02:00
Valentin Lorentz
3bedc86479 Socket: Disable resolution when using a SOCKS proxy
1. Avoids leaking DNS queries
2. necessary for onion services
2021-05-27 00:08:02 +02:00
Valentin Lorentz
cca1156b90 drivers: Log SOCKS proxy on connecting 2021-05-26 23:43:23 +02:00
Valentin Lorentz
9323302704 Socket: Recover from socks.GeneralProxyError exceptions. 2021-04-05 13:41:29 +02:00
Valentin Lorentz
92399bb6a7 drivers: Don't strip all whitespaces before parsing messages.
They matter in multiline messages, and there isn't much point to
stripping them anyway.
2021-04-01 20:10:17 +02:00
Valentin Lorentz
772ec8d6a9 When getting STS policy over insecure connection, reuse the exact same IP address
Otherwise, if some IP addresses don't work (eg. all odd ones), the bot will
consecutively fail because it can't connect, then connect + get STS + reconnect,
then fail again, then connect + get STS, etc.
2021-01-11 23:22:21 +01:00
Valentin Lorentz
ba77de0946 Try all IP addresses of a hostname.
Fixes a regression in ecc2c32950 that caused
Socket.py to ignore the IP address entirely after computing it, and
to call getSocket() and connect() with the hostname instead.
2020-12-05 14:26:52 +01:00
Valentin Lorentz
277cbb6589 Socket: Add missing self argument to setTimeout. 2020-05-30 21:54:24 +02:00
Valentin Lorentz
2bcdfd069a Socket: Detect closed TCP connections.
So far Limnoria relied on detecting 'ERROR :closing link' (see doError
in src/irclib.py), but that's not a standard at all, and fails on
Oragono; so we need to do this to check we're disconnected.

Plus, parsing the argument of ERROR is awful in the first place.
2020-05-29 19:50:43 +02:00
Valentin Lorentz
d9b1d1f49d Socket: make setTimeout catch errors.
setTimeout may be called as a supybot.drivers.poll callback,
which may by the access to supybot.drivers.poll() in _select;
so a crash in setTimeout will propage up to _run(), which would
cause a random driver to be killed because another one failed
and that's bad.

For example:

INFO 2020-05-27T18:40:18 supybot Received SIGHUP, reloading configuration.
ERROR 2020-05-27T18:40:19 supybot Uncaught exception in in drivers.run:
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/supybot/drivers/__init__.py", line 104, in run
    driver.run()
  File "/usr/lib/python3/dist-packages/supybot/drivers/Socket.py", line 194, in run
    self._select()
  File "/usr/lib/python3/dist-packages/supybot/drivers/Socket.py", line 167, in _select
    [], [], conf.supybot.drivers.poll())
  File "/usr/lib/python3/dist-packages/supybot/registry.py", line 422, in __call__
    self.set(_cache[self._name])
  File "/usr/lib/python3/dist-packages/supybot/registry.py", line 476, in set
    self.setValue(float(s))
  File "/usr/lib/python3/dist-packages/supybot/registry.py", line 495, in setValue
    super(PositiveFloat, self).setValue(v)
  File "/usr/lib/python3/dist-packages/supybot/registry.py", line 482, in setValue
    super(Float, self).setValue(float(v))
  File "/usr/lib/python3/dist-packages/supybot/registry.py", line 385, in setValue
    callback(*args, **kwargs)
  File "/usr/lib/python3/dist-packages/supybot/drivers/Socket.py", line 305, in setTimeout
    self.conn.settimeout(conf.supybot.drivers.poll())
OSError: [Errno 9] Bad file descriptor
ERROR 2020-05-27T18:40:19 supybot Exception id: 0x86ecf
INFO 2020-05-27T18:40:21 supybot Removing driver SocketDriver(Irc object for irchaven).
2020-05-29 19:50:28 +02:00
Valentin Lorentz
fabe8a284e Socket: de-register setTimeout from supybot.drivers.poll's callbacks when dying. 2020-05-29 19:42:42 +02:00
Valentin Lorentz
88549f9faa Socket: Move call to supybot.drivers.poll outside the critical section.
It may do some non-trivial stuff (eg. calling registry callbacks);
and the less code in the locked-section the better.
2020-05-29 19:41:25 +02:00
Valentin Lorentz
f9bf75aeee net: Give more context to TLS errors.
They are notoriously hard to read, so let's at least say which
part of ssl_wrap_socket triggered them so the user have some
idea what is going on.
2020-05-26 23:06:39 +02:00
Valentin Lorentz
d56e8ef73d Socket: Remove misleading error fallback for Python <3.4.
We no longer support this Python version.

Fixes GH-1412.
2020-05-26 23:01:10 +02:00
Valentin Lorentz
22120ee862 Fix various issues with STS handling. 2020-05-01 19:46:19 +02:00
Valentin Lorentz
51ff013fcc Apply STS policies when connecting to a server. 2020-05-01 19:46:19 +02:00
Valentin Lorentz
ecc2c32950 Add support for storing STS policies.
If on an insecure connection: reconnect.
If on a secure connect: store it and do nothing else.

For now, stored STS policies are not read when connecting to an
insecure server.
2020-05-01 19:46:19 +02:00
Valentin Lorentz
ff5edd95a3 Remove Twisted.
There's no reason to use it anymore instead of Socket.
It's already missing features compared to Socket, and I don't want to
maintain it anymore so it will keep getting worse.
2020-05-01 19:46:19 +02:00
Valentin Lorentz
3576503e3f Update links to the documentation. 2020-03-17 19:22:52 +01:00
Valentin Lorentz
5efd2afa27 Socket: Don't add instances twice in cls._instances.
The connect() method already adds it, so it was in the list twice
(added both by __init__() and connect()).

This caused _select() to call _read() twice on the same instance,
except there is usually nothing to read on the second call,
so it blocks for up to conf.supybot.drivers.poll().
2020-01-25 21:00:42 +01:00
Valentin Lorentz
777d8e4920 Socket: use a proper lock instead of a boolean. 2020-01-23 16:47:49 +01:00
Valentin Lorentz
11dd5049fe Fix MITM warning. 2018-10-06 08:13:10 +02:00
James Lu
c5175110e0 Socket: fix 91a38887a with backported ipaddress on Python 2
Closes GH-1342.
2018-07-09 03:37:10 +00:00
James Lu
72c4801bb9 Socket: fix previous commit 2018-06-19 12:13:45 -07:00
James Lu
91a38887a2 Socket: suppress "not using TLS" errors on loopback addresses
This is a refined version of #1317.
2018-06-19 11:59:42 -07:00
James Lu
afc8d828b2 Merge remote-tracking branch 'origin/patch-1' into drivers/logging
Conflicts:
	src/drivers/Socket.py
2016-02-24 07:07:29 -08:00
Valentin Lorentz
d163d1a1a3 Add support for authority certificates. 2016-02-23 20:52:36 +01:00
James Lu
b344126318 Socket: update logging text to flow better 2016-02-23 07:29:16 -08:00
Valentin Lorentz
78cf550674 Socket: fix crash on Python versions that do no support certificate validation. 2016-02-23 16:25:37 +01:00
James Lu
aee7ac3583 Socket: drop SSL-related logging from critical to warning / error, and fix spacing 2016-02-22 07:09:56 -08:00
Valentin Lorentz
a7096f8b3e Disable SSL cert verification by default.
Having it enabled by default would break existing bots just by
doing the update.
Let's just show a warning and give owners some time to update
their config, for the moment.
2016-02-21 14:47:44 +01:00
Valentin Lorentz
ae560dbd2a Add supybot.protocols.ssl.verifyCertificates.
And remove unused variable supybot.protocols.ssl.verifyMode.
2016-02-21 14:42:41 +01:00
Valentin Lorentz
e77e78e79e Add support for using server certificate fingerprint instead of CA signature. 2016-02-21 14:18:14 +01:00
Valentin Lorentz
d922af1043 Verify server certificate, and deprecate Python < 2.7.9. Closes GH-1031. 2016-02-21 13:20:09 +01:00
Valentin Lorentz
6d4ea07b72 Remove a driver from the list of dead drivers after it has been restarted. Closes GH-1165. 2016-02-09 17:31:39 +00:00