Implementazione open-source del protocollo di Strong Customer Authentication di Poste Italiane, (https://posteid.poste.it), lato client.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

25 lines
658 B

2 years ago
  1. import hmac
  2. import json
  3. from base64 import b64encode, urlsafe_b64encode
  4. from hashlib import sha256
  5. def sha256_base64(payload):
  6. out = payload.encode('utf-8')
  7. out = sha256(out).digest()
  8. out = b64encode(out)
  9. return out.decode('utf-8')
  10. def hmac_sha256(key, message):
  11. hm = hmac.new(key.encode('utf-8'), digestmod=sha256)
  12. hm.update(message.encode('utf-8'))
  13. digest = hm.digest()
  14. return urlsafe_b64encode(digest).decode('utf-8').replace('=', '')
  15. class RequestFailure(Exception):
  16. def __init__(self, message, ans, error_code=None):
  17. super().__init__(message)
  18. self.ans = ans
  19. self.error_code = error_code