Blame SOURCES/nss-3.67-fix-private-key-mac.patch

feeac0
diff -up ./lib/softoken/sftkpwd.c.orig ./lib/softoken/sftkpwd.c
feeac0
--- ./lib/softoken/sftkpwd.c.orig	2021-06-10 05:33:12.000000000 -0700
feeac0
+++ ./lib/softoken/sftkpwd.c	2021-07-01 14:04:34.068596942 -0700
feeac0
@@ -287,9 +287,12 @@ sftkdb_DecryptAttribute(SFTKDBHandle *ha
5f43a7
     }
5f43a7
 
5f43a7
     /* If we are using aes 256, we need to check authentication as well.*/
5f43a7
-    if ((type != CKT_INVALID_TYPE) && (cipherValue.alg == SEC_OID_AES_256_CBC)) {
5f43a7
+    if ((type != CKT_INVALID_TYPE) && 
5f43a7
+	(cipherValue.alg == SEC_OID_PKCS5_PBES2) &&
5f43a7
+        (cipherValue.param->encAlg == SEC_OID_AES_256_CBC)) {
5f43a7
         SECItem signature;
5f43a7
         unsigned char signData[SDB_MAX_META_DATA_LEN];
feeac0
+        CK_RV crv;
5f43a7
 
5f43a7
         /* if we get here from the old legacy db, there is clearly an
5f43a7
          * error, don't return the plaintext */
feeac0
@@ -301,15 +304,28 @@ sftkdb_DecryptAttribute(SFTKDBHandle *ha
feeac0
 
feeac0
         signature.data = signData;
feeac0
         signature.len = sizeof(signData);
feeac0
-        rv = sftkdb_GetAttributeSignature(handle, handle, id, type,
feeac0
+        rv = SECFailure;
feeac0
+        /* sign sftkdb_GetAttriibuteSignature returns a crv, not an rv */
feeac0
+        crv = sftkdb_GetAttributeSignature(handle, handle, id, type,
5f43a7
                                           &signature);
feeac0
-        if (rv != SECSuccess) {
feeac0
-            goto loser;
feeac0
+        if (crv == CKR_OK) {
feeac0
+            rv = sftkdb_VerifyAttribute(handle, passKey, CK_INVALID_HANDLE,
feeac0
+                                        type, *plain, &signature);
5f43a7
         }
feeac0
-        rv = sftkdb_VerifyAttribute(handle, passKey, CK_INVALID_HANDLE, type,
feeac0
-                                    *plain, &signature);
5f43a7
         if (rv != SECSuccess) {
5f43a7
-            goto loser;
5f43a7
+            /*  handle a bug where old versions of NSS misfiled the signature
5f43a7
+             *  attribute on password update */
5f43a7
+            id |= SFTK_KEYDB_TYPE|SFTK_TOKEN_TYPE;
5f43a7
+            signature.len = sizeof(signData);
feeac0
+            crv = sftkdb_GetAttributeSignature(handle, handle, id, type,
5f43a7
+                                              &signature);
feeac0
+            if (crv != CKR_OK) {
feeac0
+                rv = SECFailure;
feeac0
+                PORT_SetError(SEC_ERROR_BAD_SIGNATURE);
5f43a7
+                goto loser;
5f43a7
+            }
5f43a7
+            rv = sftkdb_VerifyAttribute(handle, passKey, CK_INVALID_HANDLE,
5f43a7
+                                        type, *plain, &signature);
5f43a7
         }
5f43a7
     }
5f43a7
 
feeac0
@@ -1198,6 +1214,7 @@ sftk_updateEncrypted(PLArenaPool *arena,
5f43a7
     unsigned int i;
5f43a7
     for (i = 0; i < privAttrCount; i++) {
5f43a7
         // Read the old attribute in the clear.
5f43a7
+        CK_OBJECT_HANDLE sdbId = id & SFTK_OBJ_ID_MASK;
5f43a7
         CK_ATTRIBUTE privAttr = { privAttrTypes[i], NULL, 0 };
5f43a7
         CK_RV crv = sftkdb_GetAttributeValue(keydb, id, &privAttr, 1);
5f43a7
         if (crv != CKR_OK) {
feeac0
@@ -1222,7 +1239,7 @@ sftk_updateEncrypted(PLArenaPool *arena,
5f43a7
         plainText.data = privAttr.pValue;
5f43a7
         plainText.len = privAttr.ulValueLen;
5f43a7
         if (sftkdb_EncryptAttribute(arena, keydb, keydb->db, newKey,
5f43a7
-                                    iterationCount, id, privAttr.type,
5f43a7
+                                    iterationCount, sdbId, privAttr.type,
5f43a7
                                     &plainText, &result) != SECSuccess) {
5f43a7
             return CKR_GENERAL_ERROR;
5f43a7
         }
feeac0
@@ -1232,10 +1249,9 @@ sftk_updateEncrypted(PLArenaPool *arena,
5f43a7
         PORT_Memset(plainText.data, 0, plainText.len);
5f43a7
 
5f43a7
         // Write the newly encrypted attributes out directly.
5f43a7
-        CK_OBJECT_HANDLE newId = id & SFTK_OBJ_ID_MASK;
5f43a7
         keydb->newKey = newKey;
5f43a7
         keydb->newDefaultIterationCount = iterationCount;
5f43a7
-        crv = (*keydb->db->sdb_SetAttributeValue)(keydb->db, newId, &privAttr, 1);
5f43a7
+        crv = (*keydb->db->sdb_SetAttributeValue)(keydb->db, sdbId, &privAttr, 1);
5f43a7
         keydb->newKey = NULL;
5f43a7
         if (crv != CKR_OK) {
5f43a7
             return crv;