25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.
 
 
 
 
 
 

62 satır
2.2 KiB

  1. # Copyright 2014-2016 OpenMarket Ltd
  2. # Copyright 2018 New Vector Ltd
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. """Contains the URL paths to prefix various aspects of the server with. """
  16. import hmac
  17. from hashlib import sha256
  18. from urllib.parse import urlencode
  19. from synapse.config import ConfigError
  20. from synapse.config.homeserver import HomeServerConfig
  21. SYNAPSE_CLIENT_API_PREFIX = "/_synapse/client"
  22. CLIENT_API_PREFIX = "/_matrix/client"
  23. FEDERATION_PREFIX = "/_matrix/federation"
  24. FEDERATION_V1_PREFIX = FEDERATION_PREFIX + "/v1"
  25. FEDERATION_V2_PREFIX = FEDERATION_PREFIX + "/v2"
  26. FEDERATION_UNSTABLE_PREFIX = FEDERATION_PREFIX + "/unstable"
  27. STATIC_PREFIX = "/_matrix/static"
  28. SERVER_KEY_PREFIX = "/_matrix/key"
  29. MEDIA_R0_PREFIX = "/_matrix/media/r0"
  30. MEDIA_V3_PREFIX = "/_matrix/media/v3"
  31. LEGACY_MEDIA_PREFIX = "/_matrix/media/v1"
  32. class ConsentURIBuilder:
  33. def __init__(self, hs_config: HomeServerConfig):
  34. if hs_config.key.form_secret is None:
  35. raise ConfigError("form_secret not set in config")
  36. self._hmac_secret = hs_config.key.form_secret.encode("utf-8")
  37. self._public_baseurl = hs_config.server.public_baseurl
  38. def build_user_consent_uri(self, user_id: str) -> str:
  39. """Build a URI which we can give to the user to do their privacy
  40. policy consent
  41. Args:
  42. user_id: mxid or username of user
  43. Returns
  44. The URI where the user can do consent
  45. """
  46. mac = hmac.new(
  47. key=self._hmac_secret, msg=user_id.encode("ascii"), digestmod=sha256
  48. ).hexdigest()
  49. consent_uri = "%s_matrix/consent?%s" % (
  50. self._public_baseurl,
  51. urlencode({"u": user_id, "h": mac}),
  52. )
  53. return consent_uri