On further testing and reading the description of generateCRMFRequest() method doc, I figured out why the key generation was failing.
I have to pass keySize as integer type not string type.
function testKeyGeneration()
{
doGenerateCRMFCSRByCryptoTest("cn=xxx,o=abc.com", "rsa', parseInt("1024")); doGenerateCRMFCSRByCryptoTest("cn=xxx,o=abc.com", "dsa', parseInt("1024")); doGenerateCRMFCSRByCryptoTest("cn=xxx,o=abc.com", "ec', parseInt("1024"));
}
The key genartion now works for RSA and DSA key types but it still fails for EC key type.
Is  key generation for EC type is supported on Firefox 3.0.10?
--
Subrata


Subrata Mazumdar wrote:
Hi,
I am not able generate key using window.crypto.generateCRMFRequest() method. I have tried all there possible types : rsa, dsa, and ec. I am attached my test code fragment. I am running the test within an add-on - on Firefox 3.0.10/Fedora8.
I am getting   NS_ERROR_FAILURE in exception message.


function testKeyGeneration()
{
   doGenerateCRMFCSRByCryptoTest("cn=xxx,o=abc.com", "rsa', "1024");
   doGenerateCRMFCSRByCryptoTest("cn=xxx,o=abc.com", "dsa', "1024");
   doGenerateCRMFCSRByCryptoTest("cn=xxx,o=abc.com", "ec', "1024");
}
var crmfObject = null;
function doGenerateCRMFCSRByCryptoTest (subject, keyType, keySize)
{
// For more info: https://developer.mozilla.org/En/JavaScript_crypto/GenerateCRMFRequest

   var reqDN = subject;                // argv[0]
   var regTokenArg = null;             // argv[1]
   var authenticatorArg = null;        // argv[2]
   var escrowCertArg = null;           // argv[3]
   var jsCallbackArg = doGenerateCRMFCSRByCryptoCB(); // argv[4]
   var keyParams = null;
   var keyGenAlg = null;
   // var keyGenAlg = "rsa-dual-use";

   if (keyType == "rsa") {
       keyGenAlg = "rsa-dual-use";
       keyParams = null;
   }
   else if (keyType == "dsa") {
       keyGenAlg = "dsa-sign-nonrepudiation";
       keyParams = null;
   }
   if (keyType == "ec") {
keyGenAlg = "ec-dual-use"; // ec-sign-nonrepudiation | ec-sign | ec-nonrepudiation | ec-ex
       keyParams = "curve=secp256r1";
   }
   try {
       crmfObject = window.crypto.generateCRMFRequest(
subject, regTokenArg, authenticatorArg, escrowCertArg, jsCallbackFuncArg,
                       keySize,  keyParams,  keyGenAlg
                       );
   } catch (ex) {
dump("doGenerateCRMFCSRByCryptoTest(): window.crypto.generateCRMFRequest() failed - " + ex + "\n");
       return;
   }
   alert("crmfObject.request: " + crmfObject.request);
}
function doGenerateCRMFCSRByCryptoCB()
{
dump("uploadCRMFCSRForm.js: doGenerateCRMFCSRByCryptoDummyCB(): ......Start.\n"); dump("uploadCRMFCSRForm.js: doGenerateCRMFCSRByCryptoDummyCB(): ......End.\n");
}

What am I doing wrong? It used to work for RSA key type on Firefox 1.5. I have not used the code since then.

The main reason I testing this method is I failed to generate key for DSA and EC tyeps using keygen tag. So I thiought that I will see if the key generation work using the window.crypto.generateCRMFRequest() method. I have tried all three links at the bottom this page: https://developer.mozilla.org/En/HTML/HTML_Extensions/KEYGEN_Tag. I only see key-generation dialog for RSA key type. For other two cases, keys are not generated - instead the choice name (HIGH or MEDIUM) is used for the key.

Any help will be greatly appreciated. Thanks.
--
dev-tech-crypto mailing list
dev-tech-crypto@lists.mozilla.org
https://lists.mozilla.org/listinfo/dev-tech-crypto

Reply via email to