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

Commit 3057095

Browse files
anoadragon453richvdh
authored andcommitted
Revert "Use the v2 lookup API for 3PID invites (#5897)" (#5937)
This reverts commit 71fc040. This broke 3PID invites as #5892 was required for it to work correctly.
1 parent 5625abe commit 3057095

File tree

4 files changed

+9
-166
lines changed

4 files changed

+9
-166
lines changed

changelog.d/5897.feature

-1
This file was deleted.

synapse/handlers/identity.py

-13
Original file line numberDiff line numberDiff line change
@@ -282,16 +282,3 @@ def requestMsisdnToken(
282282
except HttpResponseException as e:
283283
logger.info("Proxied requestToken failed: %r", e)
284284
raise e.to_synapse_error()
285-
286-
287-
class LookupAlgorithm:
288-
"""
289-
Supported hashing algorithms when performing a 3PID lookup.
290-
291-
SHA256 - Hashing an (address, medium, pepper) combo with sha256, then url-safe base64
292-
encoding
293-
NONE - Not performing any hashing. Simply sending an (address, medium) combo in plaintext
294-
"""
295-
296-
SHA256 = "sha256"
297-
NONE = "none"

synapse/handlers/room_member.py

+9-119
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,9 @@
2929
from synapse import types
3030
from synapse.api.constants import EventTypes, Membership
3131
from synapse.api.errors import AuthError, Codes, HttpResponseException, SynapseError
32-
from synapse.handlers.identity import LookupAlgorithm
3332
from synapse.types import RoomID, UserID
3433
from synapse.util.async_helpers import Linearizer
3534
from synapse.util.distributor import user_joined_room, user_left_room
36-
from synapse.util.hash import sha256_and_url_safe_base64
3735

3836
from ._base import BaseHandler
3937

@@ -525,7 +523,7 @@ def send_membership_event(
525523
event (SynapseEvent): The membership event.
526524
context: The context of the event.
527525
is_guest (bool): Whether the sender is a guest.
528-
remote_room_hosts (list[str]|None): Homeservers which are likely to already be in
526+
room_hosts ([str]): Homeservers which are likely to already be in
529527
the room, and could be danced with in order to join this
530528
homeserver for the first time.
531529
ratelimit (bool): Whether to rate limit this request.
@@ -636,7 +634,7 @@ def lookup_room_alias(self, room_alias):
636634
servers.remove(room_alias.domain)
637635
servers.insert(0, room_alias.domain)
638636

639-
return RoomID.from_string(room_id), servers
637+
return (RoomID.from_string(room_id), servers)
640638

641639
@defer.inlineCallbacks
642640
def _get_inviter(self, user_id, room_id):
@@ -699,44 +697,6 @@ def _lookup_3pid(self, id_server, medium, address):
699697
raise SynapseError(
700698
403, "Looking up third-party identifiers is denied from this server"
701699
)
702-
703-
# Check what hashing details are supported by this identity server
704-
use_v1 = False
705-
hash_details = None
706-
try:
707-
hash_details = yield self.simple_http_client.get_json(
708-
"%s%s/_matrix/identity/v2/hash_details" % (id_server_scheme, id_server)
709-
)
710-
except (HttpResponseException, ValueError) as e:
711-
# Catch HttpResponseExcept for a non-200 response code
712-
# Catch ValueError for non-JSON response body
713-
714-
# Check if this identity server does not know about v2 lookups
715-
if e.code == 404:
716-
# This is an old identity server that does not yet support v2 lookups
717-
use_v1 = True
718-
else:
719-
logger.warn("Error when looking up hashing details: %s" % (e,))
720-
return None
721-
722-
if use_v1:
723-
return (yield self._lookup_3pid_v1(id_server, medium, address))
724-
725-
return (yield self._lookup_3pid_v2(id_server, medium, address, hash_details))
726-
727-
@defer.inlineCallbacks
728-
def _lookup_3pid_v1(self, id_server, medium, address):
729-
"""Looks up a 3pid in the passed identity server using v1 lookup.
730-
731-
Args:
732-
id_server (str): The server name (including port, if required)
733-
of the identity server to use.
734-
medium (str): The type of the third party identifier (e.g. "email").
735-
address (str): The third party identifier (e.g. "[email protected]").
736-
737-
Returns:
738-
str: the matrix ID of the 3pid, or None if it is not recognized.
739-
"""
740700
try:
741701
data = yield self.simple_http_client.get_json(
742702
"%s%s/_matrix/identity/api/v1/lookup" % (id_server_scheme, id_server),
@@ -751,83 +711,8 @@ def _lookup_3pid_v1(self, id_server, medium, address):
751711

752712
except IOError as e:
753713
logger.warn("Error from identity server lookup: %s" % (e,))
754-
755-
return None
756-
757-
@defer.inlineCallbacks
758-
def _lookup_3pid_v2(self, id_server, medium, address, hash_details):
759-
"""Looks up a 3pid in the passed identity server using v2 lookup.
760-
761-
Args:
762-
id_server (str): The server name (including port, if required)
763-
of the identity server to use.
764-
medium (str): The type of the third party identifier (e.g. "email").
765-
address (str): The third party identifier (e.g. "[email protected]").
766-
hash_details (dict[str, str|list]): A dictionary containing hashing information
767-
provided by an identity server.
768-
769-
Returns:
770-
Deferred[str|None]: the matrix ID of the 3pid, or None if it is not recognised.
771-
"""
772-
# Extract information from hash_details
773-
supported_lookup_algorithms = hash_details["algorithms"]
774-
lookup_pepper = hash_details["lookup_pepper"]
775-
776-
# Check if any of the supported lookup algorithms are present
777-
if LookupAlgorithm.SHA256 in supported_lookup_algorithms:
778-
# Perform a hashed lookup
779-
lookup_algorithm = LookupAlgorithm.SHA256
780-
781-
# Hash address, medium and the pepper with sha256
782-
to_hash = "%s %s %s" % (address, medium, lookup_pepper)
783-
lookup_value = sha256_and_url_safe_base64(to_hash)
784-
785-
elif LookupAlgorithm.NONE in supported_lookup_algorithms:
786-
# Perform a non-hashed lookup
787-
lookup_algorithm = LookupAlgorithm.NONE
788-
789-
# Combine together plaintext address and medium
790-
lookup_value = "%s %s" % (address, medium)
791-
792-
else:
793-
logger.warn(
794-
"None of the provided lookup algorithms of %s%s are supported: %s",
795-
id_server_scheme,
796-
id_server,
797-
hash_details["algorithms"],
798-
)
799-
raise SynapseError(
800-
400,
801-
"Provided identity server does not support any v2 lookup "
802-
"algorithms that this homeserver supports.",
803-
)
804-
805-
try:
806-
lookup_results = yield self.simple_http_client.post_json_get_json(
807-
"%s%s/_matrix/identity/v2/lookup" % (id_server_scheme, id_server),
808-
{
809-
"addresses": [lookup_value],
810-
"algorithm": lookup_algorithm,
811-
"pepper": lookup_pepper,
812-
},
813-
)
814-
except (HttpResponseException, ValueError) as e:
815-
# Catch HttpResponseExcept for a non-200 response code
816-
# Catch ValueError for non-JSON response body
817-
logger.warn("Error when performing a 3pid lookup: %s" % (e,))
818-
return None
819-
820-
# Check for a mapping from what we looked up to an MXID
821-
if "mappings" not in lookup_results or not isinstance(
822-
lookup_results["mappings"], dict
823-
):
824-
logger.debug("No results from 3pid lookup")
825714
return None
826715

827-
# Return the MXID if it's available, or None otherwise
828-
mxid = lookup_results["mappings"].get(lookup_value)
829-
return mxid
830-
831716
@defer.inlineCallbacks
832717
def _verify_any_signature(self, data, server_hostname):
833718
if server_hostname not in data["signatures"]:
@@ -1077,7 +962,9 @@ def _is_remote_room_too_complex(self, room_id, remote_room_hosts):
1077962
)
1078963

1079964
if complexity:
1080-
return complexity["v1"] > max_complexity
965+
if complexity["v1"] > max_complexity:
966+
return True
967+
return False
1081968
return None
1082969

1083970
@defer.inlineCallbacks
@@ -1093,7 +980,10 @@ def _is_local_room_too_complex(self, room_id):
1093980
max_complexity = self.hs.config.limit_remote_rooms.complexity
1094981
complexity = yield self.store.get_room_complexity(room_id)
1095982

1096-
return complexity["v1"] > max_complexity
983+
if complexity["v1"] > max_complexity:
984+
return True
985+
986+
return False
1097987

1098988
@defer.inlineCallbacks
1099989
def _remote_join(self, requester, remote_room_hosts, room_id, user, content):

synapse/util/hash.py

-33
This file was deleted.

0 commit comments

Comments
 (0)