summaryrefslogtreecommitdiffstats
path: root/base/common/src/com/netscape/cmscore/security
diff options
context:
space:
mode:
authorAbhishek Koneru <akoneru@redhat.com>2012-05-18 16:12:17 -0400
committerAde Lee <alee@redhat.com>2012-05-24 23:08:51 -0400
commit9db76ed1d1f8969e93aaff320e49662f53688e2e (patch)
tree2e7af87ca0f72cdf4eb982764757d2884b21ce7b /base/common/src/com/netscape/cmscore/security
parenta4db0f39e257950a5c89203452c1184c7080e5bd (diff)
downloadpki-9db76ed1d1f8969e93aaff320e49662f53688e2e.tar.gz
pki-9db76ed1d1f8969e93aaff320e49662f53688e2e.tar.xz
pki-9db76ed1d1f8969e93aaff320e49662f53688e2e.zip
Fixes for Coverity Defects of Category : FB.SBSC_USE_STRINGBUFFER_CONCATENATION
Diffstat (limited to 'base/common/src/com/netscape/cmscore/security')
-rw-r--r--base/common/src/com/netscape/cmscore/security/JssSubsystem.java55
-rw-r--r--base/common/src/com/netscape/cmscore/security/KeyCertUtil.java14
-rw-r--r--base/common/src/com/netscape/cmscore/security/PWCBsdr.java8
-rw-r--r--base/common/src/com/netscape/cmscore/security/PWsdrCache.java24
4 files changed, 45 insertions, 56 deletions
diff --git a/base/common/src/com/netscape/cmscore/security/JssSubsystem.java b/base/common/src/com/netscape/cmscore/security/JssSubsystem.java
index 42249e324..2d6fe7d88 100644
--- a/base/common/src/com/netscape/cmscore/security/JssSubsystem.java
+++ b/base/common/src/com/netscape/cmscore/security/JssSubsystem.java
@@ -508,7 +508,8 @@ public final class JssSubsystem implements ICryptoSubsystem {
}
public String getTokenList() throws EBaseException {
- String tokenList = "";
+ StringBuffer tokenList = new StringBuffer();
+
@SuppressWarnings("unchecked")
Enumeration<CryptoToken> tokens = mCryptoManager.getExternalTokens();
int num = 0;
@@ -522,10 +523,9 @@ public final class JssSubsystem implements ICryptoSubsystem {
continue;
}
- if (num++ == 0)
- tokenList = tokenList + c.getName();
- else
- tokenList = tokenList + "," + c.getName();
+ if (num++ != 0)
+ tokenList.append(",");
+ tokenList.append(c.getName());
}
} catch (TokenException e) {
String[] params = { mId, e.toString() };
@@ -536,10 +536,10 @@ public final class JssSubsystem implements ICryptoSubsystem {
throw ex;
}
- if (tokenList.equals(""))
+ if (tokenList.length()==0)
return Constants.PR_INTERNAL_TOKEN;
else
- return (tokenList + "," + Constants.PR_INTERNAL_TOKEN);
+ return tokenList.append(",").append(Constants.PR_INTERNAL_TOKEN).toString();
}
public boolean isTokenLoggedIn(String name) throws EBaseException {
@@ -596,7 +596,7 @@ public final class JssSubsystem implements ICryptoSubsystem {
}
public String getAllCerts() throws EBaseException {
- String certNames = "";
+ StringBuffer certNames = new StringBuffer();
try {
@SuppressWarnings("unchecked")
@@ -610,10 +610,9 @@ public final class JssSubsystem implements ICryptoSubsystem {
for (int i = 0; i < list.length; i++) {
String nickname = list[i].getNickname();
- if (certNames.equals(""))
- certNames = certNames + nickname;
- else
- certNames = certNames + "," + nickname;
+ if (i > 0)
+ certNames.append(",");
+ certNames.append(nickname);
}
}
} catch (TokenException e) {
@@ -625,13 +624,13 @@ public final class JssSubsystem implements ICryptoSubsystem {
throw ex;
}
- return certNames;
+ return certNames.toString();
}
public String getCertListWithoutTokenName(String name) throws EBaseException {
CryptoToken c = null;
- String certNames = "";
+ StringBuffer certNames = new StringBuffer();
try {
if (name.equals(Constants.PR_INTERNAL_TOKEN)) {
@@ -653,12 +652,11 @@ public final class JssSubsystem implements ICryptoSubsystem {
if (index != -1)
nickname = nickname.substring(index + 1);
- if (i == 0)
- certNames = certNames + nickname;
- else
- certNames = certNames + "," + nickname;
+ if (i != 0)
+ certNames.append(",");
+ certNames.append(nickname);
}
- return certNames;
+ return certNames.toString();
} else
return "";
@@ -682,7 +680,7 @@ public final class JssSubsystem implements ICryptoSubsystem {
public String getCertList(String name) throws EBaseException {
CryptoToken c = null;
- String certNames = "";
+ StringBuffer certNames = new StringBuffer();
try {
if (name.equals(Constants.PR_INTERNAL_TOKEN)) {
@@ -701,12 +699,12 @@ public final class JssSubsystem implements ICryptoSubsystem {
for (int i = 0; i < list.length; i++) {
String nickname = list[i].getNickname();
- if (i == 0)
- certNames = certNames + nickname;
- else
- certNames = certNames + "," + nickname;
+ if (i != 0)
+ certNames.append(",");
+ certNames.append(nickname);
}
- return certNames;
+
+ return certNames.toString();
} else
return "";
@@ -2004,7 +2002,8 @@ public final class JssSubsystem implements ICryptoSubsystem {
} catch (CertificateException e) {
// failed to decode as a certificate, try decoding
// as a PKCS #7 blob
- String content = "";
+ StringBuffer content = new StringBuffer();
+
String noHeader = CertUtils.stripCertBrackets(b64E);
String normalized = CertUtils.normalizeCertStr(noHeader);
byte data[] = Utils.base64decode(normalized);
@@ -2030,10 +2029,10 @@ public final class JssSubsystem implements ICryptoSubsystem {
ASN1Util.encode(cert));
CertPrettyPrint print = new CertPrettyPrint(certImpl);
- content += print.toString(Locale.getDefault());
+ content.append(print.toString(Locale.getDefault()));
}
- return content;
+ return content.toString();
}
} catch (InvalidBERException e) {
log(ILogger.LL_FAILURE, CMS.getLogMessage("CMSCORE_SECURITY_PRINT_CERT", e.toString()));
diff --git a/base/common/src/com/netscape/cmscore/security/KeyCertUtil.java b/base/common/src/com/netscape/cmscore/security/KeyCertUtil.java
index 7a980c621..844052e4b 100644
--- a/base/common/src/com/netscape/cmscore/security/KeyCertUtil.java
+++ b/base/common/src/com/netscape/cmscore/security/KeyCertUtil.java
@@ -151,7 +151,8 @@ public class KeyCertUtil {
public static String getTokenNames(CryptoManager manager)
throws TokenException {
- String tokenList = "";
+ StringBuffer tokenList = new StringBuffer();
+
@SuppressWarnings("unchecked")
Enumeration<CryptoToken> tokens = manager.getExternalTokens();
int num = 0;
@@ -159,16 +160,15 @@ public class KeyCertUtil {
while (tokens.hasMoreElements()) {
CryptoToken c = tokens.nextElement();
- if (num++ == 0)
- tokenList = tokenList + c.getName();
- else
- tokenList = tokenList + "," + c.getName();
+ if (num++ != 0)
+ tokenList.append(",");
+ tokenList.append(c.getName());
}
- if (tokenList.equals(""))
+ if (tokenList.length() == 0)
return Constants.PR_INTERNAL_TOKEN;
else
- return (tokenList + "," + Constants.PR_INTERNAL_TOKEN);
+ return (tokenList.toString() + "," + Constants.PR_INTERNAL_TOKEN);
}
public static String base64Encode(byte[] bytes) throws IOException {
diff --git a/base/common/src/com/netscape/cmscore/security/PWCBsdr.java b/base/common/src/com/netscape/cmscore/security/PWCBsdr.java
index 4017a7869..0ff50668c 100644
--- a/base/common/src/com/netscape/cmscore/security/PWCBsdr.java
+++ b/base/common/src/com/netscape/cmscore/security/PWCBsdr.java
@@ -17,7 +17,6 @@
// --- END COPYRIGHT BLOCK ---
package com.netscape.cmscore.security;
-import java.io.File;
import java.io.InputStream;
import java.io.OutputStream;
@@ -79,13 +78,12 @@ public class PWCBsdr implements PasswordCallback {
}
// System.out.println("after CMS.getConfigStore");
- if (File.separator.equals("/")) {
+
// Unix
mCB = new PWsdrConsolePasswordCallback(prompt);
- } else {
- mCB = new PWsdrConsolePasswordCallback(prompt);
+
// mCB = new PWsdrDialogPasswordCallback( prompt );
- }
+
// System.out.println( "Created PWCBsdr with prompt of "
// + mprompt );
diff --git a/base/common/src/com/netscape/cmscore/security/PWsdrCache.java b/base/common/src/com/netscape/cmscore/security/PWsdrCache.java
index 2e0dfd550..e4e8a432b 100644
--- a/base/common/src/com/netscape/cmscore/security/PWsdrCache.java
+++ b/base/common/src/com/netscape/cmscore/security/PWsdrCache.java
@@ -231,11 +231,12 @@ public class PWsdrCache {
*/
public void addEntry(String tag, String pwd, Hashtable<String, String> tagPwds) throws EBaseException {
- String stringToAdd = null;
+ StringBuffer stringToAdd = new StringBuffer();
+
String bufs = null;
if (tagPwds == null) {
- stringToAdd = tag + ":" + pwd + "\n";
+ stringToAdd.append(tag + ":" + pwd + System.getProperty("line.separator"));
} else {
Enumeration<String> enum1 = tagPwds.keys();
@@ -244,11 +245,7 @@ public class PWsdrCache {
pwd = tagPwds.get(tag);
debug("password tag: " + tag + " stored in " + mPWcachedb);
- if (stringToAdd == null) {
- stringToAdd = tag + ":" + pwd + "\n";
- } else {
- stringToAdd += tag + ":" + pwd + "\n";
- }
+ stringToAdd.append(tag + ":" + pwd + System.getProperty("line.separator"));
}
}
@@ -269,7 +266,7 @@ public class PWsdrCache {
bufs = hashtable2String(ht);
} else {
debug("adding new tag: " + tag);
- bufs = stringToAdd;
+ bufs = stringToAdd.toString();
}
// write update to cache
@@ -436,19 +433,14 @@ public class PWsdrCache {
public String hashtable2String(Hashtable<String, String> ht) {
Enumeration<String> enum1 = ht.keys();
- String returnString = null;
+ StringBuffer returnString = new StringBuffer();
while (enum1.hasMoreElements()) {
String tag = enum1.nextElement();
String pwd = ht.get(tag);
-
- if (returnString == null) {
- returnString = tag + ":" + pwd + "\n";
- } else {
- returnString += tag + ":" + pwd + "\n";
- }
+ returnString.append(tag + ":" + pwd + System.getProperty("line.separator"));
}
- return returnString;
+ return returnString.toString();
}
public Hashtable<String, String> string2Hashtable(String cache) {