Blame SOURCES/jss-key_pair_usage_with_op_flags.patch

b93447
diff -rupN jss-4.2.5/mozilla/security/jss/lib/jss.def jss-4.2.6/mozilla/security/jss/lib/jss.def
b93447
--- jss-4.2.5/mozilla/security/jss/lib/jss.def	2007-05-08 18:40:14.000000000 -0700
b93447
+++ jss-4.2.6/mozilla/security/jss/lib/jss.def	2009-05-30 01:57:48.000000000 -0700
b93447
@@ -316,3 +316,12 @@ Java_org_mozilla_jss_ssl_SSLSocket_isFip
b93447
 ;+    local:
b93447
 ;+       *;
b93447
 ;+};
b93447
+;+JSS_4.2.6 {     # JSS 4.2.6 release
b93447
+;+    global:
b93447
+Java_org_mozilla_jss_pkcs11_PK11KeyPairGenerator_generateECKeyPairWithOpFlags;
b93447
+Java_org_mozilla_jss_pkcs11_PK11KeyPairGenerator_generateRSAKeyPairWithOpFlags;
b93447
+Java_org_mozilla_jss_pkcs11_PK11KeyPairGenerator_generateDSAKeyPairWithOpFlags;
b93447
+;+    local:
b93447
+;+       *;
b93447
+;+};
b93447
+
b93447
diff -rupN jss-4.2.5/mozilla/security/jss/org/mozilla/jss/crypto/KeyPairGenerator.java jss-4.2.6/mozilla/security/jss/org/mozilla/jss/crypto/KeyPairGenerator.java
b93447
--- jss-4.2.5/mozilla/security/jss/org/mozilla/jss/crypto/KeyPairGenerator.java	2005-11-14 14:15:06.000000000 -0800
b93447
+++ jss-4.2.6/mozilla/security/jss/org/mozilla/jss/crypto/KeyPairGenerator.java	2009-05-22 07:40:14.000000000 -0700
b93447
@@ -81,7 +81,6 @@ public class KeyPairGenerator {
b93447
 	genKeyPair() throws TokenException {
b93447
 		return engine.generateKeyPair();
b93447
 	}
b93447
-
b93447
     /**
b93447
      * @return The type of key that this generator generates.
b93447
      */
b93447
@@ -192,6 +191,15 @@ public class KeyPairGenerator {
b93447
         engine.extractablePairs(extractable);
b93447
     }
b93447
 
b93447
+    public void setKeyPairUsages(KeyPairGeneratorSpi.Usage[] usages, 
b93447
+                                 KeyPairGeneratorSpi.Usage[] usages_mask) {
b93447
+        engine.setKeyPairUsages(usages,usages_mask);
b93447
+    }
b93447
+   
b93447
+
b93447
+
b93447
+
b93447
+
b93447
 	protected KeyPairAlgorithm algorithm;
b93447
 	protected KeyPairGeneratorSpi engine;
b93447
 }
b93447
diff -rupN jss-4.2.5/mozilla/security/jss/org/mozilla/jss/crypto/KeyPairGeneratorSpi.java jss-4.2.6/mozilla/security/jss/org/mozilla/jss/crypto/KeyPairGeneratorSpi.java
b93447
--- jss-4.2.5/mozilla/security/jss/org/mozilla/jss/crypto/KeyPairGeneratorSpi.java	2005-11-14 14:15:06.000000000 -0800
b93447
+++ jss-4.2.6/mozilla/security/jss/org/mozilla/jss/crypto/KeyPairGeneratorSpi.java	2009-05-30 03:24:31.000000000 -0700
b93447
@@ -60,4 +60,38 @@ public abstract class KeyPairGeneratorSp
b93447
     public abstract void extractablePairs(boolean extractable);
b93447
 
b93447
     public abstract boolean keygenOnInternalToken();
b93447
+
b93447
+    /**
b93447
+     * In PKCS #11, each keypair can be marked with the operations it will
b93447
+     * be used to perform. Some tokens require that a key be marked for
b93447
+     * an operation before the key can be used to perform that operation;
b93447
+     * other tokens don't care. NSS provides a way to specify a set of
b93447
+     * flags and a corresponding mask for these flags.  If a specific usage
b93447
+     * is desired set the value for that usage. If it is not set, let NSS
b93447
+     * behave in it's default fashion.  If a behavior is desired, also set
b93447
+     * that behavior in the mask as well as the flags.
b93447
+     * 
b93447
+     */
b93447
+    public final static class Usage {
b93447
+        private Usage() { }
b93447
+        private Usage(int val) { this.val = val;}
b93447
+        private int val;
b93447
+
b93447
+        public int getVal() { return val; }
b93447
+
b93447
+        // these enums must match the 
b93447
+        // and the opFlagForUsage list in PK11KeyPairGenerator.java
b93447
+        public static final Usage ENCRYPT = new Usage(0);
b93447
+        public static final Usage DECRYPT = new Usage(1);
b93447
+        public static final Usage SIGN = new Usage(2);
b93447
+        public static final Usage SIGN_RECOVER = new Usage(3);
b93447
+        public static final Usage VERIFY = new Usage(4);
b93447
+        public static final Usage VERIFY_RECOVER = new Usage(5);
b93447
+        public static final Usage WRAP = new Usage(6);
b93447
+        public static final Usage UNWRAP = new Usage(7);
b93447
+        public static final Usage DERIVE = new Usage(8);
b93447
+    }
b93447
+
b93447
+    public abstract void setKeyPairUsages(KeyPairGeneratorSpi.Usage[] usages, 
b93447
+                                          KeyPairGeneratorSpi.Usage[] usages_mask);
b93447
 }
b93447
diff -rupN jss-4.2.5/mozilla/security/jss/org/mozilla/jss/pkcs11/PK11KeyPairGenerator.c jss-4.2.6/mozilla/security/jss/org/mozilla/jss/pkcs11/PK11KeyPairGenerator.c
b93447
--- jss-4.2.5/mozilla/security/jss/org/mozilla/jss/pkcs11/PK11KeyPairGenerator.c	2006-02-22 17:21:42.000000000 -0800
b93447
+++ jss-4.2.6/mozilla/security/jss/org/mozilla/jss/pkcs11/PK11KeyPairGenerator.c	2009-06-02 10:36:46.819581000 -0700
b93447
@@ -120,13 +120,11 @@ finish:
b93447
 
b93447
 int PK11_NumberObjectsFor(PK11SlotInfo*, CK_ATTRIBUTE*, int);
b93447
 
b93447
-/*
b93447
- * make a common key gen function for both this file and PK11Token.c
b93447
- */
b93447
 SECStatus
b93447
-JSS_PK11_generateKeyPair(JNIEnv *env, CK_MECHANISM_TYPE mechanism, 
b93447
+JSS_PK11_generateKeyPairWithOpFlags(JNIEnv *env, CK_MECHANISM_TYPE mechanism, 
b93447
     PK11SlotInfo *slot, SECKEYPublicKey **pubk, SECKEYPrivateKey **privk,
b93447
-    void *params, PRBool temporary, jint sensitive, jint extractable)
b93447
+    void *params, PRBool temporary, jint sensitive, jint extractable,
b93447
+    jint op_flags, jint op_flags_mask)
b93447
 {
b93447
     PK11AttrFlags attrFlags = 0;
b93447
     *privk=NULL;
b93447
@@ -173,12 +171,16 @@ JSS_PK11_generateKeyPair(JNIEnv *env, CK
b93447
     } else {
b93447
         attrFlags |= (PK11_ATTR_INSENSITIVE | PK11_ATTR_PUBLIC);
b93447
     }
b93447
-    *privk = PK11_GenerateKeyPairWithFlags(slot,
b93447
+
b93447
+    *privk = PK11_GenerateKeyPairWithOpFlags(slot,
b93447
                                           mechanism,
b93447
                                           params, 
b93447
                                           pubk,
b93447
                                           attrFlags,
b93447
+                                          (CK_FLAGS) op_flags,
b93447
+                                          (CK_FLAGS) op_flags_mask/* the ones we don't want*/,
b93447
                                           NULL /* default PW callback */ );
b93447
+
b93447
     if( *privk == NULL ) {
b93447
         int errLength;
b93447
         char *errBuf;
b93447
@@ -217,13 +219,28 @@ finish:
b93447
     return SECFailure;
b93447
 }
b93447
 
b93447
+/*
b93447
+ * make a common key gen function for both this file and PK11Token.c
b93447
+ */
b93447
+SECStatus
b93447
+JSS_PK11_generateKeyPair(JNIEnv *env, CK_MECHANISM_TYPE mechanism,
b93447
+    PK11SlotInfo *slot, SECKEYPublicKey **pubk, SECKEYPrivateKey **privk,
b93447
+    void *params, PRBool temporary, jint sensitive, jint extractable)
b93447
+{
b93447
+
b93447
+    return JSS_PK11_generateKeyPairWithOpFlags(env, mechanism, slot, pubk, privk, params, temporary, sensitive, extractable, 0, 0);
b93447
+}
b93447
+
b93447
+
b93447
 /**********************************************************************
b93447
- * Local generic helper
b93447
+ * Local generic helpers
b93447
  */
b93447
+
b93447
 static jobject 
b93447
-PK11KeyPairGenerator(JNIEnv *env, jobject this, jobject token, 
b93447
+PK11KeyPairGeneratorWithOpFlags(JNIEnv *env, jobject this, jobject token, 
b93447
     CK_MECHANISM_TYPE mechanism, void *params, 
b93447
-    jboolean temporary, jint sensitive, jint extractable)
b93447
+    jboolean temporary, jint sensitive, jint extractable,
b93447
+    jint op_flags, jint op_flags_mask)
b93447
 {
b93447
     PK11SlotInfo* slot;
b93447
     SECKEYPrivateKey *privk=NULL;
b93447
@@ -242,8 +259,8 @@ PK11KeyPairGenerator(JNIEnv *env, jobjec
b93447
     }
b93447
     PR_ASSERT(slot != NULL);
b93447
 
b93447
-    rv = JSS_PK11_generateKeyPair(env, mechanism, slot, &pubk, &privk,
b93447
-    	params, temporary, sensitive, extractable);
b93447
+    rv = JSS_PK11_generateKeyPairWithOpFlags(env, mechanism, slot, &pubk, &privk,
b93447
+    	params, temporary, sensitive, extractable, op_flags, op_flags_mask);
b93447
     if (rv != SECSuccess) {
b93447
         goto finish;
b93447
     }
b93447
@@ -267,6 +284,16 @@ finish:
b93447
     return keyPair;
b93447
 }
b93447
 
b93447
+static jobject
b93447
+PK11KeyPairGenerator(JNIEnv *env, jobject this, jobject token,
b93447
+    CK_MECHANISM_TYPE mechanism, void *params,
b93447
+    jboolean temporary, jint sensitive, jint extractable)
b93447
+{
b93447
+    return PK11KeyPairGeneratorWithOpFlags(env, this, token, mechanism, params, temporary, sensitive, extractable, 0, 0);
b93447
+}
b93447
+
b93447
+
b93447
+
b93447
 /**********************************************************************
b93447
  * PK11KeyPairGenerator.generateRSAKeyPair
b93447
  */
b93447
@@ -289,6 +316,30 @@ Java_org_mozilla_jss_pkcs11_PK11KeyPairG
b93447
      &params, temporary, sensitive, extractable);
b93447
 }
b93447
 
b93447
+/**********************************************************************
b93447
+ * PK11KeyPairGenerator.generateRSAKeyPairWithOpFlags
b93447
+ */
b93447
+JNIEXPORT jobject JNICALL
b93447
+Java_org_mozilla_jss_pkcs11_PK11KeyPairGenerator_generateRSAKeyPairWithOpFlags
b93447
+  (JNIEnv *env, jobject this, jobject token, jint keySize, jlong publicExponent,
b93447
+    jboolean temporary, jint sensitive, jint extractable,
b93447
+    jint op_flags, jint op_flags_mask)
b93447
+{
b93447
+    PK11RSAGenParams params;
b93447
+
b93447
+    PR_ASSERT(env!=NULL && this!=NULL && token!=NULL);
b93447
+
b93447
+    /**************************************************
b93447
+     * setup parameters
b93447
+     *************************************************/
b93447
+    params.keySizeInBits = keySize;
b93447
+    params.pe = publicExponent;
b93447
+
b93447
+    return PK11KeyPairGeneratorWithOpFlags(env, this, token, CKM_RSA_PKCS_KEY_PAIR_GEN,
b93447
+     &params, temporary, sensitive, extractable, op_flags, op_flags_mask);
b93447
+}
b93447
+
b93447
+
b93447
 #define ZERO_SECITEM(item) {(item).len=0; (item).data=NULL;}
b93447
 
b93447
 /**********************************************************************
b93447
@@ -339,6 +390,57 @@ finish:
b93447
     return keyPair;
b93447
 }
b93447
 
b93447
+/**********************************************************************
b93447
+ *
b93447
+ * PK11KeyPairGenerator.generateDSAKeyPair
b93447
+ *
b93447
+ */
b93447
+JNIEXPORT jobject JNICALL
b93447
+Java_org_mozilla_jss_pkcs11_PK11KeyPairGenerator_generateDSAKeyPairWithOpFlags
b93447
+  (JNIEnv *env, jobject this, jobject token, jbyteArray P, jbyteArray Q,
b93447
+    jbyteArray G, jboolean temporary, jint sensitive, jint extractable,
b93447
+    jint op_flags, jint op_flags_mask)
b93447
+{
b93447
+    SECItem p, q, g;
b93447
+    PQGParams *params=NULL;
b93447
+    jobject keyPair=NULL;
b93447
+
b93447
+    PR_ASSERT(env!=NULL && this!=NULL && token!=NULL && P!=NULL && Q!=NULL
b93447
+                && G!=NULL);
b93447
+
b93447
+    /* zero these so we can free them indiscriminately later */
b93447
+    ZERO_SECITEM(p);
b93447
+    ZERO_SECITEM(q);
b93447
+    ZERO_SECITEM(g);
b93447
+
b93447
+    /**************************************************
b93447
+     * Setup the parameters
b93447
+     *************************************************/
b93447
+    if( JSS_ByteArrayToOctetString(env, P, &p) ||
b93447
+        JSS_ByteArrayToOctetString(env, Q, &q) ||
b93447
+        JSS_ByteArrayToOctetString(env, G, &g) )
b93447
+    {
b93447
+        PR_ASSERT( (*env)->ExceptionOccurred(env) != NULL);
b93447
+        goto finish;
b93447
+    }
b93447
+    params = PK11_PQG_NewParams(&p, &q, &g);
b93447
+    if(params == NULL) {
b93447
+        JSS_throw(env, OUT_OF_MEMORY_ERROR);
b93447
+        goto finish;
b93447
+    }
b93447
+    keyPair = PK11KeyPairGeneratorWithOpFlags(env, this, token, CKM_DSA_KEY_PAIR_GEN,
b93447
+                        params, temporary, sensitive, extractable,
b93447
+                        op_flags, op_flags_mask);
b93447
+
b93447
+finish:
b93447
+    SECITEM_FreeItem(&p, PR_FALSE);
b93447
+    SECITEM_FreeItem(&q, PR_FALSE);
b93447
+    SECITEM_FreeItem(&g, PR_FALSE);
b93447
+    PK11_PQG_DestroyParams(params);
b93447
+    return keyPair;
b93447
+}
b93447
+
b93447
+
b93447
 void
b93447
 DumpItem(SECItem *item)
b93447
 {
b93447
@@ -361,6 +463,7 @@ Java_org_mozilla_jss_pkcs11_PK11KeyPairG
b93447
   (JNIEnv *env, jobject this, jobject token, jbyteArray Curve, 
b93447
     jboolean temporary, jint sensitive, jint extractable)
b93447
 {
b93447
+
b93447
     SECItem curve;
b93447
     jobject keyPair=NULL;
b93447
 
b93447
@@ -385,3 +488,39 @@ finish:
b93447
     SECITEM_FreeItem(&curve, PR_FALSE);
b93447
     return keyPair;
b93447
 }
b93447
+
b93447
+/**********************************************************************
b93447
+ *
b93447
+ * PK11KeyPairGenerator.generateECKeyPairWithOpFlags
b93447
+ *
b93447
+ */
b93447
+JNIEXPORT jobject JNICALL
b93447
+Java_org_mozilla_jss_pkcs11_PK11KeyPairGenerator_generateECKeyPairWithOpFlags
b93447
+  (JNIEnv *env, jobject this, jobject token, jbyteArray Curve, 
b93447
+    jboolean temporary, jint sensitive, jint extractable,
b93447
+    jint op_flags, jint op_flags_mask)
b93447
+{
b93447
+    SECItem curve;
b93447
+    jobject keyPair=NULL;
b93447
+
b93447
+    PR_ASSERT(env!=NULL && this!=NULL && token!=NULL && Curve!=NULL );
b93447
+
b93447
+    /* zero these so we can free them indiscriminately later */
b93447
+    ZERO_SECITEM(curve);
b93447
+
b93447
+    /**************************************************
b93447
+     * Setup the parameters
b93447
+     *************************************************/
b93447
+    if( JSS_ByteArrayToOctetString(env, Curve, &curve))
b93447
+    {
b93447
+        PR_ASSERT( (*env)->ExceptionOccurred(env) != NULL);
b93447
+        goto finish;
b93447
+    }
b93447
+    keyPair = PK11KeyPairGeneratorWithOpFlags(env, this, token, CKM_EC_KEY_PAIR_GEN,
b93447
+     			&curve, temporary, sensitive, extractable,
b93447
+                op_flags, op_flags_mask);
b93447
+
b93447
+finish:
b93447
+    SECITEM_FreeItem(&curve, PR_FALSE);
b93447
+    return keyPair;
b93447
+}
b93447
diff -rupN jss-4.2.5/mozilla/security/jss/org/mozilla/jss/pkcs11/PK11KeyPairGenerator.java jss-4.2.6/mozilla/security/jss/org/mozilla/jss/pkcs11/PK11KeyPairGenerator.java
b93447
--- jss-4.2.5/mozilla/security/jss/org/mozilla/jss/pkcs11/PK11KeyPairGenerator.java	2006-02-22 17:21:42.000000000 -0800
b93447
+++ jss-4.2.6/mozilla/security/jss/org/mozilla/jss/pkcs11/PK11KeyPairGenerator.java	2009-05-30 05:30:25.000000000 -0700
b93447
@@ -55,6 +55,39 @@ public final class PK11KeyPairGenerator
b93447
     extends org.mozilla.jss.crypto.KeyPairGeneratorSpi
b93447
 {
b93447
 
b93447
+    // opFlag constants: each of these flags specifies a crypto operation
b93447
+    // the key will support.  Their values must match the same-named C
b93447
+    // preprocessor macros defined in the PKCS #11 header pkcs11t.h.
b93447
+    private static final int CKF_ENCRYPT = 0x00000100;
b93447
+    private static final int CKF_DECRYPT = 0x00000200;
b93447
+    private static final int CKF_SIGN = 0x00000800;
b93447
+    private static final int CKF_SIGN_RECOVER = 0x00001000;
b93447
+    private static final int CKF_VERIFY = 0x00002000;
b93447
+    private static final int CKF_VERIFY_RECOVER = 0x00004000;
b93447
+    private static final int CKF_WRAP = 0x00020000;
b93447
+    private static final int CKF_UNWRAP = 0x00040000;
b93447
+    private static final int CKF_DERIVE = 0x00080000;
b93447
+
b93447
+    // A table for mapping SymmetricKey.Usage to opFlag.  This must be
b93447
+    // synchronized with SymmetricKey.Usage.
b93447
+    private static final int opFlagForUsage[] = {
b93447
+        CKF_ENCRYPT,        /* 0 */
b93447
+        CKF_DECRYPT,        /* 1 */
b93447
+        CKF_SIGN,           /* 2 */
b93447
+        CKF_SIGN_RECOVER,   /* 3 */
b93447
+        CKF_VERIFY,         /* 4 */
b93447
+        CKF_VERIFY_RECOVER, /* 5 */
b93447
+        CKF_WRAP,           /* 6 */
b93447
+        CKF_UNWRAP,         /* 7 */
b93447
+        CKF_DERIVE          /* 8 */
b93447
+    };
b93447
+
b93447
+    // The crypto operations the key will support.  It is the logical OR
b93447
+    // of the opFlag constants, each specifying a supported operation.
b93447
+    private int opFlags = 0;
b93447
+    private int opFlagsMask = 0;
b93447
+
b93447
+
b93447
     ///////////////////////////////////////////////////////////////////////
b93447
     ///////////////////////////////////////////////////////////////////////
b93447
     // Constructors
b93447
@@ -189,41 +222,45 @@ public final class PK11KeyPairGenerator
b93447
      * Generates a key pair on a token. Uses parameters if they were passed
b93447
      * in through a call to initialize, otherwise uses defaults.
b93447
      */
b93447
+
b93447
     public KeyPair generateKeyPair()
b93447
         throws TokenException
b93447
     {
b93447
         if(algorithm == KeyPairAlgorithm.RSA) {
b93447
             if(params != null) {
b93447
                 RSAParameterSpec rsaparams = (RSAParameterSpec)params;
b93447
-                return generateRSAKeyPair(
b93447
+                return generateRSAKeyPairWithOpFlags(
b93447
                                     token,
b93447
                                     rsaparams.getKeySize(),
b93447
                                     rsaparams.getPublicExponent().longValue(),
b93447
                                     temporaryPairMode,
b93447
                                     sensitivePairMode,
b93447
-                                    extractablePairMode);
b93447
+                                    extractablePairMode,
b93447
+                                    opFlags, opFlagsMask);
b93447
             } else {
b93447
-                return generateRSAKeyPair(
b93447
+                return generateRSAKeyPairWithOpFlags(
b93447
                                     token,
b93447
                                     DEFAULT_RSA_KEY_SIZE,
b93447
                                     DEFAULT_RSA_PUBLIC_EXPONENT.longValue(),
b93447
                                     temporaryPairMode,
b93447
                                     sensitivePairMode,
b93447
-                                    extractablePairMode);
b93447
+                                    extractablePairMode,
b93447
+                                    opFlags, opFlagsMask);
b93447
             }
b93447
         } else if(algorithm == KeyPairAlgorithm.DSA ) {
b93447
             if(params==null) {
b93447
                 params = PQG1024;
b93447
             }
b93447
             DSAParameterSpec dsaParams = (DSAParameterSpec)params;
b93447
-            return generateDSAKeyPair(
b93447
+            return generateDSAKeyPairWithOpFlags(
b93447
                 token,
b93447
                 PQGParams.BigIntegerToUnsignedByteArray(dsaParams.getP()),
b93447
                 PQGParams.BigIntegerToUnsignedByteArray(dsaParams.getQ()),
b93447
                 PQGParams.BigIntegerToUnsignedByteArray(dsaParams.getG()),
b93447
                 temporaryPairMode,
b93447
                 sensitivePairMode,
b93447
-                extractablePairMode);
b93447
+                extractablePairMode,
b93447
+                opFlags, opFlagsMask);
b93447
         } else {
b93447
             Assert._assert( algorithm == KeyPairAlgorithm.EC );
b93447
             // requires JAVA 1.5 for ECParameters.
b93447
@@ -233,12 +270,14 @@ public final class PK11KeyPairGenerator
b93447
 	    // ecParams.init(params);
b93447
             PK11ParameterSpec ecParams = (PK11ParameterSpec) params;
b93447
 
b93447
-            return generateECKeyPair(
b93447
+            return generateECKeyPairWithOpFlags(
b93447
                 token,
b93447
 		ecParams.getEncoded(), /* curve */
b93447
                 temporaryPairMode,
b93447
                 sensitivePairMode,
b93447
-                extractablePairMode);
b93447
+                extractablePairMode,
b93447
+                opFlags,
b93447
+                opFlagsMask);
b93447
         } 
b93447
     }
b93447
 
b93447
@@ -266,6 +305,17 @@ public final class PK11KeyPairGenerator
b93447
         throws TokenException;
b93447
 
b93447
     /**
b93447
+     * Generates an RSA key pair with the given size and public exponent.
b93447
+     * Adds the ability to specify a set of flags and masks
b93447
+     * to control how NSS generates the key pair.
b93447
+     */
b93447
+    private native KeyPair
b93447
+    generateRSAKeyPairWithOpFlags(PK11Token token, int keySize, long publicExponent,
b93447
+            boolean temporary, int sensitive, int extractable,
b93447
+            int op_flags, int op_flags_mask)
b93447
+        throws TokenException;
b93447
+
b93447
+    /**
b93447
      * Generates a DSA key pair with the given P, Q, and G values.
b93447
      * P, Q, and G are stored as big-endian twos-complement octet strings.
b93447
      */
b93447
@@ -275,6 +325,19 @@ public final class PK11KeyPairGenerator
b93447
         throws TokenException;
b93447
 
b93447
     /**
b93447
+     * Generates a DSA key pair with the given P, Q, and G values.
b93447
+     * P, Q, and G are stored as big-endian twos-complement octet strings.
b93447
+     * Adds the ability to specify a set of flags and masks
b93447
+     * to control how NSS generates the key pair.
b93447
+     */
b93447
+    private native KeyPair
b93447
+    generateDSAKeyPairWithOpFlags(PK11Token token, byte[] P, byte[] Q, byte[] G,
b93447
+            boolean temporary, int sensitive, int extractable,
b93447
+            int op_flags, int op_flags_mask)
b93447
+        throws TokenException;
b93447
+
b93447
+
b93447
+    /**
b93447
      * Generates a EC key pair with the given a curve.
b93447
      * Curves are stored as DER Encoded Parameters.
b93447
      */
b93447
@@ -282,6 +345,18 @@ public final class PK11KeyPairGenerator
b93447
     generateECKeyPair(PK11Token token, byte[] Curve, 
b93447
             boolean temporary, int sensitive, int extractable)
b93447
         throws TokenException;
b93447
+    /**
b93447
+     * Generates a EC key pair with the given a curve.
b93447
+     * Curves are stored as DER Encoded Parameters.
b93447
+     * Adds the ability to specify a set of flags and masks
b93447
+     * to control how NSS generates the key pair.
b93447
+     */
b93447
+
b93447
+    private native KeyPair
b93447
+    generateECKeyPairWithOpFlags(PK11Token token, byte[] Curve, 
b93447
+            boolean temporary, int sensitive, int extractable,
b93447
+            int op_flags, int op_flags_mask)
b93447
+        throws TokenException;
b93447
 
b93447
     ///////////////////////////////////////////////////////////////////////
b93447
     ///////////////////////////////////////////////////////////////////////
b93447
@@ -397,6 +472,38 @@ public final class PK11KeyPairGenerator
b93447
         extractablePairMode = extractable ? 1 : 0;
b93447
     }
b93447
 
b93447
+    /**
b93447
+     * Sets the requested key usages desired for the 
b93447
+     * generated key pair. 
b93447
+     * This allows the caller to suggest how NSS generates the key pair.
b93447
+     * @param usages List of desired key usages. 
b93447
+     * @param usages_mask Corresponding mask for the key usages.
b93447
+     * if a usages is desired, make sure it is in the mask as well.
b93447
+     */
b93447
+
b93447
+    public void setKeyPairUsages(org.mozilla.jss.crypto.KeyPairGeneratorSpi.Usage[] usages, 
b93447
+                                 org.mozilla.jss.crypto.KeyPairGeneratorSpi.Usage[] usages_mask) {
b93447
+
b93447
+        this.opFlags = 0;
b93447
+        this.opFlagsMask = 0;
b93447
+
b93447
+        if(usages != null) {
b93447
+            for( int i = 0; i < usages.length; i++ ) {
b93447
+                if( usages[i] != null ) {
b93447
+                    this.opFlags |= opFlagForUsage[usages[i].getVal()];
b93447
+                }
b93447
+            }
b93447
+        }
b93447
+
b93447
+        if(usages_mask != null) {
b93447
+            for( int i = 0; i < usages_mask.length; i++ ) {
b93447
+                if( usages_mask[i] != null ) {
b93447
+                    this.opFlagsMask |= opFlagForUsage[usages_mask[i].getVal()];
b93447
+                }
b93447
+            }
b93447
+        }
b93447
+    }
b93447
+
b93447
     //
b93447
     // requires JAVA 1.5
b93447
     //
b93447
diff -rupN jss-4.2.5/mozilla/security/jss/org/mozilla/jss/pkcs11/pk11util.h jss-4.2.6/mozilla/security/jss/org/mozilla/jss/pkcs11/pk11util.h
b93447
--- jss-4.2.5/mozilla/security/jss/org/mozilla/jss/pkcs11/pk11util.h	2006-02-22 17:21:42.000000000 -0800
b93447
+++ jss-4.2.6/mozilla/security/jss/org/mozilla/jss/pkcs11/pk11util.h	2009-05-29 08:34:24.000000000 -0700
b93447
@@ -157,6 +157,12 @@ JSS_PK11_generateKeyPair(JNIEnv *env, CK
b93447
     PK11SlotInfo *slot, SECKEYPublicKey **pubk, SECKEYPrivateKey **privK,
b93447
     void *params, PRBool temporary, jint senstive, jint extractable);
b93447
 
b93447
+SECStatus
b93447
+JSS_PK11_generateKeyPair_withOpFlags(JNIEnv *env, CK_MECHANISM_TYPE mechanism,
b93447
+    PK11SlotInfo *slot, SECKEYPublicKey **pubk, SECKEYPrivateKey **privk,
b93447
+    void *params, PRBool temporary, jint sensitive, jint extractable,
b93447
+    jint op_flags, jint op_flags_mask);
b93447
+
b93447
 /*=====================================================================
b93447
                        C E R T I F I C A T E S
b93447
 =====================================================================*/