Closed Bug 1804091 Opened 1 year ago Closed 1 year ago

NSS needs to move off of DSA for integrity checks.

Categories

(NSS :: Libraries, defect)

3.84
defect

Tracking

(Not tracked)

RESOLVED FIXED

People

(Reporter: rrelyea, Assigned: rrelyea)

Details

(Whiteboard: [nss-fx])

Attachments

(1 file)

When we first added integrity checks to NSS for FIPS compliance, the only signature method allowed was DSA. NIST will be sunsetting DSA in 2023, so we need to update our integrity checks again. Since the time we added these checks, NIST has started accepting HMAC as a valid signature algorithm for integrity checks. HMAC is easier, faster and requires smaller .chk files and openssl and gnutls has been using hmac now for years for this purpose.

Since we need to move off of DSA anyway it's time to move to HMAC.

When we first added integrity checks to NSS for FIPS compliance, the only signature method allowed was DSA. NIST will be sunsetting DSA in 2023, so we need to update our integrity checks again. Since the time we added these checks, NIST has started accepting HMAC as a valid signature algorithm for integrity checks. HMAC is easier, faster and requires smaller .chk files and openssl and gnutls has been using hmac now for years for this purpose.

Since we need to move off of DSA anyway it's time to move to HMAC.

This patch does this move. shlibsign now produces HMAC_256 by default. It moves the version number up because even though nss includes a type field, previous versions of NSS did not look at the type field when checking integrity. Bumping the version number will cause previous versions of NSS to fail early if presented with a newly generated integrity check file (even though it should fail later anyway). shlibsign now has the ability to generate 'legacy' check files so it can be used to generate check files for older versions of NSS.

NSS can still accept older check files unless NSS_STRICT_INTEGRITY is set at compile time. This means tools which may be using old shlibsign to resign nss shared libraries will continue to work. At some point we can remove all DSA support (maybe after one enterprise release cycle).

While completing this work, we also complete some integrity code cleanup. There are lots of magic numbers defining where things fall in the integrity check header. These are now moved to a structure and defined in the shsign.h header. Both shlibsign and shvfy have been updated to use this header.

New test cases are not needed since fips.sh adequately tests our integrity code (both normal case and against mangled libraries which should fail). Though the lowhash test was updated to catch a particular issue we can run into when we use the LOWHASH code. On RHEL-7, we use the NSSLOWHASH_ interface in freebl in libc, which needs to run independently of nspr and nssutil. This requirement puts a pretty heavy burned on freebl to be self-contained when used for NSSLOWHASH_, including running integrity checks. The previous test program linked with nssutil and nspr (just like all of the rest of the nss tests) and weren't detecting issues when unimplemented stub functions where called. This patch includes fixing those lowhash tests and also implementing the stubs needed by the current integrity check code.

cmd/lowhashtest/Makefile
remove linking lowhashtest with all the libraries except freebl.

cmd/lowhashtest/lowhashtest.c
remove any dependency NSPR or NSSUTIL in the code.

cmd/lowhashtest/manifest.mn
remove spurious requires statements.

cmd/shlibsign/shlibsign.c
add hmac code.
add ability to select the hash type from the command line.
separate signature processing into their own functions for DSA and HMAC
General cleanups.
Use PR_ARRAY_SIZE rather then a custom define.
move error printing outside utility functions (so we don't have to pass around filenames everywhere)
Use NSSSignChkHeader instead of a Buf with magic offsets for the Check file Header.
Add ability to make old style .chk files for old versions of NSS.
Add option to revert to DSA
Add option to use old version numbers: only valid if DSA is set.

lib/freebl/Makefile
All NSS_STRICT_INTEGRITY to be set at build time. Setting NSS_STRICT_INTEGRITY only accepts hmac256, hmac384, hmac512. If it's not set, NSS will accept older .chk file formats (like DSA-2).

lib/freebl/nsslowhash.c
lowhashtest files expect to set NSS_FIPS to force fips mode when testing the lowhash interface, but NSS_FIPS was not being looked at in the nsslow_GetFIPSEnabled. NOTE: setting NSS_FIPS to true will force FIPS mode if the system isn't already in FIPS mode. Setting it to FALSE will not turn it off if the system is already in FIPS mode.

lib/freebl/shsign.h
Update version.
Add new defines for HMAC
add new Header structure to remove magic offsets into a raw buffer in the code.

lib/freebl/shvfy.c
Add HMAC processing.
Turn off DSA processing if NSS_STRICT_INTEGERITY is set.
Refactor the signature processing.

lib/freebl/stubs.c
Add SECITEM_ItemsAreEqual for HMAC shvfy
Add implementations for SECITEM_ItemsAreEqual, SECITEM_ZfreeItem, and PR_GetEnvSecure. The first is new. The second solves and existing bug which is only seen on RHEL7, and the last is needed for the fix to nsslowhash.c above.
PR_GetEnvSecure() calls secure_getenv if _USE_GNU is set, otherwise it falls back to the normal getenv. This should be safe since it's only used in LOWHASH to get the NSS_FIPS environment variable, which only has the effect of making LOWHASH run in fips mode when it otherwise wouldn't.

lib/freebl/stubs.c
Add SECITEM_ItemsAreEqual for HMAC shvfy

tests/lowhash/lowhash.sh
Make the test executable so it can be run on it's own.

Assignee: nobody → rrelyea
Status: NEW → ASSIGNED

The severity field is not set for this bug.
:beurdouche, could you have a look please?

For more information, please visit auto_nag documentation.

Flags: needinfo?(bbeurdouche)

Benjamin: I don't know the definitions, but I would say severity should be relatively low. It's important for us, but it isn't a crash fix that affects a large number of users:).

Status: ASSIGNED → RESOLVED
Closed: 1 year ago
Resolution: --- → FIXED
Flags: needinfo?(bbeurdouche)
Whiteboard: [nss-fx]
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: