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