Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Commit

Permalink
Suppress CryptographyDeprecationWarning (#9698)
Browse files Browse the repository at this point in the history
This warning is somewhat confusing to users, so let's suppress it
  • Loading branch information
richvdh authored Mar 26, 2021
1 parent b5efcb5 commit 7c8402d
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 14 deletions.
1 change: 1 addition & 0 deletions changelog.d/9698.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Suppress "CryptographyDeprecationWarning: int_from_bytes is deprecated".
21 changes: 21 additions & 0 deletions synapse/app/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@
import socket
import sys
import traceback
import warnings
from typing import Awaitable, Callable, Iterable

from cryptography.utils import CryptographyDeprecationWarning
from typing_extensions import NoReturn

from twisted.internet import defer, error, reactor
Expand Down Expand Up @@ -195,6 +197,25 @@ def listen_metrics(bind_addresses, port):
start_http_server(port, addr=host, registry=RegistryProxy)


def listen_manhole(bind_addresses: Iterable[str], port: int, manhole_globals: dict):
# twisted.conch.manhole 21.1.0 uses "int_from_bytes", which produces a confusing
# warning. It's fixed by https://github.com/twisted/twisted/pull/1522), so
# suppress the warning for now.
warnings.filterwarnings(
action="ignore",
category=CryptographyDeprecationWarning,
message="int_from_bytes is deprecated",
)

from synapse.util.manhole import manhole

listen_tcp(
bind_addresses,
port,
manhole(username="matrix", password="rabbithole", globals=manhole_globals),
)


def listen_tcp(bind_addresses, port, factory, reactor=reactor, backlog=50):
"""
Create a TCP socket for a port and several addresses
Expand Down
9 changes: 2 additions & 7 deletions synapse/app/generic_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,6 @@
from synapse.types import ReadReceipt
from synapse.util.async_helpers import Linearizer
from synapse.util.httpresourcetree import create_resource_tree
from synapse.util.manhole import manhole
from synapse.util.versionstring import get_version_string

logger = logging.getLogger("synapse.app.generic_worker")
Expand Down Expand Up @@ -640,12 +639,8 @@ def start_listening(self, listeners: Iterable[ListenerConfig]):
if listener.type == "http":
self._listen_http(listener)
elif listener.type == "manhole":
_base.listen_tcp(
listener.bind_addresses,
listener.port,
manhole(
username="matrix", password="rabbithole", globals={"hs": self}
),
_base.listen_manhole(
listener.bind_addresses, listener.port, manhole_globals={"hs": self}
)
elif listener.type == "metrics":
if not self.get_config().enable_metrics:
Expand Down
9 changes: 2 additions & 7 deletions synapse/app/homeserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@
from synapse.storage.engines import IncorrectDatabaseSetup
from synapse.storage.prepare_database import UpgradeDatabaseException
from synapse.util.httpresourcetree import create_resource_tree
from synapse.util.manhole import manhole
from synapse.util.module_loader import load_module
from synapse.util.versionstring import get_version_string

Expand Down Expand Up @@ -288,12 +287,8 @@ def start_listening(self, listeners: Iterable[ListenerConfig]):
if listener.type == "http":
self._listening_services.extend(self._listener_http(config, listener))
elif listener.type == "manhole":
listen_tcp(
listener.bind_addresses,
listener.port,
manhole(
username="matrix", password="rabbithole", globals={"hs": self}
),
_base.listen_manhole(
listener.bind_addresses, listener.port, manhole_globals={"hs": self}
)
elif listener.type == "replication":
services = listen_tcp(
Expand Down

0 comments on commit 7c8402d

Please sign in to comment.