Blob Blame History Raw
From 78fa2f5955225cd38f3c5b996396453899017b31 Mon Sep 17 00:00:00 2001
From: "Endi S. Dewata" <edewata@redhat.com>
Date: Wed, 12 Oct 2016 03:26:41 +0200
Subject: [PATCH] Fixed CryptoUtil.getTokenName().

The CryptoUtil.getTokenName() has been modified to check both the
short name and full name of the internal token.

The ConfigurationUtils.deleteCert() has also been modified to call
CryptoUtil.getTokenName().

https://fedorahosted.org/pki/ticket/2500
(cherry picked from commit 5be68e38fd77f171331d27ca52a291f06f7c686c)
(cherry picked from commit 42c52b18467212dde0cdebedca55ab22c4629cb5)
---
 .../cms/servlet/csadmin/ConfigurationUtils.java    |  2 +-
 .../com/netscape/cmsutil/crypto/CryptoUtil.java    | 23 +++++++++++++---------
 2 files changed, 15 insertions(+), 10 deletions(-)

diff --git a/base/server/cms/src/com/netscape/cms/servlet/csadmin/ConfigurationUtils.java b/base/server/cms/src/com/netscape/cms/servlet/csadmin/ConfigurationUtils.java
index ecf8157..afd8d28 100644
--- a/base/server/cms/src/com/netscape/cms/servlet/csadmin/ConfigurationUtils.java
+++ b/base/server/cms/src/com/netscape/cms/servlet/csadmin/ConfigurationUtils.java
@@ -3419,7 +3419,7 @@ public class ConfigurationUtils {
             NoSuchTokenException, TokenException {
 
         CryptoManager cm = CryptoManager.getInstance();
-        CryptoToken tok = cm.getTokenByName(tokenname);
+        CryptoToken tok = CryptoUtil.getTokenByName(tokenname);
         CryptoStore store = tok.getCryptoStore();
         String fullnickname = nickname;
         if (!tokenname.equals("") &&
diff --git a/base/util/src/com/netscape/cmsutil/crypto/CryptoUtil.java b/base/util/src/com/netscape/cmsutil/crypto/CryptoUtil.java
index b02c363..b6b5e6a 100644
--- a/base/util/src/com/netscape/cmsutil/crypto/CryptoUtil.java
+++ b/base/util/src/com/netscape/cmsutil/crypto/CryptoUtil.java
@@ -135,6 +135,9 @@ import netscape.security.x509.X509Key;
 @SuppressWarnings("serial")
 public class CryptoUtil {
 
+    public final static String INTERNAL_TOKEN_NAME = "internal";
+    public final static String INTERNAL_TOKEN_FULL_NAME = "Internal Key Storage Token";
+
     public static final String CERTREQ_BEGIN_HEADING = "-----BEGIN CERTIFICATE REQUEST-----";
     public static final String CERTREQ_END_HEADING = "-----END CERTIFICATE REQUEST-----";
     public static final int LINE_COUNT = 76;
@@ -472,21 +475,23 @@ public class CryptoUtil {
         return true;
     }
 
+    public static boolean isInternalToken(String name) {
+        return name.equalsIgnoreCase(INTERNAL_TOKEN_NAME) || name.equalsIgnoreCase(INTERNAL_TOKEN_FULL_NAME);
+    }
+
     /**
      * Retrieves handle to a JSS token.
      */
-    public static CryptoToken getTokenByName(String token)
-            throws CryptoManager.NotInitializedException,
-                NoSuchTokenException {
+    public static CryptoToken getTokenByName(String name)
+            throws NotInitializedException, NoSuchTokenException {
+
         CryptoManager cm = CryptoManager.getInstance();
-        CryptoToken t = null;
 
-        if (token.equals("internal")) {
-            t = cm.getInternalKeyStorageToken();
-        } else {
-            t = cm.getTokenByName(token);
+        if (isInternalToken(name)) {
+            return cm.getInternalKeyStorageToken();
         }
-        return t;
+
+        return cm.getTokenByName(name);
     }
 
     /**
-- 
1.8.3.1