Skip to content

Commit

Permalink
Fixed CryptoUtil.getTokenName().
Browse files Browse the repository at this point in the history
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
  • Loading branch information
edewata committed Oct 14, 2016
1 parent b123909 commit 5be68e3
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3435,7 +3435,7 @@ public static void deleteCert(String tokenname, String nickname) throws NotIniti
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("") &&
Expand Down
23 changes: 14 additions & 9 deletions base/util/src/com/netscape/cmsutil/crypto/CryptoUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,9 @@
@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;
Expand Down Expand Up @@ -472,21 +475,23 @@ public static boolean arraysEqual(byte[] bytes, byte[] ints) {
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);
}

/**
Expand Down

0 comments on commit 5be68e3

Please sign in to comment.