Blame SOURCES/nss-3.79-dont-verify-default.patch

7093c5
diff --git a/lib/softoken/legacydb/pcertdb.c b/lib/softoken/legacydb/pcertdb.c
7093c5
--- a/lib/softoken/legacydb/pcertdb.c
7093c5
+++ b/lib/softoken/legacydb/pcertdb.c
7093c5
@@ -4272,16 +4272,17 @@ CreateTrust(void)
7093c5
 {
7093c5
     NSSLOWCERTTrust *trust = NULL;
7093c5
 
7093c5
     nsslowcert_LockFreeList();
7093c5
     trust = trustListHead;
7093c5
     if (trust) {
7093c5
         trustListCount--;
7093c5
         trustListHead = trust->next;
7093c5
+        trust->next = NULL;
7093c5
     }
7093c5
     PORT_Assert(trustListCount >= 0);
7093c5
     nsslowcert_UnlockFreeList();
7093c5
     if (trust) {
7093c5
         return trust;
7093c5
     }
7093c5
 
7093c5
     return PORT_ZNew(NSSLOWCERTTrust);
7093c5
@@ -5155,19 +5156,21 @@ done:
7093c5
 }
7093c5
 
7093c5
 PRBool
7093c5
 nsslowcert_hasTrust(NSSLOWCERTCertTrust *trust)
7093c5
 {
7093c5
     if (trust == NULL) {
7093c5
         return PR_FALSE;
7093c5
     }
7093c5
-    return !((trust->sslFlags & CERTDB_TRUSTED_UNKNOWN) &&
7093c5
-             (trust->emailFlags & CERTDB_TRUSTED_UNKNOWN) &&
7093c5
-             (trust->objectSigningFlags & CERTDB_TRUSTED_UNKNOWN));
7093c5
+    /* if we only have CERTDB__USER and CERTDB_TRUSTED_UNKNOWN bits, then
7093c5
+     * we don't have a trust record. */
7093c5
+    return !(((trust->sslFlags & ~(CERTDB_USER|CERTDB_TRUSTED_UNKNOWN)) == 0) &&
7093c5
+        ((trust->emailFlags & ~(CERTDB_USER|CERTDB_TRUSTED_UNKNOWN)) == 0) &&
7093c5
+        ((trust->objectSigningFlags & ~(CERTDB_USER|CERTDB_TRUSTED_UNKNOWN)) == 0));
7093c5
 }
7093c5
 
7093c5
 /*
7093c5
  * This function has the logic that decides if another person's cert and
7093c5
  * email profile from an S/MIME message should be saved.  It can deal with
7093c5
  * the case when there is no profile.
7093c5
  */
7093c5
 static SECStatus
7093c5
diff --git a/lib/softoken/sftkdb.c b/lib/softoken/sftkdb.c
7093c5
--- a/lib/softoken/sftkdb.c
7093c5
+++ b/lib/softoken/sftkdb.c
7093c5
@@ -119,47 +119,79 @@ sftkdb_isAuthenticatedAttribute(CK_ATTRI
7093c5
         case CKA_TRUST_STEP_UP_APPROVED:
7093c5
         case CKA_NSS_OVERRIDE_EXTENSIONS:
7093c5
             return PR_TRUE;
7093c5
         default:
7093c5
             break;
7093c5
     }
7093c5
     return PR_FALSE;
7093c5
 }
7093c5
-
7093c5
 /*
7093c5
  * convert a native ULONG to a database ulong. Database ulong's
7093c5
  * are all 4 byte big endian values.
7093c5
  */
7093c5
 void
7093c5
 sftk_ULong2SDBULong(unsigned char *data, CK_ULONG value)
7093c5
 {
7093c5
     int i;
7093c5
 
7093c5
     for (i = 0; i < SDB_ULONG_SIZE; i++) {
7093c5
         data[i] = (value >> (SDB_ULONG_SIZE - 1 - i) * BBP) & 0xff;
7093c5
     }
7093c5
 }
7093c5
 
7093c5
 /*
7093c5
  * convert a database ulong back to a native ULONG. (reverse of the above
7093c5
- * function.
7093c5
+ * function).
7093c5
  */
7093c5
 static CK_ULONG
7093c5
 sftk_SDBULong2ULong(unsigned char *data)
7093c5
 {
7093c5
     int i;
7093c5
     CK_ULONG value = 0;
7093c5
 
7093c5
     for (i = 0; i < SDB_ULONG_SIZE; i++) {
7093c5
         value |= (((CK_ULONG)data[i]) << (SDB_ULONG_SIZE - 1 - i) * BBP);
7093c5
     }
7093c5
     return value;
7093c5
 }
7093c5
 
7093c5
+/* certain trust records are default values, which are the values
7093c5
+ * returned if the signature check fails anyway.
7093c5
+ * In those cases, we can skip the signature check. */
7093c5
+PRBool
7093c5
+sftkdb_isNullTrust(const CK_ATTRIBUTE *template)
7093c5
+{
7093c5
+    switch (template->type) {
7093c5
+        case CKA_TRUST_SERVER_AUTH:
7093c5
+        case CKA_TRUST_CLIENT_AUTH:
7093c5
+        case CKA_TRUST_EMAIL_PROTECTION:
7093c5
+        case CKA_TRUST_CODE_SIGNING:
7093c5
+            if (template->ulValueLen != SDB_ULONG_SIZE) {
7093c5
+                break;
7093c5
+            }
7093c5
+            if (sftk_SDBULong2ULong(template->pValue) == 
7093c5
+                CKT_NSS_TRUST_UNKNOWN) {
7093c5
+                return PR_TRUE;
7093c5
+            }
7093c5
+            break;
7093c5
+        case CKA_TRUST_STEP_UP_APPROVED:
7093c5
+            if (template->ulValueLen != 1) {
7093c5
+                break;
7093c5
+            }
7093c5
+            if (*((unsigned char *)(template->pValue)) == 0) {
7093c5
+                return PR_TRUE;
7093c5
+            }
7093c5
+            break;
7093c5
+        default:
7093c5
+            break;
7093c5
+    }
7093c5
+    return PR_FALSE;
7093c5
+}
7093c5
+
7093c5
 /*
7093c5
  * fix up the input templates. Our fixed up ints are stored in data and must
7093c5
  * be freed by the caller. The new template must also be freed. If there are no
7093c5
  * CK_ULONG attributes, the orignal template is passed in as is.
7093c5
  */
7093c5
 static CK_ATTRIBUTE *
7093c5
 sftkdb_fixupTemplateIn(const CK_ATTRIBUTE *template, int count,
7093c5
                        unsigned char **dataOut, int *dataOutSize)
7093c5
@@ -410,17 +442,18 @@ sftkdb_fixupTemplateOut(CK_ATTRIBUTE *te
7093c5
             }
7093c5
 
7093c5
             /* copy the plain text back into the template */
7093c5
             PORT_Memcpy(template[i].pValue, plainText->data, plainText->len);
7093c5
             template[i].ulValueLen = plainText->len;
7093c5
             SECITEM_ZfreeItem(plainText, PR_TRUE);
7093c5
         }
7093c5
         /* make sure signed attributes are valid */
7093c5
-        if (checkSig && sftkdb_isAuthenticatedAttribute(ntemplate[i].type)) {
7093c5
+        if (checkSig && sftkdb_isAuthenticatedAttribute(ntemplate[i].type)
7093c5
+            && !sftkdb_isNullTrust(&ntemplate[i])) {
7093c5
             SECStatus rv;
7093c5
             CK_RV local_crv;
7093c5
             SECItem signText;
7093c5
             SECItem plainText;
7093c5
             unsigned char signData[SDB_MAX_META_DATA_LEN];
7093c5
 
7093c5
             signText.data = signData;
7093c5
             signText.len = sizeof(signData);
7093c5
@@ -2387,16 +2420,18 @@ sftkdb_mergeObject(SFTKDBHandle *handle,
7093c5
     crv = (*source->sdb_GetAttributeValue)(source, id,
7093c5
                                            ptemplate, max_attributes);
7093c5
     if (crv != CKR_OK) {
7093c5
         goto loser;
7093c5
     }
7093c5
 
7093c5
     objectType = sftkdb_getULongFromTemplate(CKA_CLASS, ptemplate,
7093c5
                                              max_attributes);
7093c5
+/*printf(" - merging object Type 0x%08lx id=0x%08lx updateID=%s\n", objectType, id,
7093c5
+       handle->updateID?handle->updateID: "<NULL>");*/
7093c5
 
7093c5
     /*
7093c5
      * Update Object updates the object template if necessary then returns
7093c5
      * whether or not we need to actually write the object out to our target
7093c5
      * database.
7093c5
      */
7093c5
     if (!handle->updateID) {
7093c5
         crv = sftkdb_CreateObject(arena, handle, target, &newID,