VirtualBox

Changeset 60343 in vbox for trunk


Ignore:
Timestamp:
Apr 6, 2016 12:05:54 AM (9 years ago)
Author:
vboxsync
Message:

Certificate: The data need not be backupable as the object is immutable (see, no setters). So, drop the extra indirection (s/mData->m->/m->/g).

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

Legend:

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

    r60341 r60343  
    2828using namespace std;
    2929
    30 class ATL_NO_VTABLE Certificate :
    31     public CertificateWrap
     30/**
     31 * Implemenation of ICertificate.
     32 *
     33 * This implemenation is a very thin wrapper around an immutable
     34 * RTCRX509CERTIFICATE and a few caller stated views.
     35 *
     36 * The views are whether the caller thinks the certificate is trustworthly, and
     37 * whether the caller thinks it's expired or not.  The caller could be sitting
     38 * on more information, like timestamp and intermediate certificates, that helps
     39 * inform the caller's view on these two topics.
     40 *
     41 * @remarks It could be helpful to let the caller also add certificate paths
     42 *          showing how this certificate ends up being trusted.  However, that's
     43 *          possibly quite some work and will have to wait till required...
     44 */
     45class ATL_NO_VTABLE Certificate
     46    : public CertificateWrap
    3247{
    3348
     
    7893    /** @} */
    7994
    80     //data
    8195    struct Data;
    82     Data *mData;
    83 
     96    /** Pointer to the private instance data   */
     97    Data *m;
    8498};
    8599
  • trunk/src/VBox/Main/src-server/CertificateImpl.cpp

    r60342 r60343  
    2929using namespace std;
    3030
    31 struct CertificateData
    32 {
    33     CertificateData()
     31
     32/**
     33 * Private instance data for the #Certificate class.
     34 * @see Certificate::m
     35 */
     36struct Certificate::Data
     37{
     38    Data()
    3439        : fTrusted(false)
    3540        , fExpired(false)
     
    3944    }
    4045
    41     ~CertificateData()
     46    ~Data()
    4247    {
    4348        if (fValidX509)
     
    5964
    6065private:
    61     CertificateData(const CertificateData &rTodo) { AssertFailed(); NOREF(rTodo); }
    62     CertificateData &operator=(const CertificateData &rTodo) { AssertFailed(); NOREF(rTodo); return *this; }
     66    Data(const Certificate::Data &rTodo) { AssertFailed(); NOREF(rTodo); }
     67    Data &operator=(const Certificate::Data &rTodo) { AssertFailed(); NOREF(rTodo); return *this; }
    6368};
    6469
    65 struct Certificate::Data
    66 {
    67     Backupable<CertificateData> m;
    68 };
    6970
    7071///////////////////////////////////////////////////////////////////////////////////
     
    104105    AssertReturn(autoInitSpan.isOk(), E_FAIL);
    105106
    106     mData = new Data();
    107     mData->m.allocate();
    108 
    109     int vrc = RTCrX509Certificate_Clone(&mData->m->X509, a_pCert, &g_RTAsn1DefaultAllocator);
     107    m = new Data();
     108
     109    int vrc = RTCrX509Certificate_Clone(&m->X509, a_pCert, &g_RTAsn1DefaultAllocator);
    110110    if (RT_SUCCESS(vrc))
    111111    {
    112         mData->m->fValidX509 = true;
    113         mData->m->fTrusted   = a_fTrusted;
    114         mData->m->fExpired   = a_fExpired;
     112        m->fValidX509 = true;
     113        m->fTrusted   = a_fTrusted;
     114        m->fExpired   = a_fExpired;
    115115        autoInitSpan.setSucceeded();
    116116    }
     
    129129        return;
    130130
    131     mData->m.free();
    132     delete mData;
    133     mData = NULL;
     131    delete m;
     132    m = NULL;
    134133}
    135134
     
    143142    AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
    144143
    145     Assert(mData->m->fValidX509);
    146     switch (mData->m->X509.TbsCertificate.T0.Version.uValue.u)
     144    Assert(m->fValidX509);
     145    switch (m->X509.TbsCertificate.T0.Version.uValue.u)
    147146    {
    148147        case RTCRX509TBSCERTIFICATE_V1: *aVersionNumber = (CertificateVersion_T)CertificateVersion_V1; break;
     
    158157    AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
    159158
    160     Assert(mData->m->fValidX509);
     159    Assert(m->fValidX509);
    161160
    162161    char szTmp[_2K];
    163     int vrc = RTAsn1Integer_ToString(&mData->m->X509.TbsCertificate.SerialNumber, szTmp, sizeof(szTmp), 0, NULL);
     162    int vrc = RTAsn1Integer_ToString(&m->X509.TbsCertificate.SerialNumber, szTmp, sizeof(szTmp), 0, NULL);
    164163    if (RT_SUCCESS(vrc))
    165164        aSerialNumber = szTmp;
     
    174173    AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
    175174
    176     Assert(mData->m->fValidX509);
    177     aSignatureAlgorithmOID = mData->m->X509.TbsCertificate.Signature.Algorithm.szObjId;
     175    Assert(m->fValidX509);
     176    aSignatureAlgorithmOID = m->X509.TbsCertificate.Signature.Algorithm.szObjId;
    178177
    179178    return S_OK;
     
    184183    AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
    185184
    186     Assert(mData->m->fValidX509);
    187     return i_getAlgorithmName(&mData->m->X509.TbsCertificate.Signature, aSignatureAlgorithmName);
     185    Assert(m->fValidX509);
     186    return i_getAlgorithmName(&m->X509.TbsCertificate.Signature, aSignatureAlgorithmName);
    188187}
    189188
     
    192191    AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
    193192
    194     Assert(mData->m->fValidX509);
    195     return i_getX509Name(&mData->m->X509.TbsCertificate.Issuer, aIssuerName);
     193    Assert(m->fValidX509);
     194    return i_getX509Name(&m->X509.TbsCertificate.Issuer, aIssuerName);
    196195}
    197196
     
    200199    AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
    201200
    202     Assert(mData->m->fValidX509);
    203     return i_getX509Name(&mData->m->X509.TbsCertificate.Subject, aSubjectName);
     201    Assert(m->fValidX509);
     202    return i_getX509Name(&m->X509.TbsCertificate.Subject, aSubjectName);
    204203}
    205204
     
    208207    AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
    209208
    210     Assert(mData->m->fValidX509);
    211 
    212     PCRTCRX509NAME pName = &mData->m->X509.TbsCertificate.Subject;
     209    Assert(m->fValidX509);
     210
     211    PCRTCRX509NAME pName = &m->X509.TbsCertificate.Subject;
    213212
    214213    /*
     
    288287    AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
    289288
    290     Assert(mData->m->fValidX509);
    291     return i_getTime(&mData->m->X509.TbsCertificate.Validity.NotBefore, aValidityPeriodNotBefore);
     289    Assert(m->fValidX509);
     290    return i_getTime(&m->X509.TbsCertificate.Validity.NotBefore, aValidityPeriodNotBefore);
    292291}
    293292
     
    296295    AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
    297296
    298     Assert(mData->m->fValidX509);
    299     return i_getTime(&mData->m->X509.TbsCertificate.Validity.NotAfter, aValidityPeriodNotAfter);
     297    Assert(m->fValidX509);
     298    return i_getTime(&m->X509.TbsCertificate.Validity.NotAfter, aValidityPeriodNotAfter);
    300299}
    301300
     
    304303    AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
    305304
    306     Assert(mData->m->fValidX509);
    307     aPublicKeyAlgorithmOID = mData->m->X509.TbsCertificate.SubjectPublicKeyInfo.Algorithm.Algorithm.szObjId;
     305    Assert(m->fValidX509);
     306    aPublicKeyAlgorithmOID = m->X509.TbsCertificate.SubjectPublicKeyInfo.Algorithm.Algorithm.szObjId;
    308307    return S_OK;
    309308}
     
    313312    AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
    314313
    315     Assert(mData->m->fValidX509);
    316     return i_getAlgorithmName(&mData->m->X509.TbsCertificate.SubjectPublicKeyInfo.Algorithm, aPublicKeyAlgorithm);
     314    Assert(m->fValidX509);
     315    return i_getAlgorithmName(&m->X509.TbsCertificate.SubjectPublicKeyInfo.Algorithm, aPublicKeyAlgorithm);
    317316}
    318317
     
    321320
    322321    AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS); /* Getting encoded ASN.1 bytes may make changes to X509. */
    323     return i_getEncodedBytes(&mData->m->X509.TbsCertificate.SubjectPublicKeyInfo.SubjectPublicKey.Asn1Core, aSubjectPublicKey);
     322    return i_getEncodedBytes(&m->X509.TbsCertificate.SubjectPublicKeyInfo.SubjectPublicKey.Asn1Core, aSubjectPublicKey);
    324323}
    325324
     
    328327    AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
    329328
    330     return i_getUniqueIdentifier(&mData->m->X509.TbsCertificate.T1.IssuerUniqueId, aIssuerUniqueIdentifier);
     329    return i_getUniqueIdentifier(&m->X509.TbsCertificate.T1.IssuerUniqueId, aIssuerUniqueIdentifier);
    331330}
    332331
     
    335334    AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
    336335
    337     return i_getUniqueIdentifier(&mData->m->X509.TbsCertificate.T2.SubjectUniqueId, aSubjectUniqueIdentifier);
     336    return i_getUniqueIdentifier(&m->X509.TbsCertificate.T2.SubjectUniqueId, aSubjectUniqueIdentifier);
    338337}
    339338
     
    342341    AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
    343342
    344     *aCertificateAuthority = mData->m->X509.TbsCertificate.T3.pBasicConstraints
    345                           && mData->m->X509.TbsCertificate.T3.pBasicConstraints->CA.fValue;
     343    *aCertificateAuthority = m->X509.TbsCertificate.T3.pBasicConstraints
     344                          && m->X509.TbsCertificate.T3.pBasicConstraints->CA.fValue;
    346345
    347346    return S_OK;
     
    352351    AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
    353352
    354     *aKeyUsage = mData->m->X509.TbsCertificate.T3.fKeyUsage;
     353    *aKeyUsage = m->X509.TbsCertificate.T3.fKeyUsage;
    355354    return S_OK;
    356355}
     
    366365{
    367366    AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS); /* Getting encoded ASN.1 bytes may make changes to X509. */
    368     return i_getEncodedBytes(&mData->m->X509.SeqCore.Asn1Core, aRawCertData);
     367    return i_getEncodedBytes(&m->X509.SeqCore.Asn1Core, aRawCertData);
    369368}
    370369
     
    373372    AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
    374373
    375     Assert(mData->m->fValidX509);
    376     *aSelfSigned = RTCrX509Certificate_IsSelfSigned(&mData->m->X509);
     374    Assert(m->fValidX509);
     375    *aSelfSigned = RTCrX509Certificate_IsSelfSigned(&m->X509);
    377376
    378377    return S_OK;
     
    383382    AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
    384383
    385     Assert(mData->m->fValidX509);
    386     *aTrusted = mData->m->fTrusted;
     384    Assert(m->fValidX509);
     385    *aTrusted = m->fTrusted;
    387386
    388387    return S_OK;
     
    392391{
    393392    AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
    394     Assert(mData->m->fValidX509);
    395     *aExpired = mData->m->fExpired;
     393    Assert(m->fValidX509);
     394    *aExpired = m->fExpired;
    396395    return S_OK;
    397396}
     
    405404HRESULT Certificate::isCurrentlyExpired(BOOL *aResult)
    406405{
    407     AssertReturnStmt(mData->m->fValidX509, *aResult = TRUE, E_UNEXPECTED);
     406    AssertReturnStmt(m->fValidX509, *aResult = TRUE, E_UNEXPECTED);
    408407    RTTIMESPEC Now;
    409     *aResult = RTCrX509Validity_IsValidAtTimeSpec(&mData->m->X509.TbsCertificate.Validity, RTTimeNow(&Now)) ? FALSE : TRUE;
     408    *aResult = RTCrX509Validity_IsValidAtTimeSpec(&m->X509.TbsCertificate.Validity, RTTimeNow(&Now)) ? FALSE : TRUE;
    410409    return S_OK;
    411410}
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