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

Commit 36f34e6

Browse files
Remove unused methods from c/s api v1 in register.py (#5963)
These methods were part of the v1 C/S API. Remove them as they are no longer used by any code paths.
1 parent ce7803b commit 36f34e6

File tree

3 files changed

+2
-137
lines changed

3 files changed

+2
-137
lines changed

changelog.d/5963.misc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Remove left-over methods from C/S registration API.

synapse/handlers/register.py

Lines changed: 0 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,11 @@
2424
AuthError,
2525
Codes,
2626
ConsentNotGivenError,
27-
InvalidCaptchaError,
2827
LimitExceededError,
2928
RegistrationError,
3029
SynapseError,
3130
)
3231
from synapse.config.server import is_threepid_reserved
33-
from synapse.http.client import CaptchaServerHttpClient
3432
from synapse.http.servlet import assert_params_in_dict
3533
from synapse.replication.http.login import RegisterDeviceReplicationServlet
3634
from synapse.replication.http.register import (
@@ -39,7 +37,6 @@
3937
)
4038
from synapse.types import RoomAlias, RoomID, UserID, create_requester
4139
from synapse.util.async_helpers import Linearizer
42-
from synapse.util.threepids import check_3pid_allowed
4340

4441
from ._base import BaseHandler
4542

@@ -59,7 +56,6 @@ def __init__(self, hs):
5956
self._auth_handler = hs.get_auth_handler()
6057
self.profile_handler = hs.get_profile_handler()
6158
self.user_directory_handler = hs.get_user_directory_handler()
62-
self.captcha_client = CaptchaServerHttpClient(hs)
6359
self.identity_handler = self.hs.get_handlers().identity_handler
6460
self.ratelimiter = hs.get_registration_ratelimiter()
6561

@@ -362,70 +358,6 @@ def appservice_register(self, user_localpart, as_token):
362358
)
363359
return user_id
364360

365-
@defer.inlineCallbacks
366-
def check_recaptcha(self, ip, private_key, challenge, response):
367-
"""
368-
Checks a recaptcha is correct.
369-
370-
Used only by c/s api v1
371-
"""
372-
373-
captcha_response = yield self._validate_captcha(
374-
ip, private_key, challenge, response
375-
)
376-
if not captcha_response["valid"]:
377-
logger.info(
378-
"Invalid captcha entered from %s. Error: %s",
379-
ip,
380-
captcha_response["error_url"],
381-
)
382-
raise InvalidCaptchaError(error_url=captcha_response["error_url"])
383-
else:
384-
logger.info("Valid captcha entered from %s", ip)
385-
386-
@defer.inlineCallbacks
387-
def register_email(self, threepidCreds):
388-
"""
389-
Registers emails with an identity server.
390-
391-
Used only by c/s api v1
392-
"""
393-
394-
for c in threepidCreds:
395-
logger.info(
396-
"validating threepidcred sid %s on id server %s",
397-
c["sid"],
398-
c["idServer"],
399-
)
400-
try:
401-
threepid = yield self.identity_handler.threepid_from_creds(c)
402-
except Exception:
403-
logger.exception("Couldn't validate 3pid")
404-
raise RegistrationError(400, "Couldn't validate 3pid")
405-
406-
if not threepid:
407-
raise RegistrationError(400, "Couldn't validate 3pid")
408-
logger.info(
409-
"got threepid with medium '%s' and address '%s'",
410-
threepid["medium"],
411-
threepid["address"],
412-
)
413-
414-
if not check_3pid_allowed(self.hs, threepid["medium"], threepid["address"]):
415-
raise RegistrationError(403, "Third party identifier is not allowed")
416-
417-
@defer.inlineCallbacks
418-
def bind_emails(self, user_id, threepidCreds):
419-
"""Links emails with a user ID and informs an identity server.
420-
421-
Used only by c/s api v1
422-
"""
423-
424-
# Now we have a matrix ID, bind it to the threepids we were given
425-
for c in threepidCreds:
426-
# XXX: This should be a deferred list, shouldn't it?
427-
yield self.identity_handler.bind_threepid(c, user_id)
428-
429361
def check_user_id_not_appservice_exclusive(self, user_id, allowed_appservice=None):
430362
# don't allow people to register the server notices mxid
431363
if self._server_notices_mxid is not None:
@@ -463,42 +395,6 @@ def _generate_user_id(self, reseed=False):
463395
self._next_generated_user_id += 1
464396
return str(id)
465397

466-
@defer.inlineCallbacks
467-
def _validate_captcha(self, ip_addr, private_key, challenge, response):
468-
"""Validates the captcha provided.
469-
470-
Used only by c/s api v1
471-
472-
Returns:
473-
dict: Containing 'valid'(bool) and 'error_url'(str) if invalid.
474-
475-
"""
476-
response = yield self._submit_captcha(ip_addr, private_key, challenge, response)
477-
# parse Google's response. Lovely format..
478-
lines = response.split("\n")
479-
json = {
480-
"valid": lines[0] == "true",
481-
"error_url": "http://www.recaptcha.net/recaptcha/api/challenge?"
482-
+ "error=%s" % lines[1],
483-
}
484-
return json
485-
486-
@defer.inlineCallbacks
487-
def _submit_captcha(self, ip_addr, private_key, challenge, response):
488-
"""
489-
Used only by c/s api v1
490-
"""
491-
data = yield self.captcha_client.post_urlencoded_get_raw(
492-
"http://www.recaptcha.net:80/recaptcha/api/verify",
493-
args={
494-
"privatekey": private_key,
495-
"remoteip": ip_addr,
496-
"challenge": challenge,
497-
"response": response,
498-
},
499-
)
500-
return data
501-
502398
@defer.inlineCallbacks
503399
def _join_user_to_room(self, requester, room_identifier):
504400
room_id = None

synapse/http/client.py

Lines changed: 1 addition & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
)
3636
from twisted.python.failure import Failure
3737
from twisted.web._newclient import ResponseDone
38-
from twisted.web.client import Agent, HTTPConnectionPool, PartialDownloadError, readBody
38+
from twisted.web.client import Agent, HTTPConnectionPool, readBody
3939
from twisted.web.http import PotentialDataLoss
4040
from twisted.web.http_headers import Headers
4141

@@ -599,38 +599,6 @@ def _readBodyToFile(response, stream, max_size):
599599
return d
600600

601601

602-
class CaptchaServerHttpClient(SimpleHttpClient):
603-
"""
604-
Separate HTTP client for talking to google's captcha servers
605-
Only slightly special because accepts partial download responses
606-
607-
used only by c/s api v1
608-
"""
609-
610-
@defer.inlineCallbacks
611-
def post_urlencoded_get_raw(self, url, args={}):
612-
query_bytes = urllib.parse.urlencode(encode_urlencode_args(args), True)
613-
614-
response = yield self.request(
615-
"POST",
616-
url,
617-
data=query_bytes,
618-
headers=Headers(
619-
{
620-
b"Content-Type": [b"application/x-www-form-urlencoded"],
621-
b"User-Agent": [self.user_agent],
622-
}
623-
),
624-
)
625-
626-
try:
627-
body = yield make_deferred_yieldable(readBody(response))
628-
return body
629-
except PartialDownloadError as e:
630-
# twisted dislikes google's response, no content length.
631-
return e.response
632-
633-
634602
def encode_urlencode_args(args):
635603
return {k: encode_urlencode_arg(v) for k, v in args.items()}
636604

0 commit comments

Comments
 (0)