mirror of https://github.com/OpenIdentityPlatform/OpenDJ.git

jvergara
29.09.2009 de38d491e77f8501800587d5829d02214eedac38
Fix for issue 4155 (UI keystore does not handle properly certificates from the same host)
If the provided certificate to be accepted in the key store is not already there, use a unique alias for the certificate.
1 files modified
35 ■■■■■ changed files
opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/util/UIKeyStore.java 35 ●●●●● patch | view | raw | blame | history
opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/util/UIKeyStore.java
@@ -35,6 +35,7 @@
import java.security.KeyStore;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.security.cert.Certificate;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
import java.util.Enumeration;
@@ -143,9 +144,18 @@
    KeyStore k = getInstance();
    for (int i = 0; i < chain.length; i++)
    {
      if (!containsCertificate(chain[i], k))
      {
      String alias = chain[i].getSubjectDN().getName();
        int j = 1;
        while (k.containsAlias(alias))
        {
          alias = chain[i].getSubjectDN().getName()+ "-" + j;
          j++;
        }
      k.setCertificateEntry(alias, chain[i]);
    }
    }
    String keyStorePath = getKeyStorePath();
    File f = new File(keyStorePath);
    if (!f.exists())
@@ -254,4 +264,29 @@
    return  instancePath + File.separator + "config" +
    File.separator + "admin-truststore";
  }
  /**
   * Returns whether the key store contains the provided certificate or not.
   * @param cert the certificate.
   * @param keyStore the key store.
   * @return whether the key store contains the provided certificate or not.
   * @throws KeyStoreException if an error occurs reading the contents of the
   * key store.
   */
  private static boolean containsCertificate(X509Certificate cert,
      KeyStore keyStore) throws KeyStoreException
  {
    boolean found = false;
    Enumeration<String> aliases = keyStore.aliases();
    while (aliases.hasMoreElements() && !found)
    {
      String alias = aliases.nextElement();
      if (keyStore.isCertificateEntry(alias))
      {
        Certificate c = keyStore.getCertificate(alias);
        found = c.equals(cert);
      }
    }
    return found;
  }
}