Closed Bug 1592984 Opened 7 years ago Closed 5 days ago

Unable to change master password of SQL key4.db, CKO_NETSCAPE_TRUST, CKR_ATTRIBUTE_TYPE_INVALID, blobData == NULL

Categories

(NSS :: Libraries, defect, P2)

3.47

Tracking

(nss 3.134)

RESOLVED FIXED
Tracking Status
nss --- 3.134

People

(Reporter: KaiE, Assigned: rrelyea)

Details

Attachments

(1 external file)

I cannot change the master password of my primary NSS key database (key4.db, 680 KB, lots of entries).

Fails with Thunderbird 68.x that uses NSS 3.44.x, and also with certutil from a local NSS 3.47.x build.

The database works fine with Thunderbird 68. I can unlock it with the existing master password, and I can access the stored keys, and haven't noticed anything missing.

Using certutil -W I can successfully unlock, I'm prompted to enter the new password twice, but then I get an error message.

I stepped through the code. Stack:

#0  sdb_GetAttributeValueNoLock (sdb=0x5555557f2690, object_id=668933197, template=0x7fffffffd7a0, count=1) at sdb.c:992
#1  0x00007ffff6135c6b in sdb_GetAttributeValue (sdb=0x5555557f2690, object_id=668933197, template=0x7fffffffd7a0, count=1) at sdb.c:1006
#2  0x00007ffff613a7cb in sftkdb_GetAttributeValue (handle=0x55555581a830, objectID=668933197, template=0x7fffffffd7a0, count=1) at sftkdb.c:1325
#3  0x00007ffff61422f5 in sftk_updateMacs (arena=0x5555559f6ec0, handle=0x55555581a830, id=668933197, newKey=0x7fffffffdbd0) at sftkpwd.c:897
#4  0x00007ffff614276b in sftk_convertAttributes (handle=0x55555581a830, id=2816416845, newKey=0x7fffffffdbd0) at sftkpwd.c:1020
#5  0x00007ffff6142899 in sftkdb_convertObjects (handle=0x55555581a830, template=0x7fffffffd970, count=1, newKey=0x7fffffffdbd0) at sftkpwd.c:1064
#6  0x00007ffff6142b2a in sftkdb_ChangePassword (keydb=0x55555581a8b0, oldPin=0x7fffffffdc80 "oldpin", newPin=0x7fffffffde80 "x", tokenRemoved=0x7fffffffdc7c) at sftkpwd.c:1144
#7  0x00007ffff611ab25 in NSC_SetPIN (hSession=16777219, pOldPin=0x5555559d0830 "oldpin", ulOldLen=25, pNewPin=0x5555559ce3d0 "x", ulNewLen=1) at pkcs11.c:3927
#8  0x00007ffff6d5a584 in PK11_ChangePW (slot=0x55555581ba70, oldpw=0x5555559d0830 "oldpin", newpw=0x5555559ce3d0 "x") at pk11auth.c:512
#9  0x000055555556df89 in SECU_ChangePW2 (slot=0x55555581ba70, oldPass=0x0, newPass=0x0, oldPwFile=0x0, newPwFile=0x0) at secutil.c:402
#10 0x00005555555694e7 in certutil_main (argc=4, argv=0x7fffffffe508, initialize=1) at certutil.c:3515
#11 0x000055555556ab14 in main (argc=4, argv=0x7fffffffe508) at certutil.c:4035

The file numbers above refer to files on the NSS_3_47_BRANCH.

Apparently there's an inconsistency between key4.db and the associated cert9.db, In sftkdb_ChangePassword it calls sftkdb_convertObjects("objectType = CKO_NETSCAPE_TRUST").

It already fails with the first attribute it's trying to convert. It queries values from sql. It finds an entry with blobSize zero and blogData NULL, sets error to CKR_ATTRIBUTE_TYPE_INVALID, which gets passed up, and which terminates the converstion.

Is this a broken state?
Could the code be changed to be more lenient?

For testing, I changed sdb_GetAttributeValueNoLock to accept result blobSize zero as a valid result.
But that doesn't fix it. Instead, it fails in sftkdb_VerifyAttribute where we get a mismatch in signature comparison.

Does that mean my cert9.db has entries that were processed using a different master password?

What kind of entries are stored in cert9.db that depend (directly or indirectly) on the master password?

Flags: needinfo?(rrelyea)

FYI, after removing cert9.db, changing the master password succeeds - which confirms the operation fails because of an inconsistency between key4 and cert9.

re Comment 1. Yes, trust attributes are explicitly signed, but the signature can only be checked if you are logged in using your master password. If you aren't logged in (and you have a non-null master password), then sftkdb_VerifyAttribute() should succeed. I believe the macs are actually stored in the key database. It looks like at some point the trust objects where changes without the macs being updated.

Probably the right thing to do here is delete the invalid trust objects and continue. (You don't want to just accept them, because the could have been invalidly updated. I believe we require you to be logged in to update the trust objects.

bob

Flags: needinfo?(rrelyea)
Priority: -- → P2
Severity: normal → S3

Changing the password re-signs every authenticated attribute and first reads it, verifying its MAC under the old key. A missing or non-matching MAC, as on trust objects whose MACs the key DB lost, fails the whole change, and NSC_SetPIN reports CKR_PIN_INCORRECT although the password is right. Firefox then calls the primary password wrong and can't change or remove it.

Skip such attributes: they are neither re-signed nor touched, so they stay unverifiable, while all others are re-signed. This covers every authenticated attribute (trust values and hashes, public key values, override extensions). Any other failure of that read still fails the change. The KDF upgrade on login (bug 1719827) shares this path and now succeeds on such databases, too.

Out of scope, related but separate:

  • MACs that can't be decoded or use an unsupported algorithm still fail the change, as they may come from a newer NSS. A well-formed MAC that a newer NSS computes differently would be skipped, though.
  • Encrypted private attributes that fail to decrypt still fail the change; skipping them would leave them under the old key.
  • Errors of the first, length-only read are skipped silently, here and in sftk_updateEncrypted, as before.
  • NSC_SetPIN and NSC_InitPIN still report any re-encryption failure as CKR_PIN_INCORRECT, e.g. a signature row longer than SDB_MAX_META_DATA_LEN.
  • Where sftkdb_fixupTemplateOut skips the check (no cached key, logout mid-loop, null trust), unchecked values get re-signed; this predates the patch.

Still reproducible with Firefox 157.0.1 / NSS 3.131. Removing the primary password failed with "You did not enter the correct current Primary Password" although login with it worked; certutil -W on a copy gave SEC_ERROR_BAD_PASSWORD. Cause, as in comment 4: four CKO_NSS_TRUST objects and one RSA CKO_PUBLIC_KEY in cert9.db had no MACs in key4.db. Deleting those rows fixed it.

Patch in D333100: attributes whose MAC is missing or doesn't match are now skipped, not re-signed, instead of failing the whole change. Related issues I did not address are listed under "Out of scope" there. The new lockstore (bug 2048600) doesn't change this, as key4.db and cert9.db stay with softoken.

The patch was written with Claude Code and went through four rounds of its automated code review (high effort) before submission; findings were fixed or listed as out of scope.

Pushed by jschanck@mozilla.com:
https://hg.mozilla.org/projects/nss/rev/ec8fc233c8f0
Don't fail a password change on attributes with unverifiable MACs. r=jschanck

Status: NEW → RESOLVED
Closed: 5 days ago
Resolution: --- → FIXED
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: