Changeset 105124 in vbox
- Timestamp:
- Jul 3, 2024 5:50:46 PM (8 months ago)
- svn:sync-xref-src-repo-rev:
- 163754
- Location:
- trunk
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/iprt/crypto/x509.h
r104745 r105124 1224 1224 * @param fKeyUsage Key usage mask: RTCRX509CERT_KEY_USAGE_F_XXX. 1225 1225 * @param fExtKeyUsage Extended key usage mask: RTCRX509CERT_EKU_F_XXX. 1226 * @param pvSubject Todo TODO:Subject name.1226 * @param pvSubject Subject name. 1227 1227 * @param pszCertFile Where to store the certificate (PEM formatting). 1228 1228 * @param pszPrivateKeyFile Where to store the unencrypted private key (PEM … … 1232 1232 */ 1233 1233 RTDECL(int) RTCrX509Certificate_GenerateSelfSignedRsa(RTDIGESTTYPE enmDigestType, uint32_t cBits, uint32_t cSecsValidFor, 1234 uint32_t fKeyUsage, uint64_t fExtKeyUsage, void *pvSubjectTodo,1234 uint32_t fKeyUsage, uint64_t fExtKeyUsage, const char *pvSubject, 1235 1235 const char *pszCertFile, const char *pszPrivateKeyFile, PRTERRINFO pErrInfo); 1236 1236 -
trunk/src/VBox/Main/include/VRDEServerImpl.h
r104570 r105124 60 60 HRESULT i_loadSettings(const settings::VRDESettings &data); 61 61 HRESULT i_saveSettings(settings::VRDESettings &data); 62 int certificateRepair(BOOL &certificateGenerated); 62 63 int i_generateServerCertificate(); 63 64 void i_rollback(); -
trunk/src/VBox/Main/src-server/VRDEServerImpl.cpp
r104745 r105124 241 241 int VRDEServer::i_generateServerCertificate() 242 242 { 243 Utf8Str strServerCertificate(" server_cert.pem");243 Utf8Str strServerCertificate("VRDEAutoGeneratedCert.pem"); 244 244 int vrc = mParent->i_calculateFullPath(strServerCertificate, strServerCertificate); 245 245 AssertRCReturn(vrc, vrc); 246 246 247 Utf8Str strServerPrivateKey(" server_key_private.pem");247 Utf8Str strServerPrivateKey("VRDEAutoGeneratedPrivateKey.pem"); 248 248 vrc = mParent->i_calculateFullPath(strServerPrivateKey, strServerPrivateKey); 249 249 AssertRCReturn(vrc, vrc); 250 250 251 AutoReadLock mlock(mParent COMMA_LOCKVAL_SRC_POS); 252 Utf8Str strVMName = mParent->i_getName(); 253 mlock.release(); 254 251 255 vrc = RTCrX509Certificate_GenerateSelfSignedRsa(RTDIGESTTYPE_SHA1, 2048 /*cBits*/, 10 * 365 * RT_SEC_1DAY, 252 0 /*fKeyUsage*/, 0 /*fExtKeyUsage*/, NULL /*pvSubjectTodo*/,256 0 /*fKeyUsage*/, 0 /*fExtKeyUsage*/, strVMName.c_str() /*pvSubject*/, 253 257 strServerCertificate.c_str(), strServerPrivateKey.c_str(), NULL /*pErrInfo*/); 254 258 if (RT_SUCCESS(vrc)) … … 281 285 } 282 286 287 /** 288 * Checks validity of auto-generated certificates, sets VRDE properties, and deletes files if necessary. 289 * 290 * @note Locks this object for writing. 291 */ 292 int VRDEServer::certificateRepair(BOOL &certificateGenerated) 293 { 294 int vrc = VINF_SUCCESS; 295 if ( (mData->mapProperties["Security/Method"] != "RDP" || mData->mapProperties["Security/Method"] != "None")) 296 { 297 Utf8Str strServerCertificate("VRDEAutoGeneratedCert.pem"); 298 vrc = mParent->i_calculateFullPath(strServerCertificate, strServerCertificate); 299 AssertRCReturn(vrc, vrc); 300 301 Utf8Str strServerPrivateKey("VRDEAutoGeneratedPrivateKey.pem"); 302 vrc = mParent->i_calculateFullPath(strServerPrivateKey, strServerPrivateKey); 303 AssertRCReturn(vrc, vrc); 304 305 if ( RTFileExists(strServerPrivateKey.c_str()) && RTFileExists(strServerCertificate.c_str()) ) 306 { 307 /* Check validity of certificate */ 308 RTCRX509CERTIFICATE pCertificate; 309 BOOL validCert = false; 310 vrc = RTCrX509Certificate_ReadFromFile(&pCertificate, strServerCertificate.c_str(), RTCRX509CERT_READ_F_PEM_ONLY, 311 &g_RTAsn1DefaultAllocator, NULL); 312 if(RT_FAILURE(vrc)) 313 { 314 RTCrX509Certificate_Delete(&pCertificate); 315 return setError(VBOX_E_IPRT_ERROR, tr("Failed to read server certificate: (%Rrc)\n"), vrc); 316 } 317 318 RTTIMESPEC Now; 319 if ( RTCrX509Validity_IsValidAtTimeSpec(&(&pCertificate)->TbsCertificate.Validity, RTTimeNow(&Now)) ) 320 validCert = true; 321 322 RTCrX509Certificate_Delete(&pCertificate); 323 324 Utf8Str strPath = mData->mapProperties["Security/ServerCertificate"]; 325 if ( strPath.isEmpty() && validCert ) 326 { 327 /* 328 * Valid auto-generated certificate and private key files exist but are not assigned to vm property 329 */ 330 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS); 331 mData.backup(); 332 mData->mapProperties["Security/Method"] = Utf8Str("TLS"); 333 mData->mapProperties["Security/ServerCertificate"] = strServerCertificate; 334 mData->mapProperties["Security/ServerPrivateKey"] = strServerPrivateKey; 335 /* Done with the properties access. */ 336 alock.release(); 337 certificateGenerated = true; 338 RTCrX509Certificate_Delete(&pCertificate); 339 } 340 else if ( (strPath.isEmpty() || strstr(strPath.c_str(),"VRDEAutoGeneratedCert.pem")) && !validCert) 341 { 342 /* Certificate is not valid so delete the files and create new ones */ 343 RTFileDelete(strServerPrivateKey.c_str()); 344 RTFileDelete(strServerCertificate.c_str()); 345 vrc = i_generateServerCertificate(); 346 if (RT_FAILURE(vrc)) 347 { 348 RTCrX509Certificate_Delete(&pCertificate); 349 i_rollback(); 350 return setError(VBOX_E_IPRT_ERROR, tr("Failed to auto generate server key and certificate: (%Rrc)\n"), vrc); 351 } 352 certificateGenerated = true; 353 } 354 } 355 else if (RTFileExists(strServerPrivateKey.c_str())) /* If only one of cert/key pair exists */ 356 { 357 RTFileDelete(strServerPrivateKey.c_str()); 358 vrc = i_generateServerCertificate(); 359 if (RT_FAILURE(vrc)) 360 { 361 i_rollback(); 362 return setError(VBOX_E_IPRT_ERROR, tr("Failed to auto generate server key and certificate: (%Rrc)\n"), vrc); 363 } 364 certificateGenerated = true; 365 } 366 else if (RTFileExists(strServerCertificate.c_str())) 367 { 368 RTFileDelete(strServerCertificate.c_str()); 369 vrc = i_generateServerCertificate(); 370 if (RT_FAILURE(vrc)) 371 { 372 i_rollback(); 373 return setError(VBOX_E_IPRT_ERROR, tr("Failed to auto generate server key and certificate: (%Rrc)\n"), vrc); 374 } 375 certificateGenerated = true; 376 } 377 else 378 { 379 /* 380 * Auto-generated certificate and key files do not exist 381 * If the server certificate property is not set 382 * or indicates an auto-generated certificate should exist, create one 383 */ 384 Utf8Str strPath = mData->mapProperties["Security/ServerCertificate"]; 385 if (strPath.isEmpty() || strstr(strPath.c_str(),"VRDEAutoGeneratedCert.pem")) 386 { 387 vrc = i_generateServerCertificate(); 388 if (RT_FAILURE(vrc)) 389 { 390 i_rollback(); 391 return setError(VBOX_E_IPRT_ERROR, tr("Failed to auto generate server key and certificate: (%Rrc)\n"), vrc); 392 } 393 certificateGenerated = true; 394 } 395 } 396 } 397 return vrc; 398 } 399 283 400 // IVRDEServer properties 284 401 ///////////////////////////////////////////////////////////////////////////// … … 312 429 313 430 /* 314 * If TLS is not explicitly disabled and there is not an existing certificate 431 * If enabling VRDE and TLS is not explicitly disabled 432 * and there is not an existing certificate 315 433 * then auto-generate a self-signed certificate for this VM. 316 434 */ 317 Utf8Str strPath = mData->mapProperties["Security/ServerCertificate"]; 318 if (aEnabled && strPath.isEmpty()) 319 { 320 if (mData->mapProperties["Security/Method"] != "RDP") 321 { 322 int vrc = i_generateServerCertificate(); 323 if (RT_FAILURE(vrc)) 324 LogRel(("Failed to auto generate server key and certificate: (%Rrc)\n", vrc)); 325 } 435 if (aEnabled) 436 { 437 BOOL certificateGenerated = false; 438 int vrc = certificateRepair(certificateGenerated); 439 if (RT_FAILURE(vrc)) 440 LogRel((("Failed to auto generate server key and certificate: (%Rrc)\n"), vrc)); 326 441 } 327 442 … … 514 629 HRESULT VRDEServer::getVRDEProperty(const com::Utf8Str &aKey, com::Utf8Str &aValue) 515 630 { 631 /* Special case for the server certificate because it might be created automatically by the code below. */ 632 if ( aKey == "Security/ServerCertificate" 633 || aKey == "Security/ServerPrivateKey") 634 { 635 BOOL certificateGenerated = false; 636 int vrc = certificateRepair(certificateGenerated); 637 if ( RT_FAILURE(vrc) ) 638 LogRel((("Failed to auto generate server key and certificate: (%Rrc)\n"), vrc)); 639 else if (certificateGenerated) 640 { 641 AutoWriteLock mlock(mParent COMMA_LOCKVAL_SRC_POS); 642 mParent->i_setModified(Machine::IsModified_VRDEServer); 643 mlock.release(); 644 } 645 } 516 646 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS); 517 647 settings::StringsMap::const_iterator it = mData->mapProperties.find(aKey); -
trunk/src/VBox/Runtime/common/crypto/x509-create-sign.cpp
r104757 r105124 62 62 63 63 RTDECL(int) RTCrX509Certificate_GenerateSelfSignedRsa(RTDIGESTTYPE enmDigestType, uint32_t cBits, uint32_t cSecsValidFor, 64 uint32_t fKeyUsage, uint64_t fExtKeyUsage, void *pvSubjectTodo,64 uint32_t fKeyUsage, uint64_t fExtKeyUsage, const char *pvSubject, 65 65 const char *pszCertFile, const char *pszPrivateKeyFile, PRTERRINFO pErrInfo) 66 66 { … … 68 68 AssertReturn(!fKeyUsage, VERR_NOT_IMPLEMENTED); 69 69 AssertReturn(!fExtKeyUsage, VERR_NOT_IMPLEMENTED); 70 AssertReturn(pvSubjectTodo == NULL, VERR_NOT_IMPLEMENTED);71 70 72 71 /* … … 159 158 /* Make it self signed: */ 160 159 X509_NAME *pX509Name = X509_get_subject_name(pNewCert); 160 rcOssl = X509_NAME_add_entry_by_txt(pX509Name, "CN", MBSTRING_ASC, (unsigned char *) pvSubject, -1, -1, 0); 161 AssertStmt(rcOssl > 0, rc = RTErrInfoSet(pErrInfo, VERR_GENERAL_FAILURE, "X509_NAME_add_entry_by_txt failed")); 161 162 rcOssl = X509_set_issuer_name(pNewCert, pX509Name); 162 163 AssertStmt(rcOssl > 0, rc = RTErrInfoSet(pErrInfo, VERR_GENERAL_FAILURE, "X509_set_issuer_name failed")); -
trunk/src/VBox/ValidationKit/tests/api/tdCloneMedium1.py
r100181 r105124 214 214 reporter.testStart("testResizeAndClone") 215 215 216 oVM = self.oTstDrv.createTestVM('test-medium- clone-only', 1, None, 4)216 oVM = self.oTstDrv.createTestVM('test-medium-resize-and-clone', 1, None, 4) 217 217 218 218 hd1 = self.createTestMedium(oVM, "hd1-resizeandclone", data=[self.iDataToWrite])
Note:
See TracChangeset
for help on using the changeset viewer.