16
16
17
17
import hmac
18
18
import logging
19
- from hashlib import sha1
20
19
21
20
from six import string_types
22
21
@@ -239,14 +238,12 @@ def on_POST(self, request):
239
238
240
239
# we do basic sanity checks here because the auth layer will store these
241
240
# in sessions. Pull out the username/password provided to us.
242
- desired_password = None
243
241
if "password" in body :
244
242
if (
245
243
not isinstance (body ["password" ], string_types )
246
244
or len (body ["password" ]) > 512
247
245
):
248
246
raise SynapseError (400 , "Invalid password" )
249
- desired_password = body ["password" ]
250
247
251
248
desired_username = None
252
249
if "username" in body :
@@ -261,8 +258,8 @@ def on_POST(self, request):
261
258
if self .auth .has_access_token (request ):
262
259
appservice = yield self .auth .get_appservice_by_req (request )
263
260
264
- # fork off as soon as possible for ASes and shared secret auth which
265
- # have completely different registration flows to normal users
261
+ # fork off as soon as possible for ASes which have completely
262
+ # different registration flows to normal users
266
263
267
264
# == Application Service Registration ==
268
265
if appservice :
@@ -285,25 +282,15 @@ def on_POST(self, request):
285
282
return (200 , result ) # we throw for non 200 responses
286
283
return
287
284
288
- # for either shared secret or regular registration, downcase the
289
- # provided username before attempting to register it. This should mean
285
+ # for regular registration, downcase the provided username before
286
+ # attempting to register it. This should mean
290
287
# that people who try to register with upper-case in their usernames
291
288
# don't get a nasty surprise. (Note that we treat username
292
289
# case-insenstively in login, so they are free to carry on imagining
293
290
# that their username is CrAzYh4cKeR if that keeps them happy)
294
291
if desired_username is not None :
295
292
desired_username = desired_username .lower ()
296
293
297
- # == Shared Secret Registration == (e.g. create new user scripts)
298
- if "mac" in body :
299
- # FIXME: Should we really be determining if this is shared secret
300
- # auth based purely on the 'mac' key?
301
- result = yield self ._do_shared_secret_registration (
302
- desired_username , desired_password , body
303
- )
304
- return (200 , result ) # we throw for non 200 responses
305
- return
306
-
307
294
# == Normal User Registration == (everyone else)
308
295
if not self .hs .config .enable_registration :
309
296
raise SynapseError (403 , "Registration has been disabled" )
@@ -512,42 +499,6 @@ def _do_appservice_registration(self, username, as_token, body):
512
499
)
513
500
return (yield self ._create_registration_details (user_id , body ))
514
501
515
- @defer .inlineCallbacks
516
- def _do_shared_secret_registration (self , username , password , body ):
517
- if not self .hs .config .registration_shared_secret :
518
- raise SynapseError (400 , "Shared secret registration is not enabled" )
519
- if not username :
520
- raise SynapseError (
521
- 400 , "username must be specified" , errcode = Codes .BAD_JSON
522
- )
523
-
524
- # use the username from the original request rather than the
525
- # downcased one in `username` for the mac calculation
526
- user = body ["username" ].encode ("utf-8" )
527
-
528
- # str() because otherwise hmac complains that 'unicode' does not
529
- # have the buffer interface
530
- got_mac = str (body ["mac" ])
531
-
532
- # FIXME this is different to the /v1/register endpoint, which
533
- # includes the password and admin flag in the hashed text. Why are
534
- # these different?
535
- want_mac = hmac .new (
536
- key = self .hs .config .registration_shared_secret .encode (),
537
- msg = user ,
538
- digestmod = sha1 ,
539
- ).hexdigest ()
540
-
541
- if not compare_digest (want_mac , got_mac ):
542
- raise SynapseError (403 , "HMAC incorrect" )
543
-
544
- user_id = yield self .registration_handler .register_user (
545
- localpart = username , password = password
546
- )
547
-
548
- result = yield self ._create_registration_details (user_id , body )
549
- return result
550
-
551
502
@defer .inlineCallbacks
552
503
def _create_registration_details (self , user_id , params ):
553
504
"""Complete registration of newly-registered user
0 commit comments