1212# See the License for the specific language governing permissions and 
1313# limitations under the License. 
1414import  logging 
15- from  typing  import  TYPE_CHECKING , Any ,  Dict ,  List ,  Optional , Tuple ,  Union 
15+ from  typing  import  TYPE_CHECKING , Optional , Tuple 
1616
1717import  pymacaroons 
1818from  netaddr  import  IPAddress 
2828    InvalidClientTokenError ,
2929    MissingClientTokenError ,
3030)
31- from  synapse .api .room_versions  import  KNOWN_ROOM_VERSIONS 
3231from  synapse .appservice  import  ApplicationService 
3332from  synapse .events  import  EventBase 
34- from  synapse .events .builder  import  EventBuilder 
3533from  synapse .http  import  get_request_user_agent 
3634from  synapse .http .site  import  SynapseRequest 
3735from  synapse .logging  import  opentracing  as  opentracing 
3836from  synapse .storage .databases .main .registration  import  TokenLookupResult 
3937from  synapse .types  import  Requester , StateMap , UserID , create_requester 
4038from  synapse .util .caches .lrucache  import  LruCache 
4139from  synapse .util .macaroons  import  get_value_from_macaroon , satisfy_expiry 
42- from  synapse .util .metrics  import  Measure 
4340
4441if  TYPE_CHECKING :
4542    from  synapse .server  import  HomeServer 
4643
4744logger  =  logging .getLogger (__name__ )
4845
4946
50- AuthEventTypes  =  (
51-     EventTypes .Create ,
52-     EventTypes .Member ,
53-     EventTypes .PowerLevels ,
54-     EventTypes .JoinRules ,
55-     EventTypes .RoomHistoryVisibility ,
56-     EventTypes .ThirdPartyInvite ,
57- )
58- 
5947# guests always get this device id. 
6048GUEST_DEVICE_ID  =  "guest_device" 
6149
@@ -66,9 +54,7 @@ class _InvalidMacaroonException(Exception):
6654
6755class  Auth :
6856    """ 
69-     FIXME: This class contains a mix of functions for authenticating users 
70-     of our client-server API and authenticating events added to room graphs. 
71-     The latter should be moved to synapse.handlers.event_auth.EventAuthHandler. 
57+     This class contains functions for authenticating users of our client-server API. 
7258    """ 
7359
7460    def  __init__ (self , hs : "HomeServer" ):
@@ -90,18 +76,6 @@ def __init__(self, hs: "HomeServer"):
9076        self ._macaroon_secret_key  =  hs .config .macaroon_secret_key 
9177        self ._force_tracing_for_users  =  hs .config .tracing .force_tracing_for_users 
9278
93-     async  def  check_from_context (
94-         self , room_version : str , event , context , do_sig_check = True 
95-     ) ->  None :
96-         auth_event_ids  =  event .auth_event_ids ()
97-         auth_events_by_id  =  await  self .store .get_events (auth_event_ids )
98-         auth_events  =  {(e .type , e .state_key ): e  for  e  in  auth_events_by_id .values ()}
99- 
100-         room_version_obj  =  KNOWN_ROOM_VERSIONS [room_version ]
101-         event_auth .check (
102-             room_version_obj , event , auth_events = auth_events , do_sig_check = do_sig_check 
103-         )
104- 
10579    async  def  check_user_in_room (
10680        self ,
10781        room_id : str ,
@@ -152,13 +126,6 @@ async def check_user_in_room(
152126
153127        raise  AuthError (403 , "User %s not in room %s"  %  (user_id , room_id ))
154128
155-     async  def  check_host_in_room (self , room_id : str , host : str ) ->  bool :
156-         with  Measure (self .clock , "check_host_in_room" ):
157-             return  await  self .store .is_host_joined (room_id , host )
158- 
159-     def  get_public_keys (self , invite_event : EventBase ) ->  List [Dict [str , Any ]]:
160-         return  event_auth .get_public_keys (invite_event )
161- 
162129    async  def  get_user_by_req (
163130        self ,
164131        request : SynapseRequest ,
@@ -489,44 +456,6 @@ async def is_server_admin(self, user: UserID) -> bool:
489456        """ 
490457        return  await  self .store .is_server_admin (user )
491458
492-     def  compute_auth_events (
493-         self ,
494-         event : Union [EventBase , EventBuilder ],
495-         current_state_ids : StateMap [str ],
496-         for_verification : bool  =  False ,
497-     ) ->  List [str ]:
498-         """Given an event and current state return the list of event IDs used 
499-         to auth an event. 
500- 
501-         If `for_verification` is False then only return auth events that 
502-         should be added to the event's `auth_events`. 
503- 
504-         Returns: 
505-             List of event IDs. 
506-         """ 
507- 
508-         if  event .type  ==  EventTypes .Create :
509-             return  []
510- 
511-         # Currently we ignore the `for_verification` flag even though there are 
512-         # some situations where we can drop particular auth events when adding 
513-         # to the event's `auth_events` (e.g. joins pointing to previous joins 
514-         # when room is publicly joinable). Dropping event IDs has the 
515-         # advantage that the auth chain for the room grows slower, but we use 
516-         # the auth chain in state resolution v2 to order events, which means 
517-         # care must be taken if dropping events to ensure that it doesn't 
518-         # introduce undesirable "state reset" behaviour. 
519-         # 
520-         # All of which sounds a bit tricky so we don't bother for now. 
521- 
522-         auth_ids  =  []
523-         for  etype , state_key  in  event_auth .auth_types_for_event (event ):
524-             auth_ev_id  =  current_state_ids .get ((etype , state_key ))
525-             if  auth_ev_id :
526-                 auth_ids .append (auth_ev_id )
527- 
528-         return  auth_ids 
529- 
530459    async  def  check_can_change_room_list (self , room_id : str , user : UserID ) ->  bool :
531460        """Determine whether the user is allowed to edit the room's entry in the 
532461        published room list. 
0 commit comments