From 5732d0f27b0f26a4125f91732659982609d75aab Mon Sep 17 00:00:00 2001 From: Fraser Tweedale Date: Tue, 23 Aug 2016 14:50:03 +1000 Subject: [PATCH 131/132] Accept LWCA entry with missing entryUSN if plugin enabled Currently we abort adding a lightweight CA if its entry does not have an 'entryUSN' attribute, and log a failure, even if the USN plugin is enabled. But if the plugin is enabled, it's fine to proceed. Update the authority monitor to check if the USN plugin is enabled and only log the failure if it is not. Clarify the log message accordingly. Part of: https://fedorahosted.org/pki/ticket/2444 --- .../src/com/netscape/ca/CertificateAuthority.java | 46 ++++++++++++++++++---- 1 file changed, 38 insertions(+), 8 deletions(-) diff --git a/base/ca/src/com/netscape/ca/CertificateAuthority.java b/base/ca/src/com/netscape/ca/CertificateAuthority.java index a5397da0c0dcea654a15f16e5becc5c430a1bb29..856317e1604d8d536af3320562da62a0dab544cb 100644 --- a/base/ca/src/com/netscape/ca/CertificateAuthority.java +++ b/base/ca/src/com/netscape/ca/CertificateAuthority.java @@ -677,6 +677,24 @@ public class CertificateAuthority } } + private boolean entryUSNPluginEnabled() { + try { + LDAPConnection conn = dbFactory.getConn(); + try { + LDAPSearchResults results = conn.search( + "cn=usn,cn=plugins,cn=config", LDAPConnection.SCOPE_BASE, + "(nsslapd-pluginEnabled=on)", null, false); + return results != null && results.hasMoreElements(); + } catch (LDAPException e) { + return false; + } finally { + dbFactory.returnConn(conn); + } + } catch (ELdapException e) { + return false; // oh well + } + } + private void initCRLPublisher() throws EBaseException { // instantiate CRL publisher if (!isHostAuthority()) { @@ -3177,17 +3195,29 @@ public class CertificateAuthority AuthorityID aid = new AuthorityID((String) aidAttr.getStringValues().nextElement()); - LDAPAttribute entryUSN = entry.getAttribute("entryUSN"); - if (entryUSN == null) { - log(ILogger.LL_FAILURE, "Authority entry has no entryUSN. " + - "This is likely because the USN plugin is not enabled in the database"); - return; + Integer newEntryUSN = null; + LDAPAttribute entryUSNAttr = entry.getAttribute("entryUSN"); + if (entryUSNAttr == null) { + CMS.debug("readAuthority: no entryUSN"); + if (!entryUSNPluginEnabled()) { + CMS.debug("readAuthority: dirsrv USN plugin is not enabled; skipping entry"); + log(ILogger.LL_FAILURE, "Lightweight authority entry has no" + + " entryUSN attribute and USN plugin not enabled;" + + " skipping. Enable dirsrv USN plugin."); + return; + } else { + CMS.debug("readAuthority: dirsrv USN plugin is enabled; continuing"); + // entryUSN plugin is enabled, but no entryUSN attribute. We + // can proceed because future modifications will result in the + // entryUSN attribute being added. + } + } else { + newEntryUSN = new Integer(entryUSNAttr.getStringValueArray()[0]); + CMS.debug("readAuthority: new entryUSN = " + newEntryUSN); } - Integer newEntryUSN = new Integer(entryUSN.getStringValueArray()[0]); - CMS.debug("readAuthority: new entryUSN = " + newEntryUSN); Integer knownEntryUSN = entryUSNs.get(aid); - if (knownEntryUSN != null) { + if (newEntryUSN != null && knownEntryUSN != null) { CMS.debug("readAuthority: known entryUSN = " + knownEntryUSN); if (newEntryUSN <= knownEntryUSN) { CMS.debug("readAuthority: data is current"); -- 2.5.5