12
12
# See the License for the specific language governing permissions and
13
13
# limitations under the License.
14
14
import logging
15
- from typing import TYPE_CHECKING , Any , Dict , List , Optional , Tuple , Union
15
+ from typing import TYPE_CHECKING , Optional , Tuple
16
16
17
17
import pymacaroons
18
18
from netaddr import IPAddress
28
28
InvalidClientTokenError ,
29
29
MissingClientTokenError ,
30
30
)
31
- from synapse .api .room_versions import KNOWN_ROOM_VERSIONS
32
31
from synapse .appservice import ApplicationService
33
32
from synapse .events import EventBase
34
- from synapse .events .builder import EventBuilder
35
33
from synapse .http import get_request_user_agent
36
34
from synapse .http .site import SynapseRequest
37
35
from synapse .logging import opentracing as opentracing
38
36
from synapse .storage .databases .main .registration import TokenLookupResult
39
37
from synapse .types import Requester , StateMap , UserID , create_requester
40
38
from synapse .util .caches .lrucache import LruCache
41
39
from synapse .util .macaroons import get_value_from_macaroon , satisfy_expiry
42
- from synapse .util .metrics import Measure
43
40
44
41
if TYPE_CHECKING :
45
42
from synapse .server import HomeServer
46
43
47
44
logger = logging .getLogger (__name__ )
48
45
49
46
50
- AuthEventTypes = (
51
- EventTypes .Create ,
52
- EventTypes .Member ,
53
- EventTypes .PowerLevels ,
54
- EventTypes .JoinRules ,
55
- EventTypes .RoomHistoryVisibility ,
56
- EventTypes .ThirdPartyInvite ,
57
- )
58
-
59
47
# guests always get this device id.
60
48
GUEST_DEVICE_ID = "guest_device"
61
49
@@ -66,9 +54,7 @@ class _InvalidMacaroonException(Exception):
66
54
67
55
class Auth :
68
56
"""
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.
72
58
"""
73
59
74
60
def __init__ (self , hs : "HomeServer" ):
@@ -90,18 +76,6 @@ def __init__(self, hs: "HomeServer"):
90
76
self ._macaroon_secret_key = hs .config .macaroon_secret_key
91
77
self ._force_tracing_for_users = hs .config .tracing .force_tracing_for_users
92
78
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
-
105
79
async def check_user_in_room (
106
80
self ,
107
81
room_id : str ,
@@ -152,13 +126,6 @@ async def check_user_in_room(
152
126
153
127
raise AuthError (403 , "User %s not in room %s" % (user_id , room_id ))
154
128
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
-
162
129
async def get_user_by_req (
163
130
self ,
164
131
request : SynapseRequest ,
@@ -489,44 +456,6 @@ async def is_server_admin(self, user: UserID) -> bool:
489
456
"""
490
457
return await self .store .is_server_admin (user )
491
458
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
-
530
459
async def check_can_change_room_list (self , room_id : str , user : UserID ) -> bool :
531
460
"""Determine whether the user is allowed to edit the room's entry in the
532
461
published room list.
0 commit comments