Funktionierender Prototyp des Serious Games zur Vermittlung von Wissen zu Software-Engineering-Arbeitsmodellen.
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.

ssl_helpers.py 1.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. # Copyright (c) Twisted Matrix Laboratories.
  2. # See LICENSE for details.
  3. """
  4. Helper classes for twisted.test.test_ssl.
  5. They are in a separate module so they will not prevent test_ssl importing if
  6. pyOpenSSL is unavailable.
  7. """
  8. from OpenSSL import SSL
  9. from twisted.internet import ssl
  10. from twisted.python.compat import nativeString
  11. from twisted.python.filepath import FilePath
  12. certPath = nativeString(FilePath(__file__.encode("utf-8")).sibling(b"server.pem").path)
  13. class ClientTLSContext(ssl.ClientContextFactory):
  14. """
  15. SSL Context Factory for client-side connections.
  16. """
  17. isClient = 1
  18. def getContext(self):
  19. """
  20. Return an L{SSL.Context} to be use for client-side connections.
  21. Will not return a cached context.
  22. This is done to improve the test coverage as most implementation
  23. are caching the context.
  24. """
  25. return SSL.Context(SSL.SSLv23_METHOD)
  26. class ServerTLSContext:
  27. """
  28. SSL Context Factory for server-side connections.
  29. """
  30. isClient = 0
  31. def __init__(self, filename=certPath, method=None):
  32. self.filename = filename
  33. if method is None:
  34. method = SSL.SSLv23_METHOD
  35. self._method = method
  36. def getContext(self):
  37. """
  38. Return an L{SSL.Context} to be use for server-side connections.
  39. Will not return a cached context.
  40. This is done to improve the test coverage as most implementation
  41. are caching the context.
  42. """
  43. ctx = SSL.Context(self._method)
  44. ctx.use_certificate_file(self.filename)
  45. ctx.use_privatekey_file(self.filename)
  46. return ctx