483b06
From f0851afdf0abd516dcd707e6e3ec0086f09f6090 Mon Sep 17 00:00:00 2001
483b06
From: Jan Cholasta <jcholast@redhat.com>
483b06
Date: Thu, 16 Mar 2017 09:44:21 +0000
483b06
Subject: [PATCH] Remove csrgen
483b06
483b06
This reverts commits:
483b06
* 72de679eb445c975ec70cd265d37d4927823ce5b
483b06
* 177f07e163d6d591a1e609d35e0a6f6f5347551e
483b06
* 80be18162921268be9c8981495c9e8a4de0c85cd
483b06
* 83e2c2b65eeb5a3aa4a59c0535e9177aac5e4637
483b06
* ada91c20588046bb147fc701718d3da4d2c080ca
483b06
* 4350dcdea22fd2284836315d0ae7d38733a7620e
483b06
* 39a5d9c5aae77687f67d9be02457733bdfb99ead
483b06
* a26cf0d7910dd4c0a4da08682b4be8d3d94ba520
483b06
* afd7c05d11432304bfdf183832a21d419f363689
483b06
* f1a1c6eca1b294f24174d7b0e1f78de46d9d5b05
483b06
* fc58eff6a3d7fe805e612b8b002304d8b9cd4ba9
483b06
* 10ef5947860f5098182b1f95c08c1158e2da15f9
483b06
483b06
https://bugzilla.redhat.com/show_bug.cgi?id=1432630
483b06
---
483b06
 freeipa.spec.in                                    |  18 -
483b06
 ipaclient/csrgen.py                                | 398 ---------------------
483b06
 ipaclient/csrgen/profiles/caIPAserviceCert.json    |  15 -
483b06
 ipaclient/csrgen/profiles/userCert.json            |  15 -
483b06
 ipaclient/csrgen/rules/dataDNS.json                |  15 -
483b06
 ipaclient/csrgen/rules/dataEmail.json              |  15 -
483b06
 ipaclient/csrgen/rules/dataHostCN.json             |  15 -
483b06
 ipaclient/csrgen/rules/dataSubjectBase.json        |  15 -
483b06
 ipaclient/csrgen/rules/dataUsernameCN.json         |  15 -
483b06
 ipaclient/csrgen/rules/syntaxSAN.json              |  15 -
483b06
 ipaclient/csrgen/rules/syntaxSubject.json          |  16 -
483b06
 ipaclient/csrgen/templates/certutil_base.tmpl      |  11 -
483b06
 ipaclient/csrgen/templates/openssl_base.tmpl       |  35 --
483b06
 ipaclient/csrgen/templates/openssl_macros.tmpl     |  29 --
483b06
 ipaclient/plugins/cert.py                          |  96 +----
483b06
 ipaclient/plugins/csrgen.py                        | 120 -------
483b06
 ipaclient/setup.py                                 |  11 +-
483b06
 ipalib/errors.py                                   |  28 --
483b06
 ipatests/setup.py                                  |   2 -
483b06
 ipatests/test_ipaclient/__init__.py                |   7 -
483b06
 .../data/test_csrgen/profiles/profile.json         |   8 -
483b06
 .../data/test_csrgen/rules/basic.json              |  12 -
483b06
 .../data/test_csrgen/rules/options.json            |  18 -
483b06
 .../scripts/caIPAserviceCert_certutil.sh           |  11 -
483b06
 .../scripts/caIPAserviceCert_openssl.sh            |  34 --
483b06
 .../data/test_csrgen/scripts/userCert_certutil.sh  |  11 -
483b06
 .../data/test_csrgen/scripts/userCert_openssl.sh   |  34 --
483b06
 .../data/test_csrgen/templates/identity_base.tmpl  |   1 -
483b06
 ipatests/test_ipaclient/test_csrgen.py             | 298 ---------------
483b06
 29 files changed, 2 insertions(+), 1316 deletions(-)
483b06
 delete mode 100644 ipaclient/csrgen.py
483b06
 delete mode 100644 ipaclient/csrgen/profiles/caIPAserviceCert.json
483b06
 delete mode 100644 ipaclient/csrgen/profiles/userCert.json
483b06
 delete mode 100644 ipaclient/csrgen/rules/dataDNS.json
483b06
 delete mode 100644 ipaclient/csrgen/rules/dataEmail.json
483b06
 delete mode 100644 ipaclient/csrgen/rules/dataHostCN.json
483b06
 delete mode 100644 ipaclient/csrgen/rules/dataSubjectBase.json
483b06
 delete mode 100644 ipaclient/csrgen/rules/dataUsernameCN.json
483b06
 delete mode 100644 ipaclient/csrgen/rules/syntaxSAN.json
483b06
 delete mode 100644 ipaclient/csrgen/rules/syntaxSubject.json
483b06
 delete mode 100644 ipaclient/csrgen/templates/certutil_base.tmpl
483b06
 delete mode 100644 ipaclient/csrgen/templates/openssl_base.tmpl
483b06
 delete mode 100644 ipaclient/csrgen/templates/openssl_macros.tmpl
483b06
 delete mode 100644 ipaclient/plugins/csrgen.py
483b06
 delete mode 100644 ipatests/test_ipaclient/__init__.py
483b06
 delete mode 100644 ipatests/test_ipaclient/data/test_csrgen/profiles/profile.json
483b06
 delete mode 100644 ipatests/test_ipaclient/data/test_csrgen/rules/basic.json
483b06
 delete mode 100644 ipatests/test_ipaclient/data/test_csrgen/rules/options.json
483b06
 delete mode 100644 ipatests/test_ipaclient/data/test_csrgen/scripts/caIPAserviceCert_certutil.sh
483b06
 delete mode 100644 ipatests/test_ipaclient/data/test_csrgen/scripts/caIPAserviceCert_openssl.sh
483b06
 delete mode 100644 ipatests/test_ipaclient/data/test_csrgen/scripts/userCert_certutil.sh
483b06
 delete mode 100644 ipatests/test_ipaclient/data/test_csrgen/scripts/userCert_openssl.sh
483b06
 delete mode 100644 ipatests/test_ipaclient/data/test_csrgen/templates/identity_base.tmpl
483b06
 delete mode 100644 ipatests/test_ipaclient/test_csrgen.py
483b06
483b06
diff --git a/freeipa.spec.in b/freeipa.spec.in
483b06
index 99e69d81dd4104063ac68a9429eeb53ee1d36245..3892e502c0c64cca25e2e50a0ff53a15a556d2f3 100644
483b06
--- a/freeipa.spec.in
483b06
+++ b/freeipa.spec.in
483b06
@@ -194,7 +194,6 @@ BuildRequires:  python-sssdconfig
483b06
 BuildRequires:  python-nose
483b06
 BuildRequires:  python-paste
483b06
 BuildRequires:  systemd-python
483b06
-BuildRequires:  python2-jinja2
483b06
 BuildRequires:  python-augeas
483b06
 
483b06
 %if 0%{?with_python3}
483b06
@@ -232,7 +231,6 @@ BuildRequires:  python3-libsss_nss_idmap
483b06
 BuildRequires:  python3-nose
483b06
 BuildRequires:  python3-paste
483b06
 BuildRequires:  python3-systemd
483b06
-BuildRequires:  python3-jinja2
483b06
 BuildRequires:  python3-augeas
483b06
 %endif # with_python3
483b06
 %endif # with_lint
483b06
@@ -541,7 +539,6 @@ Requires: %{name}-client-common = %{version}-%{release}
483b06
 Requires: %{name}-common = %{version}-%{release}
483b06
 Requires: python2-ipalib = %{version}-%{release}
483b06
 Requires: python-dns >= 1.15
483b06
-Requires: python2-jinja2
483b06
 
483b06
 %description -n python2-ipaclient
483b06
 IPA is an integrated solution to provide centrally managed Identity (users,
483b06
@@ -564,7 +561,6 @@ Requires: %{name}-client-common = %{version}-%{release}
483b06
 Requires: %{name}-common = %{version}-%{release}
483b06
 Requires: python3-ipalib = %{version}-%{release}
483b06
 Requires: python3-dns >= 1.15
483b06
-Requires: python3-jinja2
483b06
 
483b06
 %description -n python3-ipaclient
483b06
 IPA is an integrated solution to provide centrally managed Identity (users,
483b06
@@ -1425,13 +1421,6 @@ fi
483b06
 %dir %{python_sitelib}/ipaclient/remote_plugins
483b06
 %{python_sitelib}/ipaclient/remote_plugins/*.py*
483b06
 %{python_sitelib}/ipaclient/remote_plugins/2_*/*.py*
483b06
-%dir %{python_sitelib}/ipaclient/csrgen
483b06
-%dir %{python_sitelib}/ipaclient/csrgen/profiles
483b06
-%{python_sitelib}/ipaclient/csrgen/profiles/*.json
483b06
-%dir %{python_sitelib}/ipaclient/csrgen/rules
483b06
-%{python_sitelib}/ipaclient/csrgen/rules/*.json
483b06
-%dir %{python_sitelib}/ipaclient/csrgen/templates
483b06
-%{python_sitelib}/ipaclient/csrgen/templates/*.tmpl
483b06
 %{python_sitelib}/ipaclient-*.egg-info
483b06
 
483b06
 
483b06
@@ -1455,13 +1444,6 @@ fi
483b06
 %{python3_sitelib}/ipaclient/remote_plugins/__pycache__/*.py*
483b06
 %{python3_sitelib}/ipaclient/remote_plugins/2_*/*.py
483b06
 %{python3_sitelib}/ipaclient/remote_plugins/2_*/__pycache__/*.py*
483b06
-%dir %{python3_sitelib}/ipaclient/csrgen
483b06
-%dir %{python3_sitelib}/ipaclient/csrgen/profiles
483b06
-%{python3_sitelib}/ipaclient/csrgen/profiles/*.json
483b06
-%dir %{python3_sitelib}/ipaclient/csrgen/rules
483b06
-%{python3_sitelib}/ipaclient/csrgen/rules/*.json
483b06
-%dir %{python3_sitelib}/ipaclient/csrgen/templates
483b06
-%{python3_sitelib}/ipaclient/csrgen/templates/*.tmpl
483b06
 %{python3_sitelib}/ipaclient-*.egg-info
483b06
 
483b06
 %endif # with_python3
483b06
diff --git a/ipaclient/csrgen.py b/ipaclient/csrgen.py
483b06
deleted file mode 100644
483b06
index 8fb0b32c05490812b75f87db69f9df1ca38107f7..0000000000000000000000000000000000000000
483b06
--- a/ipaclient/csrgen.py
483b06
+++ /dev/null
483b06
@@ -1,398 +0,0 @@
483b06
-#
483b06
-# Copyright (C) 2016  FreeIPA Contributors see COPYING for license
483b06
-#
483b06
-
483b06
-import collections
483b06
-import errno
483b06
-import json
483b06
-import os.path
483b06
-import pipes
483b06
-import traceback
483b06
-
483b06
-import pkg_resources
483b06
-
483b06
-import jinja2
483b06
-import jinja2.ext
483b06
-import jinja2.sandbox
483b06
-import six
483b06
-
483b06
-from ipalib import api
483b06
-from ipalib import errors
483b06
-from ipalib.text import _
483b06
-from ipapython.ipa_log_manager import log_mgr
483b06
-
483b06
-if six.PY3:
483b06
-    unicode = str
483b06
-
483b06
-__doc__ = _("""
483b06
-Routines for constructing certificate signing requests using IPA data and
483b06
-stored templates.
483b06
-""")
483b06
-
483b06
-logger = log_mgr.get_logger(__name__)
483b06
-
483b06
-
483b06
-class IndexableUndefined(jinja2.Undefined):
483b06
-    def __getitem__(self, key):
483b06
-        return jinja2.Undefined(
483b06
-            hint=self._undefined_hint, obj=self._undefined_obj,
483b06
-            name=self._undefined_name, exc=self._undefined_exception)
483b06
-
483b06
-
483b06
-class IPAExtension(jinja2.ext.Extension):
483b06
-    """Jinja2 extension providing useful features for CSR generation rules."""
483b06
-
483b06
-    def __init__(self, environment):
483b06
-        super(IPAExtension, self).__init__(environment)
483b06
-
483b06
-        environment.filters.update(
483b06
-            quote=self.quote,
483b06
-            required=self.required,
483b06
-        )
483b06
-
483b06
-    def quote(self, data):
483b06
-        return pipes.quote(data)
483b06
-
483b06
-    def required(self, data, name):
483b06
-        if not data:
483b06
-            raise errors.CSRTemplateError(
483b06
-                reason=_('Required CSR generation rule %(name)s is missing data') %
483b06
-                {'name': name})
483b06
-        return data
483b06
-
483b06
-
483b06
-class Formatter(object):
483b06
-    """
483b06
-    Class for processing a set of CSR generation rules into a template.
483b06
-
483b06
-    The template can be rendered with user and database data to produce a
483b06
-    script, which generates a CSR when run.
483b06
-
483b06
-    Subclasses of Formatter should set the value of base_template_name to the
483b06
-    filename of a base template with spaces for the processed rules.
483b06
-    Additionally, they should override the _get_template_params method to
483b06
-    produce the correct output for the base template.
483b06
-    """
483b06
-    base_template_name = None
483b06
-
483b06
-    def __init__(self, csr_data_dir=None):
483b06
-        # chain loaders:
483b06
-        # 1) csr_data_dir/templates
483b06
-        # 2) /etc/ipa/csrgen/templates
483b06
-        # 3) ipaclient/csrgen/templates
483b06
-        loaders = []
483b06
-        if csr_data_dir is not None:
483b06
-            loaders.append(jinja2.FileSystemLoader(
483b06
-                os.path.join(csr_data_dir, 'templates'))
483b06
-            )
483b06
-        loaders.append(jinja2.FileSystemLoader(
483b06
-            os.path.join(api.env.confdir, 'csrgen/templates'))
483b06
-        )
483b06
-        loaders.append(jinja2.PackageLoader('ipaclient', 'csrgen/templates'))
483b06
-
483b06
-        self.jinja2 = jinja2.sandbox.SandboxedEnvironment(
483b06
-            loader=jinja2.ChoiceLoader(loaders),
483b06
-            extensions=[jinja2.ext.ExprStmtExtension, IPAExtension],
483b06
-            keep_trailing_newline=True, undefined=IndexableUndefined)
483b06
-
483b06
-        self.passthrough_globals = {}
483b06
-
483b06
-    def _define_passthrough(self, call):
483b06
-        """Some macros are meant to be interpreted during the final render, not
483b06
-        when data rules are interpolated into syntax rules. This method allows
483b06
-        those macros to be registered so that calls to them are passed through
483b06
-        to the prepared rule rather than interpreted.
483b06
-        """
483b06
-
483b06
-        def passthrough(caller):
483b06
-            return u'{%% call %s() %%}%s{%% endcall %%}' % (call, caller())
483b06
-
483b06
-        parts = call.split('.')
483b06
-        current_level = self.passthrough_globals
483b06
-        for part in parts[:-1]:
483b06
-            if part not in current_level:
483b06
-                current_level[part] = {}
483b06
-            current_level = current_level[part]
483b06
-        current_level[parts[-1]] = passthrough
483b06
-
483b06
-    def build_template(self, rules):
483b06
-        """
483b06
-        Construct a template that can produce CSR generator strings.
483b06
-
483b06
-        :param rules: list of FieldMapping to use to populate the template.
483b06
-
483b06
-        :returns: jinja2.Template that can be rendered to produce the CSR data.
483b06
-        """
483b06
-        syntax_rules = []
483b06
-        for field_mapping in rules:
483b06
-            data_rules_prepared = [
483b06
-                self._prepare_data_rule(rule)
483b06
-                for rule in field_mapping.data_rules]
483b06
-
483b06
-            data_sources = []
483b06
-            for rule in field_mapping.data_rules:
483b06
-                data_source = rule.options.get('data_source')
483b06
-                if data_source:
483b06
-                    data_sources.append(data_source)
483b06
-
483b06
-            syntax_rules.append(self._prepare_syntax_rule(
483b06
-                field_mapping.syntax_rule, data_rules_prepared,
483b06
-                field_mapping.description, data_sources))
483b06
-
483b06
-        template_params = self._get_template_params(syntax_rules)
483b06
-        base_template = self.jinja2.get_template(
483b06
-            self.base_template_name, globals=self.passthrough_globals)
483b06
-
483b06
-        try:
483b06
-            combined_template_source = base_template.render(**template_params)
483b06
-        except jinja2.UndefinedError:
483b06
-            logger.debug(traceback.format_exc())
483b06
-            raise errors.CSRTemplateError(reason=_(
483b06
-                'Template error when formatting certificate data'))
483b06
-
483b06
-        logger.debug(
483b06
-            'Formatting with template: %s' % combined_template_source)
483b06
-        combined_template = self.jinja2.from_string(combined_template_source)
483b06
-
483b06
-        return combined_template
483b06
-
483b06
-    def _wrap_conditional(self, rule, condition):
483b06
-        rule = '{%% if %s %%}%s{%% endif %%}' % (condition, rule)
483b06
-        return rule
483b06
-
483b06
-    def _wrap_required(self, rule, description):
483b06
-        template = '{%% filter required("%s") %%}%s{%% endfilter %%}' % (
483b06
-            description, rule)
483b06
-
483b06
-        return template
483b06
-
483b06
-    def _prepare_data_rule(self, data_rule):
483b06
-        template = data_rule.template
483b06
-
483b06
-        data_source = data_rule.options.get('data_source')
483b06
-        if data_source:
483b06
-            template = self._wrap_conditional(template, data_source)
483b06
-
483b06
-        return template
483b06
-
483b06
-    def _prepare_syntax_rule(
483b06
-            self, syntax_rule, data_rules, description, data_sources):
483b06
-        logger.debug('Syntax rule template: %s' % syntax_rule.template)
483b06
-        template = self.jinja2.from_string(
483b06
-            syntax_rule.template, globals=self.passthrough_globals)
483b06
-        is_required = syntax_rule.options.get('required', False)
483b06
-        try:
483b06
-            prepared_template = template.render(datarules=data_rules)
483b06
-        except jinja2.UndefinedError:
483b06
-            logger.debug(traceback.format_exc())
483b06
-            raise errors.CSRTemplateError(reason=_(
483b06
-                'Template error when formatting certificate data'))
483b06
-
483b06
-        if data_sources:
483b06
-            combinator = ' %s ' % syntax_rule.options.get(
483b06
-                'data_source_combinator', 'or')
483b06
-            condition = combinator.join(data_sources)
483b06
-            prepared_template = self._wrap_conditional(
483b06
-                prepared_template, condition)
483b06
-
483b06
-        if is_required:
483b06
-            prepared_template = self._wrap_required(
483b06
-                prepared_template, description)
483b06
-
483b06
-        return prepared_template
483b06
-
483b06
-    def _get_template_params(self, syntax_rules):
483b06
-        """
483b06
-        Package the syntax rules into fields expected by the base template.
483b06
-
483b06
-        :param syntax_rules: list of prepared syntax rules to be included in
483b06
-            the template.
483b06
-
483b06
-        :returns: dict of values needed to render the base template.
483b06
-        """
483b06
-        raise NotImplementedError('Formatter class must be subclassed')
483b06
-
483b06
-
483b06
-class OpenSSLFormatter(Formatter):
483b06
-    """Formatter class supporting the openssl command-line tool."""
483b06
-
483b06
-    base_template_name = 'openssl_base.tmpl'
483b06
-
483b06
-    # Syntax rules are wrapped in this data structure, to keep track of whether
483b06
-    # each goes in the extension or the root section
483b06
-    SyntaxRule = collections.namedtuple(
483b06
-        'SyntaxRule', ['template', 'is_extension'])
483b06
-
483b06
-    def __init__(self, *args, **kwargs):
483b06
-        super(OpenSSLFormatter, self).__init__(*args, **kwargs)
483b06
-        self._define_passthrough('openssl.section')
483b06
-
483b06
-    def _get_template_params(self, syntax_rules):
483b06
-        parameters = [rule.template for rule in syntax_rules
483b06
-                      if not rule.is_extension]
483b06
-        extensions = [rule.template for rule in syntax_rules
483b06
-                      if rule.is_extension]
483b06
-
483b06
-        return {'parameters': parameters, 'extensions': extensions}
483b06
-
483b06
-    def _prepare_syntax_rule(
483b06
-            self, syntax_rule, data_rules, description, data_sources):
483b06
-        """Overrides method to pull out whether rule is an extension or not."""
483b06
-        prepared_template = super(OpenSSLFormatter, self)._prepare_syntax_rule(
483b06
-            syntax_rule, data_rules, description, data_sources)
483b06
-        is_extension = syntax_rule.options.get('extension', False)
483b06
-        return self.SyntaxRule(prepared_template, is_extension)
483b06
-
483b06
-
483b06
-class CertutilFormatter(Formatter):
483b06
-    base_template_name = 'certutil_base.tmpl'
483b06
-
483b06
-    def _get_template_params(self, syntax_rules):
483b06
-        return {'options': syntax_rules}
483b06
-
483b06
-
483b06
-class FieldMapping(object):
483b06
-    """Representation of the rules needed to construct a complete cert field.
483b06
-
483b06
-    Attributes:
483b06
-        description: str, a name or description of this field, to be used in
483b06
-            messages
483b06
-        syntax_rule: Rule, the rule defining the syntax of this field
483b06
-        data_rules: list of Rule, the rules that produce data to be stored in
483b06
-            this field
483b06
-    """
483b06
-    __slots__ = ['description', 'syntax_rule', 'data_rules']
483b06
-
483b06
-    def __init__(self, description, syntax_rule, data_rules):
483b06
-        self.description = description
483b06
-        self.syntax_rule = syntax_rule
483b06
-        self.data_rules = data_rules
483b06
-
483b06
-
483b06
-class Rule(object):
483b06
-    __slots__ = ['name', 'template', 'options']
483b06
-
483b06
-    def __init__(self, name, template, options):
483b06
-        self.name = name
483b06
-        self.template = template
483b06
-        self.options = options
483b06
-
483b06
-
483b06
-class RuleProvider(object):
483b06
-    def rules_for_profile(self, profile_id, helper):
483b06
-        """
483b06
-        Return the rules needed to build a CSR using the given profile.
483b06
-
483b06
-        :param profile_id: str, name of the CSR generation profile to use
483b06
-        :param helper: str, name of tool (e.g. openssl, certutil) that will be
483b06
-            used to create CSR
483b06
-
483b06
-        :returns: list of FieldMapping, filled out with the appropriate rules
483b06
-        """
483b06
-        raise NotImplementedError('RuleProvider class must be subclassed')
483b06
-
483b06
-
483b06
-class FileRuleProvider(RuleProvider):
483b06
-    def __init__(self, csr_data_dir=None):
483b06
-        self.rules = {}
483b06
-        self._csrgen_data_dirs = []
483b06
-        if csr_data_dir is not None:
483b06
-            self._csrgen_data_dirs.append(csr_data_dir)
483b06
-        self._csrgen_data_dirs.append(
483b06
-            os.path.join(api.env.confdir, 'csrgen')
483b06
-        )
483b06
-        self._csrgen_data_dirs.append(
483b06
-            pkg_resources.resource_filename('ipaclient', 'csrgen')
483b06
-        )
483b06
-
483b06
-    def _open(self, subdir, filename):
483b06
-        for data_dir in self._csrgen_data_dirs:
483b06
-            path = os.path.join(data_dir, subdir, filename)
483b06
-            try:
483b06
-                return open(path)
483b06
-            except IOError as e:
483b06
-                if e.errno != errno.ENOENT:
483b06
-                    raise
483b06
-        raise IOError(
483b06
-            errno.ENOENT,
483b06
-            "'{}' not found in {}".format(
483b06
-                os.path.join(subdir, filename),
483b06
-                ", ".join(self._csrgen_data_dirs)
483b06
-            )
483b06
-        )
483b06
-
483b06
-    def _rule(self, rule_name, helper):
483b06
-        if (rule_name, helper) not in self.rules:
483b06
-            try:
483b06
-                with self._open('rules', '%s.json' % rule_name) as f:
483b06
-                    ruleset = json.load(f)
483b06
-            except IOError:
483b06
-                raise errors.NotFound(
483b06
-                    reason=_('Ruleset %(ruleset)s does not exist.') %
483b06
-                    {'ruleset': rule_name})
483b06
-
483b06
-            matching_rules = [r for r in ruleset['rules']
483b06
-                              if r['helper'] == helper]
483b06
-            if len(matching_rules) == 0:
483b06
-                raise errors.EmptyResult(
483b06
-                    reason=_('No transformation in "%(ruleset)s" rule supports'
483b06
-                             ' helper "%(helper)s"') %
483b06
-                    {'ruleset': rule_name, 'helper': helper})
483b06
-            elif len(matching_rules) > 1:
483b06
-                raise errors.RedundantMappingRule(
483b06
-                    ruleset=rule_name, helper=helper)
483b06
-            rule = matching_rules[0]
483b06
-
483b06
-            options = {}
483b06
-            if 'options' in ruleset:
483b06
-                options.update(ruleset['options'])
483b06
-            if 'options' in rule:
483b06
-                options.update(rule['options'])
483b06
-
483b06
-            self.rules[(rule_name, helper)] = Rule(
483b06
-                rule_name, rule['template'], options)
483b06
-
483b06
-        return self.rules[(rule_name, helper)]
483b06
-
483b06
-    def rules_for_profile(self, profile_id, helper):
483b06
-        try:
483b06
-            with self._open('profiles', '%s.json' % profile_id) as f:
483b06
-                profile = json.load(f)
483b06
-        except IOError:
483b06
-            raise errors.NotFound(
483b06
-                reason=_('No CSR generation rules are defined for profile'
483b06
-                         ' %(profile_id)s') % {'profile_id': profile_id})
483b06
-
483b06
-        field_mappings = []
483b06
-        for field in profile:
483b06
-            syntax_rule = self._rule(field['syntax'], helper)
483b06
-            data_rules = [self._rule(name, helper) for name in field['data']]
483b06
-            field_mappings.append(FieldMapping(
483b06
-                syntax_rule.name, syntax_rule, data_rules))
483b06
-        return field_mappings
483b06
-
483b06
-
483b06
-class CSRGenerator(object):
483b06
-    FORMATTERS = {
483b06
-        'openssl': OpenSSLFormatter,
483b06
-        'certutil': CertutilFormatter,
483b06
-    }
483b06
-
483b06
-    def __init__(self, rule_provider):
483b06
-        self.rule_provider = rule_provider
483b06
-
483b06
-    def csr_script(self, principal, config, profile_id, helper):
483b06
-        render_data = {'subject': principal, 'config': config}
483b06
-
483b06
-        formatter = self.FORMATTERS[helper]()
483b06
-        rules = self.rule_provider.rules_for_profile(profile_id, helper)
483b06
-        template = formatter.build_template(rules)
483b06
-
483b06
-        try:
483b06
-            script = template.render(render_data)
483b06
-        except jinja2.UndefinedError:
483b06
-            logger.debug(traceback.format_exc())
483b06
-            raise errors.CSRTemplateError(reason=_(
483b06
-                'Template error when formatting certificate data'))
483b06
-
483b06
-        return script
483b06
diff --git a/ipaclient/csrgen/profiles/caIPAserviceCert.json b/ipaclient/csrgen/profiles/caIPAserviceCert.json
483b06
deleted file mode 100644
483b06
index 114d2ffd4e0d8eae833eaa594f6a17a79da909be..0000000000000000000000000000000000000000
483b06
--- a/ipaclient/csrgen/profiles/caIPAserviceCert.json
483b06
+++ /dev/null
483b06
@@ -1,15 +0,0 @@
483b06
-[
483b06
-    {
483b06
-        "syntax": "syntaxSubject",
483b06
-        "data": [
483b06
-            "dataHostCN",
483b06
-            "dataSubjectBase"
483b06
-        ]
483b06
-    },
483b06
-    {
483b06
-        "syntax": "syntaxSAN",
483b06
-        "data": [
483b06
-            "dataDNS"
483b06
-        ]
483b06
-    }
483b06
-]
483b06
diff --git a/ipaclient/csrgen/profiles/userCert.json b/ipaclient/csrgen/profiles/userCert.json
483b06
deleted file mode 100644
483b06
index d6cf5cfffcfadd604fc3e8283d1be15767278c7a..0000000000000000000000000000000000000000
483b06
--- a/ipaclient/csrgen/profiles/userCert.json
483b06
+++ /dev/null
483b06
@@ -1,15 +0,0 @@
483b06
-[
483b06
-    {
483b06
-        "syntax": "syntaxSubject",
483b06
-        "data": [
483b06
-            "dataUsernameCN",
483b06
-            "dataSubjectBase"
483b06
-        ]
483b06
-    },
483b06
-    {
483b06
-        "syntax": "syntaxSAN",
483b06
-        "data": [
483b06
-            "dataEmail"
483b06
-        ]
483b06
-    }
483b06
-]
483b06
diff --git a/ipaclient/csrgen/rules/dataDNS.json b/ipaclient/csrgen/rules/dataDNS.json
483b06
deleted file mode 100644
483b06
index 2663f114123a5a73b23f6a41c1b9b3162f157ea1..0000000000000000000000000000000000000000
483b06
--- a/ipaclient/csrgen/rules/dataDNS.json
483b06
+++ /dev/null
483b06
@@ -1,15 +0,0 @@
483b06
-{
483b06
-  "rules": [
483b06
-    {
483b06
-      "helper": "openssl",
483b06
-      "template": "DNS = {{subject.krbprincipalname.0.partition('/')[2].partition('@')[0]}}"
483b06
-    },
483b06
-    {
483b06
-      "helper": "certutil",
483b06
-      "template": "dns:{{subject.krbprincipalname.0.partition('/')[2].partition('@')[0]|quote}}"
483b06
-    }
483b06
-  ],
483b06
-  "options": {
483b06
-    "data_source": "subject.krbprincipalname.0.partition('/')[2].partition('@')[0]"
483b06
-  }
483b06
-}
483b06
diff --git a/ipaclient/csrgen/rules/dataEmail.json b/ipaclient/csrgen/rules/dataEmail.json
483b06
deleted file mode 100644
483b06
index 2eae9fb25e4f09d52ec5e29e2643236641c5cecd..0000000000000000000000000000000000000000
483b06
--- a/ipaclient/csrgen/rules/dataEmail.json
483b06
+++ /dev/null
483b06
@@ -1,15 +0,0 @@
483b06
-{
483b06
-  "rules": [
483b06
-    {
483b06
-      "helper": "openssl",
483b06
-      "template": "email = {{subject.mail.0}}"
483b06
-    },
483b06
-    {
483b06
-      "helper": "certutil",
483b06
-      "template": "email:{{subject.mail.0|quote}}"
483b06
-    }
483b06
-  ],
483b06
-  "options": {
483b06
-    "data_source": "subject.mail.0"
483b06
-  }
483b06
-}
483b06
diff --git a/ipaclient/csrgen/rules/dataHostCN.json b/ipaclient/csrgen/rules/dataHostCN.json
483b06
deleted file mode 100644
483b06
index 5c415bb8cf8911ad8c24820d2466beb57f0d9a82..0000000000000000000000000000000000000000
483b06
--- a/ipaclient/csrgen/rules/dataHostCN.json
483b06
+++ /dev/null
483b06
@@ -1,15 +0,0 @@
483b06
-{
483b06
-  "rules": [
483b06
-    {
483b06
-      "helper": "openssl",
483b06
-      "template": "CN={{subject.krbprincipalname.0.partition('/')[2].partition('@')[0]}}"
483b06
-    },
483b06
-    {
483b06
-      "helper": "certutil",
483b06
-      "template": "CN={{subject.krbprincipalname.0.partition('/')[2].partition('@')[0]|quote}}"
483b06
-    }
483b06
-  ],
483b06
-  "options": {
483b06
-    "data_source": "subject.krbprincipalname.0.partition('/')[2].partition('@')[0]"
483b06
-  }
483b06
-}
483b06
diff --git a/ipaclient/csrgen/rules/dataSubjectBase.json b/ipaclient/csrgen/rules/dataSubjectBase.json
483b06
deleted file mode 100644
483b06
index 309dfb1ed57b0dfe282386181a4c887228545c55..0000000000000000000000000000000000000000
483b06
--- a/ipaclient/csrgen/rules/dataSubjectBase.json
483b06
+++ /dev/null
483b06
@@ -1,15 +0,0 @@
483b06
-{
483b06
-  "rules": [
483b06
-    {
483b06
-      "helper": "openssl",
483b06
-      "template": "{{config.ipacertificatesubjectbase.0}}"
483b06
-    },
483b06
-    {
483b06
-      "helper": "certutil",
483b06
-      "template": "{{config.ipacertificatesubjectbase.0|quote}}"
483b06
-    }
483b06
-  ],
483b06
-  "options": {
483b06
-    "data_source": "config.ipacertificatesubjectbase.0"
483b06
-  }
483b06
-}
483b06
diff --git a/ipaclient/csrgen/rules/dataUsernameCN.json b/ipaclient/csrgen/rules/dataUsernameCN.json
483b06
deleted file mode 100644
483b06
index 37e7e0113ef3146a97383355285dc1d319029e0e..0000000000000000000000000000000000000000
483b06
--- a/ipaclient/csrgen/rules/dataUsernameCN.json
483b06
+++ /dev/null
483b06
@@ -1,15 +0,0 @@
483b06
-{
483b06
-  "rules": [
483b06
-    {
483b06
-      "helper": "openssl",
483b06
-      "template": "CN={{subject.uid.0}}"
483b06
-    },
483b06
-    {
483b06
-      "helper": "certutil",
483b06
-      "template": "CN={{subject.uid.0|quote}}"
483b06
-    }
483b06
-  ],
483b06
-  "options": {
483b06
-    "data_source": "subject.uid.0"
483b06
-  }
483b06
-}
483b06
diff --git a/ipaclient/csrgen/rules/syntaxSAN.json b/ipaclient/csrgen/rules/syntaxSAN.json
483b06
deleted file mode 100644
483b06
index 122eb12443e053490ac50a3984d02a62be61e7aa..0000000000000000000000000000000000000000
483b06
--- a/ipaclient/csrgen/rules/syntaxSAN.json
483b06
+++ /dev/null
483b06
@@ -1,15 +0,0 @@
483b06
-{
483b06
-  "rules": [
483b06
-    {
483b06
-      "helper": "openssl",
483b06
-      "template": "subjectAltName = @{% call openssl.section() %}{{ datarules|join('\n') }}{% endcall %}",
483b06
-      "options": {
483b06
-        "extension": true
483b06
-      }
483b06
-    },
483b06
-    {
483b06
-      "helper": "certutil",
483b06
-      "template": "--extSAN {{ datarules|join(',') }}"
483b06
-    }
483b06
-  ]
483b06
-}
483b06
diff --git a/ipaclient/csrgen/rules/syntaxSubject.json b/ipaclient/csrgen/rules/syntaxSubject.json
483b06
deleted file mode 100644
483b06
index af6ec03d3390ba8f9fac99ed3b6c485f4c1cd64f..0000000000000000000000000000000000000000
483b06
--- a/ipaclient/csrgen/rules/syntaxSubject.json
483b06
+++ /dev/null
483b06
@@ -1,16 +0,0 @@
483b06
-{
483b06
-  "rules": [
483b06
-    {
483b06
-      "helper": "openssl",
483b06
-      "template": "distinguished_name = {% call openssl.section() %}{{ datarules|reverse|join('\n') }}{% endcall %}"
483b06
-    },
483b06
-    {
483b06
-      "helper": "certutil",
483b06
-      "template": "-s {{ datarules|join(',') }}"
483b06
-    }
483b06
-  ],
483b06
-  "options": {
483b06
-    "required": true,
483b06
-    "data_source_combinator": "and"
483b06
-  }
483b06
-}
483b06
diff --git a/ipaclient/csrgen/templates/certutil_base.tmpl b/ipaclient/csrgen/templates/certutil_base.tmpl
483b06
deleted file mode 100644
483b06
index a5556fda0e6ed854dfe67b816044b36db77d5f76..0000000000000000000000000000000000000000
483b06
--- a/ipaclient/csrgen/templates/certutil_base.tmpl
483b06
+++ /dev/null
483b06
@@ -1,11 +0,0 @@
483b06
-#!/bin/bash -e
483b06
-
483b06
-if [[ $# -lt 1 ]]; then
483b06
-echo "Usage: $0 <outfile> [<any> <certutil> <args>]"
483b06
-echo "Called as: $0 $@"
483b06
-exit 1
483b06
-fi
483b06
-
483b06
-CSR="$1"
483b06
-shift
483b06
-certutil -R -a -z <(head -c 4096 /dev/urandom) -o "$CSR" {{ options|join(' ') }} "$@"
483b06
diff --git a/ipaclient/csrgen/templates/openssl_base.tmpl b/ipaclient/csrgen/templates/openssl_base.tmpl
483b06
deleted file mode 100644
483b06
index 22b16862e88eb44c4176ee9c4580188f5b240854..0000000000000000000000000000000000000000
483b06
--- a/ipaclient/csrgen/templates/openssl_base.tmpl
483b06
+++ /dev/null
483b06
@@ -1,35 +0,0 @@
483b06
-{% raw -%}
483b06
-{% import "openssl_macros.tmpl" as openssl -%}
483b06
-{%- endraw %}
483b06
-#!/bin/bash -e
483b06
-
483b06
-if [[ $# -lt 2 ]]; then
483b06
-echo "Usage: $0 <outfile> <keyfile> <other openssl arguments>"
483b06
-echo "Called as: $0 $@"
483b06
-exit 1
483b06
-fi
483b06
-
483b06
-CONFIG="$(mktemp)"
483b06
-CSR="$1"
483b06
-KEYFILE="$2"
483b06
-shift; shift
483b06
-
483b06
-echo \
483b06
-{% raw %}{% filter quote %}{% endraw -%}
483b06
-[ req ]
483b06
-prompt = no
483b06
-encrypt_key = no
483b06
-
483b06
-{{ parameters|join('\n') }}
483b06
-{% raw %}{% set rendered_extensions -%}{% endraw %}
483b06
-{{ extensions|join('\n') }}
483b06
-{% raw -%}
483b06
-{%- endset -%}
483b06
-{% if rendered_extensions -%}
483b06
-req_extensions = {% call openssl.section() %}{{ rendered_extensions }}{% endcall %}
483b06
-{% endif %}
483b06
-{{ openssl.openssl_sections|join('\n\n') }}
483b06
-{% endfilter %}{%- endraw %} > "$CONFIG"
483b06
-
483b06
-openssl req -new -config "$CONFIG" -out "$CSR" -key "$KEYFILE" "$@"
483b06
-rm "$CONFIG"
483b06
diff --git a/ipaclient/csrgen/templates/openssl_macros.tmpl b/ipaclient/csrgen/templates/openssl_macros.tmpl
483b06
deleted file mode 100644
483b06
index d31b8fef5f2d85e1b3d5ecf425f00ec9c22ac301..0000000000000000000000000000000000000000
483b06
--- a/ipaclient/csrgen/templates/openssl_macros.tmpl
483b06
+++ /dev/null
483b06
@@ -1,29 +0,0 @@
483b06
-{# List containing rendered sections to be included at end #}
483b06
-{% set openssl_sections = [] %}
483b06
-
483b06
-{#
483b06
-List containing one entry for each section name allocated. Because of
483b06
-scoping rules, we need to use a list so that it can be a "per-render global"
483b06
-that gets updated in place. Real globals are shared by all templates with the
483b06
-same environment, and variables defined in the macro don't persist after the
483b06
-macro invocation ends.
483b06
-#}
483b06
-{% set openssl_section_num = [] %}
483b06
-
483b06
-{% macro section() -%}
483b06
-{% set name -%}
483b06
-sec{{ openssl_section_num|length -}}
483b06
-{% endset -%}
483b06
-{% do openssl_section_num.append('') -%}
483b06
-{% set contents %}{{ caller() }}{% endset -%}
483b06
-{% if contents -%}
483b06
-{% set sectiondata = formatsection(name, contents) -%}
483b06
-{% do openssl_sections.append(sectiondata) -%}
483b06
-{% endif -%}
483b06
-{{ name -}}
483b06
-{% endmacro %}
483b06
-
483b06
-{% macro formatsection(name, contents) -%}
483b06
-[ {{ name }} ]
483b06
-{{ contents -}}
483b06
-{% endmacro %}
483b06
diff --git a/ipaclient/plugins/cert.py b/ipaclient/plugins/cert.py
483b06
index 93cd3cef1a14925bc0795b32e97e44d69897be5c..8195e04fc43ffbd8ca6589d2652559198759d9e6 100644
483b06
--- a/ipaclient/plugins/cert.py
483b06
+++ b/ipaclient/plugins/cert.py
483b06
@@ -20,10 +20,6 @@
483b06
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
483b06
 
483b06
 import base64
483b06
-import subprocess
483b06
-from tempfile import NamedTemporaryFile as NTF
483b06
-
483b06
-import six
483b06
 
483b06
 from ipaclient.frontend import MethodOverride
483b06
 from ipalib import errors
483b06
@@ -33,9 +29,6 @@ from ipalib.parameters import File, Flag, Str
483b06
 from ipalib.plugable import Registry
483b06
 from ipalib.text import _
483b06
 
483b06
-if six.PY3:
483b06
-    unicode = str
483b06
-
483b06
 register = Registry()
483b06
 
483b06
 
483b06
@@ -77,99 +70,12 @@ class CertRetrieveOverride(MethodOverride):
483b06
 
483b06
 @register(override=True, no_fail=True)
483b06
 class cert_request(CertRetrieveOverride):
483b06
-    takes_options = CertRetrieveOverride.takes_options + (
483b06
-        Str(
483b06
-            'database?',
483b06
-            label=_('Path to NSS database'),
483b06
-            doc=_('Path to NSS database to use for private key'),
483b06
-        ),
483b06
-        Str(
483b06
-            'private_key?',
483b06
-            label=_('Path to private key file'),
483b06
-            doc=_('Path to PEM file containing a private key'),
483b06
-        ),
483b06
-        Str(
483b06
-            'password_file?',
483b06
-            label=_(
483b06
-                'File containing a password for the private key or database'),
483b06
-        ),
483b06
-        Str(
483b06
-            'csr_profile_id?',
483b06
-            label=_('Name of CSR generation profile (if not the same as'
483b06
-                    ' profile_id)'),
483b06
-        ),
483b06
-    )
483b06
-
483b06
     def get_args(self):
483b06
         for arg in super(cert_request, self).get_args():
483b06
             if arg.name == 'csr':
483b06
-                arg = arg.clone_retype(arg.name, File, required=False)
483b06
+                arg = arg.clone_retype(arg.name, File)
483b06
             yield arg
483b06
 
483b06
-    def forward(self, csr=None, **options):
483b06
-        database = options.pop('database', None)
483b06
-        private_key = options.pop('private_key', None)
483b06
-        csr_profile_id = options.pop('csr_profile_id', None)
483b06
-        password_file = options.pop('password_file', None)
483b06
-
483b06
-        if csr is None:
483b06
-            if database:
483b06
-                helper = u'certutil'
483b06
-                helper_args = ['-d', database]
483b06
-                if password_file:
483b06
-                    helper_args += ['-f', password_file]
483b06
-            elif private_key:
483b06
-                helper = u'openssl'
483b06
-                helper_args = [private_key]
483b06
-                if password_file:
483b06
-                    helper_args += ['-passin', 'file:%s' % password_file]
483b06
-            else:
483b06
-                raise errors.InvocationError(
483b06
-                    message=u"One of 'database' or 'private_key' is required")
483b06
-
483b06
-            with NTF() as scriptfile, NTF() as csrfile:
483b06
-                # If csr_profile_id is passed, that takes precedence.
483b06
-                # Otherwise, use profile_id. If neither are passed, the default
483b06
-                # in cert_get_requestdata will be used.
483b06
-                profile_id = csr_profile_id
483b06
-                if profile_id is None:
483b06
-                    profile_id = options.get('profile_id')
483b06
-
483b06
-                self.api.Command.cert_get_requestdata(
483b06
-                    profile_id=profile_id,
483b06
-                    principal=options.get('principal'),
483b06
-                    out=unicode(scriptfile.name),
483b06
-                    helper=helper)
483b06
-
483b06
-                helper_cmd = [
483b06
-                    'bash', '-e', scriptfile.name, csrfile.name] + helper_args
483b06
-
483b06
-                try:
483b06
-                    subprocess.check_output(helper_cmd)
483b06
-                except subprocess.CalledProcessError as e:
483b06
-                    raise errors.CertificateOperationError(
483b06
-                        error=(
483b06
-                            _('Error running "%(cmd)s" to generate CSR:'
483b06
-                              ' %(err)s') %
483b06
-                            {'cmd': ' '.join(helper_cmd), 'err': e.output}))
483b06
-
483b06
-                try:
483b06
-                    csr = unicode(csrfile.read())
483b06
-                except IOError as e:
483b06
-                    raise errors.CertificateOperationError(
483b06
-                        error=(_('Unable to read generated CSR file: %(err)s')
483b06
-                               % {'err': e}))
483b06
-                if not csr:
483b06
-                    raise errors.CertificateOperationError(
483b06
-                        error=(_('Generated CSR was empty')))
483b06
-        else:
483b06
-            if database is not None or private_key is not None:
483b06
-                raise errors.MutuallyExclusiveError(reason=_(
483b06
-                    "Options 'database' and 'private_key' are not compatible"
483b06
-                    " with 'csr'"))
483b06
-
483b06
-        return super(cert_request, self).forward(csr, **options)
483b06
-
483b06
 
483b06
 @register(override=True, no_fail=True)
483b06
 class cert_show(CertRetrieveOverride):
483b06
diff --git a/ipaclient/plugins/csrgen.py b/ipaclient/plugins/csrgen.py
483b06
deleted file mode 100644
483b06
index a0d99ef06445de268cd1872a025d0613e245ae6c..0000000000000000000000000000000000000000
483b06
--- a/ipaclient/plugins/csrgen.py
483b06
+++ /dev/null
483b06
@@ -1,120 +0,0 @@
483b06
-#
483b06
-# Copyright (C) 2016  FreeIPA Contributors see COPYING for license
483b06
-#
483b06
-
483b06
-import six
483b06
-
483b06
-from ipaclient.csrgen import CSRGenerator, FileRuleProvider
483b06
-from ipalib import api
483b06
-from ipalib import errors
483b06
-from ipalib import output
483b06
-from ipalib import util
483b06
-from ipalib.frontend import Local, Str
483b06
-from ipalib.parameters import Principal
483b06
-from ipalib.plugable import Registry
483b06
-from ipalib.text import _
483b06
-from ipapython import dogtag
483b06
-
483b06
-if six.PY3:
483b06
-    unicode = str
483b06
-
483b06
-register = Registry()
483b06
-
483b06
-__doc__ = _("""
483b06
-Commands to build certificate requests automatically
483b06
-""")
483b06
-
483b06
-
483b06
-@register()
483b06
-class cert_get_requestdata(Local):
483b06
-    __doc__ = _('Gather data for a certificate signing request.')
483b06
-
483b06
-    NO_CLI = True
483b06
-
483b06
-    takes_options = (
483b06
-        Principal(
483b06
-            'principal',
483b06
-            label=_('Principal'),
483b06
-            doc=_('Principal for this certificate (e.g.'
483b06
-                  ' HTTP/test.example.com)'),
483b06
-        ),
483b06
-        Str(
483b06
-            'profile_id?',
483b06
-            label=_('Profile ID'),
483b06
-            doc=_('CSR Generation Profile to use'),
483b06
-        ),
483b06
-        Str(
483b06
-            'helper',
483b06
-            label=_('Name of CSR generation tool'),
483b06
-            doc=_('Name of tool (e.g. openssl, certutil) that will be used to'
483b06
-                  ' create CSR'),
483b06
-        ),
483b06
-        Str(
483b06
-            'out?',
483b06
-            doc=_('Write CSR generation script to file'),
483b06
-        ),
483b06
-    )
483b06
-
483b06
-    has_output = (
483b06
-        output.Output(
483b06
-            'result',
483b06
-            type=dict,
483b06
-            doc=_('Dictionary mapping variable name to value'),
483b06
-        ),
483b06
-    )
483b06
-
483b06
-    has_output_params = (
483b06
-        Str(
483b06
-            'script',
483b06
-            label=_('Generation script'),
483b06
-        )
483b06
-    )
483b06
-
483b06
-    def execute(self, *args, **options):
483b06
-        if 'out' in options:
483b06
-            util.check_writable_file(options['out'])
483b06
-
483b06
-        principal = options.get('principal')
483b06
-        profile_id = options.get('profile_id')
483b06
-        if profile_id is None:
483b06
-            profile_id = dogtag.DEFAULT_PROFILE
483b06
-        helper = options.get('helper')
483b06
-
483b06
-        if self.api.env.in_server:
483b06
-            backend = self.api.Backend.ldap2
483b06
-        else:
483b06
-            backend = self.api.Backend.rpcclient
483b06
-        if not backend.isconnected():
483b06
-            backend.connect()
483b06
-
483b06
-        try:
483b06
-            if principal.is_host:
483b06
-                principal_obj = api.Command.host_show(
483b06
-                    principal.hostname, all=True)
483b06
-            elif principal.is_service:
483b06
-                principal_obj = api.Command.service_show(
483b06
-                    unicode(principal), all=True)
483b06
-            elif principal.is_user:
483b06
-                principal_obj = api.Command.user_show(
483b06
-                    principal.username, all=True)
483b06
-        except errors.NotFound:
483b06
-            raise errors.NotFound(
483b06
-                reason=_("The principal for this request doesn't exist."))
483b06
-        principal_obj = principal_obj['result']
483b06
-        config = api.Command.config_show()['result']
483b06
-
483b06
-        generator = CSRGenerator(FileRuleProvider())
483b06
-
483b06
-        script = generator.csr_script(
483b06
-            principal_obj, config, profile_id, helper)
483b06
-
483b06
-        result = {}
483b06
-        if 'out' in options:
483b06
-            with open(options['out'], 'wb') as f:
483b06
-                f.write(script)
483b06
-        else:
483b06
-            result = dict(script=script)
483b06
-
483b06
-        return dict(
483b06
-            result=result
483b06
-        )
483b06
diff --git a/ipaclient/setup.py b/ipaclient/setup.py
483b06
index f5be7ea61f554f04d7bde46c84182f6148820600..e3f31d2b9c46a2668a0e9264ea0cfda06aeeaa2e 100644
483b06
--- a/ipaclient/setup.py
483b06
+++ b/ipaclient/setup.py
483b06
@@ -43,18 +43,10 @@ if __name__ == '__main__':
483b06
             "ipaclient.remote_plugins.2_156",
483b06
             "ipaclient.remote_plugins.2_164",
483b06
         ],
483b06
-        package_data={
483b06
-            'ipaclient': [
483b06
-                'csrgen/profiles/*.json',
483b06
-                'csrgen/rules/*.json',
483b06
-                'csrgen/templates/*.tmpl',
483b06
-            ],
483b06
-        },
483b06
         install_requires=[
483b06
             "cryptography",
483b06
             "ipalib",
483b06
             "ipapython",
483b06
-            "jinja2",
483b06
             "python-yubico",
483b06
             "pyusb",
483b06
             "qrcode",
483b06
@@ -63,6 +55,5 @@ if __name__ == '__main__':
483b06
         extras_require={
483b06
             "install": ["ipaplatform"],
483b06
             "otptoken_yubikey": ["yubico", "usb"]
483b06
-        },
483b06
-        zip_safe=False,
483b06
+        }
483b06
     )
483b06
diff --git a/ipalib/errors.py b/ipalib/errors.py
483b06
index 6aaca708a02e609f11c4aa5ef5fe2b4a8ae8a941..88707ac313fa7c5ec247b3f9b71f96925f5627e2 100644
483b06
--- a/ipalib/errors.py
483b06
+++ b/ipalib/errors.py
483b06
@@ -1422,34 +1422,6 @@ class HTTPRequestError(RemoteRetrieveError):
483b06
     format = _('Request failed with status %(status)s: %(reason)s')
483b06
 
483b06
 
483b06
-class RedundantMappingRule(SingleMatchExpected):
483b06
-    """
483b06
-    **4036** Raised when more than one rule in a CSR generation ruleset matches
483b06
-    a particular helper.
483b06
-
483b06
-    For example:
483b06
-
483b06
-    >>> raise RedundantMappingRule(ruleset='syntaxSubject', helper='certutil')
483b06
-    Traceback (most recent call last):
483b06
-      ...
483b06
-    RedundantMappingRule: Mapping ruleset "syntaxSubject" has more than one
483b06
-    rule for the certutil helper.
483b06
-    """
483b06
-
483b06
-    errno = 4036
483b06
-    format = _('Mapping ruleset "%(ruleset)s" has more than one rule for the'
483b06
-               ' %(helper)s helper')
483b06
-
483b06
-
483b06
-class CSRTemplateError(ExecutionError):
483b06
-    """
483b06
-    **4037** Raised when evaluation of a CSR generation template fails
483b06
-    """
483b06
-
483b06
-    errno = 4037
483b06
-    format = _('%(reason)s')
483b06
-
483b06
-
483b06
 class BuiltinError(ExecutionError):
483b06
     """
483b06
     **4100** Base class for builtin execution errors (*4100 - 4199*).
483b06
diff --git a/ipatests/setup.py b/ipatests/setup.py
483b06
index 46d51ff1ccdec7b2288955b8e5abdc2b971d3d17..fe65626ec7fe09701810a99a5fb8a8ede9697f46 100644
483b06
--- a/ipatests/setup.py
483b06
+++ b/ipatests/setup.py
483b06
@@ -38,7 +38,6 @@ if __name__ == '__main__':
483b06
             "ipatests.test_cmdline",
483b06
             "ipatests.test_install",
483b06
             "ipatests.test_integration",
483b06
-            "ipatests.test_ipaclient",
483b06
             "ipatests.test_ipalib",
483b06
             "ipatests.test_ipapython",
483b06
             "ipatests.test_ipaserver",
483b06
@@ -52,7 +51,6 @@ if __name__ == '__main__':
483b06
         package_data={
483b06
             'ipatests.test_install': ['*.update'],
483b06
             'ipatests.test_integration': ['scripts/*'],
483b06
-            'ipatests.test_ipaclient': ['data/*/*/*'],
483b06
             'ipatests.test_ipalib': ['data/*'],
483b06
             'ipatests.test_pkcs10': ['*.csr'],
483b06
             "ipatests.test_ipaserver": ['data/*'],
483b06
diff --git a/ipatests/test_ipaclient/__init__.py b/ipatests/test_ipaclient/__init__.py
483b06
deleted file mode 100644
483b06
index 0c428910cabe103af3ac9bfe4cdde6678acd1585..0000000000000000000000000000000000000000
483b06
--- a/ipatests/test_ipaclient/__init__.py
483b06
+++ /dev/null
483b06
@@ -1,7 +0,0 @@
483b06
-#
483b06
-# Copyright (C) 2016  FreeIPA Contributors see COPYING for license
483b06
-#
483b06
-
483b06
-"""
483b06
-Sub-package containing unit tests for `ipaclient` package.
483b06
-"""
483b06
diff --git a/ipatests/test_ipaclient/data/test_csrgen/profiles/profile.json b/ipatests/test_ipaclient/data/test_csrgen/profiles/profile.json
483b06
deleted file mode 100644
483b06
index 676f91bef696109976826e6e61be091718172798..0000000000000000000000000000000000000000
483b06
--- a/ipatests/test_ipaclient/data/test_csrgen/profiles/profile.json
483b06
+++ /dev/null
483b06
@@ -1,8 +0,0 @@
483b06
-[
483b06
-    {
483b06
-        "syntax": "basic",
483b06
-        "data": [
483b06
-            "options"
483b06
-        ]
483b06
-    }
483b06
-]
483b06
diff --git a/ipatests/test_ipaclient/data/test_csrgen/rules/basic.json b/ipatests/test_ipaclient/data/test_csrgen/rules/basic.json
483b06
deleted file mode 100644
483b06
index feba3e91e53c5c9becb44c0d2190b5a98c04a928..0000000000000000000000000000000000000000
483b06
--- a/ipatests/test_ipaclient/data/test_csrgen/rules/basic.json
483b06
+++ /dev/null
483b06
@@ -1,12 +0,0 @@
483b06
-{
483b06
-  "rules": [
483b06
-    {
483b06
-      "helper": "openssl",
483b06
-      "template": "openssl_rule"
483b06
-    },
483b06
-    {
483b06
-      "helper": "certutil",
483b06
-      "template": "certutil_rule"
483b06
-    }
483b06
-  ]
483b06
-}
483b06
diff --git a/ipatests/test_ipaclient/data/test_csrgen/rules/options.json b/ipatests/test_ipaclient/data/test_csrgen/rules/options.json
483b06
deleted file mode 100644
483b06
index 111a6d80c8faf27376dac342a18aede1fb1242ef..0000000000000000000000000000000000000000
483b06
--- a/ipatests/test_ipaclient/data/test_csrgen/rules/options.json
483b06
+++ /dev/null
483b06
@@ -1,18 +0,0 @@
483b06
-{
483b06
-  "rules": [
483b06
-    {
483b06
-      "helper": "openssl",
483b06
-      "template": "openssl_rule",
483b06
-      "options": {
483b06
-        "helper_option": true
483b06
-      }
483b06
-    },
483b06
-    {
483b06
-      "helper": "certutil",
483b06
-      "template": "certutil_rule"
483b06
-    }
483b06
-  ],
483b06
-  "options": {
483b06
-    "global_option": true
483b06
-  }
483b06
-}
483b06
diff --git a/ipatests/test_ipaclient/data/test_csrgen/scripts/caIPAserviceCert_certutil.sh b/ipatests/test_ipaclient/data/test_csrgen/scripts/caIPAserviceCert_certutil.sh
483b06
deleted file mode 100644
483b06
index 74a704c2dd1765c7b775fded8ed957715b264b91..0000000000000000000000000000000000000000
483b06
--- a/ipatests/test_ipaclient/data/test_csrgen/scripts/caIPAserviceCert_certutil.sh
483b06
+++ /dev/null
483b06
@@ -1,11 +0,0 @@
483b06
-#!/bin/bash -e
483b06
-
483b06
-if [[ $# -lt 1 ]]; then
483b06
-echo "Usage: $0 <outfile> [<any> <certutil> <args>]"
483b06
-echo "Called as: $0 $@"
483b06
-exit 1
483b06
-fi
483b06
-
483b06
-CSR="$1"
483b06
-shift
483b06
-certutil -R -a -z <(head -c 4096 /dev/urandom) -o "$CSR" -s CN=machine.example.com,O=DOMAIN.EXAMPLE.COM --extSAN dns:machine.example.com "$@"
483b06
diff --git a/ipatests/test_ipaclient/data/test_csrgen/scripts/caIPAserviceCert_openssl.sh b/ipatests/test_ipaclient/data/test_csrgen/scripts/caIPAserviceCert_openssl.sh
483b06
deleted file mode 100644
483b06
index 811bfd763e27678adaf681a430e909b24680aeda..0000000000000000000000000000000000000000
483b06
--- a/ipatests/test_ipaclient/data/test_csrgen/scripts/caIPAserviceCert_openssl.sh
483b06
+++ /dev/null
483b06
@@ -1,34 +0,0 @@
483b06
-#!/bin/bash -e
483b06
-
483b06
-if [[ $# -lt 2 ]]; then
483b06
-echo "Usage: $0 <outfile> <keyfile> <other openssl arguments>"
483b06
-echo "Called as: $0 $@"
483b06
-exit 1
483b06
-fi
483b06
-
483b06
-CONFIG="$(mktemp)"
483b06
-CSR="$1"
483b06
-KEYFILE="$2"
483b06
-shift; shift
483b06
-
483b06
-echo \
483b06
-'[ req ]
483b06
-prompt = no
483b06
-encrypt_key = no
483b06
-
483b06
-distinguished_name = sec0
483b06
-req_extensions = sec2
483b06
-
483b06
-[ sec0 ]
483b06
-O=DOMAIN.EXAMPLE.COM
483b06
-CN=machine.example.com
483b06
-
483b06
-[ sec1 ]
483b06
-DNS = machine.example.com
483b06
-
483b06
-[ sec2 ]
483b06
-subjectAltName = @sec1
483b06
-' > "$CONFIG"
483b06
-
483b06
-openssl req -new -config "$CONFIG" -out "$CSR" -key "$KEYFILE" "$@"
483b06
-rm "$CONFIG"
483b06
diff --git a/ipatests/test_ipaclient/data/test_csrgen/scripts/userCert_certutil.sh b/ipatests/test_ipaclient/data/test_csrgen/scripts/userCert_certutil.sh
483b06
deleted file mode 100644
483b06
index 4aaeda07aabd4c36d277e339d0b761f7a8a54baf..0000000000000000000000000000000000000000
483b06
--- a/ipatests/test_ipaclient/data/test_csrgen/scripts/userCert_certutil.sh
483b06
+++ /dev/null
483b06
@@ -1,11 +0,0 @@
483b06
-#!/bin/bash -e
483b06
-
483b06
-if [[ $# -lt 1 ]]; then
483b06
-echo "Usage: $0 <outfile> [<any> <certutil> <args>]"
483b06
-echo "Called as: $0 $@"
483b06
-exit 1
483b06
-fi
483b06
-
483b06
-CSR="$1"
483b06
-shift
483b06
-certutil -R -a -z <(head -c 4096 /dev/urandom) -o "$CSR" -s CN=testuser,O=DOMAIN.EXAMPLE.COM --extSAN email:testuser@example.com "$@"
483b06
diff --git a/ipatests/test_ipaclient/data/test_csrgen/scripts/userCert_openssl.sh b/ipatests/test_ipaclient/data/test_csrgen/scripts/userCert_openssl.sh
483b06
deleted file mode 100644
483b06
index 2edf067a528456877025f63dca76d68e7edde41e..0000000000000000000000000000000000000000
483b06
--- a/ipatests/test_ipaclient/data/test_csrgen/scripts/userCert_openssl.sh
483b06
+++ /dev/null
483b06
@@ -1,34 +0,0 @@
483b06
-#!/bin/bash -e
483b06
-
483b06
-if [[ $# -lt 2 ]]; then
483b06
-echo "Usage: $0 <outfile> <keyfile> <other openssl arguments>"
483b06
-echo "Called as: $0 $@"
483b06
-exit 1
483b06
-fi
483b06
-
483b06
-CONFIG="$(mktemp)"
483b06
-CSR="$1"
483b06
-KEYFILE="$2"
483b06
-shift; shift
483b06
-
483b06
-echo \
483b06
-'[ req ]
483b06
-prompt = no
483b06
-encrypt_key = no
483b06
-
483b06
-distinguished_name = sec0
483b06
-req_extensions = sec2
483b06
-
483b06
-[ sec0 ]
483b06
-O=DOMAIN.EXAMPLE.COM
483b06
-CN=testuser
483b06
-
483b06
-[ sec1 ]
483b06
-email = testuser@example.com
483b06
-
483b06
-[ sec2 ]
483b06
-subjectAltName = @sec1
483b06
-' > "$CONFIG"
483b06
-
483b06
-openssl req -new -config "$CONFIG" -out "$CSR" -key "$KEYFILE" "$@"
483b06
-rm "$CONFIG"
483b06
diff --git a/ipatests/test_ipaclient/data/test_csrgen/templates/identity_base.tmpl b/ipatests/test_ipaclient/data/test_csrgen/templates/identity_base.tmpl
483b06
deleted file mode 100644
483b06
index 79111ab686b4fe25227796509b3cd3fcb54af728..0000000000000000000000000000000000000000
483b06
--- a/ipatests/test_ipaclient/data/test_csrgen/templates/identity_base.tmpl
483b06
+++ /dev/null
483b06
@@ -1 +0,0 @@
483b06
-{{ options|join(";") }}
483b06
diff --git a/ipatests/test_ipaclient/test_csrgen.py b/ipatests/test_ipaclient/test_csrgen.py
483b06
deleted file mode 100644
483b06
index 556f8e096976387d24057084c06d53bcb9998a69..0000000000000000000000000000000000000000
483b06
--- a/ipatests/test_ipaclient/test_csrgen.py
483b06
+++ /dev/null
483b06
@@ -1,298 +0,0 @@
483b06
-#
483b06
-# Copyright (C) 2016  FreeIPA Contributors see COPYING for license
483b06
-#
483b06
-
483b06
-import os
483b06
-import pytest
483b06
-
483b06
-from ipaclient import csrgen
483b06
-from ipalib import errors
483b06
-
483b06
-BASE_DIR = os.path.dirname(__file__)
483b06
-CSR_DATA_DIR = os.path.join(BASE_DIR, 'data', 'test_csrgen')
483b06
-
483b06
-
483b06
-@pytest.fixture
483b06
-def formatter():
483b06
-    return csrgen.Formatter(csr_data_dir=CSR_DATA_DIR)
483b06
-
483b06
-
483b06
-@pytest.fixture
483b06
-def rule_provider():
483b06
-    return csrgen.FileRuleProvider(csr_data_dir=CSR_DATA_DIR)
483b06
-
483b06
-
483b06
-@pytest.fixture
483b06
-def generator():
483b06
-    return csrgen.CSRGenerator(csrgen.FileRuleProvider())
483b06
-
483b06
-
483b06
-class StubRuleProvider(csrgen.RuleProvider):
483b06
-    def __init__(self):
483b06
-        self.syntax_rule = csrgen.Rule(
483b06
-            'syntax', '{{datarules|join(",")}}', {})
483b06
-        self.data_rule = csrgen.Rule('data', 'data_template', {})
483b06
-        self.field_mapping = csrgen.FieldMapping(
483b06
-            'example', self.syntax_rule, [self.data_rule])
483b06
-        self.rules = [self.field_mapping]
483b06
-
483b06
-    def rules_for_profile(self, profile_id, helper):
483b06
-        return self.rules
483b06
-
483b06
-
483b06
-class IdentityFormatter(csrgen.Formatter):
483b06
-    base_template_name = 'identity_base.tmpl'
483b06
-
483b06
-    def __init__(self):
483b06
-        super(IdentityFormatter, self).__init__(csr_data_dir=CSR_DATA_DIR)
483b06
-
483b06
-    def _get_template_params(self, syntax_rules):
483b06
-        return {'options': syntax_rules}
483b06
-
483b06
-
483b06
-class IdentityCSRGenerator(csrgen.CSRGenerator):
483b06
-    FORMATTERS = {'identity': IdentityFormatter}
483b06
-
483b06
-
483b06
-class test_Formatter(object):
483b06
-    def test_prepare_data_rule_with_data_source(self, formatter):
483b06
-        data_rule = csrgen.Rule('uid', '{{subject.uid.0}}',
483b06
-                                {'data_source': 'subject.uid.0'})
483b06
-        prepared = formatter._prepare_data_rule(data_rule)
483b06
-        assert prepared == '{% if subject.uid.0 %}{{subject.uid.0}}{% endif %}'
483b06
-
483b06
-    def test_prepare_data_rule_no_data_source(self, formatter):
483b06
-        """Not a normal case, but we should handle it anyway"""
483b06
-        data_rule = csrgen.Rule('uid', 'static_text', {})
483b06
-        prepared = formatter._prepare_data_rule(data_rule)
483b06
-        assert prepared == 'static_text'
483b06
-
483b06
-    def test_prepare_syntax_rule_with_data_sources(self, formatter):
483b06
-        syntax_rule = csrgen.Rule(
483b06
-            'example', '{{datarules|join(",")}}', {})
483b06
-        data_rules = ['{{subject.field1}}', '{{subject.field2}}']
483b06
-        data_sources = ['subject.field1', 'subject.field2']
483b06
-        prepared = formatter._prepare_syntax_rule(
483b06
-            syntax_rule, data_rules, 'example', data_sources)
483b06
-
483b06
-        assert prepared == (
483b06
-            '{% if subject.field1 or subject.field2 %}{{subject.field1}},'
483b06
-            '{{subject.field2}}{% endif %}')
483b06
-
483b06
-    def test_prepare_syntax_rule_with_combinator(self, formatter):
483b06
-        syntax_rule = csrgen.Rule('example', '{{datarules|join(",")}}',
483b06
-                                  {'data_source_combinator': 'and'})
483b06
-        data_rules = ['{{subject.field1}}', '{{subject.field2}}']
483b06
-        data_sources = ['subject.field1', 'subject.field2']
483b06
-        prepared = formatter._prepare_syntax_rule(
483b06
-            syntax_rule, data_rules, 'example', data_sources)
483b06
-
483b06
-        assert prepared == (
483b06
-            '{% if subject.field1 and subject.field2 %}{{subject.field1}},'
483b06
-            '{{subject.field2}}{% endif %}')
483b06
-
483b06
-    def test_prepare_syntax_rule_required(self, formatter):
483b06
-        syntax_rule = csrgen.Rule('example', '{{datarules|join(",")}}',
483b06
-                                  {'required': True})
483b06
-        data_rules = ['{{subject.field1}}']
483b06
-        data_sources = ['subject.field1']
483b06
-        prepared = formatter._prepare_syntax_rule(
483b06
-            syntax_rule, data_rules, 'example', data_sources)
483b06
-
483b06
-        assert prepared == (
483b06
-            '{% filter required("example") %}{% if subject.field1 %}'
483b06
-            '{{subject.field1}}{% endif %}{% endfilter %}')
483b06
-
483b06
-    def test_prepare_syntax_rule_passthrough(self, formatter):
483b06
-        """
483b06
-        Calls to macros defined as passthrough are still call tags in the final
483b06
-        template.
483b06
-        """
483b06
-        formatter._define_passthrough('example.macro')
483b06
-
483b06
-        syntax_rule = csrgen.Rule(
483b06
-            'example',
483b06
-            '{% call example.macro() %}{{datarules|join(",")}}{% endcall %}',
483b06
-            {})
483b06
-        data_rules = ['{{subject.field1}}']
483b06
-        data_sources = ['subject.field1']
483b06
-        prepared = formatter._prepare_syntax_rule(
483b06
-            syntax_rule, data_rules, 'example', data_sources)
483b06
-
483b06
-        assert prepared == (
483b06
-            '{% if subject.field1 %}{% call example.macro() %}'
483b06
-            '{{subject.field1}}{% endcall %}{% endif %}')
483b06
-
483b06
-    def test_prepare_syntax_rule_no_data_sources(self, formatter):
483b06
-        """Not a normal case, but we should handle it anyway"""
483b06
-        syntax_rule = csrgen.Rule(
483b06
-            'example', '{{datarules|join(",")}}', {})
483b06
-        data_rules = ['rule1', 'rule2']
483b06
-        data_sources = []
483b06
-        prepared = formatter._prepare_syntax_rule(
483b06
-            syntax_rule, data_rules, 'example', data_sources)
483b06
-
483b06
-        assert prepared == 'rule1,rule2'
483b06
-
483b06
-
483b06
-class test_FileRuleProvider(object):
483b06
-    def test_rule_basic(self, rule_provider):
483b06
-        rule_name = 'basic'
483b06
-
483b06
-        rule1 = rule_provider._rule(rule_name, 'openssl')
483b06
-        rule2 = rule_provider._rule(rule_name, 'certutil')
483b06
-
483b06
-        assert rule1.template == 'openssl_rule'
483b06
-        assert rule2.template == 'certutil_rule'
483b06
-
483b06
-    def test_rule_global_options(self, rule_provider):
483b06
-        rule_name = 'options'
483b06
-
483b06
-        rule1 = rule_provider._rule(rule_name, 'openssl')
483b06
-        rule2 = rule_provider._rule(rule_name, 'certutil')
483b06
-
483b06
-        assert rule1.options['global_option'] is True
483b06
-        assert rule2.options['global_option'] is True
483b06
-
483b06
-    def test_rule_helper_options(self, rule_provider):
483b06
-        rule_name = 'options'
483b06
-
483b06
-        rule1 = rule_provider._rule(rule_name, 'openssl')
483b06
-        rule2 = rule_provider._rule(rule_name, 'certutil')
483b06
-
483b06
-        assert rule1.options['helper_option'] is True
483b06
-        assert 'helper_option' not in rule2.options
483b06
-
483b06
-    def test_rule_nosuchrule(self, rule_provider):
483b06
-        with pytest.raises(errors.NotFound):
483b06
-            rule_provider._rule('nosuchrule', 'openssl')
483b06
-
483b06
-    def test_rule_nosuchhelper(self, rule_provider):
483b06
-        with pytest.raises(errors.EmptyResult):
483b06
-            rule_provider._rule('basic', 'nosuchhelper')
483b06
-
483b06
-    def test_rules_for_profile_success(self, rule_provider):
483b06
-        rules = rule_provider.rules_for_profile('profile', 'certutil')
483b06
-
483b06
-        assert len(rules) == 1
483b06
-        field_mapping = rules[0]
483b06
-        assert field_mapping.syntax_rule.name == 'basic'
483b06
-        assert len(field_mapping.data_rules) == 1
483b06
-        assert field_mapping.data_rules[0].name == 'options'
483b06
-
483b06
-    def test_rules_for_profile_nosuchprofile(self, rule_provider):
483b06
-        with pytest.raises(errors.NotFound):
483b06
-            rule_provider.rules_for_profile('nosuchprofile', 'certutil')
483b06
-
483b06
-
483b06
-class test_CSRGenerator(object):
483b06
-    def test_userCert_OpenSSL(self, generator):
483b06
-        principal = {
483b06
-            'uid': ['testuser'],
483b06
-            'mail': ['testuser@example.com'],
483b06
-        }
483b06
-        config = {
483b06
-            'ipacertificatesubjectbase': [
483b06
-                'O=DOMAIN.EXAMPLE.COM'
483b06
-            ],
483b06
-        }
483b06
-
483b06
-        script = generator.csr_script(principal, config, 'userCert', 'openssl')
483b06
-        with open(os.path.join(
483b06
-                CSR_DATA_DIR, 'scripts', 'userCert_openssl.sh')) as f:
483b06
-            expected_script = f.read()
483b06
-        assert script == expected_script
483b06
-
483b06
-    def test_userCert_Certutil(self, generator):
483b06
-        principal = {
483b06
-            'uid': ['testuser'],
483b06
-            'mail': ['testuser@example.com'],
483b06
-        }
483b06
-        config = {
483b06
-            'ipacertificatesubjectbase': [
483b06
-                'O=DOMAIN.EXAMPLE.COM'
483b06
-            ],
483b06
-        }
483b06
-
483b06
-        script = generator.csr_script(
483b06
-            principal, config, 'userCert', 'certutil')
483b06
-
483b06
-        with open(os.path.join(
483b06
-                CSR_DATA_DIR, 'scripts', 'userCert_certutil.sh')) as f:
483b06
-            expected_script = f.read()
483b06
-        assert script == expected_script
483b06
-
483b06
-    def test_caIPAserviceCert_OpenSSL(self, generator):
483b06
-        principal = {
483b06
-            'krbprincipalname': [
483b06
-                'HTTP/machine.example.com@DOMAIN.EXAMPLE.COM'
483b06
-            ],
483b06
-        }
483b06
-        config = {
483b06
-            'ipacertificatesubjectbase': [
483b06
-                'O=DOMAIN.EXAMPLE.COM'
483b06
-            ],
483b06
-        }
483b06
-
483b06
-        script = generator.csr_script(
483b06
-            principal, config, 'caIPAserviceCert', 'openssl')
483b06
-        with open(os.path.join(
483b06
-                CSR_DATA_DIR, 'scripts', 'caIPAserviceCert_openssl.sh')) as f:
483b06
-            expected_script = f.read()
483b06
-        assert script == expected_script
483b06
-
483b06
-    def test_caIPAserviceCert_Certutil(self, generator):
483b06
-        principal = {
483b06
-            'krbprincipalname': [
483b06
-                'HTTP/machine.example.com@DOMAIN.EXAMPLE.COM'
483b06
-            ],
483b06
-        }
483b06
-        config = {
483b06
-            'ipacertificatesubjectbase': [
483b06
-                'O=DOMAIN.EXAMPLE.COM'
483b06
-            ],
483b06
-        }
483b06
-
483b06
-        script = generator.csr_script(
483b06
-            principal, config, 'caIPAserviceCert', 'certutil')
483b06
-        with open(os.path.join(
483b06
-                CSR_DATA_DIR, 'scripts', 'caIPAserviceCert_certutil.sh')) as f:
483b06
-            expected_script = f.read()
483b06
-        assert script == expected_script
483b06
-
483b06
-
483b06
-class test_rule_handling(object):
483b06
-    def test_optionalAttributeMissing(self, generator):
483b06
-        principal = {'uid': 'testuser'}
483b06
-        rule_provider = StubRuleProvider()
483b06
-        rule_provider.data_rule.template = '{{subject.mail}}'
483b06
-        rule_provider.data_rule.options = {'data_source': 'subject.mail'}
483b06
-        generator = IdentityCSRGenerator(rule_provider)
483b06
-
483b06
-        script = generator.csr_script(
483b06
-            principal, {}, 'example', 'identity')
483b06
-        assert script == '\n'
483b06
-
483b06
-    def test_twoDataRulesOneMissing(self, generator):
483b06
-        principal = {'uid': 'testuser'}
483b06
-        rule_provider = StubRuleProvider()
483b06
-        rule_provider.data_rule.template = '{{subject.mail}}'
483b06
-        rule_provider.data_rule.options = {'data_source': 'subject.mail'}
483b06
-        rule_provider.field_mapping.data_rules.append(csrgen.Rule(
483b06
-            'data2', '{{subject.uid}}', {'data_source': 'subject.uid'}))
483b06
-        generator = IdentityCSRGenerator(rule_provider)
483b06
-
483b06
-        script = generator.csr_script(principal, {}, 'example', 'identity')
483b06
-        assert script == ',testuser\n'
483b06
-
483b06
-    def test_requiredAttributeMissing(self):
483b06
-        principal = {'uid': 'testuser'}
483b06
-        rule_provider = StubRuleProvider()
483b06
-        rule_provider.data_rule.template = '{{subject.mail}}'
483b06
-        rule_provider.data_rule.options = {'data_source': 'subject.mail'}
483b06
-        rule_provider.syntax_rule.options = {'required': True}
483b06
-        generator = IdentityCSRGenerator(rule_provider)
483b06
-
483b06
-        with pytest.raises(errors.CSRTemplateError):
483b06
-            _script = generator.csr_script(
483b06
-                principal, {}, 'example', 'identity')
483b06
-- 
483b06
2.13.5
483b06