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