Easy CA management
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.

128 lines
2.4 KiB

  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. import cmd
  4. import hashlib
  5. import json
  6. import os
  7. import os.path
  8. import shutil
  9. import sqlite3
  10. import tempfile
  11. from authority import *
  12. from certificate import *
  13. from request import *
  14. from paths import *
  15. __doc__= """
  16. Define proxy classes
  17. """
  18. class CALookup(object):
  19. """
  20. Proxy to interact with authorities
  21. """
  22. allowed_auth = [
  23. SSHAuthority,
  24. SSLAuthority,
  25. ]
  26. def __init__(self):
  27. self.path = MANAGER_PATH
  28. """
  29. """
  30. def __getitem__(self, ca_id):
  31. if SSHAuthority(ca_id):
  32. return SSHAuthority(ca_id)
  33. elif SSLAuthority(ca_id):
  34. return SSLAuthority(ca_id)
  35. else:
  36. raise IndexError('Unknown CA "%s"' % ca_id)
  37. """
  38. """
  39. raise ValueError('CA type is not supported')
  40. class RequestLookup(object):
  41. """
  42. Proxy to interact with the requests
  43. """
  44. def __init__(self):
  45. self.request_dir = REQUESTS_PATH
  46. self.output_dir = OUTPUT_PATH
  47. def __iter__(self):
  48. """
  49. Iterate over all certificate request in REQUEST_PATH
  50. """
  51. req_objs = []
  52. for request_id in os.listdir(self.request_dir):
  53. """
  54. request_id is formatted as uuid
  55. """
  56. with RequestLoader(request_id) as request:
  57. req_objs.append(request)
  58. return iter(req_objs)
  59. def __delitem__(self, request_id):
  60. """
  61. Delete a specific certificate request
  62. """
  63. os.unlink(SignRequest(request_id).path)
  64. def __getitem__(self, request_id):
  65. """
  66. Get a specific certificate request
  67. """
  68. if not SignRequest(request_id):
  69. raise IndexError
  70. with RequestLoader(request_id) as request:
  71. return request
  72. @property
  73. def ssh(self):
  74. pass
  75. @property
  76. def ssl(self):
  77. pass
  78. class CertificateLookup(object):
  79. """
  80. Proxy to interact with certificates
  81. """
  82. def __iter__(self):
  83. self.cert_dir = OUTPUT_PATH
  84. def __getitem__(self, certificate_id):
  85. """
  86. Get a specific certificate from disk
  87. """
  88. if not Certificate(certificate_id):
  89. raise IndexError
  90. return Certificate(certificate_id)
  91. def __iter__(self):
  92. """
  93. Iterate over all certificate request in OUTPUT_PATH
  94. """
  95. pass