VirtualBox

Ignore:
Timestamp:
May 14, 2020 5:40:35 PM (5 years ago)
Author:
vboxsync
Message:

IPRT/crypto: Adding RTAsn1EncodeQueryRawBits to deal with getting encoded bytes cheaply if possible and always safely. Fixed another place using RTASN1CORE_GET_RAW_ASN1_PTR and assuming input was decoded and had valid data pointers. Added RTCrStoreCertAddPkcs7 and RTCrStoreCertAddX509 for more conveniently adding decoded certs to stores. Added RTCRPKCS7VERIFY_SD_F_TRUST_ALL_CERTS to the PKCS7 verification code. Added RTCrPkcs7_ReadFromBuffer. bugref:9699

File:
1 edited

Legend:

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

    r82968 r84310  
    8989     * encoded bits are missing.
    9090     */
    91     if (   pThis->TbsCertificate.SeqCore.Asn1Core.uData.pu8
    92         && pThis->TbsCertificate.SeqCore.Asn1Core.cb > 0)
     91    const uint8_t  *pbRaw;
     92    uint32_t        cbRaw;
     93    void           *pvFree = NULL;
     94    rc = RTAsn1EncodeQueryRawBits(RTCrX509TbsCertificate_GetAsn1Core(&pThis->TbsCertificate), &pbRaw, &cbRaw, &pvFree, pErrInfo);
     95    if (RT_SUCCESS(rc))
     96    {
    9397        rc = RTCrPkixPubKeyVerifySignature(&pThis->SignatureAlgorithm.Algorithm, hPubKey, pParameters, &pThis->SignatureValue,
    94                                            RTASN1CORE_GET_RAW_ASN1_PTR(&pThis->TbsCertificate.SeqCore.Asn1Core),
    95                                            RTASN1CORE_GET_RAW_ASN1_SIZE(&pThis->TbsCertificate.SeqCore.Asn1Core),
    96                                            pErrInfo);
    97     else
    98     {
    99         uint32_t cbEncoded;
    100         rc = RTAsn1EncodePrepare((PRTASN1CORE)&pThis->TbsCertificate.SeqCore.Asn1Core, RTASN1ENCODE_F_DER, &cbEncoded, pErrInfo);
    101         if (RT_SUCCESS(rc))
    102         {
    103             void *pvTbsBits = RTMemTmpAlloc(cbEncoded);
    104             if (pvTbsBits)
    105             {
    106                 rc = RTAsn1EncodeToBuffer(&pThis->TbsCertificate.SeqCore.Asn1Core, RTASN1ENCODE_F_DER,
    107                                           pvTbsBits, cbEncoded, pErrInfo);
    108                 if (RT_SUCCESS(rc))
    109                     rc = RTCrPkixPubKeyVerifySignature(&pThis->SignatureAlgorithm.Algorithm, hPubKey, pParameters,
    110                                                        &pThis->SignatureValue, pvTbsBits, cbEncoded, pErrInfo);
    111                 else
    112                     AssertRC(rc);
    113                 RTMemTmpFree(pvTbsBits);
    114             }
    115             else
    116                 rc = VERR_NO_TMP_MEMORY;
    117         }
     98                                           pbRaw, cbRaw, pErrInfo);
     99        RTMemTmpFree(pvFree);
    118100    }
    119101
Note: See TracChangeset for help on using the changeset viewer.

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