hashdetailsservlet.py 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. # -*- coding: utf-8 -*-
  2. # Copyright 2019 The Matrix.org Foundation C.I.C.
  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. from __future__ import absolute_import
  16. from twisted.web.resource import Resource
  17. from sydent.http.auth import authIfV2
  18. import logging
  19. from sydent.http.servlets import jsonwrap, send_cors
  20. logger = logging.getLogger(__name__)
  21. class HashDetailsServlet(Resource):
  22. isLeaf = True
  23. known_algorithms = ["sha256", "none"]
  24. def __init__(self, syd, lookup_pepper):
  25. self.sydent = syd
  26. self.lookup_pepper = lookup_pepper
  27. @jsonwrap
  28. def render_GET(self, request):
  29. """
  30. Return the hashing algorithms and pepper that this IS supports. The
  31. pepper included in the response is stored in the database, or
  32. otherwise generated.
  33. Returns: An object containing an array of hashing algorithms the
  34. server supports, and a `lookup_pepper` field, which is a
  35. server-defined value that the client should include in the 3PID
  36. information before hashing.
  37. """
  38. send_cors(request)
  39. authIfV2(self.sydent, request)
  40. return {
  41. "algorithms": self.known_algorithms,
  42. "lookup_pepper": self.lookup_pepper,
  43. }
  44. def render_OPTIONS(self, request):
  45. send_cors(request)
  46. return b''