VirtualBox

Ignore:
Timestamp:
Jul 16, 2022 3:43:25 AM (3 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
152317
Message:

IPRT/RTCrPkcs7: Split out RTCrPkcs7Attributes_HashAttributes from verification. bugref:8691

Location:
trunk/src/VBox/Runtime/common/crypto
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/common/crypto/pkcs7-core.cpp

    r93115 r95668  
    3333
    3434#include <iprt/errcore.h>
     35#include <iprt/mem.h>
    3536#include <iprt/string.h>
     37#include <iprt/crypto/digest.h>
    3638#include <iprt/crypto/tsp.h>
    3739
    3840#include "pkcs7-internal.h"
    3941
    40 
    41 /*
    42  * PCKS #7 SignerInfo
     42/*
     43 * PKCS #7 Attributes
     44 */
     45
     46RTDECL(int) RTCrPkcs7Attributes_HashAttributes(PRTCRPKCS7ATTRIBUTES pAttributes, RTCRDIGEST hDigest, PRTERRINFO pErrInfo)
     47{
     48    /* ASSUMES that the attributes are encoded according to DER. */
     49    uint8_t const  *pbData;
     50    uint32_t        cbData;
     51    void           *pvFree = NULL;
     52    int rc = RTAsn1EncodeQueryRawBits(RTCrPkcs7Attributes_GetAsn1Core(pAttributes),
     53                                      &pbData, &cbData, &pvFree, pErrInfo);
     54    if (RT_SUCCESS(rc))
     55    {
     56        uint8_t bSetOfTag = ASN1_TAG_SET | ASN1_TAGCLASS_UNIVERSAL | ASN1_TAGFLAG_CONSTRUCTED;
     57        rc = RTCrDigestUpdate(hDigest, &bSetOfTag, sizeof(bSetOfTag)); /* Replace the implict tag with a SET-OF tag. */
     58        if (RT_SUCCESS(rc))
     59            rc = RTCrDigestUpdate(hDigest, pbData + sizeof(bSetOfTag), cbData - sizeof(bSetOfTag)); /* Skip the implicit tag. */
     60        if (RT_SUCCESS(rc))
     61            rc = RTCrDigestFinal(hDigest, NULL, 0);
     62        else
     63            RTErrInfoSet(pErrInfo, rc, "RTCrDigestUpdate failed");
     64        RTMemTmpFree(pvFree);
     65    }
     66    return rc;
     67}
     68
     69
     70/*
     71 * PKCS #7 SignerInfo
    4372 */
    4473
     
    177206
    178207/*
    179  * PCKS #7 ContentInfo.
     208 * PKCS #7 ContentInfo.
    180209 */
    181210
  • trunk/src/VBox/Runtime/common/crypto/pkcs7-verify.cpp

    r94157 r95668  
    328328        *phDigest = hDigest;
    329329
    330         /* ASSUMES that the attributes are encoded according to DER. */
    331         uint8_t const  *pbData;
    332         uint32_t        cbData;
    333         void           *pvFree = NULL;
    334         rc = RTAsn1EncodeQueryRawBits(RTCrPkcs7Attributes_GetAsn1Core(&pSignerInfo->AuthenticatedAttributes),
    335                                       &pbData, &cbData, &pvFree, pErrInfo);
    336         if (RT_SUCCESS(rc))
    337         {
    338             uint8_t bSetOfTag = ASN1_TAG_SET | ASN1_TAGCLASS_UNIVERSAL | ASN1_TAGFLAG_CONSTRUCTED;
    339             rc = RTCrDigestUpdate(hDigest, &bSetOfTag, sizeof(bSetOfTag)); /* Replace the implict tag with a SET-OF tag. */
    340             if (RT_SUCCESS(rc))
    341                 rc = RTCrDigestUpdate(hDigest, pbData + sizeof(bSetOfTag), cbData - sizeof(bSetOfTag)); /* Skip the implicit tag. */
    342             if (RT_SUCCESS(rc))
    343                 rc = RTCrDigestFinal(hDigest, NULL, 0);
    344             RTMemTmpFree(pvFree);
    345         }
     330        /** @todo The encoding step modifies the data, contradicting the const-ness
     331         *        of the parameter. */
     332        rc = RTCrPkcs7Attributes_HashAttributes((PRTCRPKCS7ATTRIBUTES)&pSignerInfo->AuthenticatedAttributes, hDigest, pErrInfo);
    346333    }
    347334    return rc;
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