29
29
from synapse import types
30
30
from synapse .api .constants import EventTypes , Membership
31
31
from synapse .api .errors import AuthError , Codes , HttpResponseException , SynapseError
32
- from synapse .handlers .identity import LookupAlgorithm
33
32
from synapse .types import RoomID , UserID
34
33
from synapse .util .async_helpers import Linearizer
35
34
from synapse .util .distributor import user_joined_room , user_left_room
36
- from synapse .util .hash import sha256_and_url_safe_base64
37
35
38
36
from ._base import BaseHandler
39
37
@@ -525,7 +523,7 @@ def send_membership_event(
525
523
event (SynapseEvent): The membership event.
526
524
context: The context of the event.
527
525
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
529
527
the room, and could be danced with in order to join this
530
528
homeserver for the first time.
531
529
ratelimit (bool): Whether to rate limit this request.
@@ -636,7 +634,7 @@ def lookup_room_alias(self, room_alias):
636
634
servers .remove (room_alias .domain )
637
635
servers .insert (0 , room_alias .domain )
638
636
639
- return RoomID .from_string (room_id ), servers
637
+ return ( RoomID .from_string (room_id ), servers )
640
638
641
639
@defer .inlineCallbacks
642
640
def _get_inviter (self , user_id , room_id ):
@@ -699,44 +697,6 @@ def _lookup_3pid(self, id_server, medium, address):
699
697
raise SynapseError (
700
698
403 , "Looking up third-party identifiers is denied from this server"
701
699
)
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
- """
740
700
try :
741
701
data = yield self .simple_http_client .get_json (
742
702
"%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):
751
711
752
712
except IOError as e :
753
713
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" )
825
714
return None
826
715
827
- # Return the MXID if it's available, or None otherwise
828
- mxid = lookup_results ["mappings" ].get (lookup_value )
829
- return mxid
830
-
831
716
@defer .inlineCallbacks
832
717
def _verify_any_signature (self , data , server_hostname ):
833
718
if server_hostname not in data ["signatures" ]:
@@ -1077,7 +962,9 @@ def _is_remote_room_too_complex(self, room_id, remote_room_hosts):
1077
962
)
1078
963
1079
964
if complexity :
1080
- return complexity ["v1" ] > max_complexity
965
+ if complexity ["v1" ] > max_complexity :
966
+ return True
967
+ return False
1081
968
return None
1082
969
1083
970
@defer .inlineCallbacks
@@ -1093,7 +980,10 @@ def _is_local_room_too_complex(self, room_id):
1093
980
max_complexity = self .hs .config .limit_remote_rooms .complexity
1094
981
complexity = yield self .store .get_room_complexity (room_id )
1095
982
1096
- return complexity ["v1" ] > max_complexity
983
+ if complexity ["v1" ] > max_complexity :
984
+ return True
985
+
986
+ return False
1097
987
1098
988
@defer .inlineCallbacks
1099
989
def _remote_join (self , requester , remote_room_hosts , room_id , user , content ):
0 commit comments