VirtualBox

Changeset 60246 in vbox for trunk/src


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

CertificateImpl.*: Implemented the two missing internal function in the DONT_DUPLICATE_ALL_THE_DATA version of the code.

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

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/include/CertificateImpl.h

    r60243 r60246  
    4545
    4646#ifdef DONT_DUPLICATE_ALL_THE_DATA
    47     HRESULT init(PCRTCRX509CERTIFICATE a_pCert);
     47    HRESULT initCertificate(PCRTCRX509CERTIFICATE a_pCert, bool a_fTrusted);
    4848#else
    4949    HRESULT init(Appliance* appliance);
  • trunk/src/VBox/Main/src-server/CertificateImpl.cpp

    r60243 r60246  
    9999};
    100100
     101#ifndef DONT_DUPLICATE_ALL_THE_DATA
    101102const char* const strUnknownAlgorithm = "Unknown Algorithm";
    102103const char* const strRsaEncription = "rsaEncryption";
     
    109110const char* const strSha512WithRSAEncryption = "sha512WithRSAEncryption";
    110111const char* const strSha224WithRSAEncryption = "sha224WithRSAEncryption";
     112#endif
    111113
    112114///////////////////////////////////////////////////////////////////////////////////
     
    130132
    131133#ifdef DONT_DUPLICATE_ALL_THE_DATA
    132 HRESULT Certificate::init(PCRTCRX509CERTIFICATE a_pCert)
     134/**
     135 * Initializes a certificate instance.
     136 *
     137 * @returns COM status code.
     138 * @param   a_pCert         The certificate.
     139 * @param   a_fTrusted      Whether the caller trusts the certificate or not.
     140 */
     141HRESULT Certificate::initCertificate(PCRTCRX509CERTIFICATE a_pCert, bool a_fTrusted)
    133142#else
    134143HRESULT Certificate::init(Appliance* appliance)
     
    157166    int vrc = RTCrX509Certificate_Clone(&mData->m->X509, a_pCert, &g_RTAsn1DefaultAllocator);
    158167    if (RT_SUCCESS(vrc))
     168    {
    159169        mData->m->fValidX509 = true;
     170        mData->m->fTrusted  = a_fTrusted;
     171    }
    160172    else
    161173        rc = Global::vboxStatusCodeToCOM(vrc);
     
    894906HRESULT Certificate::i_getAlgorithmName(PCRTCRX509ALGORITHMIDENTIFIER a_pAlgId, com::Utf8Str &a_rReturn)
    895907{
    896     /** @todo  */
    897     NOREF(a_pAlgId);
    898     NOREF(a_rReturn);
    899     return E_NOTIMPL;
     908    const char *pszOid = a_pAlgId->Algorithm.szObjId;
     909    const char *pszName;
     910    if (!pszOid)    pszName = "";
     911    else if (strcmp(pszOid, RTCRX509ALGORITHMIDENTIFIERID_RSA))                 pszName = "rsaEncryption";
     912    else if (strcmp(pszOid, RTCRX509ALGORITHMIDENTIFIERID_MD2_WITH_RSA))        pszName = "md2WithRSAEncryption";
     913    else if (strcmp(pszOid, RTCRX509ALGORITHMIDENTIFIERID_MD4_WITH_RSA))        pszName = "md4WithRSAEncryption";
     914    else if (strcmp(pszOid, RTCRX509ALGORITHMIDENTIFIERID_MD5_WITH_RSA))        pszName = "md5WithRSAEncryption";
     915    else if (strcmp(pszOid, RTCRX509ALGORITHMIDENTIFIERID_SHA1_WITH_RSA))       pszName = "sha1WithRSAEncryption";
     916    else if (strcmp(pszOid, RTCRX509ALGORITHMIDENTIFIERID_SHA224_WITH_RSA))     pszName = "sha224WithRSAEncryption";
     917    else if (strcmp(pszOid, RTCRX509ALGORITHMIDENTIFIERID_SHA256_WITH_RSA))     pszName = "sha256WithRSAEncryption";
     918    else if (strcmp(pszOid, RTCRX509ALGORITHMIDENTIFIERID_SHA384_WITH_RSA))     pszName = "sha384WithRSAEncryption";
     919    else if (strcmp(pszOid, RTCRX509ALGORITHMIDENTIFIERID_SHA512_WITH_RSA))     pszName = "sha512WithRSAEncryption";
     920    else
     921        pszName = pszOid;
     922    a_rReturn = pszName;
     923    return S_OK;
    900924}
    901925
    902926HRESULT Certificate::i_getX509Name(PCRTCRX509NAME a_pName, std::vector<com::Utf8Str> &a_rReturn)
    903927{
    904     /** @todo  */
    905     NOREF(a_pName);
    906     NOREF(a_rReturn);
    907     return E_NOTIMPL;
     928    if (RTCrX509Name_IsPresent(a_pName))
     929    {
     930        for (uint32_t i = 0; i < a_pName->cItems; i++)
     931        {
     932            PCRTCRX509RELATIVEDISTINGUISHEDNAME pRdn = &a_pName->paItems[i];
     933            for (uint32_t j = 0; j < pRdn->cItems; j++)
     934            {
     935                PCRTCRX509ATTRIBUTETYPEANDVALUE pComponent = &pRdn->paItems[j];
     936
     937                AssertReturn(pComponent->Value.enmType == RTASN1TYPE_STRING,
     938                             setErrorVrc(VERR_CR_X509_NAME_NOT_STRING, "VERR_CR_X509_NAME_NOT_STRING"));
     939
     940                /* Get the prefix for this name component. */
     941                const char *pszPrefix = RTCrX509Name_GetShortRdn(&pComponent->Type);
     942                AssertStmt(pszPrefix, pszPrefix = pComponent->Type.szObjId);
     943
     944                /* Get the string. */
     945                const char *pszUtf8;
     946                int vrc = RTAsn1String_QueryUtf8(&pComponent->Value.u.String, &pszUtf8, NULL /*pcch*/);
     947                AssertRCReturn(vrc, setErrorVrc(vrc, "RTAsn1String_QueryUtf8(%u/%u,,) -> %Rrc", i, j, vrc));
     948
     949                a_rReturn.push_back(Utf8StrFmt("%s=%s", pszPrefix, pszUtf8));
     950            }
     951        }
     952    }
     953    return S_OK;
    908954}
    909955
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