Create a Certificate parameter

Up until now, Bytes parameter was used for certificate parameters
throughout the framework. However, the Bytes parameter does nothing
special for certificates, like validation, so this had to be done
for each of the parameters which were supposed to represent a
certificate.

This commit introduces a special Certificate parameter which takes
care of certificate validation so this does not have to be done
separately. It also makes sure that the certificates represented by
this parameter are always converted to DER format so that we can work
with them in a unified manner throughout the framework.

This commit also makes it possible to pass bytes directly during
instantiation of the Certificate parameter and they are still
represented correctly after their conversion in the _convert_scalar()
method.

https://pagure.io/freeipa/issue/4985

Reviewed-By: Fraser Tweedale <ftweedal@redhat.com>
Reviewed-By: Rob Crittenden <rcritten@redhat.com>
Reviewed-By: Martin Basti <mbasti@redhat.com>
This commit is contained in:
Stanislav Laznicka
2017-07-03 17:10:34 +02:00
committed by Pavel Vomacka
parent 5ff1de8490
commit 5a44ca6383
19 changed files with 178 additions and 188 deletions

View File

@@ -23,10 +23,9 @@ import dbus
import six
from ipalib import api, errors, x509
from ipalib import Bytes
from ipalib.crud import Search
from ipalib.frontend import Object
from ipalib.parameters import Bool, DNSNameParam, Flag, Int, Str
from ipalib.parameters import Bool, DNSNameParam, Flag, Int, Str, Certificate
from ipalib.plugable import Registry
from .baseldap import (
LDAPCreate,
@@ -39,7 +38,6 @@ from .baseldap import (
pkey_to_value)
from ipalib import _, ngettext
from ipalib import output
from ipaserver.plugins.service import validate_certificate
if six.PY3:
@@ -521,8 +519,8 @@ class certmap_match(Search):
if arg.name == 'criteria':
continue
yield arg
yield Bytes(
'certificate', validate_certificate,
yield Certificate(
'certificate',
cli_name='certificate',
label=_('Certificate'),
doc=_('Base-64 encoded user certificate'),