summaryrefslogtreecommitdiffstats
path: root/base/util
diff options
context:
space:
mode:
authorEndi S. Dewata <edewata@redhat.com>2017-01-24 16:14:42 +0100
committerEndi S. Dewata <edewata@redhat.com>2017-01-26 00:54:53 +0100
commit97ac6024c813621856b3cbfc8207416a46855108 (patch)
treef98e71baabba7c35de7e71837c7d564f9999dab8 /base/util
parent49dbe641d3f1fd8fe4d8c141a93b7533eea1b70f (diff)
downloadpki-97ac6024c813621856b3cbfc8207416a46855108.tar.gz
pki-97ac6024c813621856b3cbfc8207416a46855108.tar.xz
pki-97ac6024c813621856b3cbfc8207416a46855108.zip
Updated CryptoUtil.
The CryptoUtil has been modified to provide two separate methods to obtain a token given the token name: - getCryptoToken() returns crypto token - getKeyStorageToken() returns key storage token The getKeyStorageToken() was renamed from the existing getTokenByName(). All codes using the old method have been updated accordingly. If the provided token name matches internal token name the methods will return the corresponding internal crypto/key storage token. The isInternalToken() was modified to check for empty string in addition to the short and full name of the internal token. https://fedorahosted.org/pki/ticket/2556
Diffstat (limited to 'base/util')
-rw-r--r--base/util/src/com/netscape/cmsutil/crypto/CryptoUtil.java32
1 files changed, 25 insertions, 7 deletions
diff --git a/base/util/src/com/netscape/cmsutil/crypto/CryptoUtil.java b/base/util/src/com/netscape/cmsutil/crypto/CryptoUtil.java
index b6b5e6af3..57119ce2c 100644
--- a/base/util/src/com/netscape/cmsutil/crypto/CryptoUtil.java
+++ b/base/util/src/com/netscape/cmsutil/crypto/CryptoUtil.java
@@ -47,6 +47,7 @@ import java.util.Random;
import java.util.StringTokenizer;
import java.util.Vector;
+import org.apache.commons.lang.StringUtils;
import org.mozilla.jss.CryptoManager;
import org.mozilla.jss.CryptoManager.NotInitializedException;
import org.mozilla.jss.NoSuchTokenException;
@@ -476,13 +477,30 @@ public class CryptoUtil {
}
public static boolean isInternalToken(String name) {
- return name.equalsIgnoreCase(INTERNAL_TOKEN_NAME) || name.equalsIgnoreCase(INTERNAL_TOKEN_FULL_NAME);
+ return StringUtils.isEmpty(name)
+ || name.equalsIgnoreCase(INTERNAL_TOKEN_NAME)
+ || name.equalsIgnoreCase(INTERNAL_TOKEN_FULL_NAME);
}
/**
- * Retrieves handle to a JSS token.
+ * Retrieves handle to a crypto token.
*/
- public static CryptoToken getTokenByName(String name)
+ public static CryptoToken getCryptoToken(String name)
+ throws NotInitializedException, NoSuchTokenException {
+
+ CryptoManager cm = CryptoManager.getInstance();
+
+ if (isInternalToken(name)) {
+ return cm.getInternalCryptoToken();
+ }
+
+ return cm.getTokenByName(name);
+ }
+
+ /**
+ * Retrieves handle to a key store token.
+ */
+ public static CryptoToken getKeyStorageToken(String name)
throws NotInitializedException, NoSuchTokenException {
CryptoManager cm = CryptoManager.getInstance();
@@ -502,7 +520,7 @@ public class CryptoUtil {
NoSuchTokenException,
NoSuchAlgorithmException,
TokenException {
- CryptoToken t = getTokenByName(token);
+ CryptoToken t = getKeyStorageToken(token);
KeyPairGenerator g = t.getKeyPairGenerator(KeyPairAlgorithm.RSA);
g.initialize(keysize);
@@ -555,7 +573,7 @@ public class CryptoUtil {
NoSuchAlgorithmException,
TokenException {
- CryptoToken t = getTokenByName(token);
+ CryptoToken t = getKeyStorageToken(token);
KeyPairAlgorithm alg = KeyPairAlgorithm.EC;
KeyPairGenerator keygen = t.getKeyPairGenerator(alg);
@@ -608,7 +626,7 @@ public class CryptoUtil {
NoSuchTokenException,
NoSuchAlgorithmException,
TokenException {
- CryptoToken t = getTokenByName(token);
+ CryptoToken t = getKeyStorageToken(token);
return generateECCKeyPair(t, curveName, usage_ops, usage_mask);
}
@@ -620,7 +638,7 @@ public class CryptoUtil {
NoSuchTokenException,
NoSuchAlgorithmException,
TokenException {
- CryptoToken t = getTokenByName(token);
+ CryptoToken t = getKeyStorageToken(token);
return generateECCKeyPair(t, curveName, usage_ops, usage_mask,
temporary, sensitive, extractable);
}