>From 08b234681c3efab382c5e407945b6e97b406c910 Mon Sep 17 00:00:00 2001
From: "Endi S. Dewata" <edewata@redhat.com>
Date: Sat, 21 Jan 2017 01:16:35 +0100
Subject: [PATCH] Refactored Constants.PR_INTERNAL_TOKEN.

The Constants.PR_INTERNAL_TOKEN has been replaced with
CryptoUtil.INTERNAL_TOKEN_NAME since they are identical.

https://fedorahosted.org/pki/ticket/2556
---
 base/ca/src/com/netscape/ca/SigningUnit.java       |  4 +-
 .../src/com/netscape/certsrv/common/Constants.java |  1 -
 .../admin/certsrv/config/install/WIKeyPage.java    | 54 +++++++++++++---------
 base/ocsp/src/com/netscape/ocsp/SigningUnit.java   |  4 +-
 .../cms/servlet/admin/CMSAdminServlet.java         | 11 +++--
 .../cms/servlet/cert/scep/CRSEnrollment.java       |  6 +--
 .../netscape/cmscore/security/JssSubsystem.java    | 12 ++---
 .../com/netscape/cmscore/security/KeyCertUtil.java |  8 ++--
 8 files changed, 56 insertions(+), 44 deletions(-)

diff --git a/base/ca/src/com/netscape/ca/SigningUnit.java b/base/ca/src/com/netscape/ca/SigningUnit.java
index 405f20c064f749a08190af7e7b2daf62ec4e7cd1..e711f491e40ac3c69d6059bc498a141cdee9943e 100644
--- a/base/ca/src/com/netscape/ca/SigningUnit.java
+++ b/base/ca/src/com/netscape/ca/SigningUnit.java
@@ -41,10 +41,10 @@ import com.netscape.certsrv.base.ISubsystem;
 import com.netscape.certsrv.ca.CAMissingCertException;
 import com.netscape.certsrv.ca.CAMissingKeyException;
 import com.netscape.certsrv.ca.ECAException;
-import com.netscape.certsrv.common.Constants;
 import com.netscape.certsrv.logging.ILogger;
 import com.netscape.certsrv.security.ISigningUnit;
 import com.netscape.cmscore.security.JssSubsystem;
+import com.netscape.cmsutil.crypto.CryptoUtil;
 import com.netscape.cmsutil.util.Cert;
 
 import netscape.security.x509.AlgorithmId;
@@ -151,7 +151,7 @@ public final class SigningUnit implements ISigningUnit {
             }
 
             tokenname = config.getString(PROP_TOKEN_NAME);
-            if (tokenname.equalsIgnoreCase(Constants.PR_INTERNAL_TOKEN) ||
+            if (tokenname.equalsIgnoreCase(CryptoUtil.INTERNAL_TOKEN_NAME) ||
                     tokenname.equalsIgnoreCase("Internal Key Storage Token")) {
                 mToken = mManager.getInternalKeyStorageToken();
                 setNewNickName(mNickname);
diff --git a/base/common/src/com/netscape/certsrv/common/Constants.java b/base/common/src/com/netscape/certsrv/common/Constants.java
index e37d807346ca8efe1c44199a12c142bfa0b7fda0..408dfbe2c3033b8890bb7583f01d161c29436015 100644
--- a/base/common/src/com/netscape/certsrv/common/Constants.java
+++ b/base/common/src/com/netscape/certsrv/common/Constants.java
@@ -519,7 +519,6 @@ public interface Constants {
     /* Token and Certificates */
     public final static String PR_TOKEN_LIST = "tokenlist";
     public final static String PR_TOKEN_PREFIX = "token_";
-    public final static String PR_INTERNAL_TOKEN = "internal";
     public final static String PR_KEY_LIST = "keylist";
 
     /* SSL Cipher Preferences */
diff --git a/base/console/src/com/netscape/admin/certsrv/config/install/WIKeyPage.java b/base/console/src/com/netscape/admin/certsrv/config/install/WIKeyPage.java
index 425ecb869c02eff4dff62900506192916341130f..c45b93cdc13d6c10773f07d10b0b53ec61d584ad 100644
--- a/base/console/src/com/netscape/admin/certsrv/config/install/WIKeyPage.java
+++ b/base/console/src/com/netscape/admin/certsrv/config/install/WIKeyPage.java
@@ -17,21 +17,33 @@
 // --- END COPYRIGHT BLOCK ---
 package com.netscape.admin.certsrv.config.install;
 
-import java.awt.*;
-import java.awt.event.*;
-import java.util.*;
-import javax.swing.*;
-import javax.swing.text.*;
-import javax.swing.border.*;
-import javax.swing.event.*;
-import com.netscape.admin.certsrv.*;
-import com.netscape.admin.certsrv.connection.*;
-import com.netscape.admin.certsrv.wizard.*;
-import com.netscape.certsrv.common.*;
-import com.netscape.admin.certsrv.config.*;
-import com.netscape.admin.certsrv.task.*;
-import com.netscape.management.client.console.*;
-import com.netscape.management.client.util.*;
+import java.awt.Color;
+import java.awt.GridBagConstraints;
+import java.awt.GridBagLayout;
+import java.awt.Insets;
+import java.awt.event.ActionEvent;
+import java.awt.event.ItemEvent;
+import java.awt.event.ItemListener;
+import java.util.StringTokenizer;
+
+import javax.swing.JComboBox;
+import javax.swing.JComponent;
+import javax.swing.JLabel;
+import javax.swing.JPanel;
+import javax.swing.JPasswordField;
+import javax.swing.JTextArea;
+import javax.swing.JTextField;
+import javax.swing.text.JTextComponent;
+
+import com.netscape.admin.certsrv.CMSAdminUtil;
+import com.netscape.admin.certsrv.wizard.IWizardPanel;
+import com.netscape.admin.certsrv.wizard.WizardBasePanel;
+import com.netscape.admin.certsrv.wizard.WizardInfo;
+import com.netscape.certsrv.common.ConfigConstants;
+import com.netscape.certsrv.common.Constants;
+import com.netscape.certsrv.common.OpDef;
+import com.netscape.certsrv.common.TaskId;
+import com.netscape.cmsutil.crypto.CryptoUtil;
 
 /**
  * Setup key information for certificate setup wizard.
@@ -77,7 +89,7 @@ class WIKeyPage extends WizardBasePanel implements IWizardPanel, ItemListener {
         StringTokenizer tokenizer = new StringTokenizer(tokenList, ":");
         int count = tokenizer.countTokens();
         while (tokenizer.hasMoreTokens()) {
-            mTokenBox.addItem((String)tokenizer.nextToken());
+            mTokenBox.addItem(tokenizer.nextToken());
         }
 
         String initializedList = mWizardInfo.getTokensInit();
@@ -85,7 +97,7 @@ class WIKeyPage extends WizardBasePanel implements IWizardPanel, ItemListener {
         int i=0;
         mTokenInitialized = new String[count];
         while (tokenizer.hasMoreElements()) {
-            mTokenInitialized[i] = (String)tokenizer.nextToken();
+            mTokenInitialized[i] = tokenizer.nextToken();
             i++;
         }
 
@@ -94,7 +106,7 @@ class WIKeyPage extends WizardBasePanel implements IWizardPanel, ItemListener {
         i=0;
         mTokenLogin = new String[count];
         while (tokenizer.hasMoreElements()) {
-            mTokenLogin[i] = (String)tokenizer.nextToken();
+            mTokenLogin[i] = tokenizer.nextToken();
             i++;
         }
 
@@ -131,14 +143,14 @@ class WIKeyPage extends WizardBasePanel implements IWizardPanel, ItemListener {
                     }else if (mKeyTypeBox.isVisible()) {
                         String type = (String)mKeyTypeBox.getSelectedItem();
                         if (type.equals("RSA")) {
-                            float fraction = (float)num / (float)8.0;
+                            float fraction = num / (float)8.0;
                             int wholeNumber = (int)fraction;
                             if((fraction - wholeNumber)!=0) {
                                 setErrorMessage("RSAINVALID");
                                 return false;
                             }
                         }else {
-                            float fraction = (float)num / (float)64.0;
+                            float fraction = num / (float)64.0;
                             int wholeNumber = (int)fraction;
                             if(num < 512 || num > 1024 || (fraction - wholeNumber)!=0){
                                 setErrorMessage("DSAINVALID");
@@ -529,7 +541,7 @@ class WIKeyPage extends WizardBasePanel implements IWizardPanel, ItemListener {
     public void getUpdateInfo(WizardInfo info) {
         mWizardInfo = (InstallWizardInfo)info;
         String name = (String)mTokenBox.getSelectedItem();
-        if (name.equalsIgnoreCase(Constants.PR_INTERNAL_TOKEN))
+        if (name.equalsIgnoreCase(CryptoUtil.INTERNAL_TOKEN_NAME))
             name = Constants.PR_INTERNAL_TOKEN_NAME;
         mWizardInfo.put(ConfigConstants.PR_TOKEN_NAME, name);
         if (mPassword.isEditable()) {
diff --git a/base/ocsp/src/com/netscape/ocsp/SigningUnit.java b/base/ocsp/src/com/netscape/ocsp/SigningUnit.java
index f1c4feb7c4bb4ed9fe19853082308c3bd9307073..78f18b697428ccbaa52c4c2562de309209a46e71 100644
--- a/base/ocsp/src/com/netscape/ocsp/SigningUnit.java
+++ b/base/ocsp/src/com/netscape/ocsp/SigningUnit.java
@@ -38,10 +38,10 @@ import com.netscape.certsrv.apps.CMS;
 import com.netscape.certsrv.base.EBaseException;
 import com.netscape.certsrv.base.IConfigStore;
 import com.netscape.certsrv.base.ISubsystem;
-import com.netscape.certsrv.common.Constants;
 import com.netscape.certsrv.logging.ILogger;
 import com.netscape.certsrv.security.ISigningUnit;
 import com.netscape.cmscore.security.JssSubsystem;
+import com.netscape.cmsutil.crypto.CryptoUtil;
 import com.netscape.cmsutil.util.Cert;
 
 import netscape.security.x509.AlgorithmId;
@@ -138,7 +138,7 @@ public final class SigningUnit implements ISigningUnit {
             CMS.debug("OCSP nickname " + mNickname);
 
             tokenname = config.getString(PROP_TOKEN_NAME);
-            if (tokenname.equalsIgnoreCase(Constants.PR_INTERNAL_TOKEN) ||
+            if (tokenname.equalsIgnoreCase(CryptoUtil.INTERNAL_TOKEN_NAME) ||
                     tokenname.equalsIgnoreCase("Internal Key Storage Token")) {
                 mToken = mManager.getInternalKeyStorageToken();
             } else {
diff --git a/base/server/cms/src/com/netscape/cms/servlet/admin/CMSAdminServlet.java b/base/server/cms/src/com/netscape/cms/servlet/admin/CMSAdminServlet.java
index 18be8a854f148ab682aabe5d731b3dfe6d73aee1..755c8c4f74e90d544273247a86808eb19927894a 100644
--- a/base/server/cms/src/com/netscape/cms/servlet/admin/CMSAdminServlet.java
+++ b/base/server/cms/src/com/netscape/cms/servlet/admin/CMSAdminServlet.java
@@ -71,6 +71,7 @@ import com.netscape.certsrv.selftests.ESelfTestException;
 import com.netscape.certsrv.selftests.ISelfTest;
 import com.netscape.certsrv.selftests.ISelfTestSubsystem;
 import com.netscape.certsrv.tks.ITKSAuthority;
+import com.netscape.cmsutil.crypto.CryptoUtil;
 import com.netscape.cmsutil.util.Cert;
 import com.netscape.cmsutil.util.Utils;
 import com.netscape.symkey.SessionKey;
@@ -436,7 +437,7 @@ public final class CMSAdminServlet extends AdminServlet {
             caTokenName = signingUnit.getTokenName();
 
             if (caTokenName.equals(jssSubSystem.getInternalTokenName()))
-                caTokenName = Constants.PR_INTERNAL_TOKEN;
+                caTokenName = CryptoUtil.INTERNAL_TOKEN_NAME;
 
             String caNickName = signingUnit.getNickname();
 
@@ -493,7 +494,7 @@ public final class CMSAdminServlet extends AdminServlet {
             if (tokenizer.countTokens() > 1) {
                 tokenName = (String) tokenizer.nextElement();
             } else {
-                tokenName = Constants.PR_INTERNAL_TOKEN;
+                tokenName = CryptoUtil.INTERNAL_TOKEN_NAME;
             }
             return tokenName + "," + ((String) tokenizer.nextElement());
         }
@@ -587,7 +588,7 @@ public final class CMSAdminServlet extends AdminServlet {
                         String tokenName = (String) tokenizer.nextElement();
                         String nickName = (String) tokenizer.nextElement();
 
-                        if (tokenName.equals(Constants.PR_INTERNAL_TOKEN)) {
+                        if (tokenName.equals(CryptoUtil.INTERNAL_TOKEN_NAME)) {
                             tokenName = jssSubSystem.getInternalTokenName();
                         } else {
                             nickName = tokenName + ":" + nickName;
@@ -692,7 +693,7 @@ public final class CMSAdminServlet extends AdminServlet {
         }
         String tokenName = (String) tokenizer.nextElement();
 
-        if (tokenName.equals(Constants.PR_INTERNAL_TOKEN))
+        if (tokenName.equals(CryptoUtil.INTERNAL_TOKEN_NAME))
             tokenName = "";
         else
             tokenName = tokenName + ":";
@@ -1099,7 +1100,7 @@ public final class CMSAdminServlet extends AdminServlet {
                 String value = req.getParameter(key);
 
                 if (key.equals(Constants.PR_TOKEN_NAME)) {
-                    if (!value.equals(Constants.PR_INTERNAL_TOKEN))
+                    if (!value.equals(CryptoUtil.INTERNAL_TOKEN_NAME))
                         tokenName = value;
                 } else if (key.equals(Constants.PR_KEY_LENGTH)) {
                     keyLength = Integer.parseInt(value);
diff --git a/base/server/cms/src/com/netscape/cms/servlet/cert/scep/CRSEnrollment.java b/base/server/cms/src/com/netscape/cms/servlet/cert/scep/CRSEnrollment.java
index fa36dea2657238949cd1b716d43676eb5244fb31..5861e45583dc481ba6580bb340fe44845a64ba63 100644
--- a/base/server/cms/src/com/netscape/cms/servlet/cert/scep/CRSEnrollment.java
+++ b/base/server/cms/src/com/netscape/cms/servlet/cert/scep/CRSEnrollment.java
@@ -72,7 +72,6 @@ import com.netscape.certsrv.base.IConfigStore;
 import com.netscape.certsrv.base.ISubsystem;
 import com.netscape.certsrv.base.SessionContext;
 import com.netscape.certsrv.ca.ICertificateAuthority;
-import com.netscape.certsrv.common.Constants;
 import com.netscape.certsrv.ldap.ILdapConnFactory;
 import com.netscape.certsrv.logging.AuditFormat;
 import com.netscape.certsrv.logging.ILogger;
@@ -88,6 +87,7 @@ import com.netscape.certsrv.request.IRequestQueue;
 import com.netscape.certsrv.request.RequestId;
 import com.netscape.certsrv.request.RequestStatus;
 import com.netscape.cms.servlet.profile.SSLClientCertProvider;
+import com.netscape.cmsutil.crypto.CryptoUtil;
 import com.netscape.cmsutil.scep.CRSPKIMessage;
 import com.netscape.cmsutil.util.Utils;
 
@@ -245,7 +245,7 @@ public class CRSEnrollment extends HttpServlet {
                     mTokenName = scepConfig.getString("tokenname", "");
                     mUseCA = false;
                 }
-                if (!(mTokenName.equalsIgnoreCase(Constants.PR_INTERNAL_TOKEN) ||
+                if (!(mTokenName.equalsIgnoreCase(CryptoUtil.INTERNAL_TOKEN_NAME) ||
                         mTokenName.equalsIgnoreCase("Internal Key Storage Token") || mTokenName.length() == 0)) {
                     int i = mNickname.indexOf(':');
                     if (!((i > -1) && (mTokenName.length() == i) && (mNickname.startsWith(mTokenName)))) {
@@ -1964,7 +1964,7 @@ public class CRSEnrollment extends HttpServlet {
                 cm = CryptoManager.getInstance();
                 internalToken = cm.getInternalCryptoToken();
                 DESkg = internalToken.getKeyGenerator(kga);
-                if (mTokenName.equalsIgnoreCase(Constants.PR_INTERNAL_TOKEN) ||
+                if (mTokenName.equalsIgnoreCase(CryptoUtil.INTERNAL_TOKEN_NAME) ||
                         mTokenName.equalsIgnoreCase("Internal Key Storage Token") ||
                         mTokenName.length() == 0) {
                     keyStorageToken = cm.getInternalKeyStorageToken();
diff --git a/base/server/cmscore/src/com/netscape/cmscore/security/JssSubsystem.java b/base/server/cmscore/src/com/netscape/cmscore/security/JssSubsystem.java
index ed8bbfbdf5559639400eaa4448a0f7240324bb03..77967dc8acf21c97106b972d0177e358bb4e14e0 100644
--- a/base/server/cmscore/src/com/netscape/cmscore/security/JssSubsystem.java
+++ b/base/server/cmscore/src/com/netscape/cmscore/security/JssSubsystem.java
@@ -533,9 +533,9 @@ public final class JssSubsystem implements ICryptoSubsystem {
         }
 
         if (tokenList.length()==0)
-            return Constants.PR_INTERNAL_TOKEN;
+            return CryptoUtil.INTERNAL_TOKEN_NAME;
         else
-            return tokenList.append("," + Constants.PR_INTERNAL_TOKEN).toString();
+            return tokenList.append("," + CryptoUtil.INTERNAL_TOKEN_NAME).toString();
     }
 
     public boolean isTokenLoggedIn(String name) throws EBaseException {
@@ -631,7 +631,7 @@ public final class JssSubsystem implements ICryptoSubsystem {
         StringBuffer certNames = new StringBuffer();
 
         try {
-            if (name.equals(Constants.PR_INTERNAL_TOKEN)) {
+            if (name.equals(CryptoUtil.INTERNAL_TOKEN_NAME)) {
                 c = mCryptoManager.getInternalKeyStorageToken();
             } else {
                 c = mCryptoManager.getTokenByName(name);
@@ -681,7 +681,7 @@ public final class JssSubsystem implements ICryptoSubsystem {
         StringBuffer certNames = new StringBuffer();
 
         try {
-            if (name.equals(Constants.PR_INTERNAL_TOKEN)) {
+            if (name.equals(CryptoUtil.INTERNAL_TOKEN_NAME)) {
                 c = mCryptoManager.getInternalKeyStorageToken();
             } else {
                 c = mCryptoManager.getTokenByName(name);
@@ -794,7 +794,7 @@ public final class JssSubsystem implements ICryptoSubsystem {
             int keySize, PQGParams pqg) throws EBaseException {
 
         String t = tokenName;
-        if (tokenName.equals(Constants.PR_INTERNAL_TOKEN))
+        if (tokenName.equals(CryptoUtil.INTERNAL_TOKEN_NAME))
             t = Constants.PR_FULL_INTERNAL_TOKEN_NAME;
         CryptoToken token = null;
 
@@ -912,7 +912,7 @@ public final class JssSubsystem implements ICryptoSubsystem {
         String tmp = (String) properties.get(Constants.PR_TOKEN_NAME);
 
         if ((tmp != null) &&
-                (!tmp.equals(Constants.PR_INTERNAL_TOKEN)))
+                (!tmp.equals(CryptoUtil.INTERNAL_TOKEN_NAME)))
             tokenname = tmp;
         tmp = (String) properties.get(Constants.PR_KEY_TYPE);
         if (tmp != null)
diff --git a/base/server/cmscore/src/com/netscape/cmscore/security/KeyCertUtil.java b/base/server/cmscore/src/com/netscape/cmscore/security/KeyCertUtil.java
index 989be3f0518928ccd510d34e4280c8528c4cc800..4fa20261e0e93f88ef51952ea7237e636f50e3a4 100644
--- a/base/server/cmscore/src/com/netscape/cmscore/security/KeyCertUtil.java
+++ b/base/server/cmscore/src/com/netscape/cmscore/security/KeyCertUtil.java
@@ -166,9 +166,9 @@ public class KeyCertUtil {
         }
 
         if (tokenList.length() == 0)
-            return Constants.PR_INTERNAL_TOKEN;
+            return CryptoUtil.INTERNAL_TOKEN_NAME;
         else
-            return (tokenList.toString() + "," + Constants.PR_INTERNAL_TOKEN);
+            return (tokenList.toString() + "," + CryptoUtil.INTERNAL_TOKEN_NAME);
     }
 
     public static String base64Encode(byte[] bytes) throws IOException {
@@ -499,11 +499,11 @@ public class KeyCertUtil {
 
         CryptoToken token = null;
 
-        if (tokenName.equalsIgnoreCase(Constants.PR_INTERNAL_TOKEN))
+        if (tokenName.equalsIgnoreCase(CryptoUtil.INTERNAL_TOKEN_NAME))
             tokenName = Constants.PR_INTERNAL_TOKEN_NAME;
 
         try {
-            if (tokenName.equalsIgnoreCase(Constants.PR_INTERNAL_TOKEN)) {
+            if (tokenName.equalsIgnoreCase(CryptoUtil.INTERNAL_TOKEN_NAME)) {
                 token = CryptoManager.getInstance().getInternalKeyStorageToken();
             } else {
                 token = CryptoManager.getInstance().getTokenByName(tokenName);
-- 
2.5.5

