keystore_settings.py 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. #
  2. # Copyright (c) Contributors to the Open 3D Engine Project.
  3. # For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. #
  5. # SPDX-License-Identifier: Apache-2.0 OR MIT
  6. #
  7. class KeystoreSettings:
  8. """
  9. This class contains all the configuration parameters that are required
  10. to create a keystore for android applications.
  11. """
  12. DEFAULT_PASSWORD = "password"
  13. DEFAULT_KEY_ALIAS = "app_key_alias"
  14. DEFAULT_KEY_SIZE = "2048"
  15. DEFAULT_VALIDITY_DAYS = "10000"
  16. DEFAULT_CN = "MyAppName"
  17. DEFAULT_OU = "MyOrganizationalUnit"
  18. DEFAULT_O = "MyCompany"
  19. DEFAULT_C = "US"
  20. def __init__(self):
  21. self.keystore_file = ""
  22. self.keystore_password = self.DEFAULT_PASSWORD
  23. self.key_alias = self.DEFAULT_KEY_ALIAS
  24. self.key_password = (
  25. self.keystore_password
  26. ) # Must be same as store password.
  27. self.key_size = self.DEFAULT_KEY_SIZE
  28. self.validity_days = self.DEFAULT_VALIDITY_DAYS
  29. # Parts of a distiguished name string:
  30. self.dn_common_name = self.DEFAULT_CN
  31. self.dn_organizational_unit = self.DEFAULT_OU
  32. self.dn_organization = self.DEFAULT_O
  33. self.dn_country_code = self.DEFAULT_C
  34. def get_distinguished_name(self) -> str:
  35. return f"cn={self.dn_common_name}, ou={self.dn_organizational_unit}, o={self.dn_organization}, c={self.dn_country_code}"
  36. def configure_distinguished_name(self,
  37. app_name: str, organizational_unit: str,
  38. company_name: str, country_code: str):
  39. self.dn_common_name = app_name
  40. self.dn_organizational_unit = organizational_unit
  41. self.dn_organization = company_name
  42. self.dn_country_code = country_code
  43. @classmethod
  44. def from_dictionary(cls, d: dict) -> "KeystoreSettings":
  45. ks = KeystoreSettings()
  46. ks.keystore_file = d.get("keystore_file", "")
  47. ks.keystore_password = d.get("keystore_password", cls.DEFAULT_PASSWORD)
  48. ks.key_alias = d.get("key_alias", cls.DEFAULT_KEY_ALIAS)
  49. ks.key_password = d.get("key_password", cls.DEFAULT_PASSWORD)
  50. ks.key_size = d.get("key_size", cls.DEFAULT_KEY_SIZE)
  51. ks.validity_days = d.get("validity_days", cls.DEFAULT_VALIDITY_DAYS)
  52. # Parts of a distiguished name string:
  53. ks.dn_common_name = d.get("dn_common_name", cls.DEFAULT_CN)
  54. ks.dn_organizational_unit = d.get("dn_organizational_unit", cls.DEFAULT_OU)
  55. ks.dn_organization = d.get("dn_organization", cls.DEFAULT_O)
  56. ks.dn_country_code = d.get("dn_country_code", cls.DEFAULT_C)
  57. return ks
  58. def as_dictionary(self) -> dict:
  59. d = {
  60. "keystore_file" : self.keystore_file,
  61. "keystore_password" : self.keystore_password,
  62. "key_alias" : self.key_alias,
  63. "key_password" : self.key_password,
  64. "validity_days" : self.validity_days,
  65. "dn_common_name" : self.dn_common_name,
  66. "dn_organizational_unit" : self.dn_organizational_unit,
  67. "dn_organization" : self.dn_organization,
  68. "dn_country_code" : self.dn_country_code,
  69. }
  70. return d
  71. # class KeystoreSettings END
  72. ######################################################