Exemple #1
0
    def del_entry(self, alias=None, password=None, keystore=None):
        """
        keytool -delete -alias mydomain -keystore keystore.jks
        """
        keytool = self.get_keytool()
        if not util.exe_exists(keytool):
            self.print_error('Error, keytool command not found')
            return 4

        alias = alias if alias is not None else self.jks_alias
        password = password if password is not None else self.password
        keystore = keystore if keystore is not None else self.jks_path

        cmd = 'sudo -E -H %s -delete -alias "%s" -keystore "%s" -srcstorepass "%s"' \
              % (keytool, alias, keystore, password)

        log_obj = self.KEYTOOL_LOG
        ret, out, err = util.cli_cmd_sync(cmd,
                                          log_obj=log_obj,
                                          write_dots=self.print_output)
        if ret != 0:
            self.print_error('\nKeyTool command failed.')
            self.print_error(
                'For more information please refer to the log file: %s' %
                log_obj)
            return 6
        return 0
Exemple #2
0
    def certonly(self, email=None, domains=None, expand=False):
        if email is not None:
            self.email = email
        if domains is not None:
            self.domains = domains

        email = self.email
        if (self.email is None or len(self.email) == 0) \
                and self.FALLBACK_EMAIL is not None and len(self.FALLBACK_EMAIL) > 0:
            email = self.FALLBACK_EMAIL

        cmd = self.get_standalone_cmd(self.domains,
                                      email=email,
                                      expand=expand,
                                      staging=self.staging)
        cmd_exec = 'sudo -E -H %s %s' % (self.CERTBOT_PATH, cmd)
        log_obj = self.CERTBOT_LOG

        ret, out, err = util.cli_cmd_sync(cmd_exec,
                                          log_obj=log_obj,
                                          write_dots=self.print_output)
        if ret != 0:
            self.print_error('\nCertbot command failed: %s\n' % cmd_exec)
            self.print_error(
                'For more information please refer to the log file: %s' %
                log_obj)

        return ret, out, err
Exemple #3
0
    def renew(self):
        cmd = self.get_renew_cmd()
        cmd_exec = 'sudo -E -H %s %s' % (self.CERTBOT_PATH, cmd)
        log_obj = self.CERTBOT_LOG

        ret, out, err = util.cli_cmd_sync(cmd_exec,
                                          log_obj=log_obj,
                                          write_dots=self.print_output)
        if ret != 0 and self.print_output:
            self.print_error('\nCertbot command failed: %s\n' % cmd_exec)
            self.print_error(
                'For more information please refer to the log file: %s' %
                log_obj)

        return ret, out, err
Exemple #4
0
    def start(self):
        """
        Trigger the new verification
        """
        ret, out, err = util.cli_cmd_sync(self.cmd_exec,
                                          log_obj=self.log_obj,
                                          write_dots=self.print_output,
                                          on_err=self.answer_manual_dns_err,
                                          on_out=self.answer_manual_dns_out)
        if ret != 0:
            self.print_error('\nCertbot command failed: %s\n' % self.cmd_exec)
            self.print_error(
                'For more information please refer to the log file: %s' %
                self.log_obj)

        return ret, out, err
Exemple #5
0
    def cli_cmd(self,
                cmd,
                log_obj=None,
                write_dots=False,
                on_out=None,
                on_err=None,
                ant_answer=True,
                cwd=None):
        """
        Runs command line task
        Used for ant and jboss-cli.sh
        :return:
        """
        default_cwd = self.get_ejbca_home()
        if on_out is None and ant_answer is not None:
            on_out = self.ant_answer
        cwd = cwd if cwd is not None else default_cwd

        return util.cli_cmd_sync(cmd,
                                 log_obj=log_obj,
                                 write_dots=write_dots,
                                 on_out=on_out,
                                 on_err=on_err,
                                 cwd=cwd)
Exemple #6
0
    def convert(self):
        file_check = self.check_files()
        if file_check == 1:
            self.print_error('Error, private key not found at %s\n' %
                             self.priv_file)
            return 1
        elif file_check == 2:
            self.print_error('Error, cert not found at %s\n' % self.cert_file)
            return 2
        elif file_check == 3:
            self.print_error('Error, fullchain file not found at %s\n' %
                             self.ca_file)
            return 3

        keytool = self.get_keytool()
        if not util.exe_exists(keytool):
            self.print_error('Error, keytool command not found')
            return 4

        openssl = 'openssl'
        if not util.exe_exists(openssl):
            self.print_error('Error, openssl command not found')
            return 5

        # 1. step - create p12 file
        p12_file, p12_name = util.unique_file(self.TMP_P12, mode=0o600)
        p12_file.close()

        try:
            cmd = 'sudo -E -H %s pkcs12 -export -out "%s" ' \
                  ' -password pass:"******" ' \
                  ' -inkey "%s" ' \
                  ' -in "%s" ' \
                  ' -certfile "%s" ' \
                  ' -name "%s" ' % (openssl, p12_name, self.password, self.priv_file, self.cert_file, self.ca_file, self.jks_alias)

            log_obj = self.OPENSSL_LOG
            ret, out, err = util.cli_cmd_sync(cmd,
                                              log_obj=log_obj,
                                              write_dots=self.print_output)
            if ret != 0:
                self.print_error('\nOpenSSL command failed.')
                self.print_error(
                    'For more information please refer to the log file: %s' %
                    log_obj)
                return 6

            # 2. step - create JKS
            cmd = 'sudo -E -H %s -importkeystore -deststorepass "%s" ' \
                  ' -destkeypass "%s" ' \
                  ' -destkeystore "%s" ' \
                  ' -srckeystore "%s" ' \
                  ' -srcstoretype PKCS12 ' \
                  ' -srcstorepass "%s" ' \
                  ' -alias "%s" ' % (keytool, self.password, self.password, self.jks_path, p12_name, self.password, self.jks_alias)

            log_obj = self.KEYTOOL_LOG
            ret, out, err = util.cli_cmd_sync(cmd,
                                              log_obj=log_obj,
                                              write_dots=self.print_output)
            if ret != 0:
                self.print_error('\nKeytool command failed.')
                self.print_error(
                    'For more information please refer to the log file: %s' %
                    log_obj)
                return 7

            return 0

        finally:
            if os.path.exists(p12_name):
                os.remove(p12_name)