-
- /*
- * If this non-root cert is in the provided anchors list,
- * we can stop building the chain at this point.
- *
- * If this cert is a leaf, the chain ends in an anchor, but if it's
- * also temporally invalid, we can't do anything further. However,
- * if it's not a leaf, then we need to roll back the chain to a
- * point just before this cert, so Case 1 will subsequently find
- * the anchor (and handle the anchor correctly if it's expired.)
- */
- if(numAnchorCerts && anchorCerts) {
- bool foundNonRootAnchor = false;
- for(certDex=0; certDex<numAnchorCerts; certDex++) {
- if(tp_CompareCerts(subjCert->itemData(), &anchorCerts[certDex])) {
- foundNonRootAnchor = true;
- /* if it's not the leaf, remove it from the outgoing cert group. */
- if(!firstSubjectIsInGroup || (mNumCerts > 1)) {
- if(mNumCerts) {
- /* roll back to previous cert */
- mNumCerts--;
- }
- if(mNumCerts == 0) {
- /* roll back to caller's initial condition */
- thisSubject = &subjectItem;
- }
- else {
- thisSubject = lastCert();
- }
- tpAnchorDebug("buildCertGroup: CA cert in input AND anchors");
- } /* not leaf */
- else {
- if(subjCert->isExpired() || subjCert->isNotValidYet()) {
- crtn = CSSM_CERT_STATUS_EXPIRED;
- } else {
- crtn = CSSM_OK;
- }
- subjCert->isAnchor(true);
- verifiedToAnchor = CSSM_TRUE;
- tpAnchorDebug("buildCertGroup: leaf cert in input AND anchors");
- } /* leaf */
- break; /* out of anchor-checking loop */
- }
- }
- if(foundNonRootAnchor) {
- break; /* out of main loop */
- }
- } /* non-root */
-