Blame SOURCES/nss-3.53-fix-private_key_mac.patch

4f0b43
diff --git a/lib/softoken/sftkpwd.c b/lib/softoken/sftkpwd.c
4f0b43
--- a/lib/softoken/sftkpwd.c
4f0b43
+++ b/lib/softoken/sftkpwd.c
4f0b43
@@ -277,17 +277,19 @@ sftkdb_DecryptAttribute(SFTKDBHandle *ha
4f0b43
     *plain = nsspkcs5_CipherData(cipherValue.param, passKey, &cipherValue.value,
4f0b43
                                  PR_FALSE, NULL);
4f0b43
     if (*plain == NULL) {
4f0b43
         rv = SECFailure;
4f0b43
         goto loser;
4f0b43
     }
4f0b43
 
4f0b43
     /* If we are using aes 256, we need to check authentication as well.*/
4f0b43
-    if ((type != CKT_INVALID_TYPE) && (cipherValue.alg == SEC_OID_AES_256_CBC)) {
4f0b43
+    if ((type != CKT_INVALID_TYPE) && 
4f0b43
+	(cipherValue.alg == SEC_OID_PKCS5_PBES2) &&
4f0b43
+        (cipherValue.param->encAlg == SEC_OID_AES_256_CBC)) {
4f0b43
         SECItem signature;
4f0b43
         unsigned char signData[SDB_MAX_META_DATA_LEN];
4f0b43
 
4f0b43
         /* if we get here from the old legacy db, there is clearly an
4f0b43
          * error, don't return the plaintext */
4f0b43
         if (handle == NULL) {
4f0b43
             rv = SECFailure;
4f0b43
             PORT_SetError(SEC_ERROR_LIBRARY_FAILURE);
4f0b43
@@ -299,17 +301,27 @@ sftkdb_DecryptAttribute(SFTKDBHandle *ha
4f0b43
         rv = sftkdb_GetAttributeSignature(handle, handle, id, type,
4f0b43
                                           &signature);
4f0b43
         if (rv != SECSuccess) {
4f0b43
             goto loser;
4f0b43
         }
4f0b43
         rv = sftkdb_VerifyAttribute(handle, passKey, CK_INVALID_HANDLE, type,
4f0b43
                                     *plain, &signature);
4f0b43
         if (rv != SECSuccess) {
4f0b43
-            goto loser;
4f0b43
+            /*  handle a bug where old versions of NSS misfiled the signature
4f0b43
+             *  attribute on password update */
4f0b43
+            id |= SFTK_KEYDB_TYPE|SFTK_TOKEN_TYPE;
4f0b43
+            signature.len = sizeof(signData);
4f0b43
+            rv = sftkdb_GetAttributeSignature(handle, handle, id, type,
4f0b43
+                                              &signature);
4f0b43
+            if (rv != SECSuccess) {
4f0b43
+                goto loser;
4f0b43
+            }
4f0b43
+            rv = sftkdb_VerifyAttribute(handle, passKey, CK_INVALID_HANDLE,
4f0b43
+                                        type, *plain, &signature);
4f0b43
         }
4f0b43
     }
4f0b43
 
4f0b43
 loser:
4f0b43
     if (cipherValue.param) {
4f0b43
         nsspkcs5_DestroyPBEParameter(cipherValue.param);
4f0b43
     }
4f0b43
     if (cipherValue.arena) {
4f0b43
@@ -1186,16 +1198,17 @@ sftk_updateEncrypted(PLArenaPool *arena,
4f0b43
     };
4f0b43
     const CK_ULONG privAttrCount = sizeof(privAttrTypes) / sizeof(privAttrTypes[0]);
4f0b43
 
4f0b43
     // We don't know what attributes this object has, so we update them one at a
4f0b43
     // time.
4f0b43
     unsigned int i;
4f0b43
     for (i = 0; i < privAttrCount; i++) {
4f0b43
         // Read the old attribute in the clear.
4f0b43
+        CK_OBJECT_HANDLE sdbId = id & SFTK_OBJ_ID_MASK;
4f0b43
         CK_ATTRIBUTE privAttr = { privAttrTypes[i], NULL, 0 };
4f0b43
         CK_RV crv = sftkdb_GetAttributeValue(keydb, id, &privAttr, 1);
4f0b43
         if (crv != CKR_OK) {
4f0b43
             continue;
4f0b43
         }
4f0b43
         if ((privAttr.ulValueLen == -1) || (privAttr.ulValueLen == 0)) {
4f0b43
             continue;
4f0b43
         }
4f0b43
@@ -1210,30 +1223,29 @@ sftk_updateEncrypted(PLArenaPool *arena,
4f0b43
         if ((privAttr.ulValueLen == -1) || (privAttr.ulValueLen == 0)) {
4f0b43
             return CKR_GENERAL_ERROR;
4f0b43
         }
4f0b43
         SECItem plainText;
4f0b43
         SECItem *result;
4f0b43
         plainText.data = privAttr.pValue;
4f0b43
         plainText.len = privAttr.ulValueLen;
4f0b43
         if (sftkdb_EncryptAttribute(arena, keydb, keydb->db, newKey,
4f0b43
-                                    iterationCount, id, privAttr.type,
4f0b43
+                                    iterationCount, sdbId, privAttr.type,
4f0b43
                                     &plainText, &result) != SECSuccess) {
4f0b43
             return CKR_GENERAL_ERROR;
4f0b43
         }
4f0b43
         privAttr.pValue = result->data;
4f0b43
         privAttr.ulValueLen = result->len;
4f0b43
         // Clear sensitive data.
4f0b43
         PORT_Memset(plainText.data, 0, plainText.len);
4f0b43
 
4f0b43
         // Write the newly encrypted attributes out directly.
4f0b43
-        CK_OBJECT_HANDLE newId = id & SFTK_OBJ_ID_MASK;
4f0b43
         keydb->newKey = newKey;
4f0b43
         keydb->newDefaultIterationCount = iterationCount;
4f0b43
-        crv = (*keydb->db->sdb_SetAttributeValue)(keydb->db, newId, &privAttr, 1);
4f0b43
+        crv = (*keydb->db->sdb_SetAttributeValue)(keydb->db, sdbId, &privAttr, 1);
4f0b43
         keydb->newKey = NULL;
4f0b43
         if (crv != CKR_OK) {
4f0b43
             return crv;
4f0b43
         }
4f0b43
     }
4f0b43
 
4f0b43
     return CKR_OK;
4f0b43
 }