pgreco / rpms / ipa

Forked from forks/areguera/rpms/ipa 4 years ago
Clone

Blame SOURCES/0012-Fix-cert-find-for-CA-less-installations.patch

c58629
From 6049b791567dad33be050b05bb08ef2040f473ee Mon Sep 17 00:00:00 2001
c58629
From: Rob Crittenden <rcritten@redhat.com>
c58629
Date: Tue, 24 Oct 2017 15:43:08 -0400
c58629
Subject: [PATCH] Fix cert-find for CA-less installations
c58629
c58629
Change 49f9d799c171c7ae2ac546a33a353c2c40b4719c deferred the
c58629
detailed lookup until all certs were collected but introduced
c58629
a bug where the ra backend was always retrieved. This generated a
c58629
backtrace in a CA-less install because there is no ra backend in
c58629
the CA-less case.
c58629
c58629
The deferral also removes the certificate value from the LDAP
c58629
search output resulting in only the serial number being displayed
c58629
unless --all is provided. Add a new class variable,
c58629
self.ca_enabled, to add an exception for the CA-less case.
c58629
c58629
Fixes https://pagure.io/freeipa/issue/7202
c58629
c58629
Signed-off-by: Rob Crittenden <rcritten@redhat.com>
c58629
Reviewed-By: Stanislav Laznicka <slaznick@redhat.com>
c58629
---
c58629
 ipaserver/plugins/cert.py | 22 ++++++++++++++++++++--
c58629
 1 file changed, 20 insertions(+), 2 deletions(-)
c58629
c58629
diff --git a/ipaserver/plugins/cert.py b/ipaserver/plugins/cert.py
c58629
index bb11713317abad55577b1c280253ab5d6d68c508..c1d389217265f44e646ac27d9adc8d5524c74ce7 100644
c58629
--- a/ipaserver/plugins/cert.py
c58629
+++ b/ipaserver/plugins/cert.py
c58629
@@ -1453,6 +1453,7 @@ class cert_find(Search, CertMethod):
c58629
 
c58629
             truncated = bool(truncated)
c58629
 
c58629
+        ca_enabled = getattr(context, 'ca_enabled')
c58629
         for entry in entries:
c58629
             for attr in ('usercertificate', 'usercertificate;binary'):
c58629
                 for cert in entry.get(attr, []):
c58629
@@ -1466,7 +1467,12 @@ class cert_find(Search, CertMethod):
c58629
                         obj = result[issuer, serial_number]
c58629
                     except KeyError:
c58629
                         obj = {'serial_number': serial_number}
c58629
-                        if not pkey_only and all:
c58629
+                        if not pkey_only and (all or not ca_enabled):
c58629
+                            # Retrieving certificate details is now deferred
c58629
+                            # until after all certificates are collected.
c58629
+                            # For the case of CA-less we need to keep
c58629
+                            # the certificate because getting it again later
c58629
+                            # would require unnecessary LDAP searches.
c58629
                             obj['certificate'] = (
c58629
                                 base64.b64encode(cert).decode('ascii'))
c58629
                         result[issuer, serial_number] = obj
c58629
@@ -1480,6 +1486,11 @@ class cert_find(Search, CertMethod):
c58629
 
c58629
     def execute(self, criteria=None, all=False, raw=False, pkey_only=False,
c58629
                 no_members=True, timelimit=None, sizelimit=None, **options):
c58629
+        # Store ca_enabled status in the context to save making the API
c58629
+        # call multiple times.
c58629
+        ca_enabled = self.api.Command.ca_is_enabled()['result']
c58629
+        setattr(context, 'ca_enabled', ca_enabled)
c58629
+
c58629
         if 'cacn' in options:
c58629
             ca_obj = api.Command.ca_show(options['cacn'])['result']
c58629
             ca_sdn = unicode(ca_obj['ipacasubjectdn'][0])
c58629
@@ -1534,7 +1545,8 @@ class cert_find(Search, CertMethod):
c58629
 
c58629
         if not pkey_only:
c58629
             ca_objs = {}
c58629
-            ra = self.api.Backend.ra
c58629
+            if ca_enabled:
c58629
+                ra = self.api.Backend.ra
c58629
 
c58629
             for key, obj in six.iteritems(result):
c58629
                 if all and 'cacn' in obj:
c58629
@@ -1561,6 +1573,12 @@ class cert_find(Search, CertMethod):
c58629
 
c58629
                 if not raw:
c58629
                     self.obj._parse(obj, all)
c58629
+                    if not ca_enabled and not all:
c58629
+                        # For the case of CA-less don't display the full
c58629
+                        # certificate unless requested. It is kept in the
c58629
+                        # entry from _ldap_search() so its attributes can
c58629
+                        # be retrieved.
c58629
+                        obj.pop('certificate', None)
c58629
                     self.obj._fill_owners(obj)
c58629
 
c58629
         result = list(six.itervalues(result))
c58629
-- 
c58629
2.13.6
c58629