Skip to content

Instantly share code, notes, and snippets.

@hynek
Created January 15, 2013 15:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hynek/4539676 to your computer and use it in GitHub Desktop.
Save hynek/4539676 to your computer and use it in GitHub Desktop.
from OpenSSL import SSL
from twisted.internet import ssl
class TLSContextWithChainFileFactory(ssl.DefaultOpenSSLContextFactory):
"""
A SSLContext factory for TLS only and C{certificateFileName} is set as the
chain file. Add all chain files that lead from the CA to your certificate.
"""
def cacheContext(self):
if self._context is None:
ctx = SSL.Context(SSL.TLSv1_METHOD)
ctx.use_certificate_chain_file(self.certificateFileName)
ctx.use_privatekey_file(self.privateKeyFileName)
self._context = ctx
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment