- Timestamp:
- Apr 6, 2016 12:05:54 AM (9 years ago)
- Location:
- trunk/src/VBox/Main
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/include/CertificateImpl.h
r60341 r60343 28 28 using namespace std; 29 29 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 */ 45 class ATL_NO_VTABLE Certificate 46 : public CertificateWrap 32 47 { 33 48 … … 78 93 /** @} */ 79 94 80 //data81 95 struct Data; 82 Data *mData;83 96 /** Pointer to the private instance data */ 97 Data *m; 84 98 }; 85 99 -
trunk/src/VBox/Main/src-server/CertificateImpl.cpp
r60342 r60343 29 29 using namespace std; 30 30 31 struct CertificateData 32 { 33 CertificateData() 31 32 /** 33 * Private instance data for the #Certificate class. 34 * @see Certificate::m 35 */ 36 struct Certificate::Data 37 { 38 Data() 34 39 : fTrusted(false) 35 40 , fExpired(false) … … 39 44 } 40 45 41 ~ CertificateData()46 ~Data() 42 47 { 43 48 if (fValidX509) … … 59 64 60 65 private: 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; } 63 68 }; 64 69 65 struct Certificate::Data66 {67 Backupable<CertificateData> m;68 };69 70 70 71 /////////////////////////////////////////////////////////////////////////////////// … … 104 105 AssertReturn(autoInitSpan.isOk(), E_FAIL); 105 106 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); 110 110 if (RT_SUCCESS(vrc)) 111 111 { 112 m Data->m->fValidX509 = true;113 m Data->m->fTrusted = a_fTrusted;114 m Data->m->fExpired = a_fExpired;112 m->fValidX509 = true; 113 m->fTrusted = a_fTrusted; 114 m->fExpired = a_fExpired; 115 115 autoInitSpan.setSucceeded(); 116 116 } … … 129 129 return; 130 130 131 mData->m.free(); 132 delete mData; 133 mData = NULL; 131 delete m; 132 m = NULL; 134 133 } 135 134 … … 143 142 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS); 144 143 145 Assert(m Data->m->fValidX509);146 switch (m Data->m->X509.TbsCertificate.T0.Version.uValue.u)144 Assert(m->fValidX509); 145 switch (m->X509.TbsCertificate.T0.Version.uValue.u) 147 146 { 148 147 case RTCRX509TBSCERTIFICATE_V1: *aVersionNumber = (CertificateVersion_T)CertificateVersion_V1; break; … … 158 157 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS); 159 158 160 Assert(m Data->m->fValidX509);159 Assert(m->fValidX509); 161 160 162 161 char szTmp[_2K]; 163 int vrc = RTAsn1Integer_ToString(&m Data->m->X509.TbsCertificate.SerialNumber, szTmp, sizeof(szTmp), 0, NULL);162 int vrc = RTAsn1Integer_ToString(&m->X509.TbsCertificate.SerialNumber, szTmp, sizeof(szTmp), 0, NULL); 164 163 if (RT_SUCCESS(vrc)) 165 164 aSerialNumber = szTmp; … … 174 173 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS); 175 174 176 Assert(m Data->m->fValidX509);177 aSignatureAlgorithmOID = m Data->m->X509.TbsCertificate.Signature.Algorithm.szObjId;175 Assert(m->fValidX509); 176 aSignatureAlgorithmOID = m->X509.TbsCertificate.Signature.Algorithm.szObjId; 178 177 179 178 return S_OK; … … 184 183 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS); 185 184 186 Assert(m Data->m->fValidX509);187 return i_getAlgorithmName(&m Data->m->X509.TbsCertificate.Signature, aSignatureAlgorithmName);185 Assert(m->fValidX509); 186 return i_getAlgorithmName(&m->X509.TbsCertificate.Signature, aSignatureAlgorithmName); 188 187 } 189 188 … … 192 191 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS); 193 192 194 Assert(m Data->m->fValidX509);195 return i_getX509Name(&m Data->m->X509.TbsCertificate.Issuer, aIssuerName);193 Assert(m->fValidX509); 194 return i_getX509Name(&m->X509.TbsCertificate.Issuer, aIssuerName); 196 195 } 197 196 … … 200 199 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS); 201 200 202 Assert(m Data->m->fValidX509);203 return i_getX509Name(&m Data->m->X509.TbsCertificate.Subject, aSubjectName);201 Assert(m->fValidX509); 202 return i_getX509Name(&m->X509.TbsCertificate.Subject, aSubjectName); 204 203 } 205 204 … … 208 207 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS); 209 208 210 Assert(m Data->m->fValidX509);211 212 PCRTCRX509NAME pName = &m Data->m->X509.TbsCertificate.Subject;209 Assert(m->fValidX509); 210 211 PCRTCRX509NAME pName = &m->X509.TbsCertificate.Subject; 213 212 214 213 /* … … 288 287 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS); 289 288 290 Assert(m Data->m->fValidX509);291 return i_getTime(&m Data->m->X509.TbsCertificate.Validity.NotBefore, aValidityPeriodNotBefore);289 Assert(m->fValidX509); 290 return i_getTime(&m->X509.TbsCertificate.Validity.NotBefore, aValidityPeriodNotBefore); 292 291 } 293 292 … … 296 295 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS); 297 296 298 Assert(m Data->m->fValidX509);299 return i_getTime(&m Data->m->X509.TbsCertificate.Validity.NotAfter, aValidityPeriodNotAfter);297 Assert(m->fValidX509); 298 return i_getTime(&m->X509.TbsCertificate.Validity.NotAfter, aValidityPeriodNotAfter); 300 299 } 301 300 … … 304 303 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS); 305 304 306 Assert(m Data->m->fValidX509);307 aPublicKeyAlgorithmOID = m Data->m->X509.TbsCertificate.SubjectPublicKeyInfo.Algorithm.Algorithm.szObjId;305 Assert(m->fValidX509); 306 aPublicKeyAlgorithmOID = m->X509.TbsCertificate.SubjectPublicKeyInfo.Algorithm.Algorithm.szObjId; 308 307 return S_OK; 309 308 } … … 313 312 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS); 314 313 315 Assert(m Data->m->fValidX509);316 return i_getAlgorithmName(&m Data->m->X509.TbsCertificate.SubjectPublicKeyInfo.Algorithm, aPublicKeyAlgorithm);314 Assert(m->fValidX509); 315 return i_getAlgorithmName(&m->X509.TbsCertificate.SubjectPublicKeyInfo.Algorithm, aPublicKeyAlgorithm); 317 316 } 318 317 … … 321 320 322 321 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS); /* Getting encoded ASN.1 bytes may make changes to X509. */ 323 return i_getEncodedBytes(&m Data->m->X509.TbsCertificate.SubjectPublicKeyInfo.SubjectPublicKey.Asn1Core, aSubjectPublicKey);322 return i_getEncodedBytes(&m->X509.TbsCertificate.SubjectPublicKeyInfo.SubjectPublicKey.Asn1Core, aSubjectPublicKey); 324 323 } 325 324 … … 328 327 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS); 329 328 330 return i_getUniqueIdentifier(&m Data->m->X509.TbsCertificate.T1.IssuerUniqueId, aIssuerUniqueIdentifier);329 return i_getUniqueIdentifier(&m->X509.TbsCertificate.T1.IssuerUniqueId, aIssuerUniqueIdentifier); 331 330 } 332 331 … … 335 334 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS); 336 335 337 return i_getUniqueIdentifier(&m Data->m->X509.TbsCertificate.T2.SubjectUniqueId, aSubjectUniqueIdentifier);336 return i_getUniqueIdentifier(&m->X509.TbsCertificate.T2.SubjectUniqueId, aSubjectUniqueIdentifier); 338 337 } 339 338 … … 342 341 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS); 343 342 344 *aCertificateAuthority = m Data->m->X509.TbsCertificate.T3.pBasicConstraints345 && m Data->m->X509.TbsCertificate.T3.pBasicConstraints->CA.fValue;343 *aCertificateAuthority = m->X509.TbsCertificate.T3.pBasicConstraints 344 && m->X509.TbsCertificate.T3.pBasicConstraints->CA.fValue; 346 345 347 346 return S_OK; … … 352 351 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS); 353 352 354 *aKeyUsage = m Data->m->X509.TbsCertificate.T3.fKeyUsage;353 *aKeyUsage = m->X509.TbsCertificate.T3.fKeyUsage; 355 354 return S_OK; 356 355 } … … 366 365 { 367 366 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS); /* Getting encoded ASN.1 bytes may make changes to X509. */ 368 return i_getEncodedBytes(&m Data->m->X509.SeqCore.Asn1Core, aRawCertData);367 return i_getEncodedBytes(&m->X509.SeqCore.Asn1Core, aRawCertData); 369 368 } 370 369 … … 373 372 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS); 374 373 375 Assert(m Data->m->fValidX509);376 *aSelfSigned = RTCrX509Certificate_IsSelfSigned(&m Data->m->X509);374 Assert(m->fValidX509); 375 *aSelfSigned = RTCrX509Certificate_IsSelfSigned(&m->X509); 377 376 378 377 return S_OK; … … 383 382 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS); 384 383 385 Assert(m Data->m->fValidX509);386 *aTrusted = m Data->m->fTrusted;384 Assert(m->fValidX509); 385 *aTrusted = m->fTrusted; 387 386 388 387 return S_OK; … … 392 391 { 393 392 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS); 394 Assert(m Data->m->fValidX509);395 *aExpired = m Data->m->fExpired;393 Assert(m->fValidX509); 394 *aExpired = m->fExpired; 396 395 return S_OK; 397 396 } … … 405 404 HRESULT Certificate::isCurrentlyExpired(BOOL *aResult) 406 405 { 407 AssertReturnStmt(m Data->m->fValidX509, *aResult = TRUE, E_UNEXPECTED);406 AssertReturnStmt(m->fValidX509, *aResult = TRUE, E_UNEXPECTED); 408 407 RTTIMESPEC Now; 409 *aResult = RTCrX509Validity_IsValidAtTimeSpec(&m Data->m->X509.TbsCertificate.Validity, RTTimeNow(&Now)) ? FALSE : TRUE;408 *aResult = RTCrX509Validity_IsValidAtTimeSpec(&m->X509.TbsCertificate.Validity, RTTimeNow(&Now)) ? FALSE : TRUE; 410 409 return S_OK; 411 410 }
Note:
See TracChangeset
for help on using the changeset viewer.