diff options
author | Robert Relyea <rrelyea@redhat.com> | 2023-03-03 21:54:41 +0000 |
---|---|---|
committer | Robert Relyea <rrelyea@redhat.com> | 2023-03-03 21:54:41 +0000 |
commit | 2af96ef910c717d1ecb2d77f05c4306f660a0c4c (patch) | |
tree | a5875d9c8078279bc10c3af31a1e9752ea123883 /lib/nss | |
parent | 9afee96e42bccaead43e7234b9e48f0cb58e7ff6 (diff) | |
download | nss-hg-2af96ef910c717d1ecb2d77f05c4306f660a0c4c.tar.gz |
Bug 1767883 - Need to add policy control to keys lengths for signatures. r=nss-reviewers
There are three changes in the patch which are related to key length processing:
Change RSA_MIN_MODULUS_BITS in blalpit.h from 128 to 1023. This necessitated changes to the following tests: testcrmf.c: up the generated key for the test from 512 to 1024. pk11_rsapkcs1_unittest.cc (in pk11_gtest): skip the min padding test if the MIN_RSA_MODULUS_BITS is more than 736 (The largest hash we support is 512, which fits in an RSA key less then 736. If we can't generate a key less than 736, we can't test minimum padding, but we can never get into that situation anyway now). tls_subcerts_unittest.cc: set our key size to at least RSA_MIN_MODULUS_BITS, and then make sure the policy had a higher minimum key length so we still trigger the 'weakKey' event. pk11kea.c: use 1024 bits for the transfer key now that smaller keysizes aren't supported by softoken.
Expand the add a new flag to meaning of NSS_XXX_MIN_KEY_SIZE beyond it's use in SSL (add the ability to limit signing and verification to this as well). This allows us to set strict FIPS 140-3 policies, where we can only sign with 2048, but can still verify 1024. This part includes: New utility functions in seckey.c: SECKEY_PrivateKeyStrengthInBits(): The private key equivalent to SECKEY_PublicKeyStrengthInBits(). This function could be exported globally, but isn't in this patch. seckey_EnforceKeySize(). Takes a key type and a length and makes sure that length falls into the range set by policy. secsign.c and secvfy.c: add policy length check where we check the other policy flags. nss.h, nssoptions.c: add NSS_KEY_SIZE_POLICY_FLAGS and define flags for SSL, VERIFY, and SIGN. SSL is set by default (to maintain the current behavior). pk11parse.c: add keywords for the new NSS_KEY_SIZE_POLICY_FLAGS. ssl3con.c: use the flags to decide if the policy lengths are active for SSL. policy.txt: Test that the new policy flags are parsed correctly sslpolicy.txt: Add tests to make sure the policy flags are functioning.
Update fips_algorithms.h to make sure the FIPS indicators are exactly compliant with FIPS 140-3 current guidance (RSA 2028 and above, any key size, Legacy verification allowed for 1024, 1280, 1536, and 1792 [1024-1792, step 256]).
The previous attempt to push failed because the pk11_rsapkcs1_unittest.cc
change was eaten in the merge.
Differential Revision: https://phabricator.services.mozilla.com/D146341
Diffstat (limited to 'lib/nss')
-rw-r--r-- | lib/nss/nss.h | 22 | ||||
-rw-r--r-- | lib/nss/nssoptions.c | 28 | ||||
-rw-r--r-- | lib/nss/nssoptions.h | 2 |
3 files changed, 51 insertions, 1 deletions
diff --git a/lib/nss/nss.h b/lib/nss/nss.h index 081422e91..b3ef5057c 100644 --- a/lib/nss/nss.h +++ b/lib/nss/nss.h @@ -302,6 +302,28 @@ SECStatus NSS_UnregisterShutdown(NSS_ShutdownFunc sFunc, void *appData); #define NSS_DEFAULT_LOCKS 0x00d /* lock default values */ #define NSS_DEFAULT_SSL_LOCK 1 /* lock the ssl default values */ +/* NSS_KEY_SIZE_POLICY controls what kinds of operations are subject to + * the NSS_XXX_MIN_KEY_SIZE values. + * NSS_KEY_SIZE_POLICY_FLAGS sets and clears all the flags to the input + * value + * On get it returns all the flags + * NSS_KEY_SIZE_POLICY_SET_FLAGS sets only the flags=1 in theinput value and + * does not affect the other flags + * On get it returns all the flags + * NSS_KEY_SIZE_POLICY_CLEAR_FLAGS clears only the flags=1 in the input + * value and does not affect the other flags + * On get it returns all the compliment of all the flags + * (cleared flags == 1) */ +#define NSS_KEY_SIZE_POLICY_FLAGS 0x00e +#define NSS_KEY_SIZE_POLICY_SET_FLAGS 0x00f +#define NSS_KEY_SIZE_POLICY_CLEAR_FLAGS 0x010 +/* currently defined flags */ +#define NSS_KEY_SIZE_POLICY_SSL_FLAG 1 +#define NSS_KEY_SIZE_POLICY_VERIFY_FLAG 2 +#define NSS_KEY_SIZE_POLICY_SIGN_FLAG 4 + +#define NSS_ECC_MIN_KEY_SIZE 0x011 + /* * Set and get global options for the NSS library. */ diff --git a/lib/nss/nssoptions.c b/lib/nss/nssoptions.c index f7225c414..cc637ffda 100644 --- a/lib/nss/nssoptions.c +++ b/lib/nss/nssoptions.c @@ -26,6 +26,8 @@ struct nssOps { PRInt32 dtlsVersionMaxPolicy; PRInt32 pkcs12DecodeForceUnicode; PRInt32 defaultLocks; + PRInt32 keySizePolicyFlags; + PRInt32 eccMinKeySize; }; static struct nssOps nss_ops = { @@ -37,7 +39,9 @@ static struct nssOps nss_ops = { 1, 0xffff, PR_FALSE, - 0 + 0, + NSS_KEY_SIZE_POLICY_SSL_FLAG, + SSL_ECC_MIN_CURVE_BITS }; SECStatus @@ -78,6 +82,18 @@ NSS_OptionSet(PRInt32 which, PRInt32 value) case NSS_DEFAULT_LOCKS: nss_ops.defaultLocks = value; break; + case NSS_KEY_SIZE_POLICY_FLAGS: + nss_ops.keySizePolicyFlags = value; + break; + case NSS_KEY_SIZE_POLICY_SET_FLAGS: + nss_ops.keySizePolicyFlags |= value; + break; + case NSS_KEY_SIZE_POLICY_CLEAR_FLAGS: + nss_ops.keySizePolicyFlags &= ~value; + break; + case NSS_ECC_MIN_KEY_SIZE: + nss_ops.eccMinKeySize = value; + break; default: PORT_SetError(SEC_ERROR_INVALID_ARGS); rv = SECFailure; @@ -119,6 +135,16 @@ NSS_OptionGet(PRInt32 which, PRInt32 *value) case NSS_DEFAULT_LOCKS: *value = nss_ops.defaultLocks; break; + case NSS_KEY_SIZE_POLICY_FLAGS: + case NSS_KEY_SIZE_POLICY_SET_FLAGS: + *value = nss_ops.keySizePolicyFlags; + break; + case NSS_KEY_SIZE_POLICY_CLEAR_FLAGS: + *value = ~nss_ops.keySizePolicyFlags; + break; + case NSS_ECC_MIN_KEY_SIZE: + *value = nss_ops.eccMinKeySize; + break; default: rv = SECFailure; } diff --git a/lib/nss/nssoptions.h b/lib/nss/nssoptions.h index 024c1e92f..3f19c61ed 100644 --- a/lib/nss/nssoptions.h +++ b/lib/nss/nssoptions.h @@ -18,3 +18,5 @@ * happens because NSS used to count bit lengths incorrectly. */ #define SSL_DH_MIN_P_BITS 1023 #define SSL_DSA_MIN_P_BITS 1023 +/* not really used by SSL, but define it here for consistency */ +#define SSL_ECC_MIN_CURVE_BITS 255 |