def make_ssl_context(key_file=None, cert_file=None, pem_file=None, ca_dir=None, verify_peer=False, url=None, method=SSL.TLSv1_METHOD, key_file_passphrase=None):
 ssl_context = SSL.Context(method)
 if cert_file:
  ssl_context.use_certificate_file(cert_file)
 if key_file_passphrase:
  passwd_cb = (lambda max_passphrase_len, set_prompt, userdata: key_file_passphrase)
  ssl_context.set_passwd_cb(passwd_cb)
 if key_file:
  ssl_context.use_privatekey_file(key_file)
 elif cert_file:
  ssl_context.use_privatekey_file(cert_file)
 if (pem_file or ca_dir):
  ssl_context.load_verify_locations(pem_file, ca_dir)
 def _callback(conn, x509, errnum, errdepth, preverify_ok):
  'Default certification verification callback.\n        Performs no checks and returns the status passed in.\n        '
  return preverify_ok
 verify_callback = _callback
 if verify_peer:
  ssl_context.set_verify_depth(9)
  if url:
   set_peer_verification_for_url_hostname(ssl_context, url)
  else:
   ssl_context.set_verify(SSL.VERIFY_PEER, verify_callback)
 else:
  ssl_context.set_verify(SSL.VERIFY_NONE, verify_callback)
 return ssl_context

def make_ssl_context ( key_file = None , cert_file = None , pem_file = None , ca_dir = None , verify_peer = False , url = None , method = SSL . TLSv1_METHOD , key_file_passphrase = None ) : ssl_context = SSL . Context ( method ) if cert_file : ssl_context . use_certificate_file ( cert_file ) if key_file_passphrase : passwd_cb = ( lambda max_passphrase_len , set_prompt , userdata : key_file_passphrase ) ssl_context . set_passwd_cb ( passwd_cb ) if key_file : ssl_context . use_privatekey_file ( key_file ) elif cert_file : ssl_context . use_privatekey_file ( cert_file ) if ( pem_file or ca_dir ) : ssl_context . load_verify_locations ( pem_file , ca_dir ) def _callback ( conn , x509 , errnum , errdepth , preverify_ok ) : return preverify_ok verify_callback = _callback if verify_peer : ssl_context . set_verify_depth ( 9 ) if url : set_peer_verification_for_url_hostname ( ssl_context , url ) else : ssl_context . set_verify ( SSL . VERIFY_PEER , verify_callback ) else : ssl_context . set_verify ( SSL . VERIFY_NONE , verify_callback ) return ssl_context
creates ssl context containing certificate and key file locations .