summaryrefslogtreecommitdiffstats
path: root/ipalib/plugins/cert.py
diff options
context:
space:
mode:
authorRob Crittenden <rcritten@redhat.com>2009-09-10 16:15:14 -0400
committerRob Crittenden <rcritten@redhat.com>2009-09-15 10:01:08 -0400
commit49b36583a50e7f542e0667f3e2432ab1aa63924e (patch)
tree1c11b906018784db6e9415c17f116db4a1fd49e0 /ipalib/plugins/cert.py
parentbb09db2228694cd78b5e4e281109e55df9de97be (diff)
downloadfreeipa-49b36583a50e7f542e0667f3e2432ab1aa63924e.tar.gz
freeipa-49b36583a50e7f542e0667f3e2432ab1aa63924e.tar.xz
freeipa-49b36583a50e7f542e0667f3e2432ab1aa63924e.zip
Add external CA signing and abstract out the RA backend
External CA signing is a 2-step process. You first have to run the IPA installer which will generate a CSR. You pass this CSR to your external CA and get back a cert. You then pass this cert and the CA cert and re-run the installer. The CSR is always written to /root/ipa.csr. A run would look like: # ipa-server-install --ca --external-ca -p password -a password -r EXAMPLE.COM -u dirsrv -n example.com --hostname=ipa.example.com -U [ sign cert request ] # ipa-server-install --ca --external-ca -p password -a password --external_cert_file=/tmp/rob.crt --external_ca_file=/tmp/cacert.crt -U -p password -a password -r EXAMPLE.COM -u dirsrv -n example.com --hostname=ipa.example.com This also abstracts out the RA backend plugin so the self-signed CA we create can be used in a running server. This means that the cert plugin can request certs (and nothing else). This should let us do online replica creation. To handle the self-signed CA the simple ca_serialno file now contains additional data so we don't have overlapping serial numbers in replicas. This isn't used yet. Currently the cert plugin will not work on self-signed replicas. One very important change for self-signed CAs is that the CA is no longer held in the DS database. It is now in the Apache database. Lots of general fixes were also made in ipaserver.install.certs including: - better handling when multiple CA certificates are in a single file - A temporary directory for request certs is not always created when the class is instantiated (you have to call setup_cert_request())
Diffstat (limited to 'ipalib/plugins/cert.py')
-rw-r--r--ipalib/plugins/cert.py53
1 files changed, 49 insertions, 4 deletions
diff --git a/ipalib/plugins/cert.py b/ipalib/plugins/cert.py
index e38ec1812..1681a22f6 100644
--- a/ipalib/plugins/cert.py
+++ b/ipalib/plugins/cert.py
@@ -30,6 +30,24 @@ from ipalib import Command, Str, Int, Bytes, Flag
from ipalib import errors
from ipalib.plugins.virtual import *
import base64
+from OpenSSL import crypto
+
+def get_serial(certificate):
+ """
+ Given a certificate, return the serial number in that cert
+
+ In theory there should be only one cert per object so even if we get
+ passed in a list/tuple only return the first one.
+ """
+ if type(certificate) in (list, tuple):
+ certificate = certificate[0]
+ try:
+ x509 = crypto.load_certificate(crypto.FILETYPE_ASN1, certificate)
+ serial = str(x509.get_serial_number())
+ except crypto.Error:
+ raise errors.GenericError(format='Unable to decode certificate in entry')
+
+ return serial
def validate_csr(ugettext, csr):
"""
@@ -76,14 +94,14 @@ class cert_request(VirtualCommand):
# See if the service exists and punt if it doesn't and we aren't
# going to add it
try:
- service = api.Command['service_show'](principal, **skw)
- if service.get('usercertificate'):
+ (dn, service) = api.Command['service_show'](principal, **skw)
+ if 'usercertificate' in service:
# FIXME, what to do here? Do we revoke the old cert?
- raise errors.GenericError(format='entry already has a certificate')
+ raise errors.GenericError(format='entry already has a certificate, serial number %s' % get_serial(service['usercertificate']))
except errors.NotFound, e:
if not add:
- raise e
+ raise errors.NotFound(reason="The service principal for this request doesn't exist.")
# Request the certificate
result = self.Backend.ra.request_certificate(csr, **kw)
@@ -104,6 +122,33 @@ class cert_request(VirtualCommand):
else:
textui.print_plain('Failed to submit a certificate request.')
+ def run(self, *args, **options):
+ """
+ Dispatch to forward() and execute() to do work locally and on the
+ server.
+ """
+ if self.env.in_server:
+ return self.execute(*args, **options)
+
+ # Client-side code
+ csr = args[0]
+ if csr[:7] == "file://":
+ file = csr[7:]
+ try:
+ f = open(file, "r")
+ csr = f.readlines()
+ f.close()
+ except IOError, err:
+ raise errors.ValidationError(name='csr', error=err[1])
+ csr = "".join(csr)
+ # We just want the CSR bits, make sure there is nothing else
+ s = csr.find("-----BEGIN NEW CERTIFICATE REQUEST-----")
+ e = csr.find("-----END NEW CERTIFICATE REQUEST-----")
+ if s >= 0:
+ csr = csr[s+40:e]
+ csr = csr.decode('UTF-8')
+ return self.forward(csr, **options)
+
api.register(cert_request)