VirtualBox

Ignore:
Timestamp:
Dec 15, 2016 3:26:20 PM (8 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
112290
Message:

IPRT/ASN.1: Refactored array handling (SET OF, SEQUENCE OF) to use a pointer array instead of an object instance array. The old approach would move objects around in memory after they'd be initialized/decoded, making certain core optimziations involving pointers to object members impossible, as well as causing potentially causing trouble when modifying structures that takes down pointers after decoding. Fixed validation bug in rtCrX509Name_CheckSanityExtra where it didn't check that the RDNs had subitems but instead checked the parent twice (slight risk).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/common/crypto/x509-certpaths.cpp

    r64531 r64883  
    723723    if (pThis->pUntrustedCertsSet)
    724724    {
    725         uint32_t const  cCerts  = pThis->pUntrustedCertsSet->cItems;
    726         PCRTCRPKCS7CERT paCerts = pThis->pUntrustedCertsSet->paItems;
     725        uint32_t const        cCerts   = pThis->pUntrustedCertsSet->cItems;
     726        PRTCRPKCS7CERT const *papCerts = pThis->pUntrustedCertsSet->papItems;
    727727        for (uint32_t i = 0; i < cCerts; i++)
    728             if (   paCerts[i].enmChoice == RTCRPKCS7CERTCHOICE_X509
    729                 && RTCrX509Certificate_MatchSubjectOrAltSubjectByRfc5280(paCerts[i].u.pX509Cert, pIssuer))
    730                 rtCrX509CertPathsAddIssuer(pThis, pNode, paCerts[i].u.pX509Cert, NULL, RTCRX509CERTPATHNODE_SRC_UNTRUSTED_SET);
     728        {
     729            PCRTCRPKCS7CERT pCert = papCerts[i];
     730            if (   pCert->enmChoice == RTCRPKCS7CERTCHOICE_X509
     731                && RTCrX509Certificate_MatchSubjectOrAltSubjectByRfc5280(pCert->u.pX509Cert, pIssuer))
     732                rtCrX509CertPathsAddIssuer(pThis, pNode, pCert->u.pX509Cert, NULL, RTCRX509CERTPATHNODE_SRC_UNTRUSTED_SET);
     733        }
    731734    }
    732735}
     
    10571060{
    10581061    for (uint32_t i = 0; i < pName->cItems; i++)
    1059         for (uint32_t j = 0; j < pName->paItems[i].cItems; j++)
    1060         {
    1061             PRTCRX509ATTRIBUTETYPEANDVALUE pAttrib = &pName->paItems[i].paItems[j];
     1062    {
     1063        PCRTCRX509RELATIVEDISTINGUISHEDNAME const pRdn = pName->papItems[i];
     1064        for (uint32_t j = 0; j < pRdn->cItems; j++)
     1065        {
     1066            PRTCRX509ATTRIBUTETYPEANDVALUE pAttrib = pRdn->papItems[j];
    10621067
    10631068            const char *pszType = pAttrib->Type.szObjId;
     
    11181123                rtDumpPrintf(pfnPrintfV, pvUser, "<not-string: uTag=%#x>", pAttrib->Value.u.Core.uTag);
    11191124        }
     1125    }
    11201126}
    11211127
     
    13501356 * @param   pThis               The validator instance.
    13511357 * @param   cSubtrees           The number of sub-trees to add.
    1352  * @param   paSubtrees          Array of sub-trees to add.
    1353  */
    1354 static bool rtCrX509CpvAddPermittedSubtrees(PRTCRX509CERTPATHSINT pThis, uint32_t cSubtrees, PCRTCRX509GENERALSUBTREE paSubtrees)
     1358 * @param   papSubtrees         Array of sub-trees to add.
     1359 */
     1360static bool rtCrX509CpvAddPermittedSubtrees(PRTCRX509CERTPATHSINT pThis, uint32_t cSubtrees,
     1361                                            PRTCRX509GENERALSUBTREE const *papSubtrees)
    13551362{
    13561363    /*
     
    13751382    for (uint32_t iSrc = 0; iSrc < cSubtrees; iSrc++)
    13761383    {
    1377         if (!rtCrX509CpvCheckSubtreeValidity(pThis, &paSubtrees[iSrc]))
     1384        if (!rtCrX509CpvCheckSubtreeValidity(pThis, papSubtrees[iSrc]))
    13781385            return false;
    1379         pThis->v.papPermittedSubtrees[iDst] = &paSubtrees[iSrc];
     1386        pThis->v.papPermittedSubtrees[iDst] = papSubtrees[iSrc];
    13801387        iDst++;
    13811388    }
     
    13831390
    13841391    return true;
     1392}
     1393
     1394
     1395/**
     1396 * Adds a one permitted sub-tree.
     1397 *
     1398 * We store reference to each individual sub-tree because we must support
     1399 * intersection calculation.
     1400 *
     1401 * @returns success indiciator.
     1402 * @param   pThis               The validator instance.
     1403 * @param   pSubtree            Array of sub-trees to add.
     1404 */
     1405static bool rtCrX509CpvAddPermittedSubtree(PRTCRX509CERTPATHSINT pThis, PCRTCRX509GENERALSUBTREE pSubtree)
     1406{
     1407    return rtCrX509CpvAddPermittedSubtrees(pThis, 1, (PRTCRX509GENERALSUBTREE const *)&pSubtree);
    13851408}
    13861409
     
    14051428    }
    14061429
    1407     uint32_t                    cRight  = pSubtrees->cItems;
    1408     PCRTCRX509GENERALSUBTREE    paRight = pSubtrees->paItems;
     1430    uint32_t                       cRight   = pSubtrees->cItems;
     1431    PRTCRX509GENERALSUBTREE const *papRight = pSubtrees->papItems;
    14091432    if (cRight == 0)
    14101433    {
     
    14171440    PCRTCRX509GENERALSUBTREE   *papLeft = pThis->v.papPermittedSubtrees;
    14181441    if (!cLeft) /* first name constraint, no initial constraint */
    1419         return rtCrX509CpvAddPermittedSubtrees(pThis, cRight, paRight);
     1442        return rtCrX509CpvAddPermittedSubtrees(pThis, cRight, papRight);
    14201443
    14211444    /*
     
    14311454    for (uint32_t iRight = 0; iRight < cRight; iRight++)
    14321455    {
    1433         if (!rtCrX509CpvCheckSubtreeValidity(pThis, &paRight[iRight]))
     1456        if (!rtCrX509CpvCheckSubtreeValidity(pThis, papRight[iRight]))
    14341457            return false;
    14351458
    1436         RTCRX509GENERALNAMECHOICE const enmRightChoice = paRight[iRight].Base.enmChoice;
     1459        RTCRX509GENERALNAMECHOICE const enmRightChoice = papRight[iRight]->Base.enmChoice;
    14371460        afRightTags[enmRightChoice] = true;
    14381461
     
    14411464            if (papLeft[iLeft]->Base.enmChoice == enmRightChoice)
    14421465            {
    1443                 if (RTCrX509GeneralSubtree_Compare(papLeft[iLeft], &paRight[iRight]) == 0)
     1466                if (RTCrX509GeneralSubtree_Compare(papLeft[iLeft], papRight[iRight]) == 0)
    14441467                {
    14451468                    if (!fHaveRight)
    14461469                    {
    14471470                        fHaveRight = true;
    1448                         rtCrX509CpvAddPermittedSubtrees(pThis, 1, papLeft[iLeft]);
     1471                        rtCrX509CpvAddPermittedSubtree(pThis, papLeft[iLeft]);
    14491472                    }
    14501473                }
    1451                 else if (RTCrX509GeneralSubtree_ConstraintMatch(papLeft[iLeft], &paRight[iRight]))
     1474                else if (RTCrX509GeneralSubtree_ConstraintMatch(papLeft[iLeft], papRight[iRight]))
    14521475                {
    14531476                    if (!fHaveRight)
    14541477                    {
    14551478                        fHaveRight = true;
    1456                         rtCrX509CpvAddPermittedSubtrees(pThis, 1, &paRight[iRight]);
     1479                        rtCrX509CpvAddPermittedSubtree(pThis, papRight[iRight]);
    14571480                    }
    14581481                }
    1459                 else if (RTCrX509GeneralSubtree_ConstraintMatch(&paRight[iRight], papLeft[iLeft]))
    1460                     rtCrX509CpvAddPermittedSubtrees(pThis, 1, papLeft[iLeft]);
     1482                else if (RTCrX509GeneralSubtree_ConstraintMatch(papRight[iRight], papLeft[iLeft]))
     1483                    rtCrX509CpvAddPermittedSubtree(pThis, papLeft[iLeft]);
    14611484            }
    14621485    }
     
    14671490    for (uint32_t iLeft = 0; iLeft < cLeft; iLeft++)
    14681491        if (!afRightTags[papLeft[iLeft]->Base.enmChoice])
    1469             rtCrX509CpvAddPermittedSubtrees(pThis, 1, papLeft[iLeft]);
     1492            rtCrX509CpvAddPermittedSubtree(pThis, papLeft[iLeft]);
    14701493
    14711494    /*
     
    15411564        uint32_t j = pSubTrees->cItems;
    15421565        while (j-- > 0)
    1543             if (   RTCRX509GENERALNAME_IS_DIRECTORY_NAME(&pSubTrees->paItems[j].Base)
    1544                 && RTCrX509Name_ConstraintMatch(&pSubTrees->paItems[j].Base.u.pT4->DirectoryName, pName))
     1566        {
     1567            PCRTCRX509GENERALSUBTREE const pSubTree = pSubTrees->papItems[j];
     1568            if (   RTCRX509GENERALNAME_IS_DIRECTORY_NAME(&pSubTree->Base)
     1569                && RTCrX509Name_ConstraintMatch(&pSubTree->Base.u.pT4->DirectoryName, pName))
    15451570                return true;
     1571        }
    15461572    }
    15471573    return false;
     
    15661592        uint32_t j = pSubTrees->cItems;
    15671593        while (j-- > 0)
    1568             if (RTCrX509GeneralName_ConstraintMatch(&pSubTrees->paItems[j].Base, pGeneralName))
     1594            if (RTCrX509GeneralName_ConstraintMatch(&pSubTrees->papItems[j]->Base, pGeneralName))
    15691595                return true;
    15701596    }
     
    19511977    if (pThis->pInitialPermittedSubtrees)
    19521978        rtCrX509CpvAddPermittedSubtrees(pThis, pThis->pInitialPermittedSubtrees->cItems,
    1953                                         pThis->pInitialPermittedSubtrees->paItems);
     1979                                        pThis->pInitialPermittedSubtrees->papItems);
    19541980    if (pThis->pInitialExcludedSubtrees)
    19551981        rtCrX509CpvAddExcludedSubtrees(pThis, pThis->pInitialExcludedSubtrees);
     
    20532079        uint32_t i = pAltSubjectName->cItems;
    20542080        while (i-- > 0)
    2055             if (   !rtCrX509CpvIsGeneralNamePermitted(pThis, &pAltSubjectName->paItems[i])
    2056                 || rtCrX509CpvIsGeneralNameExcluded(pThis, &pAltSubjectName->paItems[i]))
     2081            if (   !rtCrX509CpvIsGeneralNamePermitted(pThis, pAltSubjectName->papItems[i])
     2082                || rtCrX509CpvIsGeneralNameExcluded(pThis, pAltSubjectName->papItems[i]))
    20572083                return rtCrX509CpvFailed(pThis, VERR_CR_X509_CPV_ALT_NAME_NOT_PERMITTED,
    20582084                                         "Alternative name #%u is is not permitted by current name constraints", i);
     
    20812107        while (i-- > 0)
    20822108        {
    2083             PCRTCRX509POLICYQUALIFIERINFOS const    pQualifiers = &pPolicies->paItems[i].PolicyQualifiers;
    2084             PCRTASN1OBJID const                     pIdP        = &pPolicies->paItems[i].PolicyIdentifier;
     2109            PCRTCRX509POLICYQUALIFIERINFOS const    pQualifiers = &pPolicies->papItems[i]->PolicyQualifiers;
     2110            PCRTASN1OBJID const                     pIdP        = &pPolicies->papItems[i]->PolicyIdentifier;
    20852111            if (RTAsn1ObjId_CompareWithString(pIdP, RTCRX509_ID_CE_CP_ANY_POLICY_OID) == 0)
    20862112            {
     
    21322158                || (pNode->pParent && fSelfIssued) ) )
    21332159        {
    2134             PCRTCRX509POLICYQUALIFIERINFOS pApQ = &pPolicies->paItems[iAnyPolicy].PolicyQualifiers;
     2160            PCRTCRX509POLICYQUALIFIERINFOS pApQ = &pPolicies->papItems[iAnyPolicy]->PolicyQualifiers;
    21352161            RTListForEach(pListAbove, pCur, RTCRX509CERTPATHSPOLICYNODE, DepthEntry)
    21362162            {
     
    21832209    while (i-- > 0)
    21842210    {
    2185         if (RTAsn1ObjId_CompareWithString(&pPolicyMappings->paItems[i].IssuerDomainPolicy, RTCRX509_ID_CE_CP_ANY_POLICY_OID) == 0)
     2211        PCRTCRX509POLICYMAPPING const pOne = pPolicyMappings->papItems[i];
     2212        if (RTAsn1ObjId_CompareWithString(&pOne->IssuerDomainPolicy, RTCRX509_ID_CE_CP_ANY_POLICY_OID) == 0)
    21862213            return rtCrX509CpvFailed(pThis, VERR_CR_X509_CPV_INVALID_POLICY_MAPPING,
    21872214                                     "Invalid policy mapping %#u: IssuerDomainPolicy is anyPolicy.", i);
    21882215
    2189         if (RTAsn1ObjId_CompareWithString(&pPolicyMappings->paItems[i].SubjectDomainPolicy, RTCRX509_ID_CE_CP_ANY_POLICY_OID) == 0)
     2216        if (RTAsn1ObjId_CompareWithString(&pOne->SubjectDomainPolicy, RTCRX509_ID_CE_CP_ANY_POLICY_OID) == 0)
    21902217            return rtCrX509CpvFailed(pThis, VERR_CR_X509_CPV_INVALID_POLICY_MAPPING,
    21912218                                     "Invalid policy mapping %#u: SubjectDomainPolicy is anyPolicy.", i);
     
    22012228        while (i-- > 0)
    22022229        {
     2230            PCRTCRX509POLICYMAPPING const pOne = pPolicyMappings->papItems[i];
     2231
    22032232            uint32_t cFound = 0;
    22042233            RTListForEach(&pThis->v.paValidPolicyDepthLists[iDepth], pCur, RTCRX509CERTPATHSPOLICYNODE, DepthEntry)
    22052234            {
    2206                 if (RTAsn1ObjId_Compare(pCur->pValidPolicy, &pPolicyMappings->paItems[i].IssuerDomainPolicy))
     2235                if (RTAsn1ObjId_Compare(pCur->pValidPolicy, &pOne->IssuerDomainPolicy))
    22072236                {
    22082237                    if (!pCur->fAlreadyMapped)
    22092238                    {
    22102239                        pCur->fAlreadyMapped = true;
    2211                         pCur->pExpectedPolicyFirst = &pPolicyMappings->paItems[i].SubjectDomainPolicy;
     2240                        pCur->pExpectedPolicyFirst = &pOne->SubjectDomainPolicy;
    22122241                    }
    22132242                    else
     
    22212250                                                     pCur->cMoreExpectedPolicySet, iDepth);
    22222251                        pCur->papMoreExpectedPolicySet = (PCRTASN1OBJID *)pvNew;
    2223                         pCur->papMoreExpectedPolicySet[iExpected] = &pPolicyMappings->paItems[i].SubjectDomainPolicy;
     2252                        pCur->papMoreExpectedPolicySet[iExpected] = &pOne->SubjectDomainPolicy;
    22242253                        pCur->cMoreExpectedPolicySet = iExpected  + 1;
    22252254                    }
     
    22382267                    {
    22392268                        if (!rtCrX509CpvPolicyTreeInsertNew(pThis, pCur->pParent, iDepth,
    2240                                                             &pPolicyMappings->paItems[i].IssuerDomainPolicy,
     2269                                                            &pOne->IssuerDomainPolicy,
    22412270                                                            pCur->pPolicyQualifiers,
    2242                                                             &pPolicyMappings->paItems[i].SubjectDomainPolicy))
     2271                                                            &pOne->SubjectDomainPolicy))
    22432272                            return false;
    22442273                        break;
     
    22582287        while (i-- > 0)
    22592288        {
     2289            PCRTCRX509POLICYMAPPING const pOne = pPolicyMappings->papItems[i];
    22602290            RTListForEachSafe(&pThis->v.paValidPolicyDepthLists[iDepth], pCur, pNext, RTCRX509CERTPATHSPOLICYNODE, DepthEntry)
    22612291            {
    2262                 if (RTAsn1ObjId_Compare(pCur->pValidPolicy, &pPolicyMappings->paItems[i].IssuerDomainPolicy))
     2292                if (RTAsn1ObjId_Compare(pCur->pValidPolicy, &pOne->IssuerDomainPolicy))
    22632293                {
    22642294                    rtCrX509CpvPolicyTreeDestroyNode(pThis, pCur);
     
    24102440static bool rtCrX509CpvCheckCriticalExtensions(PRTCRX509CERTPATHSINT pThis, PRTCRX509CERTPATHNODE pNode)
    24112441{
    2412     uint32_t                cLeft = pNode->pCert->TbsCertificate.T3.Extensions.cItems;
    2413     PCRTCRX509EXTENSION     pCur  = pNode->pCert->TbsCertificate.T3.Extensions.paItems;
     2442    uint32_t                  cLeft = pNode->pCert->TbsCertificate.T3.Extensions.cItems;
     2443    PRTCRX509EXTENSION const *ppCur = pNode->pCert->TbsCertificate.T3.Extensions.papItems;
    24142444    while (cLeft-- > 0)
    24152445    {
     2446        PCRTCRX509EXTENSION const pCur = *ppCur;
    24162447        if (pCur->Critical.fValue)
    24172448        {
     
    24312462        }
    24322463
    2433         pCur++;
     2464        ppCur++;
    24342465    }
    24352466
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette