tracim_http_authenticator.py 2.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. from wsgidav.http_authenticator import HTTPAuthenticator
  2. from wsgidav import util
  3. _logger = util.getModuleLogger(__name__, True)
  4. class TracimHTTPAuthenticator(HTTPAuthenticator):
  5. def computeDigestResponse(
  6. self,
  7. username,
  8. realm,
  9. password,
  10. method,
  11. uri,
  12. nonce,
  13. cnonce,
  14. qop,
  15. nc
  16. ):
  17. """
  18. Override standard computeDigestResponse : as user password is already
  19. hashed in database, we need to use left_digest_response_hash
  20. to have correctly hashed digest_response.
  21. """
  22. # TODO - G.M - 13-03-2018 Check if environ is useful
  23. # for get_left_digest_response. If true, find a solution
  24. # to obtain it here without recopy-paste whole authDigestAuthRequest
  25. # method.
  26. left_digest_response_hash = self._domaincontroller.get_left_digest_response_hash(realm, username, None) # nopep8
  27. if left_digest_response_hash:
  28. return self.tracim_compute_digest_response(
  29. left_digest_response_hash=left_digest_response_hash,
  30. method=method,
  31. uri=uri,
  32. nonce=nonce,
  33. cnonce=cnonce,
  34. qop=qop,
  35. nc=nc,
  36. )
  37. else:
  38. return None
  39. def tracim_compute_digest_response(
  40. self,
  41. left_digest_response_hash,
  42. method,
  43. uri,
  44. nonce,
  45. cnonce,
  46. qop,
  47. nc
  48. ):
  49. # TODO : Rename A to something more correct
  50. A = "{method}:{uri}".format(method=method, uri=uri)
  51. if qop:
  52. right_digest_response_hash = "{nonce}:{nc}:{cnonce}:{qop}:{A}".format( # nopep8
  53. nonce=nonce,
  54. nc=nc,
  55. cnonce=cnonce,
  56. qop=qop,
  57. method=method,
  58. uri=uri,
  59. A=self.md5h(A),
  60. )
  61. else:
  62. right_digest_response_hash = "{nonce}:{A}".format(
  63. nonce=nonce,
  64. A=self.md5h(A),
  65. )
  66. digestresp = self.md5kd(
  67. left_digest_response_hash,
  68. right_digest_response_hash,
  69. )
  70. return digestresp