From f9602afdbf9484d0d04bc9018568e85fbe558191 Mon Sep 17 00:00:00 2001
From: jvergara <jvergara@localhost>
Date: Sat, 17 Jan 2009 00:16:44 +0000
Subject: [PATCH] Fix for issue 3724 (ApplicationTrustManager.java use hard coded provider and algorithm ~)

---
 opendj-sdk/opends/src/ads/org/opends/admin/ads/util/ApplicationKeyManager.java |   41 ++++++++++++++++-------------------------
 1 files changed, 16 insertions(+), 25 deletions(-)

diff --git a/opendj-sdk/opends/src/ads/org/opends/admin/ads/util/ApplicationKeyManager.java b/opendj-sdk/opends/src/ads/org/opends/admin/ads/util/ApplicationKeyManager.java
index f2f2d37..f568e4a 100644
--- a/opendj-sdk/opends/src/ads/org/opends/admin/ads/util/ApplicationKeyManager.java
+++ b/opendj-sdk/opends/src/ads/org/opends/admin/ads/util/ApplicationKeyManager.java
@@ -31,7 +31,6 @@
 import java.security.KeyStore;
 import java.security.KeyStoreException;
 import java.security.NoSuchAlgorithmException;
-import java.security.NoSuchProviderException;
 import java.security.Principal;
 import java.security.PrivateKey;
 import java.security.UnrecoverableKeyException;
@@ -64,7 +63,7 @@
   /**
    * The default keyManager.
    */
-  private X509KeyManager sunJSSEX509KeyManager = null ;
+  private X509KeyManager keyManager = null ;
 
   /**
    * The default constructor.
@@ -74,11 +73,10 @@
   public ApplicationKeyManager(KeyStore keystore, char[] password)
   {
     KeyManagerFactory kmf = null;
-    String algo = "SunX509";
-    String provider = "SunJSSE";
     try
     {
-      kmf = KeyManagerFactory.getInstance(algo, provider);
+      String algo = KeyManagerFactory.getDefaultAlgorithm();
+      kmf = KeyManagerFactory.getInstance(algo);
       kmf.init(keystore, password);
       KeyManager kms[] = kmf.getKeyManagers();
 
@@ -91,11 +89,10 @@
       {
         if (kms[i] instanceof X509KeyManager)
         {
-          sunJSSEX509KeyManager = (X509KeyManager) kms[i];
+          keyManager = (X509KeyManager) kms[i];
           break;
         }
       }
-
     }
     catch (NoSuchAlgorithmException e)
     {
@@ -103,12 +100,6 @@
       // in a best effor mode.
       LOG.log(Level.WARNING, "Error with the algorithm", e);
     }
-    catch (NoSuchProviderException e)
-    {
-      // Nothing to do. Maybe we should avoid this and be strict, but we are
-      // in a best effor mode.
-      LOG.log(Level.WARNING, "Error with the provider", e);
-    }
     catch (KeyStoreException e)
     {
       // Nothing to do. Maybe we should avoid this and be strict, but we are
@@ -145,9 +136,9 @@
   public String chooseClientAlias(String[] keyType, Principal[] issuers,
       Socket socket)
   {
-    if (sunJSSEX509KeyManager != null)
+    if (keyManager != null)
     {
-      return sunJSSEX509KeyManager.chooseClientAlias(keyType, issuers, socket);
+      return keyManager.chooseClientAlias(keyType, issuers, socket);
     }
     else
     {
@@ -176,9 +167,9 @@
   public String chooseServerAlias(String keyType, Principal[] issuers,
       Socket socket)
   {
-    if (sunJSSEX509KeyManager != null)
+    if (keyManager != null)
     {
-      return sunJSSEX509KeyManager.chooseServerAlias(keyType, issuers, socket);
+      return keyManager.chooseServerAlias(keyType, issuers, socket);
     }
     else
     {
@@ -197,9 +188,9 @@
    */
   public X509Certificate[] getCertificateChain(String alias)
   {
-    if (sunJSSEX509KeyManager != null)
+    if (keyManager != null)
     {
-      return sunJSSEX509KeyManager.getCertificateChain(alias);
+      return keyManager.getCertificateChain(alias);
     }
     else
     {
@@ -222,9 +213,9 @@
    */
   public String[] getClientAliases(String keyType, Principal[] issuers)
   {
-    if (sunJSSEX509KeyManager != null)
+    if (keyManager != null)
     {
-      return sunJSSEX509KeyManager.getClientAliases(keyType, issuers);
+      return keyManager.getClientAliases(keyType, issuers);
     }
     else
     {
@@ -241,9 +232,9 @@
    */
   public PrivateKey getPrivateKey(String alias)
   {
-    if (sunJSSEX509KeyManager != null)
+    if (keyManager != null)
     {
-      return sunJSSEX509KeyManager.getPrivateKey(alias);
+      return keyManager.getPrivateKey(alias);
     }
     else
     {
@@ -266,9 +257,9 @@
    */
   public String[] getServerAliases(String keyType, Principal[] issuers)
   {
-    if (sunJSSEX509KeyManager != null)
+    if (keyManager != null)
     {
-      return sunJSSEX509KeyManager.getServerAliases(keyType, issuers);
+      return keyManager.getServerAliases(keyType, issuers);
     }
     else
     {

--
Gitblit v1.10.0