def create_https_certificates(ssl_cert, ssl_key):
 from headphones import logger
 from OpenSSL import crypto
 from certgen import createKeyPair, createCertRequest, createCertificate, TYPE_RSA, serial
 cakey = createKeyPair(TYPE_RSA, 2048)
 careq = createCertRequest(cakey, CN='Certificate Authority')
 cacert = createCertificate(careq, (careq, cakey), serial, (0, ((((60 * 60) * 24) * 365) * 10)))
 pkey = createKeyPair(TYPE_RSA, 2048)
 req = createCertRequest(pkey, CN='Headphones')
 cert = createCertificate(req, (cacert, cakey), serial, (0, ((((60 * 60) * 24) * 365) * 10)))
 try:
  with open(ssl_key, 'w') as fp:
   fp.write(crypto.dump_privatekey(crypto.FILETYPE_PEM, pkey))
  with open(ssl_cert, 'w') as fp:
   fp.write(crypto.dump_certificate(crypto.FILETYPE_PEM, cert))
 except IOError as e:
  logger.error('Error creating SSL key and certificate: %s', e)
  return False
 return True

def create_https_certificates ( ssl_cert , ssl_key ) : from headphones import logger from OpenSSL import crypto from certgen import createKeyPair , createCertRequest , createCertificate , TYPE_RSA , serial cakey = createKeyPair ( TYPE_RSA , 2048 ) careq = createCertRequest ( cakey , CN = 'Certificate Authority' ) cacert = createCertificate ( careq , ( careq , cakey ) , serial , ( 0 , ( ( ( ( 60 * 60 ) * 24 ) * 365 ) * 10 ) ) ) pkey = createKeyPair ( TYPE_RSA , 2048 ) req = createCertRequest ( pkey , CN = 'Headphones' ) cert = createCertificate ( req , ( cacert , cakey ) , serial , ( 0 , ( ( ( ( 60 * 60 ) * 24 ) * 365 ) * 10 ) ) ) try : with open ( ssl_key , 'w' ) as fp : fp . write ( crypto . dump_privatekey ( crypto . FILETYPE_PEM , pkey ) ) with open ( ssl_cert , 'w' ) as fp : fp . write ( crypto . dump_certificate ( crypto . FILETYPE_PEM , cert ) ) except IOError as e : logger . error ( 'Error creating SSL key and certificate: %s' , e ) return False return True
create self-signed https certificates and store in paths ssl_cert and ssl_key .