e3ffab
From ccaacaaf054e9d597159e14714ab41069173da10 Mon Sep 17 00:00:00 2001
e3ffab
From: Jan Cholasta <jcholast@redhat.com>
e3ffab
Date: Tue, 14 Oct 2014 11:26:15 +0200
e3ffab
Subject: [PATCH] Fail if certmonger can't see new CA certificate in LDAP in
e3ffab
 ipa-cacert-manage
e3ffab
e3ffab
This should not normally happen, but if it does, report an error instead of
e3ffab
waiting idefinitely for the certificate to appear.
e3ffab
e3ffab
https://fedorahosted.org/freeipa/ticket/4629
e3ffab
e3ffab
Reviewed-By: David Kupka <dkupka@redhat.com>
e3ffab
---
e3ffab
 .../certmonger/dogtag-ipa-ca-renew-agent-submit    | 40 +++++++++-------------
e3ffab
 ipaserver/install/ipa_cacert_manage.py             |  3 +-
e3ffab
 2 files changed, 19 insertions(+), 24 deletions(-)
e3ffab
e3ffab
diff --git a/install/certmonger/dogtag-ipa-ca-renew-agent-submit b/install/certmonger/dogtag-ipa-ca-renew-agent-submit
e3ffab
index 9a01eb3a08900a5c8d04953b41f4493f30c2b56f..e5ad9639b03b95e6e265214067a985f6c3ca0b2a 100755
e3ffab
--- a/install/certmonger/dogtag-ipa-ca-renew-agent-submit
e3ffab
+++ b/install/certmonger/dogtag-ipa-ca-renew-agent-submit
e3ffab
@@ -311,25 +311,11 @@ def retrieve_or_reuse_cert():
e3ffab
 
e3ffab
     return (ISSUED, cert)
e3ffab
 
e3ffab
-def retrieve_cert():
e3ffab
+def retrieve_cert_continuous():
e3ffab
     """
e3ffab
-    Retrieve new certificate from LDAP.
e3ffab
+    Retrieve new certificate from LDAP. Repeat every eight hours until the
e3ffab
+    certificate is available.
e3ffab
     """
e3ffab
-    operation = os.environ.get('CERTMONGER_OPERATION')
e3ffab
-    if operation == 'SUBMIT':
e3ffab
-        attempts = 0
e3ffab
-    elif operation == 'POLL':
e3ffab
-        cookie = os.environ.get('CERTMONGER_CA_COOKIE')
e3ffab
-        if not cookie:
e3ffab
-            return (UNCONFIGURED, "Cookie not provided")
e3ffab
-
e3ffab
-        try:
e3ffab
-            attempts = int(cookie)
e3ffab
-        except ValueError:
e3ffab
-            return (UNCONFIGURED, "Invalid cookie: %r" % cookie)
e3ffab
-    else:
e3ffab
-        return (OPERATION_NOT_SUPPORTED_BY_HELPER,)
e3ffab
-
e3ffab
     old_cert = os.environ.get('CERTMONGER_CERTIFICATE')
e3ffab
     if old_cert:
e3ffab
         old_cert = x509.normalize_certificate(old_cert)
e3ffab
@@ -340,11 +326,19 @@ def retrieve_cert():
e3ffab
 
e3ffab
     new_cert = x509.normalize_certificate(result[1])
e3ffab
     if new_cert == old_cert:
e3ffab
-        attempts += 1
e3ffab
-        if attempts < 4:
e3ffab
-            syslog.syslog(syslog.LOG_INFO, "Updated certificate not available")
e3ffab
-            # No cert available yet, tell certmonger to wait another 8 hours
e3ffab
-            return (WAIT_WITH_DELAY, 8 * 60 * 60, str(attempts))
e3ffab
+        syslog.syslog(syslog.LOG_INFO, "Updated certificate not available")
e3ffab
+        # No cert available yet, tell certmonger to wait another 8 hours
e3ffab
+        return (WAIT_WITH_DELAY, 8 * 60 * 60, '')
e3ffab
+
e3ffab
+    return result
e3ffab
+
e3ffab
+def retrieve_cert():
e3ffab
+    """
e3ffab
+    Retrieve new certificate from LDAP.
e3ffab
+    """
e3ffab
+    result = call_handler(retrieve_cert_continuous)
e3ffab
+    if result[0] == WAIT_WITH_DELAY:
e3ffab
+        return (REJECTED, "Updated certificate not available")
e3ffab
 
e3ffab
     return result
e3ffab
 
e3ffab
@@ -451,7 +445,7 @@ def main():
e3ffab
             if ca.is_renewal_master():
e3ffab
                 handler = request_and_store_cert
e3ffab
             else:
e3ffab
-                handler = retrieve_cert
e3ffab
+                handler = retrieve_cert_continuous
e3ffab
 
e3ffab
         res = call_handler(handler)
e3ffab
         for item in res[1:]:
e3ffab
diff --git a/ipaserver/install/ipa_cacert_manage.py b/ipaserver/install/ipa_cacert_manage.py
e3ffab
index a521e3965321d3345075d7fc4a55fb9c6904a652..2a8d95fdbebecf543a05afd47275c32684cad970 100644
e3ffab
--- a/ipaserver/install/ipa_cacert_manage.py
e3ffab
+++ b/ipaserver/install/ipa_cacert_manage.py
e3ffab
@@ -297,7 +297,8 @@ class CACertManage(admintool.AdminTool):
e3ffab
             raise admintool.ScriptError(
e3ffab
                 "Resubmitting certmonger request '%s' timed out, "
e3ffab
                 "please check the request manually" % self.request_id)
e3ffab
-        if state != 'MONITORING':
e3ffab
+        ca_error = certmonger.get_request_value(self.request_id, 'ca-error')
e3ffab
+        if state != 'MONITORING' or ca_error:
e3ffab
             raise admintool.ScriptError(
e3ffab
                 "Error resubmitting certmonger request '%s', "
e3ffab
                 "please check the request manually" % self.request_id)
e3ffab
-- 
e3ffab
2.1.0
e3ffab