(path=None)
This method will generate a secure self-signed SSL key/certificate pair
    (using the `openssl <http://www.openssl.org/docs/apps/openssl.html>`_
    command) saving the result as 'certificate.pem' and 'keyfile.pem' to *path*.
    If *path* is not given the result will be saved in the current working
    directory.  The certificate will be valid for 10 years.

    .. note:: The self-signed certificate will utilize 4096-bit RSA encryption.
This method will generate a secure self-signed SSL key/certificate pair
    (using the `openssl <http://www.openssl.org/docs/apps/openssl.html>`_
    command) saving the result as 'certificate.pem' and 'keyfile.pem' to *path*.
    If *path* is not given the result will be saved in the current working
    directory.  The certificate will be valid for 10 years.
This method will generate a secure self - signed SSL key / certificate pair ( using the openssl <http : // www . openssl . org / docs / apps / openssl . html > _ command ) saving the result as certificate . pem and keyfile . pem to * path * . If * path * is not given the result will be saved in the current working directory . The certificate will be valid for 10 years .
def gen_self_signed_openssl(path=None):
    """
    This method will generate a secure self-signed SSL key/certificate pair
    (using the `openssl <http://www.openssl.org/docs/apps/openssl.html>`_
    command) saving the result as 'certificate.pem' and 'keyfile.pem' to *path*.
    If *path* is not given the result will be saved in the current working
    directory.  The certificate will be valid for 10 years.

    .. note:: The self-signed certificate will utilize 4096-bit RSA encryption.
    """
    if not path:
        path = os.path.abspath(os.curdir)
    keyfile_path = os.path.join(path, "keyfile.pem")
    certfile_path = os.path.join(path, "certificate.pem")
    subject = (
        '-subj "/OU=%s (Self-Signed)/CN=Gate One/O=Liftoff Software"' %
        os.uname()[1] # Hostname
    )
    gen_command = (
        "openssl genrsa -aes256 -out %s.tmp -passout pass:password 4096" %
        keyfile_path
    )
    decrypt_key_command = (
        "openssl rsa -in {0}.tmp -passin pass:password -out {0}".format(
            keyfile_path)
    )
    csr_command = (
        "openssl req -new -key %s -out temp.csr %s" % (
            keyfile_path, subject)
    )
    cert_command = (
        "openssl x509 -req "    # Create a new x509 certificate
        "-days 3650 "           # That lasts 10 years
        "-in temp.csr "         # Using the CSR we just generated
        "-signkey %s "          # Sign it with keyfile.pem that we just created
        "-out %s"               # Save it as certificate.pem
    )
    cert_command = cert_command % (keyfile_path, certfile_path)
    logging.debug(_(
        "Generating private key with command: %s" % gen_command))
    exitstatus, output = shell_command(gen_command, 30)
    if exitstatus != 0:
        error_msg = _(
            "An error occurred trying to create private SSL key:\n%s" % output)
        if os.path.exists('%s.tmp' % keyfile_path):
            os.remove('%s.tmp' % keyfile_path)
        raise SSLGenerationError(error_msg)
    logging.debug(_(
        "Decrypting private key with command: %s" % decrypt_key_command))
    exitstatus, output = shell_command(decrypt_key_command, 30)
    if exitstatus != 0:
        error_msg = _(
            "An error occurred trying to decrypt private SSL key:\n%s" % output)
        if os.path.exists('%s.tmp' % keyfile_path):
            os.remove('%s.tmp' % keyfile_path)
        raise SSLGenerationError(error_msg)
    logging.debug(_(
        "Creating CSR with command: %s" % csr_command))
    exitstatus, output = shell_command(csr_command, 30)
    if exitstatus != 0:
        error_msg = _(
            "An error occurred trying to create CSR:\n%s" % output)
        if os.path.exists('%s.tmp' % keyfile_path):
            os.remove('%s.tmp' % keyfile_path)
        if os.path.exists('temp.csr'):
            os.remove('temp.csr')
        raise SSLGenerationError(error_msg)
    logging.debug(_(
        "Generating self-signed certificate with command: %s" % gen_command))
    exitstatus, output = shell_command(cert_command, 30)
    if exitstatus != 0:
        error_msg = _(
            "An error occurred trying to create certificate:\n%s" % output)
        if os.path.exists('%s.tmp' % keyfile_path):
            os.remove('%s.tmp' % keyfile_path)
        if os.path.exists('temp.csr'):
            os.remove('temp.csr')
        if os.path.exists(certfile_path):
            os.remove(certfile_path)
        raise SSLGenerationError(error_msg)
    # Clean up unnecessary leftovers
    os.remove('%s.tmp' % keyfile_path)
    os.remove('temp.csr')
def gen_self_signed_openssl ( path = None ) : if not path : path = os . path . abspath ( os . curdir ) keyfile_path = os . path . join ( path , "keyfile.pem" ) certfile_path = os . path . join ( path , "certificate.pem" ) subject = ( '-subj "/OU=%s (Self-Signed)/CN=Gate One/O=Liftoff Software"' % os . uname ( ) [ 1 ] # Hostname ) gen_command = ( "openssl genrsa -aes256 -out %s.tmp -passout pass:password 4096" % keyfile_path ) decrypt_key_command = ( "openssl rsa -in {0}.tmp -passin pass:password -out {0}" . format ( keyfile_path ) ) csr_command = ( "openssl req -new -key %s -out temp.csr %s" % ( keyfile_path , subject ) ) cert_command = ( "openssl x509 -req " # Create a new x509 certificate "-days 3650 " # That lasts 10 years "-in temp.csr " # Using the CSR we just generated "-signkey %s " # Sign it with keyfile.pem that we just created "-out %s" # Save it as certificate.pem ) cert_command = cert_command % ( keyfile_path , certfile_path ) logging . debug ( _ ( "Generating private key with command: %s" % gen_command ) ) exitstatus , output = shell_command ( gen_command , 30 ) if exitstatus != 0 : error_msg = _ ( "An error occurred trying to create private SSL key:\n%s" % output ) if os . path . exists ( '%s.tmp' % keyfile_path ) : os . remove ( '%s.tmp' % keyfile_path ) raise SSLGenerationError ( error_msg ) logging . debug ( _ ( "Decrypting private key with command: %s" % decrypt_key_command ) ) exitstatus , output = shell_command ( decrypt_key_command , 30 ) if exitstatus != 0 : error_msg = _ ( "An error occurred trying to decrypt private SSL key:\n%s" % output ) if os . path . exists ( '%s.tmp' % keyfile_path ) : os . remove ( '%s.tmp' % keyfile_path ) raise SSLGenerationError ( error_msg ) logging . debug ( _ ( "Creating CSR with command: %s" % csr_command ) ) exitstatus , output = shell_command ( csr_command , 30 ) if exitstatus != 0 : error_msg = _ ( "An error occurred trying to create CSR:\n%s" % output ) if os . path . exists ( '%s.tmp' % keyfile_path ) : os . remove ( '%s.tmp' % keyfile_path ) if os . path . exists ( 'temp.csr' ) : os . remove ( 'temp.csr' ) raise SSLGenerationError ( error_msg ) logging . debug ( _ ( "Generating self-signed certificate with command: %s" % gen_command ) ) exitstatus , output = shell_command ( cert_command , 30 ) if exitstatus != 0 : error_msg = _ ( "An error occurred trying to create certificate:\n%s" % output ) if os . path . exists ( '%s.tmp' % keyfile_path ) : os . remove ( '%s.tmp' % keyfile_path ) if os . path . exists ( 'temp.csr' ) : os . remove ( 'temp.csr' ) if os . path . exists ( certfile_path ) : os . remove ( certfile_path ) raise SSLGenerationError ( error_msg ) # Clean up unnecessary leftovers os . remove ( '%s.tmp' % keyfile_path ) os . remove ( 'temp.csr' )