def acme_sign_certificate(common_name, size=DEFAULT_KEY_SIZE):
    '''
        Sign certificate with acme_tiny for let's encrypt
    '''
    private_key_path = '{}/{}.key'.format(CERTIFICATES_PATH, common_name)
    certificate_path = '{}/{}.crt'.format(CERTIFICATES_PATH, common_name)
    certificate_request_path = '{}/{}.csr'.format(CERTIFICATES_PATH,
                                                  common_name)
    signed_cert = '{certificates_path}/{common_name}-signed.crt'.format(
        certificates_path=CERTIFICATES_PATH,
        common_name=common_name)

    generate_certificate(common_name, size)

    cmd = 'openssl req -new -sha256 -key {private_key_path}'
    cmd += ' -subj "/CN={common_name}" -out {certificate_request_path}'
    cmd = cmd.format(
        private_key_path=private_key_path,
        common_name=common_name,
        certificate_request_path=certificate_request_path
    )
    p = subprocess.Popen(cmd,
                         shell=True,
                         stdout=subprocess.PIPE,
                         close_fds=True)
    p.communicate()

    _internal_sign_certificate(certificate_path, certificate_request_path,
                              signed_cert)

    cron = "/etc/cron.monthly/acme-renew"
    if not os.path.exists(cron):
        with open(cron, "w") as file:
            file.write("#!/bin/bash\ncozy_management renew_certificates\n")
        st = os.stat(cron)
        os.chmod(cron, st.st_mode | S_IXUSR)
def acme_sign_certificate ( common_name , size = DEFAULT_KEY_SIZE ) : private_key_path = '{}/{}.key' . format ( CERTIFICATES_PATH , common_name ) certificate_path = '{}/{}.crt' . format ( CERTIFICATES_PATH , common_name ) certificate_request_path = '{}/{}.csr' . format ( CERTIFICATES_PATH , common_name ) signed_cert = '{certificates_path}/{common_name}-signed.crt' . format ( certificates_path = CERTIFICATES_PATH , common_name = common_name ) generate_certificate ( common_name , size ) cmd = 'openssl req -new -sha256 -key {private_key_path}' cmd += ' -subj "/CN={common_name}" -out {certificate_request_path}' cmd = cmd . format ( private_key_path = private_key_path , common_name = common_name , certificate_request_path = certificate_request_path ) p = subprocess . Popen ( cmd , shell = True , stdout = subprocess . PIPE , close_fds = True ) p . communicate ( ) _internal_sign_certificate ( certificate_path , certificate_request_path , signed_cert ) cron = "/etc/cron.monthly/acme-renew" if not os . path . exists ( cron ) : with open ( cron , "w" ) as file : file . write ( "#!/bin/bash\ncozy_management renew_certificates\n" ) st = os . stat ( cron ) os . chmod ( cron , st . st_mode | S_IXUSR )
Sign certificate with acme_tiny for let's encrypt