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.

36 lines
911 B

  1. # -*- coding: utf-8 -*-
  2. from .. import random_tokens
  3. try:
  4. from jwcrypto import jwk
  5. except ImportError:
  6. pass
  7. def init_keys(IrConfigParameter):
  8. keys = {
  9. "galicea_openid_connect.authorization_code_jwk": lambda: jwk.JWK.generate(
  10. kty="oct",
  11. size=256,
  12. kid=random_tokens.alpha_numeric(16),
  13. use="sig",
  14. alg="HS256",
  15. ).export(),
  16. "galicea_openid_connect.id_token_jwk": lambda: jwk.JWK.generate(
  17. kty="RSA",
  18. size=2054,
  19. kid=random_tokens.alpha_numeric(16),
  20. use="sig",
  21. alg="RS256",
  22. ).export(),
  23. }
  24. for key, gen in keys.iteritems():
  25. if not IrConfigParameter.search([("key", "=", key)]):
  26. IrConfigParameter.create(
  27. {
  28. "key": key,
  29. "value": gen(),
  30. }
  31. )