2008-12-21 15:15:53 -06:00
|
|
|
# Authors:
|
|
|
|
# Andrew Wnuk <awnuk@redhat.com>
|
|
|
|
# Jason Gerard DeRose <jderose@redhat.com>
|
2009-12-08 15:57:07 -06:00
|
|
|
# John Dennis <jdennis@redhat.com>
|
2008-12-21 15:15:53 -06:00
|
|
|
#
|
|
|
|
# Copyright (C) 2009 Red Hat
|
|
|
|
# see file 'COPYING' for use and warranty information
|
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or
|
|
|
|
# modify it under the terms of the GNU General Public License as
|
|
|
|
# published by the Free Software Foundation; version 2 only
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software
|
|
|
|
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
|
|
|
|
"""
|
2010-06-02 13:08:50 -05:00
|
|
|
IPA certificate operations
|
|
|
|
|
|
|
|
Implements a set of commands for managing server SSL certificates.
|
|
|
|
|
2010-08-24 22:40:32 -05:00
|
|
|
Certificate request exist in the form of a Certificate Signing Request (CSR)
|
2010-06-02 13:08:50 -05:00
|
|
|
in PEM format.
|
|
|
|
|
|
|
|
If using the selfsign backend then the subject in the CSR needs to match
|
|
|
|
the subject configured in the server. The dogtag CA uses just the CN
|
|
|
|
value of the CSR and forces the rest of the subject.
|
|
|
|
|
|
|
|
A certificate is stored with a service principal and a service principal
|
2010-08-24 22:40:32 -05:00
|
|
|
needs a host.
|
2010-06-02 13:08:50 -05:00
|
|
|
|
2010-08-24 22:40:32 -05:00
|
|
|
In order to request a certificate:
|
|
|
|
|
|
|
|
* The host must exist
|
|
|
|
* The service must exist (or you use the --add option to automatically add it)
|
2010-06-02 13:08:50 -05:00
|
|
|
|
|
|
|
EXAMPLES:
|
|
|
|
|
2010-08-24 22:40:32 -05:00
|
|
|
Request a new certificate and add the principal:
|
2010-06-02 13:08:50 -05:00
|
|
|
ipa cert-request --add --principal=HTTP/lion.example.com example.csr
|
|
|
|
|
|
|
|
Retrieve an existing certificate:
|
2010-06-24 10:40:02 -05:00
|
|
|
ipa cert-show 1032
|
2010-06-02 13:08:50 -05:00
|
|
|
|
|
|
|
Revoke a certificate (see RFC 5280 for reason details):
|
|
|
|
ipa cert-revoke --revocation-reason=6 1032
|
|
|
|
|
|
|
|
Remove a certificate from revocation hold status:
|
|
|
|
ipa cert-remove-hold 1032
|
|
|
|
|
|
|
|
Check the status of a signing request:
|
|
|
|
ipa cert-status 10
|
|
|
|
|
2010-08-24 22:40:32 -05:00
|
|
|
IPA currently immediately issues (or declines) all certificate requests so
|
|
|
|
the status of a request is not normally useful. This is for future-use
|
|
|
|
or the case where a CA does not immediately issue a certificate.
|
2008-12-21 15:15:53 -06:00
|
|
|
"""
|
|
|
|
|
2009-02-12 03:10:12 -06:00
|
|
|
from ipalib import api, SkipPluginModule
|
|
|
|
if api.env.enable_ra is not True:
|
2009-02-12 18:18:54 -06:00
|
|
|
# In this case, abort loading this plugin module...
|
|
|
|
raise SkipPluginModule(reason='env.enable_ra is not True')
|
2009-11-06 04:04:00 -06:00
|
|
|
from ipalib import Command, Str, Int, Bytes, Flag, File
|
2009-05-05 14:18:33 -05:00
|
|
|
from ipalib import errors
|
2009-11-24 15:07:44 -06:00
|
|
|
from ipalib import pkcs10
|
|
|
|
from ipalib import x509
|
2009-07-10 15:40:39 -05:00
|
|
|
from ipalib.plugins.virtual import *
|
2009-10-20 10:59:07 -05:00
|
|
|
from ipalib.plugins.service import split_principal
|
2009-05-05 14:18:33 -05:00
|
|
|
import base64
|
2009-11-24 15:07:44 -06:00
|
|
|
import logging
|
|
|
|
import traceback
|
2010-02-19 10:08:16 -06:00
|
|
|
from ipalib.text import _
|
2009-12-16 15:04:53 -06:00
|
|
|
from ipalib.request import context
|
2010-02-12 15:34:21 -06:00
|
|
|
from ipalib.output import Output
|
2010-06-24 10:40:02 -05:00
|
|
|
from ipalib.plugins.service import validate_principal
|
|
|
|
import nss.nss as nss
|
2010-07-20 13:00:43 -05:00
|
|
|
from nss.error import NSPRError
|
2010-01-20 09:03:42 -06:00
|
|
|
|
2009-10-20 10:59:07 -05:00
|
|
|
def get_csr_hostname(csr):
|
|
|
|
"""
|
2010-07-20 13:00:43 -05:00
|
|
|
Return the value of CN in the subject of the request or None
|
2009-10-20 10:59:07 -05:00
|
|
|
"""
|
|
|
|
try:
|
2009-11-24 15:07:44 -06:00
|
|
|
request = pkcs10.load_certificate_request(csr)
|
2010-07-20 13:00:43 -05:00
|
|
|
subject = pkcs10.get_subject(request)
|
|
|
|
return subject.common_name
|
|
|
|
except NSPRError, nsprerr:
|
|
|
|
raise errors.CertificateOperationError(error=_('Failure decoding Certificate Signing Request:'))
|
2009-10-20 10:59:07 -05:00
|
|
|
|
2009-11-24 15:07:44 -06:00
|
|
|
def get_subjectaltname(csr):
|
|
|
|
"""
|
2010-07-20 13:00:43 -05:00
|
|
|
Return the first value of the subject alt name, if any
|
2009-11-24 15:07:44 -06:00
|
|
|
"""
|
|
|
|
try:
|
|
|
|
request = pkcs10.load_certificate_request(csr)
|
2010-07-20 13:00:43 -05:00
|
|
|
for extension in request.extensions:
|
|
|
|
if extension.oid_tag == nss.SEC_OID_X509_SUBJECT_ALT_NAME:
|
|
|
|
return nss.x509_alt_name(extension.value)[0]
|
|
|
|
return None
|
|
|
|
except NSPRError, nsprerr:
|
2009-12-08 15:57:07 -06:00
|
|
|
raise errors.CertificateOperationError(error=_('Failure decoding Certificate Signing Request'))
|
2009-11-24 15:07:44 -06:00
|
|
|
|
2009-05-05 14:18:33 -05:00
|
|
|
def validate_csr(ugettext, csr):
|
|
|
|
"""
|
2009-11-24 15:07:44 -06:00
|
|
|
Ensure the CSR is base64-encoded and can be decoded by our PKCS#10
|
|
|
|
parser.
|
2009-05-05 14:18:33 -05:00
|
|
|
"""
|
|
|
|
try:
|
2009-11-24 15:07:44 -06:00
|
|
|
request = pkcs10.load_certificate_request(csr)
|
|
|
|
except TypeError, e:
|
2009-05-05 14:18:33 -05:00
|
|
|
raise errors.Base64DecodeError(reason=str(e))
|
2010-07-20 13:00:43 -05:00
|
|
|
except NSPRError:
|
2009-12-08 15:57:07 -06:00
|
|
|
raise errors.CertificateOperationError(error=_('Failure decoding Certificate Signing Request'))
|
2009-11-24 15:07:44 -06:00
|
|
|
except Exception, e:
|
2009-12-08 15:57:07 -06:00
|
|
|
raise errors.CertificateOperationError(error=_('Failure decoding Certificate Signing Request: %s') % str(e))
|
2008-12-21 15:15:53 -06:00
|
|
|
|
2010-01-20 09:03:42 -06:00
|
|
|
def normalize_csr(csr):
|
|
|
|
"""
|
|
|
|
Strip any leading and trailing cruft around the BEGIN/END block
|
|
|
|
"""
|
|
|
|
end_len = 37
|
|
|
|
s = csr.find('-----BEGIN NEW CERTIFICATE REQUEST-----')
|
|
|
|
if s == -1:
|
|
|
|
s = csr.find('-----BEGIN CERTIFICATE REQUEST-----')
|
|
|
|
e = csr.find('-----END NEW CERTIFICATE REQUEST-----')
|
|
|
|
if e == -1:
|
|
|
|
e = csr.find('-----END CERTIFICATE REQUEST-----')
|
|
|
|
if e != -1:
|
|
|
|
end_len = 33
|
|
|
|
|
|
|
|
if s > -1 and e > -1:
|
|
|
|
# We're normalizing here, not validating
|
|
|
|
csr = csr[s:e+end_len]
|
|
|
|
|
|
|
|
return csr
|
2008-12-21 15:15:53 -06:00
|
|
|
|
2010-06-24 10:40:02 -05:00
|
|
|
def get_host_from_principal(principal):
|
|
|
|
"""
|
|
|
|
Given a principal with or without a realm return the
|
|
|
|
host portion.
|
|
|
|
"""
|
|
|
|
validate_principal(None, principal)
|
|
|
|
realm = principal.find('@')
|
|
|
|
slash = principal.find('/')
|
|
|
|
if realm == -1:
|
|
|
|
realm = len(principal)
|
|
|
|
hostname = principal[slash+1:realm]
|
|
|
|
|
|
|
|
return hostname
|
|
|
|
|
2009-07-10 15:40:39 -05:00
|
|
|
class cert_request(VirtualCommand):
|
2009-02-12 03:10:12 -06:00
|
|
|
"""
|
2009-10-20 10:59:07 -05:00
|
|
|
Submit a certificate signing request.
|
2009-02-12 03:10:12 -06:00
|
|
|
"""
|
2008-12-21 15:15:53 -06:00
|
|
|
|
2009-11-06 04:04:00 -06:00
|
|
|
takes_args = (
|
|
|
|
File('csr', validate_csr,
|
|
|
|
cli_name='csr_file',
|
2010-01-20 09:03:42 -06:00
|
|
|
normalizer=normalize_csr,
|
2009-11-06 04:04:00 -06:00
|
|
|
),
|
|
|
|
)
|
2009-07-10 15:40:39 -05:00
|
|
|
operation="request certificate"
|
2008-12-21 15:15:53 -06:00
|
|
|
|
2009-02-12 03:10:12 -06:00
|
|
|
takes_options = (
|
2009-05-05 14:18:33 -05:00
|
|
|
Str('principal',
|
2010-02-19 10:08:16 -06:00
|
|
|
label=_('Principal'),
|
|
|
|
doc=_('Service principal for this certificate (e.g. HTTP/test.example.com)'),
|
2009-05-05 14:18:33 -05:00
|
|
|
),
|
|
|
|
Str('request_type',
|
|
|
|
default=u'pkcs10',
|
|
|
|
autofill=True,
|
|
|
|
),
|
|
|
|
Flag('add',
|
2010-02-19 10:08:16 -06:00
|
|
|
doc=_("automatically add the principal if it doesn't exist"),
|
2009-05-05 14:18:33 -05:00
|
|
|
default=False,
|
|
|
|
autofill=True
|
|
|
|
),
|
2010-06-24 10:40:02 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
has_output_params = (
|
2010-02-12 15:34:21 -06:00
|
|
|
Str('certificate?',
|
2010-02-19 10:08:16 -06:00
|
|
|
label=_('Certificate'),
|
2010-02-12 15:34:21 -06:00
|
|
|
flags=['no_create', 'no_update', 'no_search'],
|
|
|
|
),
|
|
|
|
Str('subject?',
|
2010-02-19 10:08:16 -06:00
|
|
|
label=_('Subject'),
|
2010-02-12 15:34:21 -06:00
|
|
|
flags=['no_create', 'no_update', 'no_search'],
|
|
|
|
),
|
2010-06-24 10:40:02 -05:00
|
|
|
Str('issuer?',
|
|
|
|
label=_('Issuer'),
|
|
|
|
flags=['no_create', 'no_update', 'no_search'],
|
|
|
|
),
|
|
|
|
Str('valid_not_before?',
|
|
|
|
label=_('Not Before'),
|
|
|
|
flags=['no_create', 'no_update', 'no_search'],
|
|
|
|
),
|
|
|
|
Str('valid_not_after?',
|
|
|
|
label=_('Not After'),
|
|
|
|
flags=['no_create', 'no_update', 'no_search'],
|
|
|
|
),
|
|
|
|
Str('md5_fingerprint?',
|
|
|
|
label=_('Fingerprint (MD5)'),
|
|
|
|
flags=['no_create', 'no_update', 'no_search'],
|
|
|
|
),
|
|
|
|
Str('sha1_fingerprint?',
|
|
|
|
label=_('Fingerprint (SHA1)'),
|
|
|
|
flags=['no_create', 'no_update', 'no_search'],
|
|
|
|
),
|
2010-02-12 15:34:21 -06:00
|
|
|
Str('serial_number?',
|
2010-02-19 10:08:16 -06:00
|
|
|
label=_('Serial number'),
|
2010-02-12 15:34:21 -06:00
|
|
|
flags=['no_create', 'no_update', 'no_search'],
|
|
|
|
),
|
|
|
|
)
|
|
|
|
|
|
|
|
has_output = (
|
|
|
|
Output('result',
|
|
|
|
type=dict,
|
2010-03-05 15:11:21 -06:00
|
|
|
doc=_('Dictionary mapping variable name to value'),
|
2010-02-12 15:34:21 -06:00
|
|
|
),
|
2009-02-12 03:10:12 -06:00
|
|
|
)
|
2008-12-21 15:15:53 -06:00
|
|
|
|
2009-05-05 14:18:33 -05:00
|
|
|
def execute(self, csr, **kw):
|
2009-11-03 08:35:19 -06:00
|
|
|
ldap = self.api.Backend.ldap2
|
2009-05-05 14:18:33 -05:00
|
|
|
principal = kw.get('principal')
|
|
|
|
add = kw.get('add')
|
|
|
|
del kw['principal']
|
|
|
|
del kw['add']
|
|
|
|
service = None
|
|
|
|
|
2009-11-24 15:07:44 -06:00
|
|
|
"""
|
|
|
|
Access control is partially handled by the ACI titled
|
|
|
|
'Hosts can modify service userCertificate'. This is for the case
|
|
|
|
where a machine binds using a host/ prinicpal. It can only do the
|
|
|
|
request if the target hostname is in the managedBy attribute which
|
|
|
|
is managed using the add/del member commands.
|
|
|
|
|
|
|
|
Binding with a user principal one needs to be in the request_certs
|
|
|
|
taskgroup (directly or indirectly via role membership).
|
|
|
|
"""
|
2009-11-06 04:04:00 -06:00
|
|
|
|
2009-12-16 15:04:53 -06:00
|
|
|
bind_principal = getattr(context, 'principal')
|
2009-10-20 10:59:07 -05:00
|
|
|
# Can this user request certs?
|
2009-12-16 15:04:53 -06:00
|
|
|
if not bind_principal.startswith('host/'):
|
|
|
|
self.check_access()
|
2009-10-20 10:59:07 -05:00
|
|
|
|
|
|
|
# FIXME: add support for subject alt name
|
|
|
|
|
|
|
|
# Ensure that the hostname in the CSR matches the principal
|
2009-11-24 15:07:44 -06:00
|
|
|
subject_host = get_csr_hostname(csr)
|
2009-10-20 10:59:07 -05:00
|
|
|
(servicename, hostname, realm) = split_principal(principal)
|
|
|
|
if subject_host.lower() != hostname.lower():
|
|
|
|
raise errors.ACIError(info="hostname in subject of request '%s' does not match principal hostname '%s'" % (subject_host, hostname))
|
|
|
|
|
2009-11-24 15:07:44 -06:00
|
|
|
dn = None
|
|
|
|
service = None
|
2009-05-05 14:18:33 -05:00
|
|
|
# See if the service exists and punt if it doesn't and we aren't
|
|
|
|
# going to add it
|
|
|
|
try:
|
2009-12-16 15:04:53 -06:00
|
|
|
if not principal.startswith('host/'):
|
2009-12-18 10:01:00 -06:00
|
|
|
service = api.Command['service_show'](principal, all=True, raw=True)['result']
|
2009-12-16 15:04:53 -06:00
|
|
|
dn = service['dn']
|
|
|
|
else:
|
2010-06-24 10:40:02 -05:00
|
|
|
hostname = get_host_from_principal(principal)
|
2009-12-16 15:04:53 -06:00
|
|
|
service = api.Command['host_show'](hostname, all=True, raw=True)['result']
|
|
|
|
dn = service['dn']
|
2009-05-05 14:18:33 -05:00
|
|
|
except errors.NotFound, e:
|
|
|
|
if not add:
|
2009-09-10 15:15:14 -05:00
|
|
|
raise errors.NotFound(reason="The service principal for this request doesn't exist.")
|
2009-11-03 08:35:19 -06:00
|
|
|
try:
|
2010-07-22 13:16:22 -05:00
|
|
|
service = api.Command['service_add'](principal, **{'force': True})['result']
|
2009-12-16 15:04:53 -06:00
|
|
|
dn = service['dn']
|
2009-11-03 08:35:19 -06:00
|
|
|
except errors.ACIError:
|
|
|
|
raise errors.ACIError(info='You need to be a member of the serviceadmin role to add services')
|
|
|
|
|
|
|
|
# We got this far so the service entry exists, can we write it?
|
|
|
|
if not ldap.can_write(dn, "usercertificate"):
|
|
|
|
raise errors.ACIError(info="Insufficient 'write' privilege to the 'userCertificate' attribute of entry '%s'." % dn)
|
2009-05-05 14:18:33 -05:00
|
|
|
|
2009-11-24 15:07:44 -06:00
|
|
|
# Validate the subject alt name, if any
|
2010-07-20 13:00:43 -05:00
|
|
|
request = pkcs10.load_certificate_request(csr)
|
|
|
|
subjectaltname = pkcs10.get_subjectaltname(request)
|
2009-11-24 15:07:44 -06:00
|
|
|
if subjectaltname is not None:
|
|
|
|
for name in subjectaltname:
|
|
|
|
try:
|
2009-12-16 15:04:53 -06:00
|
|
|
hostentry = api.Command['host_show'](name, all=True, raw=True)['result']
|
|
|
|
hostdn = hostentry['dn']
|
2009-11-24 15:07:44 -06:00
|
|
|
except errors.NotFound:
|
|
|
|
# We don't want to issue any certificates referencing
|
|
|
|
# machines we don't know about. Nothing is stored in this
|
|
|
|
# host record related to this certificate.
|
|
|
|
raise errors.NotFound(reason='no host record for subject alt name %s in certificate request' % name)
|
|
|
|
authprincipal = getattr(context, 'principal')
|
|
|
|
if authprincipal.startswith("host/"):
|
|
|
|
if not hostdn in service.get('managedby', []):
|
|
|
|
raise errors.ACIError(info="Insufficient privilege to create a certificate with subject alt name '%s'." % name)
|
|
|
|
|
2010-01-28 14:48:10 -06:00
|
|
|
if 'usercertificate' in service:
|
2010-06-24 10:40:02 -05:00
|
|
|
serial = x509.get_serial_number(service['usercertificate'][0], datatype=x509.DER)
|
2010-01-28 14:48:10 -06:00
|
|
|
# revoke the certificate and remove it from the service
|
2010-02-26 11:30:01 -06:00
|
|
|
# entry before proceeding. First we retrieve the certificate to
|
|
|
|
# see if it is already revoked, if not then we revoke it.
|
2010-02-12 15:34:21 -06:00
|
|
|
try:
|
2010-06-24 10:40:02 -05:00
|
|
|
result = api.Command['cert_show'](unicode(serial))['result']
|
2010-02-26 11:30:01 -06:00
|
|
|
if 'revocation_reason' not in result:
|
|
|
|
try:
|
|
|
|
api.Command['cert_revoke'](unicode(serial), revocation_reason=4)
|
|
|
|
except errors.NotImplementedError:
|
|
|
|
# some CA's might not implement revoke
|
|
|
|
pass
|
2010-02-12 15:34:21 -06:00
|
|
|
except errors.NotImplementedError:
|
2010-02-26 11:30:01 -06:00
|
|
|
# some CA's might not implement get
|
2010-02-12 15:34:21 -06:00
|
|
|
pass
|
2010-06-24 10:40:02 -05:00
|
|
|
if not principal.startswith('host/'):
|
|
|
|
api.Command['service_mod'](principal, usercertificate=None)
|
|
|
|
else:
|
|
|
|
hostname = get_host_from_principal(principal)
|
|
|
|
api.Command['host_mod'](hostname, usercertificate=None)
|
2010-01-28 14:48:10 -06:00
|
|
|
|
2009-05-05 14:18:33 -05:00
|
|
|
# Request the certificate
|
|
|
|
result = self.Backend.ra.request_certificate(csr, **kw)
|
2010-06-24 10:40:02 -05:00
|
|
|
cert = x509.load_certificate(result['certificate'])
|
|
|
|
result['issuer'] = unicode(cert.issuer)
|
|
|
|
result['valid_not_before'] = unicode(cert.valid_not_before_str)
|
|
|
|
result['valid_not_after'] = unicode(cert.valid_not_after_str)
|
|
|
|
result['md5_fingerprint'] = unicode(nss.data_to_hex(nss.md5_digest(cert.der_data), 64)[0])
|
|
|
|
result['sha1_fingerprint'] = unicode(nss.data_to_hex(nss.sha1_digest(cert.der_data), 64)[0])
|
2009-05-05 14:18:33 -05:00
|
|
|
|
2009-11-03 08:35:19 -06:00
|
|
|
# Success? Then add it to the service entry.
|
2009-12-16 15:04:53 -06:00
|
|
|
if 'certificate' in result:
|
|
|
|
if not principal.startswith('host/'):
|
|
|
|
skw = {"usercertificate": str(result.get('certificate'))}
|
|
|
|
api.Command['service_mod'](principal, **skw)
|
|
|
|
else:
|
2010-06-24 10:40:02 -05:00
|
|
|
hostname = get_host_from_principal(principal)
|
2009-12-16 15:04:53 -06:00
|
|
|
skw = {"usercertificate": str(result.get('certificate'))}
|
|
|
|
api.Command['host_mod'](hostname, **skw)
|
|
|
|
|
|
|
|
return dict(
|
|
|
|
result=result
|
|
|
|
)
|
2009-05-05 14:18:33 -05:00
|
|
|
|
2009-02-12 03:10:12 -06:00
|
|
|
api.register(cert_request)
|
2008-12-21 15:15:53 -06:00
|
|
|
|
|
|
|
|
2009-07-10 15:40:39 -05:00
|
|
|
class cert_status(VirtualCommand):
|
2009-02-12 03:10:12 -06:00
|
|
|
"""
|
|
|
|
Check status of a certificate signing request.
|
|
|
|
"""
|
2009-02-05 16:30:58 -06:00
|
|
|
|
2010-02-12 15:34:21 -06:00
|
|
|
takes_args = (
|
|
|
|
Str('request_id',
|
2010-02-19 10:08:16 -06:00
|
|
|
label=_('Request id'),
|
2010-02-12 15:34:21 -06:00
|
|
|
flags=['no_create', 'no_update', 'no_search'],
|
|
|
|
),
|
|
|
|
)
|
2010-06-24 10:40:02 -05:00
|
|
|
has_output_params = (
|
|
|
|
Str('cert_request_status',
|
2010-02-19 10:08:16 -06:00
|
|
|
label=_('Request status'),
|
2010-02-12 15:34:21 -06:00
|
|
|
),
|
|
|
|
)
|
2009-07-10 15:40:39 -05:00
|
|
|
operation = "certificate status"
|
2008-12-21 15:15:53 -06:00
|
|
|
|
|
|
|
|
2009-05-05 14:18:33 -05:00
|
|
|
def execute(self, request_id, **kw):
|
2009-10-20 10:59:07 -05:00
|
|
|
self.check_access()
|
2010-01-20 09:03:42 -06:00
|
|
|
return dict(
|
|
|
|
result=self.Backend.ra.check_request_status(request_id)
|
|
|
|
)
|
2008-12-21 15:15:53 -06:00
|
|
|
|
2009-02-12 03:10:12 -06:00
|
|
|
api.register(cert_status)
|
2008-12-21 15:15:53 -06:00
|
|
|
|
|
|
|
|
2010-02-19 10:08:16 -06:00
|
|
|
_serial_number = Str('serial_number',
|
|
|
|
label=_('Serial number'),
|
|
|
|
doc=_('Serial number in decimal or if prefixed with 0x in hexadecimal'),
|
|
|
|
)
|
|
|
|
|
2010-06-24 10:40:02 -05:00
|
|
|
class cert_show(VirtualCommand):
|
2009-02-12 03:10:12 -06:00
|
|
|
"""
|
|
|
|
Retrieve an existing certificate.
|
|
|
|
"""
|
2008-12-21 15:15:53 -06:00
|
|
|
|
2010-02-19 10:08:16 -06:00
|
|
|
takes_args = _serial_number
|
|
|
|
|
2010-06-24 10:40:02 -05:00
|
|
|
has_output_params = (
|
|
|
|
Str('certificate',
|
2010-02-19 10:08:16 -06:00
|
|
|
label=_('Certificate'),
|
2010-02-12 15:34:21 -06:00
|
|
|
),
|
2010-06-24 10:40:02 -05:00
|
|
|
Str('subject',
|
2010-02-19 10:08:16 -06:00
|
|
|
label=_('Subject'),
|
2010-06-24 10:40:02 -05:00
|
|
|
),
|
|
|
|
Str('issuer',
|
|
|
|
label=_('Issuer'),
|
|
|
|
),
|
|
|
|
Str('valid_not_before',
|
|
|
|
label=_('Not Before'),
|
|
|
|
),
|
|
|
|
Str('valid_not_after',
|
|
|
|
label=_('Not After'),
|
|
|
|
),
|
|
|
|
Str('md5_fingerprint',
|
|
|
|
label=_('Fingerprint (MD5)'),
|
|
|
|
),
|
|
|
|
Str('sha1_fingerprint',
|
|
|
|
label=_('Fingerprint (SHA1)'),
|
2010-02-12 15:34:21 -06:00
|
|
|
),
|
2010-02-26 11:30:01 -06:00
|
|
|
Str('revocation_reason?',
|
|
|
|
label=_('Revocation reason'),
|
|
|
|
),
|
2010-02-12 15:34:21 -06:00
|
|
|
)
|
|
|
|
|
2009-07-10 15:40:39 -05:00
|
|
|
operation="retrieve certificate"
|
2008-12-21 15:15:53 -06:00
|
|
|
|
2009-02-12 03:10:12 -06:00
|
|
|
def execute(self, serial_number):
|
2010-09-08 21:11:31 -05:00
|
|
|
hostname = None
|
|
|
|
try:
|
|
|
|
self.check_access()
|
|
|
|
except errors.ACIError, acierr:
|
|
|
|
self.debug("Not granted by ACI to retrieve certificate, looking at principal")
|
|
|
|
bind_principal = getattr(context, 'principal')
|
|
|
|
if not bind_principal.startswith('host/'):
|
|
|
|
raise acierr
|
|
|
|
hostname = get_host_from_principal(bind_principal)
|
|
|
|
|
2010-01-20 09:03:42 -06:00
|
|
|
result=self.Backend.ra.get_certificate(serial_number)
|
2010-06-24 10:40:02 -05:00
|
|
|
cert = x509.load_certificate(result['certificate'])
|
|
|
|
result['subject'] = unicode(cert.subject)
|
|
|
|
result['issuer'] = unicode(cert.issuer)
|
|
|
|
result['valid_not_before'] = unicode(cert.valid_not_before_str)
|
|
|
|
result['valid_not_after'] = unicode(cert.valid_not_after_str)
|
|
|
|
result['md5_fingerprint'] = unicode(nss.data_to_hex(nss.md5_digest(cert.der_data), 64)[0])
|
|
|
|
result['sha1_fingerprint'] = unicode(nss.data_to_hex(nss.sha1_digest(cert.der_data), 64)[0])
|
2010-09-08 21:11:31 -05:00
|
|
|
if hostname:
|
|
|
|
# If we have a hostname we want to verify that the subject
|
|
|
|
# of the certificate matches it, otherwise raise an error
|
|
|
|
if hostname != cert.subject.common_name:
|
|
|
|
raise acierr
|
|
|
|
|
2010-01-20 09:03:42 -06:00
|
|
|
return dict(result=result)
|
2008-12-21 15:15:53 -06:00
|
|
|
|
2010-06-24 10:40:02 -05:00
|
|
|
api.register(cert_show)
|
2008-12-21 15:15:53 -06:00
|
|
|
|
|
|
|
|
2009-07-10 15:40:39 -05:00
|
|
|
class cert_revoke(VirtualCommand):
|
2009-02-12 03:10:12 -06:00
|
|
|
"""
|
|
|
|
Revoke a certificate.
|
|
|
|
"""
|
2008-12-21 15:15:53 -06:00
|
|
|
|
2010-02-19 10:08:16 -06:00
|
|
|
takes_args = _serial_number
|
|
|
|
|
2010-06-24 10:40:02 -05:00
|
|
|
has_output_params = (
|
|
|
|
Flag('revoked',
|
2010-02-19 10:08:16 -06:00
|
|
|
label=_('Revoked'),
|
2010-02-12 15:34:21 -06:00
|
|
|
),
|
|
|
|
)
|
2009-07-10 15:40:39 -05:00
|
|
|
operation = "revoke certificate"
|
2008-12-21 15:15:53 -06:00
|
|
|
|
2009-02-12 03:10:12 -06:00
|
|
|
# FIXME: The default is 0. Is this really an Int param?
|
2009-05-08 13:10:53 -05:00
|
|
|
takes_options = (
|
|
|
|
Int('revocation_reason?',
|
2010-02-19 10:08:16 -06:00
|
|
|
label=_('Reason'),
|
|
|
|
doc=_('Reason for revoking the certificate (0-10)'),
|
2009-05-08 13:10:53 -05:00
|
|
|
minvalue=0,
|
|
|
|
maxvalue=10,
|
|
|
|
default=0,
|
|
|
|
),
|
|
|
|
)
|
2008-12-21 15:15:53 -06:00
|
|
|
|
2009-05-05 14:18:33 -05:00
|
|
|
def execute(self, serial_number, **kw):
|
2010-09-08 21:11:31 -05:00
|
|
|
hostname = None
|
|
|
|
try:
|
|
|
|
self.check_access()
|
|
|
|
except errors.ACIError, acierr:
|
|
|
|
self.debug("Not granted by ACI to revoke certificate, looking at principal")
|
|
|
|
try:
|
|
|
|
# Let cert_show() handle verifying that the subject of the
|
|
|
|
# cert we're dealing with matches the hostname in the principal
|
|
|
|
result = api.Command['cert_show'](unicode(serial_number))['result']
|
|
|
|
except errors.NotImplementedError:
|
|
|
|
pass
|
2010-01-20 09:03:42 -06:00
|
|
|
return dict(
|
|
|
|
result=self.Backend.ra.revoke_certificate(serial_number, **kw)
|
|
|
|
)
|
2008-12-21 15:15:53 -06:00
|
|
|
|
2009-02-12 03:10:12 -06:00
|
|
|
api.register(cert_revoke)
|
2008-12-21 15:15:53 -06:00
|
|
|
|
|
|
|
|
2009-07-10 15:40:39 -05:00
|
|
|
class cert_remove_hold(VirtualCommand):
|
2009-02-12 03:10:12 -06:00
|
|
|
"""
|
|
|
|
Take a revoked certificate off hold.
|
|
|
|
"""
|
2008-12-21 15:15:53 -06:00
|
|
|
|
2010-02-19 10:08:16 -06:00
|
|
|
takes_args = _serial_number
|
|
|
|
|
2010-06-24 10:40:02 -05:00
|
|
|
has_output_params = (
|
2010-02-12 15:34:21 -06:00
|
|
|
Flag('unrevoked?',
|
2010-02-19 10:08:16 -06:00
|
|
|
label=_('Unrevoked'),
|
2010-02-12 15:34:21 -06:00
|
|
|
),
|
|
|
|
Str('error_string?',
|
2010-02-19 10:08:16 -06:00
|
|
|
label=_('Error'),
|
2010-02-12 15:34:21 -06:00
|
|
|
),
|
|
|
|
)
|
2009-07-10 15:40:39 -05:00
|
|
|
operation = "certificate remove hold"
|
2008-12-21 15:15:53 -06:00
|
|
|
|
2009-05-05 14:18:33 -05:00
|
|
|
def execute(self, serial_number, **kw):
|
2009-10-20 10:59:07 -05:00
|
|
|
self.check_access()
|
2010-01-20 09:03:42 -06:00
|
|
|
return dict(
|
|
|
|
result=self.Backend.ra.take_certificate_off_hold(serial_number)
|
|
|
|
)
|
2009-02-12 03:10:12 -06:00
|
|
|
|
|
|
|
api.register(cert_remove_hold)
|