summaryrefslogtreecommitdiffstats
path: root/pki/base/common/src/com/netscape/cmscore/security/PWsdrCache.java
diff options
context:
space:
mode:
Diffstat (limited to 'pki/base/common/src/com/netscape/cmscore/security/PWsdrCache.java')
-rw-r--r--pki/base/common/src/com/netscape/cmscore/security/PWsdrCache.java146
1 files changed, 68 insertions, 78 deletions
diff --git a/pki/base/common/src/com/netscape/cmscore/security/PWsdrCache.java b/pki/base/common/src/com/netscape/cmscore/security/PWsdrCache.java
index 12412f59..1deb64e0 100644
--- a/pki/base/common/src/com/netscape/cmscore/security/PWsdrCache.java
+++ b/pki/base/common/src/com/netscape/cmscore/security/PWsdrCache.java
@@ -17,7 +17,6 @@
// --- END COPYRIGHT BLOCK ---
package com.netscape.cmscore.security;
-
import java.io.BufferedReader;
import java.io.ByteArrayOutputStream;
import java.io.File;
@@ -46,7 +45,6 @@ import com.netscape.certsrv.base.EBaseException;
import com.netscape.certsrv.logging.ILogger;
import com.netscape.cmsutil.util.Utils;
-
/*
* A class for managing passwords in the SDR password cache
*
@@ -86,13 +84,13 @@ public class PWsdrCache {
try {
cm = CryptoManager.getInstance();
mTokenName = CMS.getConfigStore().getString(PROP_PWC_TOKEN_NAME);
- log (ILogger.LL_DEBUG, "pwcTokenname specified. Use token for SDR key. tokenname= "+mTokenName);
+ log(ILogger.LL_DEBUG, "pwcTokenname specified. Use token for SDR key. tokenname= " + mTokenName);
mToken = cm.getTokenByName(mTokenName);
} catch (NotInitializedException e) {
- log (ILogger.LL_FAILURE, e.toString());
+ log(ILogger.LL_FAILURE, e.toString());
throw new EBaseException(e.toString());
} catch (Exception e) {
- log (ILogger.LL_DEBUG, "no pwcTokenname specified, use internal token for SDR key");
+ log(ILogger.LL_DEBUG, "no pwcTokenname specified, use internal token for SDR key");
mToken = cm.getInternalKeyStorageToken();
}
}
@@ -103,11 +101,11 @@ public class PWsdrCache {
if (mKeyID == null) {
try {
String keyID = CMS.getConfigStore().getString(PROP_PWC_KEY_ID);
- log (ILogger.LL_DEBUG, "retrieved PWC SDR key");
+ log(ILogger.LL_DEBUG, "retrieved PWC SDR key");
mKeyID = base64Decode(keyID);
-
+
} catch (Exception e) {
- log (ILogger.LL_DEBUG, "no pwcSDRKey specified");
+ log(ILogger.LL_DEBUG, "no pwcSDRKey specified");
throw new EBaseException(e.toString());
}
}
@@ -131,10 +129,10 @@ public class PWsdrCache {
cm = CryptoManager.getInstance();
if (mTokenName != null) {
mToken = cm.getTokenByName(mTokenName);
- mToken = cm.getInternalKeyStorageToken();
- debug("PWsdrCache: mToken = "+mTokenName);
+ mToken = cm.getInternalKeyStorageToken();
+ debug("PWsdrCache: mToken = " + mTokenName);
} else {
- mToken = cm.getInternalKeyStorageToken();
+ mToken = cm.getInternalKeyStorageToken();
debug("PWsdrCache: mToken = internal");
}
}
@@ -147,50 +145,48 @@ public class PWsdrCache {
return mTokenName;
}
- public void deleteUniqueNamedKey( String nickName )
- throws Exception
- {
- KeyManager km = new KeyManager( mToken );
- km.deleteUniqueNamedKey( nickName );
+ public void deleteUniqueNamedKey(String nickName)
+ throws Exception {
+ KeyManager km = new KeyManager(mToken);
+ km.deleteUniqueNamedKey(nickName);
}
- public byte[] generateSDRKey () throws Exception {
- return generateSDRKeyWithNickName(PROP_PWC_NICKNAME);
+ public byte[] generateSDRKey() throws Exception {
+ return generateSDRKeyWithNickName(PROP_PWC_NICKNAME);
}
- public byte[] generateSDRKeyWithNickName (String nickName)
- throws Exception
- {
+ public byte[] generateSDRKeyWithNickName(String nickName)
+ throws Exception {
try {
if (mIsTool != true) {
// generate SDR key
KeyManager km = new KeyManager(mToken);
try {
- // Bugscape Bug #54838: Due to the CMS cloning feature,
- // we must check for the presence of
- // a uniquely named symmetric key
- // prior to making an attempt to
- // generate it!
+ // Bugscape Bug #54838: Due to the CMS cloning feature,
+ // we must check for the presence of
+ // a uniquely named symmetric key
+ // prior to making an attempt to
+ // generate it!
//
- if( !( km.uniqueNamedKeyExists( nickName ) ) ) {
- mKeyID = km.generateUniqueNamedKey( nickName );
+ if (!(km.uniqueNamedKeyExists(nickName))) {
+ mKeyID = km.generateUniqueNamedKey(nickName);
}
} catch (TokenException e) {
- log (0, "generateSDRKey() failed on "+e.toString());
+ log(0, "generateSDRKey() failed on " + e.toString());
throw e;
}
}
} catch (Exception e) {
- log (ILogger.LL_FAILURE, e.toString());
+ log(ILogger.LL_FAILURE, e.toString());
throw e;
}
return mKeyID;
}
public byte[] base64Decode(String s) throws IOException {
- byte[] d = com.netscape.osutil.OSUtil.AtoB(s);
- return d;
+ byte[] d = com.netscape.osutil.OSUtil.AtoB(s);
+ return d;
}
public static String base64Encode(byte[] bytes) throws IOException {
@@ -199,9 +195,9 @@ public class PWsdrCache {
ByteArrayOutputStream output = new ByteArrayOutputStream();
Base64OutputStream b64 = new Base64OutputStream(new
PrintStream(new
- FilterOutputStream(output)
+ FilterOutputStream(output)
)
- );
+ );
b64.write(bytes);
b64.flush();
@@ -211,10 +207,9 @@ public class PWsdrCache {
return output.toString("8859_1");
}
-
// for PWCBsdr
public PWsdrCache(String pwCache, ILogger logger) throws
- EBaseException {
+ EBaseException {
mLogger = logger;
mPWcachedb = pwCache;
initToken();
@@ -236,7 +231,7 @@ public class PWsdrCache {
* add passwd in pwcache.
*/
public void addEntry(String tag, String pwd, Hashtable tagPwds) throws EBaseException {
-
+
String stringToAdd = null;
String bufs = null;
@@ -249,7 +244,7 @@ public class PWsdrCache {
tag = (String) enum1.nextElement();
pwd = (String) tagPwds.get(tag);
debug("password tag: " + tag + " stored in " + mPWcachedb);
-
+
if (stringToAdd == null) {
stringToAdd = tag + ":" + pwd + "\n";
} else {
@@ -262,7 +257,7 @@ public class PWsdrCache {
if (dcrypts != null) {
// converts to Hashtable, replace if tag exists, add
- // if tag doesn't exist
+ // if tag doesn't exist
Hashtable ht = string2Hashtable(dcrypts);
if (ht.containsKey(tag) == false) {
@@ -277,7 +272,7 @@ public class PWsdrCache {
debug("adding new tag: " + tag);
bufs = stringToAdd;
}
-
+
// write update to cache
writePWcache(bufs);
}
@@ -292,7 +287,7 @@ public class PWsdrCache {
if (dcrypts != null) {
// converts to Hashtable, replace if tag exists, add
- // if tag doesn't exist
+ // if tag doesn't exist
Hashtable ht = string2Hashtable(dcrypts);
if (ht.containsKey(tag) == false) {
@@ -307,7 +302,7 @@ public class PWsdrCache {
debug("password cache contains no tags");
return;
}
-
+
// write update to cache
writePWcache(bufs);
}
@@ -394,35 +389,35 @@ public class PWsdrCache {
File origFile = new File(mPWcachedb);
try {
- if( Utils.isNT() ) {
+ if (Utils.isNT()) {
// NT is very picky on the path
- Utils.exec( "copy " +
- tmpPWcache.getAbsolutePath().replace( '/',
- '\\' ) +
+ Utils.exec("copy " +
+ tmpPWcache.getAbsolutePath().replace('/',
+ '\\') +
" " +
- origFile.getAbsolutePath().replace( '/',
- '\\' ) );
+ origFile.getAbsolutePath().replace('/',
+ '\\'));
} else {
// Create a copy of the original file which
// preserves the original file permissions.
- Utils.exec( "cp -p " + tmpPWcache.getAbsolutePath() + " " +
- origFile.getAbsolutePath() );
+ Utils.exec("cp -p " + tmpPWcache.getAbsolutePath() + " " +
+ origFile.getAbsolutePath());
}
// Remove the original file if and only if
// the backup copy was successful.
- if( origFile.exists() ) {
- if( !Utils.isNT() ) {
+ if (origFile.exists()) {
+ if (!Utils.isNT()) {
try {
- Utils.exec( "chmod 00660 " +
- origFile.getCanonicalPath() );
- } catch( IOException e ) {
- CMS.debug( "Unable to change file permissions on "
- + origFile.toString() );
+ Utils.exec("chmod 00660 " +
+ origFile.getCanonicalPath());
+ } catch (IOException e) {
+ CMS.debug("Unable to change file permissions on "
+ + origFile.toString());
}
}
tmpPWcache.delete();
- debug( "operation completed for " + mPWcachedb );
+ debug("operation completed for " + mPWcachedb);
}
} catch (Exception exx) {
log(ILogger.LL_FAILURE, CMS.getLogMessage("CMSCORE_SECURITY_PW_CACHE", exx.toString()));
@@ -447,7 +442,7 @@ public class PWsdrCache {
while (enum1.hasMoreElements()) {
String tag = (String) enum1.nextElement();
String pwd = (String) ht.get(tag);
-
+
if (returnString == null) {
returnString = tag + ":" + pwd + "\n";
} else {
@@ -475,14 +470,14 @@ public class PWsdrCache {
ht.put(tag.trim(), passwd.trim());
} else {
- //invalid format...log or throw...later
+ // invalid format...log or throw...later
}
}
return ht;
}
/*
- * get password from cache. This one supplies cache file name
+ * get password from cache. This one supplies cache file name
*/
public Password getEntry(String fileName, String tag) {
mPWcachedb = fileName;
@@ -490,8 +485,8 @@ public class PWsdrCache {
}
/*
- * if tag found with pwd, return it
- * if tag not found, return null, which will cause it to give up
+ * if tag found with pwd, return it if tag not found, return null, which
+ * will cause it to give up
*/
public Password getEntry(String tag) {
Hashtable pwTable = null;
@@ -532,7 +527,7 @@ public class PWsdrCache {
}
}
- //copied from IOUtil.java
+ // copied from IOUtil.java
/**
* Checks if this is NT.
*/
@@ -566,22 +561,17 @@ public class PWsdrCache {
if (process.exitValue() == 0) {
/**
- pOut = new BufferedReader(
- new InputStreamReader(process.getInputStream()));
- while ((l = pOut.readLine()) != null) {
- System.out.println(l);
- }
+ * pOut = new BufferedReader( new
+ * InputStreamReader(process.getInputStream())); while ((l =
+ * pOut.readLine()) != null) { System.out.println(l); }
**/
return true;
} else {
/**
- pOut = new BufferedReader(
- new InputStreamReader(process.getErrorStream()));
- l = null;
- while ((l = pOut.readLine()) != null) {
- System.out.println(l);
- }
+ * pOut = new BufferedReader( new
+ * InputStreamReader(process.getErrorStream())); l = null; while
+ * ((l = pOut.readLine()) != null) { System.out.println(l); }
**/
return false;
}
@@ -599,7 +589,7 @@ public class PWsdrCache {
public void log(int level, String msg) {
if (mLogger != null) {
mLogger.log(ILogger.EV_SYSTEM, ILogger.S_OTHER, level,
- "PWsdrCache " + msg);
+ "PWsdrCache " + msg);
} else if (mIsTool) {
System.out.println(msg);
} // else it's most likely the installation wizard...no logging
@@ -636,9 +626,9 @@ public class PWsdrCache {
line.length());
debug(tag.trim() +
- " : " + passwd.trim());
+ " : " + passwd.trim());
} else {
- //invalid format...log or throw...later
+ // invalid format...log or throw...later
debug("invalid format");
}
}