VirtualBox

Changeset 60243 in vbox for trunk


Ignore:
Timestamp:
Mar 29, 2016 2:21:22 PM (9 years ago)
Author:
vboxsync
Message:

CertificateImpl: Sketched how this should've been done. Don't duplicate things five times over, just clone the X509 certicate object. Added lost publicKeyAlgorithmOID method (it was in my diff). Made issuerUniqueIdentifier and subjectUniqueIdentifier return a string instead of a byte array. keyUsage shouldn't have returned an safearray, my bad.

Location:
trunk/src/VBox/Main
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/idl/VirtualBox.xidl

    r60236 r60243  
    29862986  <interface
    29872987    name="ICertificate" extends="$unknown"
    2988     uuid="c2b34d6f-7a10-4901-803e-05d5ef946567"
     2988    uuid="336064ce-c853-4bd0-ad6c-b42d8ed99e5e"
    29892989    wsmap="managed"
    29902990    reservedAttributes="4" reservedMethods="2"
     
    30203020      <desc>Time stamp in milliseconds since 1970-01-01 UTC.</desc>
    30213021    </attribute>
     3022    <attribute name="publicKeyAlgorithmOID" type="wstring" readonly="yes">
     3023      <desc>The dotted OID of the public key algorithm.</desc>
     3024    </attribute>
    30223025    <attribute name="publicKeyAlgorithm" type="wstring" readonly="yes">
    30233026      <desc>The public key algorithm name (if known).</desc>
     
    30263029      <desc>The raw public key bytes.</desc>
    30273030    </attribute>
    3028     <attribute name="issuerUniqueIdentifier" type="octet" safearray="yes" readonly="yes">
    3029       <desc>Unique identifier of the issuer (optional).</desc>
    3030     </attribute>
    3031     <attribute name="subjectUniqueIdentifier" type="octet" safearray="yes" readonly="yes">
    3032       <desc>Unique identifier of this certificate (optional).</desc>
     3031    <attribute name="issuerUniqueIdentifier" type="wstring" readonly="yes">
     3032      <desc>Unique identifier of the issuer (empty string if not present).</desc>
     3033    </attribute>
     3034    <attribute name="subjectUniqueIdentifier" type="wstring" readonly="yes">
     3035      <desc>Unique identifier of this certificate (empty string if not present).</desc>
    30333036    </attribute>
    30343037    <attribute name="certificateAuthority" type="boolean" readonly="yes">
     
    30373040      </desc>
    30383041    </attribute>
    3039     <attribute name="keyUsage" type="unsigned long" safearray="yes" readonly="yes">
     3042    <attribute name="keyUsage" type="unsigned long" readonly="yes">
    30403043      <desc>Key usage mask.  Will return 0 if not present.</desc>
    30413044    </attribute>
  • trunk/src/VBox/Main/include/CertificateImpl.h

    r60239 r60243  
     1/* $Id$ */
    12/** @file
    2  * VirtualBox COM class implementation
     3 * VirtualBox COM ICertificate implementation.
    34 */
    45
    56/*
    6  * Copyright (C) 2006-2013 Oracle Corporation
     7 * Copyright (C) 2006-2016 Oracle Corporation
    78 *
    89 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    1819#define ____H_CERTIFICATEIMPL
    1920
     21//#define DONT_DUPLICATE_ALL_THE_DATA
     22
    2023/* VBox includes */
    2124#include <VBox/settings.h>
    22 
    23 
     25#include <iprt/crypto/x509.h>
    2426#include "CertificateWrap.h"
    2527
    2628#include <vector>
    2729
     30
    2831using namespace std;
    2932
     33#ifndef DONT_DUPLICATE_ALL_THE_DATA
    3034/* VBox forward declarations */
    3135class Appliance;
    32 struct RTCRX509CERTIFICATE;
     36#endif
    3337
    3438class ATL_NO_VTABLE Certificate :
     
    4044    DECLARE_EMPTY_CTOR_DTOR(Certificate)
    4145
     46#ifdef DONT_DUPLICATE_ALL_THE_DATA
     47    HRESULT init(PCRTCRX509CERTIFICATE a_pCert);
     48#else
    4249    HRESULT init(Appliance* appliance);
     50#endif
    4351    void uninit();
    4452
     
    4654    void FinalRelease();
    4755
    48     HRESULT setData(RTCRX509CERTIFICATE *inCert);
     56#ifndef DONT_DUPLICATE_ALL_THE_DATA
     57    HRESULT setData(RTCRX509CERTIFICATE const *inCert);
     58#endif
    4959
    5060private:
     61#ifndef DONT_DUPLICATE_ALL_THE_DATA /* This is a generic information object, not something that is exclusive to Appliance! */
     62    const Appliance* m_appliance;
     63#endif
    5164
    52     const Appliance* m_appliance;
    53 
     65#ifndef DONT_DUPLICATE_ALL_THE_DATA /* This is a generic information object, not something that is exclusive to Appliance! */
    5466    HRESULT setVersionNumber(uint64_t inVersionNumber);
    5567    HRESULT setSerialNumber(uint64_t inSerialNumber);
     
    7183//  HRESULT setExtendedKeyUsage(std::vector<com::Utf8Str> aExtendedKeyUsage);
    7284//  HRESULT setRawCertData(std::vector<BYTE> aRawCertData);
     85#endif
    7386
    7487    // wrapped ICertificate properties
     
    7790    HRESULT getSignatureAlgorithmOID(com::Utf8Str &aSignatureAlgorithmOID);
    7891    HRESULT getSignatureAlgorithmName(com::Utf8Str &aSignatureAlgorithmName);
     92    HRESULT getPublicKeyAlgorithmOID(com::Utf8Str &aPublicKeyAlgorithmOID);
    7993    HRESULT getPublicKeyAlgorithm(com::Utf8Str &aPublicKeyAlgorithm);
    8094    HRESULT getIssuerName(std::vector<com::Utf8Str> &aIssuerName);
     
    8397    HRESULT getValidityPeriodNotAfter(com::Utf8Str &aValidityPeriodNotAfter);
    8498    HRESULT getSubjectPublicKey(std::vector<BYTE> &aSubjectPublicKey);
    85     HRESULT getIssuerUniqueIdentifier(std::vector<BYTE> &aIssuerUniqueIdentifier);
    86     HRESULT getSubjectUniqueIdentifier(std::vector<BYTE> &aSubjectUniqueIdentifier);
     99    HRESULT getIssuerUniqueIdentifier(com::Utf8Str &aIssuerUniqueIdentifier);
     100    HRESULT getSubjectUniqueIdentifier(com::Utf8Str &aSubjectUniqueIdentifier);
    87101    HRESULT getCertificateAuthority(BOOL *aCertificateAuthority);
    88     HRESULT getKeyUsage(std::vector<ULONG> &aKeyUsage);
     102    HRESULT getKeyUsage(ULONG *aKeyUsage);
    89103    HRESULT getExtendedKeyUsage(std::vector<com::Utf8Str> &aExtendedKeyUsage);
    90104    HRESULT getRawCertData(std::vector<BYTE> &aRawCertData);
     
    94108    // wrapped ICertificate methods
    95109    HRESULT queryInfo(LONG aWhat, com::Utf8Str &aResult);
     110#ifndef DONT_DUPLICATE_ALL_THE_DATA
    96111    HRESULT checkExistence(BOOL *aPresence);
    97112    HRESULT isVerified(BOOL *aVerified);
     113#endif
     114
     115#ifdef DONT_DUPLICATE_ALL_THE_DATA
     116    /** @name Methods extracting COM data from the certificate object
     117     * @{  */
     118    HRESULT i_getAlgorithmName(PCRTCRX509ALGORITHMIDENTIFIER a_pAlgId, com::Utf8Str &a_rReturn);
     119    HRESULT i_getX509Name(PCRTCRX509NAME a_pName, std::vector<com::Utf8Str> &a_rReturn);
     120    HRESULT i_getTime(PCRTASN1TIME a_pTime, com::Utf8Str &a_rReturn);
     121    HRESULT i_getUniqueIdentifier(PCRTCRX509UNIQUEIDENTIFIER a_pUniqueId, com::Utf8Str &a_rReturn);
     122    HRESULT i_getEncodedBytes(PRTASN1CORE a_pAsn1Obj, std::vector<BYTE> &a_rReturn);
     123    /** @} */
     124#endif
    98125    //data
    99126    struct Data;
  • trunk/src/VBox/Main/src-server/CertificateImpl.cpp

    r60239 r60243  
    1 
     1/* $Id$ */
    22/** @file
    33 * ICertificate COM class implementations.
     
    2626#include "CertificateImpl.h"
    2727#include "AutoCaller.h"
     28#include "Global.h"
    2829#include "Logging.h"
    2930
     
    3233struct CertificateData
    3334{
     35#ifdef DONT_DUPLICATE_ALL_THE_DATA
     36    CertificateData()
     37        : fTrusted(false)
     38        , fValidX509(false)
     39    {
     40        RT_ZERO(X509);
     41    }
     42
     43    ~CertificateData()
     44    {
     45        if (fValidX509)
     46        {
     47            RTCrX509Certificate_Delete(&X509);
     48            RT_ZERO(X509);
     49            fValidX509 = false;
     50        }
     51    }
     52
     53    /** Whether the certificate is trusted.  */
     54    bool fTrusted;
     55    /** Valid data in mX509. */
     56    bool fValidX509;
     57    /** Clone of the X.509 certificate. */
     58    RTCRX509CERTIFICATE X509;
     59
     60private:
     61    CertificateData(const CertificateData &rTodo) { AssertFailed(); NOREF(rTodo); }
     62    CertificateData &operator=(const CertificateData &rTodo) { AssertFailed(); NOREF(rTodo); return *this; }
     63
     64#else
    3465    CertificateData() :
    3566        mVersionNumber(0),
     
    6091    std::vector<Utf8Str> mExtendedKeyUsage;
    6192    std::vector<BYTE> mRawCertData;
    62 
     93#endif
    6394};
    6495
     
    98129}
    99130
     131#ifdef DONT_DUPLICATE_ALL_THE_DATA
     132HRESULT Certificate::init(PCRTCRX509CERTIFICATE a_pCert)
     133#else
    100134HRESULT Certificate::init(Appliance* appliance)
     135#endif
    101136{
    102137    HRESULT rc = S_OK;
     
    107142    AssertReturn(autoInitSpan.isOk(), E_FAIL);
    108143
     144#ifndef DONT_DUPLICATE_ALL_THE_DATA
    109145    if(appliance!=NULL)
    110146    {
     
    114150    else
    115151        rc = E_FAIL;
     152#endif
    116153
    117154    mData = new Data();
    118155    mData->m.allocate();
     156#ifdef DONT_DUPLICATE_ALL_THE_DATA
     157    int vrc = RTCrX509Certificate_Clone(&mData->m->X509, a_pCert, &g_RTAsn1DefaultAllocator);
     158    if (RT_SUCCESS(vrc))
     159        mData->m->fValidX509 = true;
     160    else
     161        rc = Global::vboxStatusCodeToCOM(vrc);
     162#else
    119163    mData->m->mSignatureAlgorithmOID.setNull();
    120164    mData->m->mSignatureAlgorithmName.setNull();
     
    130174    mData->m->mExtendedKeyUsage.resize(0);
    131175    mData->m->mRawCertData.resize(0);
     176#endif
    132177
    133178    /* Confirm a successful initialization when it's the case */
     
    152197    mData = NULL;
    153198}
     199
     200#ifndef DONT_DUPLICATE_ALL_THE_DATA /* We'll query the data from the RTCrX509* API. */
     201
    154202/**
    155203 * Public method implementation.
     
    157205 * @return
    158206 */
    159 HRESULT Certificate::setData(RTCRX509CERTIFICATE *inCert)
     207HRESULT Certificate::setData(PCRTCRX509CERTIFICATE inCert)
    160208{
    161209
     
    452500}
    453501
     502#endif /* !DONT_DUPLICATE_ALL_THE_DATA */
     503
    454504/**
    455505 * Private method implementation.
     
    460510{
    461511    AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
     512#ifdef DONT_DUPLICATE_ALL_THE_DATA
     513    Assert(mData->m->fValidX509);
     514    /** @todo make this ULONG, or better, an ENUM. */
     515    aVersionNumber = Utf8StrFmt("%RU64", mData->m->X509.TbsCertificate.T0.Version.uValue.u + 1); /* version 1 has value 0, so +1. */
     516#else
    462517    Utf8StrFmt strVer("%Lu", mData->m->mVersionNumber);
    463518    aVersionNumber = strVer;
     519#endif
    464520    return S_OK;
    465521}
     
    473529{
    474530    AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
     531#ifdef DONT_DUPLICATE_ALL_THE_DATA
     532    Assert(mData->m->fValidX509);
     533
     534    char szTmp[_2K];
     535    int vrc = RTAsn1Integer_ToString(&mData->m->X509.TbsCertificate.SerialNumber, szTmp, sizeof(szTmp), 0, NULL);
     536    if (RT_SUCCESS(vrc))
     537        aSerialNumber = szTmp;
     538    else
     539        return Global::vboxStatusCodeToCOM(vrc);
     540#else
    475541    Utf8StrFmt strVer("%llx", mData->m->mSerialNumber);
    476542    aSerialNumber = strVer;
     543#endif
    477544    return S_OK;
    478545}
     
    486553{
    487554    AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
    488 
     555#ifdef DONT_DUPLICATE_ALL_THE_DATA
     556    Assert(mData->m->fValidX509);
     557    aSignatureAlgorithmOID = mData->m->X509.TbsCertificate.Signature.Algorithm.szObjId;
     558#else
    489559    aSignatureAlgorithmOID = mData->m->mSignatureAlgorithmOID;
    490 
     560#endif
    491561    return S_OK;
    492562}
     
    500570{
    501571    AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
    502 
     572#ifdef DONT_DUPLICATE_ALL_THE_DATA
     573    Assert(mData->m->fValidX509);
     574    return i_getAlgorithmName(&mData->m->X509.TbsCertificate.Signature, aSignatureAlgorithmName);
     575#else
    503576    aSignatureAlgorithmName = mData->m->mSignatureAlgorithmName;
    504577
    505578    return S_OK;
     579#endif
    506580}
    507581
     
    514588{
    515589    AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
    516 
     590#ifdef DONT_DUPLICATE_ALL_THE_DATA
     591    Assert(mData->m->fValidX509);
     592    return i_getX509Name(&mData->m->X509.TbsCertificate.Issuer, aIssuerName);
     593#else
    517594    aIssuerName = mData->m->mIssuerName;
    518595
    519596    return S_OK;
     597#endif
    520598}
    521599
     
    528606{
    529607    AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
     608#ifdef DONT_DUPLICATE_ALL_THE_DATA
     609    Assert(mData->m->fValidX509);
     610    return i_getX509Name(&mData->m->X509.TbsCertificate.Subject, aSubjectName);
     611#else
    530612
    531613    aSubjectName = mData->m->mSubjectName;
    532614
    533615    return S_OK;
     616#endif
    534617}
    535618
     
    542625{
    543626    AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
    544 
     627#ifdef DONT_DUPLICATE_ALL_THE_DATA
     628    Assert(mData->m->fValidX509);
     629    return i_getTime(&mData->m->X509.TbsCertificate.Validity.NotBefore, aValidityPeriodNotBefore);
     630#else
    545631    HRESULT rc = S_OK;
    546632
     
    558644
    559645    return rc;
     646#endif
    560647}
    561648
     
    568655{
    569656    AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
     657#ifdef DONT_DUPLICATE_ALL_THE_DATA
     658    Assert(mData->m->fValidX509);
     659    return i_getTime(&mData->m->X509.TbsCertificate.Validity.NotAfter, aValidityPeriodNotAfter);
     660#else
    570661
    571662    HRESULT rc = S_OK;
     
    582673    delete[] charArr;
    583674    return rc;
     675#endif
     676}
     677
     678HRESULT Certificate::getPublicKeyAlgorithmOID(com::Utf8Str &aPublicKeyAlgorithmOID)
     679{
     680    AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
     681#ifdef DONT_DUPLICATE_ALL_THE_DATA
     682    Assert(mData->m->fValidX509);
     683    aPublicKeyAlgorithmOID = mData->m->X509.TbsCertificate.SubjectPublicKeyInfo.Algorithm.Algorithm.szObjId;
     684    return S_OK;
     685#else
     686    return E_NOTIMPL;
     687#endif
    584688}
    585689
     
    592696{
    593697    AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
    594 
     698#ifdef DONT_DUPLICATE_ALL_THE_DATA
     699    Assert(mData->m->fValidX509);
     700    return i_getAlgorithmName(&mData->m->X509.TbsCertificate.SubjectPublicKeyInfo.Algorithm, aPublicKeyAlgorithm);
     701#else
    595702    aPublicKeyAlgorithm = mData->m->mPublicKeyAlgorithmName;
    596703
    597704    return S_OK;
     705#endif
    598706}
    599707
     
    605713HRESULT Certificate::getSubjectPublicKey(std::vector<BYTE> &aSubjectPublicKey)
    606714{
    607     AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
    608 
    609     return S_OK;
     715#ifdef DONT_DUPLICATE_ALL_THE_DATA
     716    AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS); /* Getting encoded ASN.1 bytes may make changes to X509. */
     717    return i_getEncodedBytes(&mData->m->X509.TbsCertificate.SubjectPublicKeyInfo.SubjectPublicKey.Asn1Core, aSubjectPublicKey);
     718#else
     719    return E_NOTIMPL;
     720#endif
    610721}
    611722
     
    615726 * @return
    616727 */
    617 HRESULT Certificate::getIssuerUniqueIdentifier(std::vector<BYTE> &aIssuerUniqueIdentifier)
    618 {
    619     AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
    620 
    621     return S_OK;
     728HRESULT Certificate::getIssuerUniqueIdentifier(com::Utf8Str &aIssuerUniqueIdentifier)
     729{
     730    AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
     731#ifdef DONT_DUPLICATE_ALL_THE_DATA
     732    return i_getUniqueIdentifier(&mData->m->X509.TbsCertificate.T1.IssuerUniqueId, aIssuerUniqueIdentifier);
     733#else
     734    return E_NOTIMPL;
     735#endif
    622736}
    623737
     
    627741 * @return
    628742 */
    629 HRESULT Certificate::getSubjectUniqueIdentifier(std::vector<BYTE> &aSubjectUniqueIdentifier)
    630 {
    631     AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
    632 
    633     return S_OK;
     743HRESULT Certificate::getSubjectUniqueIdentifier(com::Utf8Str &aSubjectUniqueIdentifier)
     744{
     745    AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
     746#ifdef DONT_DUPLICATE_ALL_THE_DATA
     747    return i_getUniqueIdentifier(&mData->m->X509.TbsCertificate.T2.SubjectUniqueId, aSubjectUniqueIdentifier);
     748#else
     749    return E_NOTIMPL;
     750#endif
    634751}
    635752
     
    642759{
    643760    AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
    644 
     761#ifdef DONT_DUPLICATE_ALL_THE_DATA
     762    *aCertificateAuthority = mData->m->X509.TbsCertificate.T3.pBasicConstraints
     763                          && mData->m->X509.TbsCertificate.T3.pBasicConstraints->CA.fValue;
     764#else
    645765    *aCertificateAuthority = mData->m->mCertificateAuthority;
    646 
     766#endif
    647767    return S_OK;
    648768}
     
    653773 * @return
    654774 */
    655 HRESULT Certificate::getKeyUsage(std::vector<ULONG> &aKeyUsage)
    656 {
    657     AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
    658 
    659     return S_OK;
     775HRESULT Certificate::getKeyUsage(ULONG *aKeyUsage)
     776{
     777    AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
     778#ifdef DONT_DUPLICATE_ALL_THE_DATA
     779    *aKeyUsage = mData->m->X509.TbsCertificate.T3.fKeyUsage;
     780    return S_OK;
     781#else
     782    return E_NOTIMPL;
     783#endif
    660784}
    661785
     
    668792{
    669793    AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
    670 
    671     return S_OK;
     794    NOREF(aExtendedKeyUsage);
     795    return E_NOTIMPL;
    672796}
    673797
     
    679803HRESULT Certificate::getRawCertData(std::vector<BYTE> &aRawCertData)
    680804{
    681     AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
    682 
    683     return S_OK;
     805#ifdef DONT_DUPLICATE_ALL_THE_DATA
     806    AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS); /* Getting encoded ASN.1 bytes may make changes to X509. */
     807    return i_getEncodedBytes(&mData->m->X509.SeqCore.Asn1Core, aRawCertData);
     808#else
     809    return E_NOTIMPL;
     810#endif
    684811}
    685812
     
    692819{
    693820    AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
    694 
     821#ifdef DONT_DUPLICATE_ALL_THE_DATA
     822    Assert(mData->m->fValidX509);
     823    *aSelfSigned = RTCrX509Certificate_IsSelfSigned(&mData->m->X509);
     824#else
    695825    *aSelfSigned = mData->m->mSelfSigned;
    696 
     826#endif
    697827    return S_OK;
    698828}
     
    706836{
    707837    AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
    708 
     838#ifdef DONT_DUPLICATE_ALL_THE_DATA
     839    *aTrusted = mData->m->fTrusted;
     840#else
    709841    *aTrusted = mData->m->mTrusted;
    710 
     842#endif
    711843    return S_OK;
    712844}
     
    721853{
    722854    AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
    723 
    724     return S_OK;
    725 }
     855    /* Insurance. */
     856    NOREF(aResult);
     857    return setError(E_FAIL, "Unknown item %u", aWhat);
     858}
     859
     860#ifndef DONT_DUPLICATE_ALL_THE_DATA  /* These are out of place. */
    726861
    727862/**
     
    755890}
    756891
     892#else  /* DONT_DUPLICATE_ALL_THE_DATA */
     893
     894HRESULT Certificate::i_getAlgorithmName(PCRTCRX509ALGORITHMIDENTIFIER a_pAlgId, com::Utf8Str &a_rReturn)
     895{
     896    /** @todo  */
     897    NOREF(a_pAlgId);
     898    NOREF(a_rReturn);
     899    return E_NOTIMPL;
     900}
     901
     902HRESULT Certificate::i_getX509Name(PCRTCRX509NAME a_pName, std::vector<com::Utf8Str> &a_rReturn)
     903{
     904    /** @todo  */
     905    NOREF(a_pName);
     906    NOREF(a_rReturn);
     907    return E_NOTIMPL;
     908}
     909
     910HRESULT Certificate::i_getTime(PCRTASN1TIME a_pTime, com::Utf8Str &a_rReturn)
     911{
     912    char szTmp[128];
     913    if (RTTimeToString(&a_pTime->Time, szTmp, sizeof(szTmp)))
     914    {
     915        a_rReturn = szTmp;
     916        return S_OK;
     917    }
     918    AssertFailed();
     919    return E_FAIL;
     920}
     921
     922HRESULT Certificate::i_getUniqueIdentifier(PCRTCRX509UNIQUEIDENTIFIER a_pUniqueId, com::Utf8Str &a_rReturn)
     923{
     924    /* The a_pUniqueId may not be present! */
     925    if (RTCrX509UniqueIdentifier_IsPresent(a_pUniqueId))
     926    {
     927        void const   *pvData = RTASN1BITSTRING_GET_BIT0_PTR(a_pUniqueId);
     928        size_t const  cbData = RTASN1BITSTRING_GET_BYTE_SIZE(a_pUniqueId);
     929        size_t const  cbFormatted = cbData * 3 - 1 + 1;
     930        a_rReturn.reserve(cbFormatted); /* throws */
     931        int vrc = RTStrPrintHexBytes(a_rReturn.mutableRaw(), cbFormatted, pvData, cbData, RTSTRPRINTHEXBYTES_F_SEP_COLON);
     932        a_rReturn.jolt();
     933        AssertRCReturn(vrc, Global::vboxStatusCodeToCOM(vrc));
     934    }
     935    else
     936        Assert(a_rReturn.isEmpty());
     937    return S_OK;
     938}
     939
     940HRESULT Certificate::i_getEncodedBytes(PRTASN1CORE a_pAsn1Obj, std::vector<BYTE> &a_rReturn)
     941{
     942    HRESULT hrc = S_OK;
     943    Assert(a_rReturn.size() == 0);
     944    if (RTAsn1Core_IsPresent(a_pAsn1Obj))
     945    {
     946        uint32_t cbEncoded;
     947        int vrc = RTAsn1EncodePrepare(a_pAsn1Obj, 0, &cbEncoded, NULL);
     948        if (RT_SUCCESS(vrc))
     949        {
     950            a_rReturn.resize(cbEncoded);
     951            Assert(a_rReturn.size() == cbEncoded);
     952            if (cbEncoded)
     953            {
     954                vrc = RTAsn1EncodeToBuffer(a_pAsn1Obj, 0, &a_rReturn.front(), a_rReturn.size(), NULL);
     955                if (RT_FAILURE(vrc))
     956                    hrc = setErrorVrc(vrc, "RTAsn1EncodeToBuffer failed with %Rrc", vrc);
     957            }
     958        }
     959        else
     960            hrc = setErrorVrc(vrc, "RTAsn1EncodePrepare failed with %Rrc", vrc);
     961    }
     962    return hrc;
     963}
     964
     965#endif /* DONT_DUPLICATE_ALL_THE_DATA */
     966
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