c58629
From 148e78d74206730c31dd7bc87eece5c5bd1440ac Mon Sep 17 00:00:00 2001
c58629
From: Rob Crittenden <rcritten@redhat.com>
c58629
Date: Wed, 9 Aug 2017 17:28:35 -0400
c58629
Subject: [PATCH] Include the CA basic constraint in CSRs when renewing a CA
c58629
c58629
The CSR generated by `ipa-cacert-manage renew --external-ca` did
c58629
not include the CA basic constraint:
c58629
c58629
  X509v3 Basic Constraints: critical
c58629
      CA:TRUE
c58629
c58629
Add a flag to certmonger::resubmit_request to specify that a
c58629
CA is being requested.
c58629
c58629
Note that this also sets pathlen to -1 which means an unlimited
c58629
pathlen. Leave it up to the issuing CA to set this.
c58629
c58629
https://pagure.io/freeipa/issue/7088
c58629
c58629
Reviewed-By: Florence Blanc-Renaud <frenaud@redhat.com>
c58629
Reviewed-By: Florence Blanc-Renaud <frenaud@redhat.com>
c58629
---
c58629
 ipalib/install/certmonger.py           | 13 +++++++++++--
c58629
 ipaserver/install/ipa_cacert_manage.py |  3 ++-
c58629
 2 files changed, 13 insertions(+), 3 deletions(-)
c58629
c58629
diff --git a/ipalib/install/certmonger.py b/ipalib/install/certmonger.py
c58629
index c286996ee2318e241b4af190d1a01f42e28aa9f3..d2b782ddb0c746a3dfd96d0222bb31c6a960fdff 100644
c58629
--- a/ipalib/install/certmonger.py
c58629
+++ b/ipalib/install/certmonger.py
c58629
@@ -519,16 +519,25 @@ def modify(request_id, ca=None, profile=None):
c58629
         request.obj_if.modify(update)
c58629
 
c58629
 
c58629
-def resubmit_request(request_id, ca=None, profile=None):
c58629
+def resubmit_request(request_id, ca=None, profile=None, is_ca=False):
c58629
+    """
c58629
+    :param request_id: the certmonger numeric request ID
c58629
+    :param ca: the nickname for the certmonger CA, e.g. IPA or SelfSign
c58629
+    :param profile: the dogtag template profile to use, e.g. SubCA
c58629
+    :param is_ca: boolean that if True adds the CA basic constraint
c58629
+    """
c58629
     request = _get_request({'nickname': request_id})
c58629
     if request:
c58629
-        if ca or profile:
c58629
+        if ca or profile or is_ca:
c58629
             update = {}
c58629
             if ca is not None:
c58629
                 cm = _certmonger()
c58629
                 update['CA'] = cm.obj_if.find_ca_by_nickname(ca)
c58629
             if profile is not None:
c58629
                 update['template-profile'] = profile
c58629
+            if is_ca:
c58629
+                update['template-is-ca'] = True
c58629
+                update['template-ca-path-length'] = -1  # no path length
c58629
             request.obj_if.modify(update)
c58629
         request.obj_if.resubmit()
c58629
 
c58629
diff --git a/ipaserver/install/ipa_cacert_manage.py b/ipaserver/install/ipa_cacert_manage.py
c58629
index fcbf09155a3abc9ce9481aa2519ed39aaa6aa9bb..9607620d6c3e63b70b9e586f94282bf478c8c53e 100644
c58629
--- a/ipaserver/install/ipa_cacert_manage.py
c58629
+++ b/ipaserver/install/ipa_cacert_manage.py
c58629
@@ -310,7 +310,8 @@ class CACertManage(admintool.AdminTool):
c58629
         timeout = api.env.startup_timeout + 60
c58629
 
c58629
         self.log.debug("resubmitting certmonger request '%s'", self.request_id)
c58629
-        certmonger.resubmit_request(self.request_id, ca=ca, profile=profile)
c58629
+        certmonger.resubmit_request(self.request_id, ca=ca, profile=profile,
c58629
+                                    is_ca=True)
c58629
         try:
c58629
             state = certmonger.wait_for_request(self.request_id, timeout)
c58629
         except RuntimeError:
c58629
-- 
c58629
2.9.5
c58629