summaryrefslogtreecommitdiffstats
path: root/base/util
diff options
context:
space:
mode:
authorChristina Fu <cfu@redhat.com>2012-04-05 13:37:01 -0700
committerChristina Fu <cfu@redhat.com>2012-04-05 13:37:01 -0700
commitdb4f081db1ea6eb38c185b34b118ed73c6a2b67d (patch)
treea94b99a921a1de8ab948fe8ddbaefd60a692a5ae /base/util
parenta37d66662a859bd706f449edddc3ae715ee2d520 (diff)
downloadpki-db4f081db1ea6eb38c185b34b118ed73c6a2b67d.tar.gz
pki-db4f081db1ea6eb38c185b34b118ed73c6a2b67d.tar.xz
pki-db4f081db1ea6eb38c185b34b118ed73c6a2b67d.zip
Fix for Bug 745278 - [RFE] ECC encryption keys cannot be archived.
For the ECC plan and the different phases, please refer to http://pki.fedoraproject.org/wiki/ECC_in_Dogtag Design for each phase is on the same wiki page. Note: the designs beyond phase 2 were more like a brain dump. Although I said "Do Not Review," you are free to take a peak at what's intended down the road. I will go back and take a closer look and refine/adjust the designs when I begin implementation for each new phase. What you need to know: * Problem 1 - nethsm issue: On the server side, if you turn on FIPS mode, in addition to nethsm, you need to attach certicom as well to have ECC SSL working on the server side. This problem has already been reported to Thales last year and they said they'd look into putting the item on their next release. Recently through a different contact, we learned there might be a way to "turn it on" (still waiting for their further instruction) * Problem 2- Certicom issue: This is a show-stopper for deployment. Initially, on the client side, I used Kai's special version of Xulrunner/Firefox, attached to Certicom token, so that the CRMF requests can be generated with key archival option. However, I encountered (or, re-encountered) an issue with certicom token. Certicom generates ECC keys with the wrong format (not PKCS7 conforming), which makes ECC key archival impossible on the server side if you use non-certicom token with DRM (but we expect an HSM in most product deployment). I have contacted Certicom for this issue, and they confirmed that they indeed have such issue. We are hoping they will fix it. But then you might ask, "I thought I saw some ECC enrollment profiles/javascripts being checked in? How were the tests done?" The tests for those profiles were done against this ECC key archival/recovery DRM prototype I implemented last year (needs to be turned on manually in 8.1), where I "cheated" (yeah, that's why it's called a prototype) by decrypting the private key in the CRMF on DRM, and then manipulating the byte array to strip off the offending bytes before archival. In the real, non-prototype implementation, which is what's in this patch, for security reasons, private keys are unwrapped directly onto the token during key archival, so there is no way to manipulate the keys in memory and bypass the Certicom issue. A word about Kai's special version of Xulrunner/Firefox. It is not yet publicly available (due out in Firefox 10.0.4 on RHEL 5.8). * Problem 3- Firefox with nethsm issue: Another option was to connect Kai's special version firefox with an HSM to test my DRM/JSS code. However, for whatever reason, I could not get SSL going between such Firefox and ECC CA ( I did not try very hard though, as I have one other option -- writing my own ECC CRMF generation tool. I might come back to try the nethsm Firefox idea later) My solution (how I work on this official implementation): * I hacked up a ECC CRMF tool by taking the CRMFPopClient (existing in current releases), gutting out the RSA part of the code, and replacing it with ECC code. I call it CRMFPopClientEC. Two types of ECC key pairs could be generated: ECDSA or ECDH (That's another benefit of writing my own tool -- I don't know if you can select which type to generate in the Javascript... maybe you can, I just don't know). I'm in no way condoning archival of signing keys!! This is just a test tool. This tool takes a curve name as option (along with others), generates an ECC key pair, crafts up an CRMF request with key archival option, and sends request directly to the specified CA. You will see a "Deferred" message in the HTML response (see attachment for example) Once CA agent approves the request, the archival request goes to DRM and the user private key is archived. For recovery, DRM agent selects key recovery, etc, and you get your pkcs12. I did some sanity test with the pkcs12 recovered: * Import the recovered pkcs12 into a certicom library: pk12util -d . -h "Certicom FIPS Cert/Key Services" -i userEC.p12 I also tested by retrieving a p12, importing it into a browser, and adding the user as an agent and the user could act as agent via ssl client auth to the CA. Finally, much of the RSA-centric code had been cleared out of the way at the time when I worked on the DRM ECC prototype, so you don't see much of that in this round. How do you test? Well, unless you want to use my CRMFPopClientEC tool hooked up with a nethsm (like I did), or write your own tool, you can't really test it until Certicom fixes their issue. (BTW CRMFPopClientEC can also be changed to work with ceriticom, although you would run into the same issue I mentioned above)
Diffstat (limited to 'base/util')
-rw-r--r--base/util/src/com/netscape/cmsutil/crypto/CryptoUtil.java92
1 files changed, 83 insertions, 9 deletions
diff --git a/base/util/src/com/netscape/cmsutil/crypto/CryptoUtil.java b/base/util/src/com/netscape/cmsutil/crypto/CryptoUtil.java
index 06f177887..82a98c082 100644
--- a/base/util/src/com/netscape/cmsutil/crypto/CryptoUtil.java
+++ b/base/util/src/com/netscape/cmsutil/crypto/CryptoUtil.java
@@ -218,15 +218,46 @@ public class CryptoUtil {
NoSuchTokenException,
NoSuchAlgorithmException,
TokenException {
+ return generateECCKeyPair(token, keysize, usage_ops, usage_mask,
+ false, -1, -1);
+ }
+
+ /*
+ * temporary, sensitive, and extractable usages are per defined in
+ * JSS pkcs11/PK11KeyPairGenerator.java
+ */
+ public static KeyPair generateECCKeyPair(String token, int keysize,
+ org.mozilla.jss.crypto.KeyPairGeneratorSpi.Usage[] usage_ops,
+ org.mozilla.jss.crypto.KeyPairGeneratorSpi.Usage[] usage_mask,
+ boolean temporary, int sensitive, int extractable)
+ throws CryptoManager.NotInitializedException,
+ NoSuchTokenException,
+ NoSuchAlgorithmException,
+ TokenException {
+
CryptoToken t = getTokenByName(token);
KeyPairAlgorithm alg = KeyPairAlgorithm.EC;
- KeyPairGenerator g = t.getKeyPairGenerator(alg);
+ KeyPairGenerator keygen = t.getKeyPairGenerator(alg);
- g.setKeyPairUsages(usage_ops, usage_mask);
- g.initialize(keysize);
+ keygen.setKeyPairUsages(usage_ops, usage_mask);
+ keygen.initialize(keysize);
+ keygen.setKeyPairUsages(usage_ops, usage_mask);
+ keygen.temporaryPairs(temporary);
- KeyPair pair = g.genKeyPair();
+ if (sensitive == 1 )
+ keygen.sensitivePairs(true);
+ else if (sensitive == 0)
+ keygen.sensitivePairs(false);
+
+ if (extractable == 1 )
+ keygen.extractablePairs(true);
+ else if (extractable == 0)
+ keygen.extractablePairs(false);
+
+ keygen.initialize(keysize);
+
+ KeyPair pair = keygen.genKeyPair();
return pair;
}
@@ -261,6 +292,20 @@ public class CryptoUtil {
return generateECCKeyPair(t, curveName, usage_ops, usage_mask);
}
+ public static KeyPair generateECCKeyPair(String token, String curveName,
+ org.mozilla.jss.crypto.KeyPairGeneratorSpi.Usage[] usage_ops,
+ org.mozilla.jss.crypto.KeyPairGeneratorSpi.Usage[] usage_mask,
+ boolean temporary, int sensitive, int extractable)
+ throws CryptoManager.NotInitializedException,
+ NoSuchTokenException,
+ NoSuchAlgorithmException,
+ TokenException {
+ CryptoToken t = getTokenByName(token);
+ return generateECCKeyPair(t, curveName, usage_ops, usage_mask,
+ temporary, sensitive, extractable);
+ }
+
+
public static KeyPair generateECCKeyPair(CryptoToken token, String curveName,
org.mozilla.jss.crypto.KeyPairGeneratorSpi.Usage[] usage_ops,
org.mozilla.jss.crypto.KeyPairGeneratorSpi.Usage[] usage_mask)
@@ -268,23 +313,52 @@ public class CryptoUtil {
NoSuchTokenException,
NoSuchAlgorithmException,
TokenException {
+ return generateECCKeyPair(token, curveName, usage_ops, usage_mask,
+ false, -1, -1);
+ }
+
+ /*
+ * temporary, sensitive, and extractable usages are per defined in
+ * JSS pkcs11/PK11KeyPairGenerator.java
+ */
+ public static KeyPair generateECCKeyPair(CryptoToken token, String curveName,
+ org.mozilla.jss.crypto.KeyPairGeneratorSpi.Usage[] usage_ops,
+ org.mozilla.jss.crypto.KeyPairGeneratorSpi.Usage[] usage_mask,
+ boolean temporary, int sensitive, int extractable)
+ throws CryptoManager.NotInitializedException,
+ NoSuchTokenException,
+ NoSuchAlgorithmException,
+ TokenException {
+
KeyPairAlgorithm alg = KeyPairAlgorithm.EC;
- KeyPairGenerator g = token.getKeyPairGenerator(alg);
+ KeyPairGenerator keygen = token.getKeyPairGenerator(alg);
+
+ keygen.setKeyPairUsages(usage_ops, usage_mask);
+ keygen.setKeyPairUsages(usage_ops, usage_mask);
+ keygen.temporaryPairs(temporary);
- g.setKeyPairUsages(usage_ops, usage_mask);
+ if (sensitive == 1 )
+ keygen.sensitivePairs(true);
+ else if (sensitive == 0)
+ keygen.sensitivePairs(false);
+
+ if (extractable == 1 )
+ keygen.extractablePairs(true);
+ else if (extractable == 0)
+ keygen.extractablePairs(false);
System.out.println("CryptoUtil: generateECCKeyPair: curve = " + curveName);
int curveCode = 0;
try {
- curveCode = g.getCurveCodeByName(curveName);
+ curveCode = keygen.getCurveCodeByName(curveName);
} catch (Exception e) {
System.out.println("CryptoUtil: generateECCKeyPair: " + e.toString());
throw new NoSuchAlgorithmException();
}
- g.initialize(curveCode);
+ keygen.initialize(curveCode);
System.out.println("CryptoUtil: generateECCKeyPair: after KeyPairGenerator initialize with:" + curveName);
- KeyPair pair = g.genKeyPair();
+ KeyPair pair = keygen.genKeyPair();
return pair;
}