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

Commit 0bab582

Browse files
Remove shared secret registration from client/r0/register endpoint
This type of registration was probably never used. It only includes the user name in the HMAC but not the password. Shared secret registration is still available via client/r0/admin/register. Signed-off-by: Manuel Stahl <[email protected]>
1 parent d514dac commit 0bab582

File tree

2 files changed

+5
-53
lines changed

2 files changed

+5
-53
lines changed

changelog.d/5877.removal

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Remove shared secret registration from client/r0/register endpoint. Contributed by Awesome Technologies Innovationslabor GmbH.

synapse/rest/client/v2_alpha/register.py

Lines changed: 4 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
import hmac
1818
import logging
19-
from hashlib import sha1
2019

2120
from six import string_types
2221

@@ -239,14 +238,12 @@ def on_POST(self, request):
239238

240239
# we do basic sanity checks here because the auth layer will store these
241240
# in sessions. Pull out the username/password provided to us.
242-
desired_password = None
243241
if "password" in body:
244242
if (
245243
not isinstance(body["password"], string_types)
246244
or len(body["password"]) > 512
247245
):
248246
raise SynapseError(400, "Invalid password")
249-
desired_password = body["password"]
250247

251248
desired_username = None
252249
if "username" in body:
@@ -261,8 +258,8 @@ def on_POST(self, request):
261258
if self.auth.has_access_token(request):
262259
appservice = yield self.auth.get_appservice_by_req(request)
263260

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
266263

267264
# == Application Service Registration ==
268265
if appservice:
@@ -285,25 +282,15 @@ def on_POST(self, request):
285282
return (200, result) # we throw for non 200 responses
286283
return
287284

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
290287
# that people who try to register with upper-case in their usernames
291288
# don't get a nasty surprise. (Note that we treat username
292289
# case-insenstively in login, so they are free to carry on imagining
293290
# that their username is CrAzYh4cKeR if that keeps them happy)
294291
if desired_username is not None:
295292
desired_username = desired_username.lower()
296293

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-
307294
# == Normal User Registration == (everyone else)
308295
if not self.hs.config.enable_registration:
309296
raise SynapseError(403, "Registration has been disabled")
@@ -512,42 +499,6 @@ def _do_appservice_registration(self, username, as_token, body):
512499
)
513500
return (yield self._create_registration_details(user_id, body))
514501

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-
551502
@defer.inlineCallbacks
552503
def _create_registration_details(self, user_id, params):
553504
"""Complete registration of newly-registered user

0 commit comments

Comments
 (0)