VirtualBox

Changeset 60328 in vbox for trunk


Ignore:
Timestamp:
Apr 5, 2016 10:44:40 AM (9 years ago)
Author:
vboxsync
Message:

bugref:8249. Improvement ICertificate interface.

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

Legend:

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

    r60243 r60328  
    29802980  </enum>
    29812981
     2982  <enum
     2983    name="CertificateVersion"
     2984    uuid="394b00ce-4b60-45ff-abe1-f58221d4f73b"
     2985    >
     2986    <desc>
     2987        Possible version of certificate
     2988    </desc>
     2989    <const name="Unknown"    value="0"/>
     2990    <const name="One"    value="1"/>
     2991    <const name="Two"    value="2"/>
     2992    <const name="Three"    value="3"/>
     2993    <const name="Four"    value="4"/>
     2994  </enum>
     2995
    29822996  <!--
    29832997  // ICertificate
     
    29933007        X509 certificate details.
    29943008    </desc>
    2995     <attribute name="versionNumber" type="wstring" readonly="yes">
    2996       <desc>Certificate version.</desc>
     3009    <attribute name="versionNumber" type="CertificateVersion" readonly="yes">
     3010      <desc>Certificate version number.</desc>
    29973011    </attribute>
    29983012    <attribute name="serialNumber" type="wstring" readonly="yes">
     
    30553069      <desc>Set if the certificate is trusted.</desc>
    30563070    </attribute>
     3071    <attribute name="presence" type="boolean" readonly="yes">
     3072      <desc>Returns true in case of presence of certificate.</desc>
     3073    </attribute>
     3074    <attribute name="verified" type="boolean" readonly="yes">
     3075      <desc>Check whether certificate was verified or not during import.</desc>
     3076    </attribute>
    30573077
    30583078    <method name="queryInfo">
     
    30603080      <param name="what" type="long" dir="in"/>
    30613081      <param name="result" type="wstring" dir="return" />
    3062     </method>
    3063 
    3064     <method name="checkExistence">
    3065       <desc>
    3066         Check whether certificate exists or not in the OVF appliance.
    3067       </desc>
    3068 
    3069       <param name="presence" type="boolean" dir="return">
    3070         <desc>Returns true in case of presence of certificate.</desc>
    3071       </param>
    3072     </method>
    3073 
    3074     <method name="isVerified">
    3075       <desc>
    3076         Check whether certificate was verified or not during import.
    3077       </desc>
    3078 
    3079       <param name="verified" type="boolean" dir="return">
    3080         <desc>Returns true if certificate was verified.</desc>
    3081       </param>
    30823082    </method>
    30833083
  • trunk/src/VBox/Main/include/CertificateImpl.h

    r60246 r60328  
    1919#define ____H_CERTIFICATEIMPL
    2020
    21 //#define DONT_DUPLICATE_ALL_THE_DATA
    22 
    2321/* VBox includes */
    2422#include <VBox/settings.h>
     
    2826#include <vector>
    2927
    30 
    3128using namespace std;
    3229
    33 #ifndef DONT_DUPLICATE_ALL_THE_DATA
    34 /* VBox forward declarations */
    3530class Appliance;
    36 #endif
    3731
    3832class ATL_NO_VTABLE Certificate :
     
    4438    DECLARE_EMPTY_CTOR_DTOR(Certificate)
    4539
    46 #ifdef DONT_DUPLICATE_ALL_THE_DATA
     40    HRESULT init(Appliance* appliance);
    4741    HRESULT initCertificate(PCRTCRX509CERTIFICATE a_pCert, bool a_fTrusted);
    48 #else
    49     HRESULT init(Appliance* appliance);
    50 #endif
    5142    void uninit();
    5243
     
    5445    void FinalRelease();
    5546
    56 #ifndef DONT_DUPLICATE_ALL_THE_DATA
    57     HRESULT setData(RTCRX509CERTIFICATE const *inCert);
    58 #endif
    59 
    6047private:
    61 #ifndef DONT_DUPLICATE_ALL_THE_DATA /* This is a generic information object, not something that is exclusive to Appliance! */
    6248    const Appliance* m_appliance;
    63 #endif
    64 
    65 #ifndef DONT_DUPLICATE_ALL_THE_DATA /* This is a generic information object, not something that is exclusive to Appliance! */
    66     HRESULT setVersionNumber(uint64_t inVersionNumber);
    67     HRESULT setSerialNumber(uint64_t inSerialNumber);
    68     HRESULT setPublicKeyAlgorithmOID(const char *aPublicKeyAlgorithmOID);
    69     HRESULT setPublicKeyAlgorithmName(const char *aPublicKeyAlgorithmOID);
    70     HRESULT setSignatureAlgorithmOID(const char *aSignatureAlgorithmOID);
    71     HRESULT setSignatureAlgorithmName(const char *aSignatureAlgorithmOID);
    72     HRESULT setIssuerName(com::Utf8Str &aIssuerName);
    73     HRESULT setSubjectName(com::Utf8Str &aSubjectName);
    74     HRESULT setValidityPeriodNotBefore(PCRTTIME aValidityPeriodNotBefore);
    75     HRESULT setValidityPeriodNotAfter(PCRTTIME aValidityPeriodNotAfter);
    76     HRESULT setCertificateAuthority(BOOL aCertificateAuthority);
    77     HRESULT setSelfSigned(BOOL aSelfSigned);
    78     HRESULT setTrusted(BOOL aTrusted);
    79 //  HRESULT setSubjectPublicKey(std::vector<BYTE> aSubjectPublicKey);
    80 //  HRESULT setIssuerUniqueIdentifier(std::vector<BYTE> aIssuerUniqueIdentifier);
    81 //  HRESULT setSubjectUniqueIdentifier(std::vector<BYTE> aSubjectUniqueIdentifier);
    82 //  HRESULT setKeyUsage(std::vector<ULONG> aKeyUsage);
    83 //  HRESULT setExtendedKeyUsage(std::vector<com::Utf8Str> aExtendedKeyUsage);
    84 //  HRESULT setRawCertData(std::vector<BYTE> aRawCertData);
    85 #endif
    8649
    8750    // wrapped ICertificate properties
    88     HRESULT getVersionNumber(com::Utf8Str &aVersionNumber);
     51    HRESULT getVersionNumber(CertificateVersion_T *aVersionNumber);
    8952    HRESULT getSerialNumber(com::Utf8Str &aSerialNumber);
    9053    HRESULT getSignatureAlgorithmOID(com::Utf8Str &aSignatureAlgorithmOID);
     
    10568    HRESULT getSelfSigned(BOOL *aSelfSigned);
    10669    HRESULT getTrusted(BOOL *aTrusted);
    107 
     70    HRESULT getVerified(BOOL *aVerified);
     71    HRESULT getPresence(BOOL *aPresence);
    10872    // wrapped ICertificate methods
    10973    HRESULT queryInfo(LONG aWhat, com::Utf8Str &aResult);
    110 #ifndef DONT_DUPLICATE_ALL_THE_DATA
    111     HRESULT checkExistence(BOOL *aPresence);
    112     HRESULT isVerified(BOOL *aVerified);
    113 #endif
    11474
    115 #ifdef DONT_DUPLICATE_ALL_THE_DATA
    11675    /** @name Methods extracting COM data from the certificate object
    11776     * @{  */
     
    12281    HRESULT i_getEncodedBytes(PRTASN1CORE a_pAsn1Obj, std::vector<BYTE> &a_rReturn);
    12382    /** @} */
    124 #endif
     83
    12584    //data
    12685    struct Data;
  • trunk/src/VBox/Main/src-server/ApplianceImplImport.cpp

    r60220 r60328  
    17161716     * digest that is encrypted with the certificate in the latter part.
    17171717     */
     1718    bool lTrusted = false;
     1719
    17181720    if (m->pbSignedDigest)
    17191721    {
     
    18291831                if (   !m->SignerCert.TbsCertificate.T3.pBasicConstraints
    18301832                    || !m->SignerCert.TbsCertificate.T3.pBasicConstraints->CA.fValue)
     1833                {
    18311834                    i_addWarning(tr("Self signed certificate used to sign '%s' is not marked as certificate authority (CA)"),
    18321835                                 pTask->locInfo.strPath.c_str());
     1836                }
     1837                else
     1838                    lTrusted = true;
    18331839            }
    18341840            else
     
    19141920                            else
    19151921                                hrc2 = setErrorVrc(vrc, "RTCrX509CertPathsSetValidTimeSpec failed: %Rrc", vrc);
     1922
     1923                            if(RT_SUCCESS(vrc))
     1924                                lTrusted = true;
    19161925                        }
    19171926                        else if (vrc == VERR_CR_X509_CPV_NO_TRUSTED_PATHS)
     
    19521961    if(m->fSignerCertLoaded)
    19531962    {
    1954         pCertificateInfo->setData(&m->SignerCert);
     1963        pCertificateInfo->initCertificate(&m->SignerCert, lTrusted);
    19551964    }
    19561965
  • trunk/src/VBox/Main/src-server/CertificateImpl.cpp

    r60246 r60328  
    3333struct CertificateData
    3434{
    35 #ifdef DONT_DUPLICATE_ALL_THE_DATA
    3635    CertificateData()
    3736        : fTrusted(false)
     
    6160    CertificateData(const CertificateData &rTodo) { AssertFailed(); NOREF(rTodo); }
    6261    CertificateData &operator=(const CertificateData &rTodo) { AssertFailed(); NOREF(rTodo); return *this; }
    63 
    64 #else
    65     CertificateData() :
    66         mVersionNumber(0),
    67         mSerialNumber(0),
    68         mSelfSigned(FALSE),
    69         mTrusted(FALSE),
    70         mCertificateAuthority(FALSE)
    71     {}
    72 
    73     uint64_t mVersionNumber;
    74     uint64_t mSerialNumber;
    75     Utf8Str mSignatureAlgorithmOID;
    76     Utf8Str mSignatureAlgorithmName;
    77     Utf8Str mPublicKeyAlgorithmOID;
    78     Utf8Str mPublicKeyAlgorithmName;
    79     PCRTTIME mValidityPeriodNotBefore;
    80     PCRTTIME mValidityPeriodNotAfter;
    81     BOOL mSelfSigned;
    82     BOOL mTrusted;
    83     BOOL mCertificateAuthority;
    84 
    85     std::vector<Utf8Str> mIssuerName;
    86     std::vector<Utf8Str> mSubjectName;
    87     std::vector<BYTE> mSubjectPublicKey;
    88     std::vector<BYTE> mIssuerUniqueIdentifier;
    89     std::vector<BYTE> mSubjectUniqueIdentifier;
    90     std::vector<ULONG> mKeyUsage;
    91     std::vector<Utf8Str> mExtendedKeyUsage;
    92     std::vector<BYTE> mRawCertData;
    93 #endif
    9462};
    9563
     
    9866    Backupable<CertificateData> m;
    9967};
    100 
    101 #ifndef DONT_DUPLICATE_ALL_THE_DATA
    102 const char* const strUnknownAlgorithm = "Unknown Algorithm";
    103 const char* const strRsaEncription = "rsaEncryption";
    104 const char* const strMd2WithRSAEncryption = "md2WithRSAEncryption";
    105 const char* const strMd4WithRSAEncryption = "md4WithRSAEncryption";
    106 const char* const strMd5WithRSAEncryption = "md5WithRSAEncryption";
    107 const char* const strSha1WithRSAEncryption = "sha1WithRSAEncryption";
    108 const char* const strSha256WithRSAEncryption = "sha256WithRSAEncryption";
    109 const char* const strSha384WithRSAEncryption = "sha384WithRSAEncryption";
    110 const char* const strSha512WithRSAEncryption = "sha512WithRSAEncryption";
    111 const char* const strSha224WithRSAEncryption = "sha224WithRSAEncryption";
    112 #endif
    11368
    11469///////////////////////////////////////////////////////////////////////////////////
     
    13186}
    13287
    133 #ifdef DONT_DUPLICATE_ALL_THE_DATA
     88HRESULT Certificate::init(Appliance* appliance)
     89{
     90    HRESULT rc = S_OK;
     91    LogFlowThisFuncEnter();
     92
     93    /* Enclose the state transition NotReady->InInit->Ready */
     94    AutoInitSpan autoInitSpan(this);
     95    AssertReturn(autoInitSpan.isOk(), E_FAIL);
     96    if(appliance!=NULL)
     97    {
     98        LogFlowThisFunc(("m_appliance: %d \n", m_appliance));
     99        m_appliance = appliance;
     100    }
     101    else
     102        rc = E_FAIL;
     103
     104    /* Confirm a successful initialization when it's the case */
     105    if (SUCCEEDED(rc))
     106        autoInitSpan.setSucceeded();
     107
     108    LogFlowThisFunc(("rc=%Rhrc\n", rc));
     109    LogFlowThisFuncLeave();
     110
     111    return rc;
     112}
     113
    134114/**
    135115 * Initializes a certificate instance.
     
    140120 */
    141121HRESULT Certificate::initCertificate(PCRTCRX509CERTIFICATE a_pCert, bool a_fTrusted)
    142 #else
    143 HRESULT Certificate::init(Appliance* appliance)
    144 #endif
    145122{
    146123    HRESULT rc = S_OK;
    147124    LogFlowThisFuncEnter();
    148125
    149     /* Enclose the state transition NotReady->InInit->Ready */
    150     AutoInitSpan autoInitSpan(this);
    151     AssertReturn(autoInitSpan.isOk(), E_FAIL);
    152 
    153 #ifndef DONT_DUPLICATE_ALL_THE_DATA
    154     if(appliance!=NULL)
    155     {
    156         LogFlowThisFunc(("m_appliance: %d \n", m_appliance));
    157         m_appliance = appliance;
    158     }
    159     else
    160         rc = E_FAIL;
    161 #endif
    162 
    163126    mData = new Data();
    164127    mData->m.allocate();
    165 #ifdef DONT_DUPLICATE_ALL_THE_DATA
     128
    166129    int vrc = RTCrX509Certificate_Clone(&mData->m->X509, a_pCert, &g_RTAsn1DefaultAllocator);
    167130    if (RT_SUCCESS(vrc))
     
    172135    else
    173136        rc = Global::vboxStatusCodeToCOM(vrc);
    174 #else
    175     mData->m->mSignatureAlgorithmOID.setNull();
    176     mData->m->mSignatureAlgorithmName.setNull();
    177     mData->m->mPublicKeyAlgorithmOID.setNull();
    178     mData->m->mPublicKeyAlgorithmName.setNull();
    179     mData->m->mIssuerName.resize(0);
    180     mData->m->mSubjectName.resize(0);
    181 
    182     mData->m->mSubjectPublicKey.resize(0);
    183     mData->m->mIssuerUniqueIdentifier.resize(0);
    184     mData->m->mSubjectUniqueIdentifier.resize(0);
    185     mData->m->mKeyUsage.resize(0);
    186     mData->m->mExtendedKeyUsage.resize(0);
    187     mData->m->mRawCertData.resize(0);
    188 #endif
    189 
    190     /* Confirm a successful initialization when it's the case */
    191     if (SUCCEEDED(rc))
    192         autoInitSpan.setSucceeded();
    193137
    194138    LogFlowThisFunc(("rc=%Rhrc\n", rc));
     
    210154}
    211155
    212 #ifndef DONT_DUPLICATE_ALL_THE_DATA /* We'll query the data from the RTCrX509* API. */
    213 
    214 /**
    215  * Public method implementation.
    216  * @param aSignatureAlgorithmOID
    217  * @return
    218  */
    219 HRESULT Certificate::setData(PCRTCRX509CERTIFICATE inCert)
    220 {
    221 
    222     /*set mData.m->mVersionNumber */
    223     setVersionNumber(inCert->TbsCertificate.T0.Version.uValue.u);
    224 
    225     /*set mData.m->mSerialNumber */
    226     setSerialNumber(inCert->TbsCertificate.SerialNumber.uValue.u);
    227 
    228     /*set mData.m->mValidityPeriodNotBefore */
    229     setValidityPeriodNotBefore(&inCert->TbsCertificate.Validity.NotBefore.Time);
    230 
    231     /*set mData.m->mValidityPeriodNotAfter */
    232     setValidityPeriodNotAfter(&inCert->TbsCertificate.Validity.NotAfter.Time);
    233 
    234     /*set mData.m->mPublicKeyAlgorithmOID and mData.m->mPublicKeyAlgorithmName*/
    235     setPublicKeyAlgorithmOID(inCert->TbsCertificate.SubjectPublicKeyInfo.Algorithm.Algorithm.szObjId);
    236 
    237     /*set mData.m->mSignatureAlgorithmOID and mData.m->mSignatureAlgorithmName*/
    238     setSignatureAlgorithmOID(inCert->TbsCertificate.Signature.Algorithm.szObjId);
    239 
    240     if (   inCert->TbsCertificate.T3.pBasicConstraints
    241         && inCert->TbsCertificate.T3.pBasicConstraints->CA.fValue)
    242     {
    243         /*set mData.m->mCertificateAuthority TRUE*/
    244         setCertificateAuthority(true);
    245     }
    246 
    247     if (RTCrX509Certificate_IsSelfSigned(inCert))
    248     {
    249         /*set mData.m->mSelfSigned TRUE*/
    250         setSelfSigned(true);
    251     }
    252 
    253     char szCharArray[512];
    254     szCharArray[sizeof(szCharArray) - 1] = '\0';
    255 
    256     /*
    257     * get inCert->TbsCertificate.Subject as string
    258     * and set mData.m->mSignatureAlgorithmName
    259     */
    260     RTCrX509Name_FormatAsString(&inCert->TbsCertificate.Subject, szCharArray, sizeof(szCharArray) - 1, NULL);
    261     com::Utf8Str aSubjectName = szCharArray;
    262     setSubjectName(aSubjectName);
    263     /*
    264     * get inCert->TbsCertificate.Issuer as string
    265     * and set mData.m->mSignatureAlgorithmName
    266     */
    267     RTCrX509Name_FormatAsString(&inCert->TbsCertificate.Issuer, szCharArray, sizeof(szCharArray) - 1, NULL);
    268     com::Utf8Str aIssuerName = szCharArray;
    269     setIssuerName(aIssuerName);
    270 
    271     return S_OK;
    272 }
    273 
    274 /**
    275  * Public method implementation.
    276  * @param aSignatureAlgorithmOID
    277  * @return
    278  */
    279 HRESULT Certificate::setSignatureAlgorithmName(const char *aSignatureAlgorithmOID)
    280 {
    281     AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
    282 
    283     HRESULT rc = S_OK;
    284     const char *actualName = strUnknownAlgorithm;
    285 
    286     if (aSignatureAlgorithmOID == NULL)
    287         rc = E_FAIL;
    288     else if(!strcmp(aSignatureAlgorithmOID, RTCRX509ALGORITHMIDENTIFIERID_MD2_WITH_RSA))
    289         actualName = strMd2WithRSAEncryption;
    290     else if(!strcmp(aSignatureAlgorithmOID, RTCRX509ALGORITHMIDENTIFIERID_MD4_WITH_RSA))
    291         actualName = strMd4WithRSAEncryption;
    292     else if(!strcmp(aSignatureAlgorithmOID, RTCRX509ALGORITHMIDENTIFIERID_MD5_WITH_RSA))
    293         actualName = strMd5WithRSAEncryption;
    294     else if(!strcmp(aSignatureAlgorithmOID, RTCRX509ALGORITHMIDENTIFIERID_SHA1_WITH_RSA))
    295         actualName = strSha1WithRSAEncryption;
    296     else if(!strcmp(aSignatureAlgorithmOID, RTCRX509ALGORITHMIDENTIFIERID_SHA224_WITH_RSA))
    297         actualName = strSha224WithRSAEncryption;
    298     else if(!strcmp(aSignatureAlgorithmOID, RTCRX509ALGORITHMIDENTIFIERID_SHA256_WITH_RSA))
    299         actualName = strSha256WithRSAEncryption;
    300     else if(!strcmp(aSignatureAlgorithmOID, RTCRX509ALGORITHMIDENTIFIERID_SHA384_WITH_RSA))
    301         actualName = strSha384WithRSAEncryption;
    302     else if(!strcmp(aSignatureAlgorithmOID, RTCRX509ALGORITHMIDENTIFIERID_SHA512_WITH_RSA))
    303         actualName = strSha512WithRSAEncryption;
    304     else
    305     {
    306         rc = E_FAIL;
    307     }
    308 
    309     mData->m->mSignatureAlgorithmName = actualName;
    310 
    311     if(FAILED(rc))
    312         Log1Warning(("Can't find an appropriate signature algorithm name for given OID %s", aSignatureAlgorithmOID));
    313 
    314     return rc;
    315 
    316 }
    317 
    318 /**
    319  * Public method implementation.
    320  * @param aSignatureAlgorithmOID
    321  * @return
    322  */
    323 HRESULT Certificate::setSignatureAlgorithmOID(const char *aSignatureAlgorithmOID)
    324 {
    325     AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
    326 
    327     mData->m->mSignatureAlgorithmOID = aSignatureAlgorithmOID;
    328 
    329     setSignatureAlgorithmName(mData->m->mSignatureAlgorithmOID.c_str());
    330 
    331     return S_OK;
    332 }
    333 
    334 /**
    335  * Private method implementation.
    336  * @param aPublicKeyAlgorithm
    337  * @return
    338  */
    339 HRESULT Certificate::setPublicKeyAlgorithmName(const char *aPublicKeyAlgorithmOID)
    340 {
    341     AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
    342 
    343     HRESULT rc = S_OK;
    344     const char *foundName = strUnknownAlgorithm;
    345 
    346     if (!strcmp(aPublicKeyAlgorithmOID, RTCRX509ALGORITHMIDENTIFIERID_RSA))
    347         foundName = strRsaEncription;
    348     else
    349     {
    350         rc = E_FAIL;
    351     }
    352 
    353     mData->m->mPublicKeyAlgorithmName = foundName;
    354 
    355     if(FAILED(rc))
    356         Log1Warning(("Can't find an appropriate public key name for given OID %s", aPublicKeyAlgorithmOID));
    357 
    358     return rc;
    359 }
    360 
    361 
    362 /**
    363  * Private method implementation.
    364  * @param aPublicKeyAlgorithmOID
    365  * @return
    366  */
    367 HRESULT Certificate::setPublicKeyAlgorithmOID(const char *aPublicKeyAlgorithmOID)
    368 {
    369     AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
    370 
    371     mData->m->mPublicKeyAlgorithmOID = aPublicKeyAlgorithmOID;
    372 
    373     setPublicKeyAlgorithmName(mData->m->mPublicKeyAlgorithmOID.c_str());
    374 
    375     return S_OK;
    376 }
    377 
    378 /**
    379  * Public method implementation.
    380  * @param inVersionNumber
    381  * @return
    382  */
    383 HRESULT Certificate::setVersionNumber(uint64_t inVersionNumber)
    384 {
    385     AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
    386 
    387     mData->m->mVersionNumber = inVersionNumber;
    388 
    389     return S_OK;
    390 }
    391 
    392 /**
    393  * Public method implementation.
    394  * @param inVersionNumber
    395  * @return
    396  */
    397 HRESULT Certificate::setSerialNumber(uint64_t inSerialNumber)
    398 {
    399     AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
    400 
    401     mData->m->mSerialNumber = inSerialNumber;
    402 
    403     return S_OK;
    404 }
    405 
    406 /**
    407  * Public method implementation.
    408  * @param aCertificateAuthority
    409  * @return
    410  */
    411 HRESULT Certificate::setCertificateAuthority(BOOL aCertificateAuthority)
    412 {
    413     AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
    414 
    415     mData->m->mCertificateAuthority = aCertificateAuthority;
    416 
    417     return S_OK;
    418 }
    419 
    420 /**
    421  * Public method implementation.
    422  * @param aIssuerName
    423  * @return
    424  */
    425 HRESULT Certificate::setIssuerName(com::Utf8Str &aIssuerName)
    426 {
    427     AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
    428 
    429     RTCList<RTCString> l_IssueNameAsList = aIssuerName.split(",");
    430     uint32_t l_sz = l_IssueNameAsList.size();
    431     if(l_sz!=0)
    432         mData->m->mIssuerName.clear();
    433     for(uint32_t i = 0; i<l_sz; ++i)
    434         mData->m->mIssuerName.push_back(l_IssueNameAsList[i]);
    435 
    436     return S_OK;
    437 }
    438 
    439 /**
    440  * Public method implementation.
    441  * @param aSubjectName
    442  * @return
    443  */
    444 HRESULT Certificate::setSubjectName(com::Utf8Str &aSubjectName)
    445 {
    446     AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
    447 
    448     RTCList<RTCString> l_SubjectNameAsList = aSubjectName.split(",");
    449     uint32_t l_sz = l_SubjectNameAsList.size();
    450     if(l_sz!=0)
    451         mData->m->mSubjectName.clear();
    452     for(uint32_t i = 0; i<l_sz; ++i)
    453         mData->m->mSubjectName.push_back(l_SubjectNameAsList[i]);
    454 
    455     return S_OK;
    456 }
    457 
    458 /**
    459  * Public method implementation.
    460  * @param aSelfSigned
    461  * @return
    462  */
    463 HRESULT Certificate::setSelfSigned(BOOL aSelfSigned)
    464 {
    465     AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
    466 
    467     mData->m->mSelfSigned = aSelfSigned;
    468 
    469     return S_OK;
    470 }
    471 
    472 /**
    473  * Public method implementation.
    474  * @param aTrusted
    475  * @return
    476  */
    477 HRESULT Certificate::setTrusted(BOOL aTrusted)
    478 {
    479     AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
    480 
    481     mData->m->mTrusted = aTrusted;
    482 
    483     return S_OK;
    484 }
    485 
    486 /**
    487  * Public method implementation.
    488  * @param aValidityPeriodNotBefore
    489  * @return
    490  */
    491 HRESULT Certificate::setValidityPeriodNotBefore(PCRTTIME aValidityPeriodNotBefore)
    492 {
    493     AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
    494 
    495     mData->m->mValidityPeriodNotBefore = aValidityPeriodNotBefore;
    496 
    497     return S_OK;
    498 }
    499 
    500 /**
    501  * Public method implementation.
    502  * @param aValidityPeriodNotAfter
    503  * @return
    504  */
    505 HRESULT Certificate::setValidityPeriodNotAfter(PCRTTIME aValidityPeriodNotAfter)
    506 {
    507     AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
    508 
    509     mData->m->mValidityPeriodNotAfter = aValidityPeriodNotAfter;
    510 
    511     return S_OK;
    512 }
    513 
    514 #endif /* !DONT_DUPLICATE_ALL_THE_DATA */
    515 
    516156/**
    517157 * Private method implementation.
     
    519159 * @return
    520160 */
    521 HRESULT Certificate::getVersionNumber(com::Utf8Str &aVersionNumber)
    522 {
    523     AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
    524 #ifdef DONT_DUPLICATE_ALL_THE_DATA
     161HRESULT Certificate::getVersionNumber(CertificateVersion_T *aVersionNumber)
     162{
     163    AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
     164
    525165    Assert(mData->m->fValidX509);
    526166    /** @todo make this ULONG, or better, an ENUM. */
    527     aVersionNumber = Utf8StrFmt("%RU64", mData->m->X509.TbsCertificate.T0.Version.uValue.u + 1); /* version 1 has value 0, so +1. */
    528 #else
    529     Utf8StrFmt strVer("%Lu", mData->m->mVersionNumber);
    530     aVersionNumber = strVer;
    531 #endif
     167    //aVersionNumber = Utf8StrFmt("%RU64", mData->m->X509.TbsCertificate.T0.Version.uValue.u + 1);                                */
     168    /* version 1 has value 0, so +1.*/
     169
     170    *aVersionNumber = mData->m->X509.TbsCertificate.T0.Version.uValue.u + 1;
     171
    532172    return S_OK;
    533173}
     
    541181{
    542182    AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
    543 #ifdef DONT_DUPLICATE_ALL_THE_DATA
     183
    544184    Assert(mData->m->fValidX509);
    545185
     
    550190    else
    551191        return Global::vboxStatusCodeToCOM(vrc);
    552 #else
    553     Utf8StrFmt strVer("%llx", mData->m->mSerialNumber);
    554     aSerialNumber = strVer;
    555 #endif
     192
    556193    return S_OK;
    557194}
     
    565202{
    566203    AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
    567 #ifdef DONT_DUPLICATE_ALL_THE_DATA
     204
    568205    Assert(mData->m->fValidX509);
    569206    aSignatureAlgorithmOID = mData->m->X509.TbsCertificate.Signature.Algorithm.szObjId;
    570 #else
    571     aSignatureAlgorithmOID = mData->m->mSignatureAlgorithmOID;
    572 #endif
     207
    573208    return S_OK;
    574209}
     
    582217{
    583218    AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
    584 #ifdef DONT_DUPLICATE_ALL_THE_DATA
     219
    585220    Assert(mData->m->fValidX509);
    586221    return i_getAlgorithmName(&mData->m->X509.TbsCertificate.Signature, aSignatureAlgorithmName);
    587 #else
    588     aSignatureAlgorithmName = mData->m->mSignatureAlgorithmName;
    589 
    590     return S_OK;
    591 #endif
    592222}
    593223
     
    600230{
    601231    AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
    602 #ifdef DONT_DUPLICATE_ALL_THE_DATA
     232
    603233    Assert(mData->m->fValidX509);
    604234    return i_getX509Name(&mData->m->X509.TbsCertificate.Issuer, aIssuerName);
    605 #else
    606     aIssuerName = mData->m->mIssuerName;
    607 
    608     return S_OK;
    609 #endif
    610235}
    611236
     
    618243{
    619244    AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
    620 #ifdef DONT_DUPLICATE_ALL_THE_DATA
     245
    621246    Assert(mData->m->fValidX509);
    622247    return i_getX509Name(&mData->m->X509.TbsCertificate.Subject, aSubjectName);
    623 #else
    624 
    625     aSubjectName = mData->m->mSubjectName;
    626 
    627     return S_OK;
    628 #endif
    629248}
    630249
     
    637256{
    638257    AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
    639 #ifdef DONT_DUPLICATE_ALL_THE_DATA
     258
    640259    Assert(mData->m->fValidX509);
    641260    return i_getTime(&mData->m->X509.TbsCertificate.Validity.NotBefore, aValidityPeriodNotBefore);
    642 #else
    643     HRESULT rc = S_OK;
    644 
    645     size_t arrSize = 40;
    646     char* charArr = new char[arrSize];
    647     char* strTimeFormat = RTTimeToString(mData->m->mValidityPeriodNotBefore, charArr, arrSize);
    648 
    649     if (strTimeFormat == NULL)
    650     {
    651         rc=E_FAIL;
    652     }
    653 
    654     aValidityPeriodNotBefore = charArr;
    655     delete[] charArr;
    656 
    657     return rc;
    658 #endif
    659261}
    660262
     
    667269{
    668270    AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
    669 #ifdef DONT_DUPLICATE_ALL_THE_DATA
     271
    670272    Assert(mData->m->fValidX509);
    671273    return i_getTime(&mData->m->X509.TbsCertificate.Validity.NotAfter, aValidityPeriodNotAfter);
    672 #else
    673 
    674     HRESULT rc = S_OK;
    675     size_t arrSize = 40;
    676     char* charArr = new char[arrSize];
    677     char* strTimeFormat = RTTimeToString(mData->m->mValidityPeriodNotAfter, charArr, arrSize);
    678 
    679     if (strTimeFormat == NULL)
    680     {
    681         rc = E_FAIL;
    682     }
    683 
    684     aValidityPeriodNotAfter = charArr;
    685     delete[] charArr;
    686     return rc;
    687 #endif
    688274}
    689275
     
    691277{
    692278    AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
    693 #ifdef DONT_DUPLICATE_ALL_THE_DATA
     279
    694280    Assert(mData->m->fValidX509);
    695281    aPublicKeyAlgorithmOID = mData->m->X509.TbsCertificate.SubjectPublicKeyInfo.Algorithm.Algorithm.szObjId;
    696282    return S_OK;
    697 #else
    698     return E_NOTIMPL;
    699 #endif
    700283}
    701284
     
    708291{
    709292    AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
    710 #ifdef DONT_DUPLICATE_ALL_THE_DATA
     293
    711294    Assert(mData->m->fValidX509);
    712295    return i_getAlgorithmName(&mData->m->X509.TbsCertificate.SubjectPublicKeyInfo.Algorithm, aPublicKeyAlgorithm);
    713 #else
    714     aPublicKeyAlgorithm = mData->m->mPublicKeyAlgorithmName;
    715 
    716     return S_OK;
    717 #endif
    718296}
    719297
     
    725303HRESULT Certificate::getSubjectPublicKey(std::vector<BYTE> &aSubjectPublicKey)
    726304{
    727 #ifdef DONT_DUPLICATE_ALL_THE_DATA
     305
    728306    AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS); /* Getting encoded ASN.1 bytes may make changes to X509. */
    729307    return i_getEncodedBytes(&mData->m->X509.TbsCertificate.SubjectPublicKeyInfo.SubjectPublicKey.Asn1Core, aSubjectPublicKey);
    730 #else
    731     return E_NOTIMPL;
    732 #endif
    733308}
    734309
     
    741316{
    742317    AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
    743 #ifdef DONT_DUPLICATE_ALL_THE_DATA
     318
    744319    return i_getUniqueIdentifier(&mData->m->X509.TbsCertificate.T1.IssuerUniqueId, aIssuerUniqueIdentifier);
    745 #else
    746     return E_NOTIMPL;
    747 #endif
    748320}
    749321
     
    756328{
    757329    AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
    758 #ifdef DONT_DUPLICATE_ALL_THE_DATA
     330
    759331    return i_getUniqueIdentifier(&mData->m->X509.TbsCertificate.T2.SubjectUniqueId, aSubjectUniqueIdentifier);
    760 #else
    761     return E_NOTIMPL;
    762 #endif
    763332}
    764333
     
    771340{
    772341    AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
    773 #ifdef DONT_DUPLICATE_ALL_THE_DATA
     342
    774343    *aCertificateAuthority = mData->m->X509.TbsCertificate.T3.pBasicConstraints
    775344                          && mData->m->X509.TbsCertificate.T3.pBasicConstraints->CA.fValue;
    776 #else
    777     *aCertificateAuthority = mData->m->mCertificateAuthority;
    778 #endif
     345
    779346    return S_OK;
    780347}
     
    788355{
    789356    AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
    790 #ifdef DONT_DUPLICATE_ALL_THE_DATA
     357
    791358    *aKeyUsage = mData->m->X509.TbsCertificate.T3.fKeyUsage;
    792359    return S_OK;
    793 #else
    794     return E_NOTIMPL;
    795 #endif
    796360}
    797361
     
    815379HRESULT Certificate::getRawCertData(std::vector<BYTE> &aRawCertData)
    816380{
    817 #ifdef DONT_DUPLICATE_ALL_THE_DATA
    818381    AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS); /* Getting encoded ASN.1 bytes may make changes to X509. */
    819382    return i_getEncodedBytes(&mData->m->X509.SeqCore.Asn1Core, aRawCertData);
    820 #else
    821     return E_NOTIMPL;
    822 #endif
    823383}
    824384
     
    831391{
    832392    AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
    833 #ifdef DONT_DUPLICATE_ALL_THE_DATA
     393
    834394    Assert(mData->m->fValidX509);
    835395    *aSelfSigned = RTCrX509Certificate_IsSelfSigned(&mData->m->X509);
    836 #else
    837     *aSelfSigned = mData->m->mSelfSigned;
    838 #endif
     396
    839397    return S_OK;
    840398}
     
    848406{
    849407    AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
    850 #ifdef DONT_DUPLICATE_ALL_THE_DATA
     408
    851409    *aTrusted = mData->m->fTrusted;
    852 #else
    853     *aTrusted = mData->m->mTrusted;
    854 #endif
     410
    855411    return S_OK;
    856412}
     
    870426}
    871427
    872 #ifndef DONT_DUPLICATE_ALL_THE_DATA  /* These are out of place. */
    873 
    874 /**
    875  * Private method implementation.
     428/**
     429 * Private method implementation.
    876430 * @param aPresence
    877431 * @return aPresence
    878432 */
    879 HRESULT Certificate::checkExistence(BOOL *aPresence)
     433HRESULT Certificate::getPresence(BOOL *aPresence)
    880434{
    881435    AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
     
    887441
    888442/**
    889  * Private method implementation. 
    890  * @param aVerified 
     443 * Private method implementation.
     444 * @param aVerified
    891445 * @return aVerified
    892446 */
    893 HRESULT Certificate::isVerified(BOOL *aVerified)
     447HRESULT Certificate::getVerified(BOOL *aVerified)
    894448{
    895449    AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
     
    901455    return S_OK;
    902456}
    903 
    904 #else  /* DONT_DUPLICATE_ALL_THE_DATA */
    905457
    906458HRESULT Certificate::i_getAlgorithmName(PCRTCRX509ALGORITHMIDENTIFIER a_pAlgId, com::Utf8Str &a_rReturn)
     
    1009561}
    1010562
    1011 #endif /* DONT_DUPLICATE_ALL_THE_DATA */
    1012 
     563
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