From 766ba6b28669b54a6a90c539822661690cf5fa2d Mon Sep 17 00:00:00 2001
From: jvergara <jvergara@localhost>
Date: Wed, 25 Nov 2009 20:42:49 +0000
Subject: [PATCH] Fix for issue 4371 (setup throws NullPointerException when trying to use a PKCS12 certificate) Handle the case where the user provides a certificate without an alias.  The code in CertificateManager has been updated to detect this situation. The code in ConfigureDS has also been updated to handle the case where the user does not provide a certificate nickname.

---
 opends/src/server/org/opends/server/util/CertificateManager.java |   40 ++++++++++++++++++++++++++++++++++++++++
 1 files changed, 40 insertions(+), 0 deletions(-)

diff --git a/opends/src/server/org/opends/server/util/CertificateManager.java b/opends/src/server/org/opends/server/util/CertificateManager.java
index 0647062..4b78091 100644
--- a/opends/src/server/org/opends/server/util/CertificateManager.java
+++ b/opends/src/server/org/opends/server/util/CertificateManager.java
@@ -97,6 +97,8 @@
 
   private final char[] password;
 
+  private Boolean realAliases;
+
   /**
    * Always return true.
    *
@@ -439,6 +441,44 @@
       }
   }
 
+  /**
+   * Returns whether this certificate manager contains 'real' aliases or not.
+   * For instance, the certificate manager can contain a PKCS12 certificate
+   * with no alias.
+   * @return whether this certificate manager contains 'real' aliases or not.
+   * @throws KeyStoreException if there is a problem accessing the key store.
+   */
+  public boolean hasRealAliases() throws KeyStoreException
+  {
+    if (realAliases == null)
+    {
+      String[] aliases = getCertificateAliases();
+      if (aliases == null || aliases.length == 0)
+      {
+        realAliases = Boolean.FALSE;
+      }
+      else if (aliases.length > 1)
+      {
+        realAliases = Boolean.TRUE;
+      }
+      else
+      {
+        CertificateManager certManager2 = new CertificateManager(keyStorePath,
+            keyStoreType, new String(password));
+        String[] aliases2 = certManager2.getCertificateAliases();
+        if (aliases2 != null && aliases2.length == 1)
+        {
+          realAliases = aliases[0].equalsIgnoreCase(aliases2[0]);
+        }
+        else
+        {
+          realAliases = Boolean.FALSE;
+        }
+      }
+    }
+    return realAliases;
+  }
+
   private static void ensureFileValid(File arg, String msgStr) {
     if(arg == null) {
       Message msg = ERR_CERTMGR_FILE_NAME_INVALID.get(msgStr);

--
Gitblit v1.10.0