Changeset 54591 in vbox for trunk/src/VBox
- Timestamp:
- Mar 2, 2015 7:55:29 PM (10 years ago)
- Location:
- trunk/src/VBox
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/Storage/DrvVD.cpp
r54340 r54591 5 5 6 6 /* 7 * Copyright (C) 2006-201 3Oracle Corporation7 * Copyright (C) 2006-2015 Oracle Corporation 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 664 664 if (pThis->pIfSecKey) 665 665 rc = pThis->pIfSecKey->pfnKeyRelease(pThis->pIfSecKey, pszId); 666 else 667 rc = VERR_NOT_SUPPORTED; 668 669 return rc; 670 } 671 672 static DECLCALLBACK(int) drvvdCryptoKeyStorePasswordRetain(void *pvUser, const char *pszId, const char **ppszPassword) 673 { 674 PVBOXDISK pThis = (PVBOXDISK)pvUser; 675 int rc = VINF_SUCCESS; 676 677 AssertPtr(pThis->pIfSecKey); 678 if (pThis->pIfSecKey) 679 rc = pThis->pIfSecKey->pfnPasswordRetain(pThis->pIfSecKey, pszId, ppszPassword); 680 else 681 rc = VERR_NOT_SUPPORTED; 682 683 return rc; 684 } 685 686 static DECLCALLBACK(int) drvvdCryptoKeyStorePasswordRelease(void *pvUser, const char *pszId) 687 { 688 PVBOXDISK pThis = (PVBOXDISK)pvUser; 689 int rc = VINF_SUCCESS; 690 691 AssertPtr(pThis->pIfSecKey); 692 if (pThis->pIfSecKey) 693 rc = pThis->pIfSecKey->pfnPasswordRelease(pThis->pIfSecKey, pszId); 666 694 else 667 695 rc = VERR_NOT_SUPPORTED; … … 2910 2938 pThis->VDIfCfg.pfnQueryBytes = NULL; 2911 2939 2912 pThis->VDIfCrypto.pfnKeyRetain = drvvdCryptoKeyRetain; 2913 pThis->VDIfCrypto.pfnKeyRelease = drvvdCryptoKeyRelease; 2940 pThis->VDIfCrypto.pfnKeyRetain = drvvdCryptoKeyRetain; 2941 pThis->VDIfCrypto.pfnKeyRelease = drvvdCryptoKeyRelease; 2942 pThis->VDIfCrypto.pfnKeyStorePasswordRetain = drvvdCryptoKeyStorePasswordRetain; 2943 pThis->VDIfCrypto.pfnKeyStorePasswordRelease = drvvdCryptoKeyStorePasswordRelease; 2914 2944 } 2915 2945 -
trunk/src/VBox/Frontends/VBoxManage/VBoxManageControlVM.cpp
r54525 r54591 1679 1679 break; 1680 1680 } 1681 1681 } 1682 else if (!strcmp(a->argv[1], "addencpassword")) 1683 { 1684 if ( a->argc != 4 1685 && a->argc != 6) 1686 { 1687 errorSyntax(USAGE_CONTROLVM, "Incorrect number of parameters"); 1688 break; 1689 } 1690 1691 if ( strcmp(a->argv[4], "--removeonsuspend") 1692 || ( strcmp(a->argv[5], "yes") 1693 && strcmp(a->argv[5], "no"))) 1694 { 1695 errorSyntax(USAGE_CONTROLVM, "Invalid parameters"); 1696 break; 1697 } 1698 1699 BOOL fRemoveOnSuspend = FALSE; 1700 Bstr bstrPwId(a->argv[2]); 1701 Bstr bstrPw(a->argv[3]); 1702 if ( a->argc == 6 1703 && !strcmp(a->argv[5], "yes")) 1704 fRemoveOnSuspend = TRUE; 1705 1706 CHECK_ERROR_BREAK(console, AddDiskEncryptionPassword(bstrPwId.raw(), bstrPw.raw(), fRemoveOnSuspend)); 1707 } 1708 else if (!strcmp(a->argv[1], "removeencpassword")) 1709 { 1710 if (a->argc != 3) 1711 { 1712 errorSyntax(USAGE_CONTROLVM, "Incorrect number of parameters"); 1713 break; 1714 } 1715 Bstr bstrPwId(a->argv[2]); 1716 CHECK_ERROR_BREAK(console, RemoveDiskEncryptionPassword(bstrPwId.raw())); 1717 } 1718 else if (!strcmp(a->argv[1], "removeallencpasswords")) 1719 { 1720 CHECK_ERROR_BREAK(console, ClearAllDiskEncryptionPasswords()); 1682 1721 } 1683 1722 else -
trunk/src/VBox/Frontends/VBoxManage/VBoxManageDisk.cpp
r54500 r54591 1641 1641 static const RTGETOPTDEF g_aEncryptMediumOptions[] = 1642 1642 { 1643 { "--newpassword", 'n', RTGETOPT_REQ_STRING }, 1644 { "--oldpassword", 'o', RTGETOPT_REQ_STRING }, 1645 { "--cipher", 'c', RTGETOPT_REQ_STRING } 1643 { "--newpassword", 'n', RTGETOPT_REQ_STRING }, 1644 { "--oldpassword", 'o', RTGETOPT_REQ_STRING }, 1645 { "--cipher", 'c', RTGETOPT_REQ_STRING }, 1646 { "--newpasswordid", 'i', RTGETOPT_REQ_STRING } 1646 1647 }; 1647 1648 … … 1655 1656 const char *pszCipher = NULL; 1656 1657 const char *pszFilenameOrUuid = NULL; 1658 const char *pszNewPasswordId = NULL; 1657 1659 1658 1660 int c; … … 1676 1678 case 'c': // --cipher 1677 1679 pszCipher = ValueUnion.psz; 1680 break; 1681 1682 case 'i': // --newpasswordid 1683 pszNewPasswordId = ValueUnion.psz; 1678 1684 break; 1679 1685 … … 1708 1714 return errorSyntax(USAGE_ENCRYPTMEDIUM, "No password specified"); 1709 1715 1716 if ( (pszPasswordNew && !pszNewPasswordId) 1717 || (!pszPasswordNew && pszNewPasswordId)) 1718 return errorSyntax(USAGE_ENCRYPTMEDIUM, "A new password must always have a valid identifier set at the same time"); 1719 1710 1720 /* Always open the medium if necessary, there is no other way. */ 1711 1721 rc = openMedium(a, pszFilenameOrUuid, DeviceType_HardDisk, … … 1722 1732 ComPtr<IProgress> progress; 1723 1733 CHECK_ERROR(hardDisk, ChangeEncryption(Bstr(pszPasswordNew).raw(), Bstr(pszPasswordOld).raw(), 1724 Bstr(pszCipher).raw(), progress.asOutParam())); 1734 Bstr(pszCipher).raw(), Bstr(pszNewPasswordId).raw(), 1735 progress.asOutParam())); 1725 1736 if (SUCCEEDED(rc)) 1726 1737 rc = showProgress(progress); -
trunk/src/VBox/Frontends/VBoxManage/VBoxManageHelp.cpp
r54487 r54591 495 495 " cpuexecutioncap <1-100>\n" 496 496 " webcam <attach [path [settings]]> | <detach [path]> | <list>\n" 497 " addencpassword <id>\n" 498 " <password>\n" 499 " [--removeonsuspend <yes|no>]\n" 500 " removeencpassword <id>\n" 501 " removeallencpasswords\n" 497 502 "\n", SEP); 498 503 } … … 637 642 " [--oldpassword <old password>]\n" 638 643 " [--cipher <cipher identifier>]\n" 644 " [--newpasswordid <password identifier>]\n" 639 645 "\n", SEP); 640 646 -
trunk/src/VBox/Main/idl/VirtualBox.xidl
r54584 r54591 7530 7530 <interface 7531 7531 name="IConsole" extends="$unknown" 7532 uuid=" e51702d7-4f8f-4ebe-ac47-4b77defffd18"7532 uuid="a0059bfc-04e8-4ff0-93d9-2e4d5257d9ee" 7533 7533 wsmap="managed" 7534 7534 > … … 8354 8354 </method> 8355 8355 8356 <method name="addDiskEncryptionPassword"> 8357 <desc> 8358 Adds a password used for hard disk encryption/decryption. 8359 </desc> 8360 <param name="id" type="wstring" dir="in"> 8361 <desc> 8362 The identifier used for the password. Must match the identifier 8363 used when the encrypted medium was created. 8364 </desc> 8365 </param> 8366 <param name="password" type="wstring" dir="in"> 8367 <desc>The password.</desc> 8368 </param> 8369 <param name="clearOnSuspend" type="boolean" dir="in"> 8370 <desc> 8371 Flag whether to clear the password on VM suspend (due to a suspending host 8372 for example). The password must be supplied again before the VM can resume. 8373 </desc> 8374 </param> 8375 </method> 8376 8377 <method name="removeDiskEncryptionPassword"> 8378 <desc> 8379 Removes a password used for hard disk encryption/decryption from 8380 the running VM. As soon as the medium requiring this password 8381 is accessed the VM is paused with an error and the password must be 8382 provided again. 8383 </desc> 8384 <param name="id" type="wstring" dir="in"> 8385 <desc> 8386 The identifier used for the password. Must match the identifier 8387 used when the encrypted medium was created. 8388 </desc> 8389 </param> 8390 </method> 8391 8392 <method name="clearAllDiskEncryptionPasswords"> 8393 <desc>Clears all provided supplied disk encryption passwords.</desc> 8394 </method> 8356 8395 </interface> 8357 8396 … … 13424 13463 <interface 13425 13464 name="IMedium" extends="$unknown" 13426 uuid="e 6aa3c67-6f51-4ba6-a012-cf4825069abb"13465 uuid="edf10636-fd4f-4e24-8d24-f38a41721a00" 13427 13466 wsmap="managed" 13428 13467 > … … 14703 14742 <param name="cipher" type="wstring" dir="in"> 14704 14743 <desc>The cipher to use for encryption.</desc> 14744 </param> 14745 <param name="newPasswordId" type="wstring" dir="in"> 14746 <desc>The ID of the new password when unlocking the medium.</desc> 14705 14747 </param> 14706 14748 <param name="progress" type="IProgress" dir="return"> -
trunk/src/VBox/Main/include/ConsoleImpl.h
r54106 r54591 5 5 6 6 /* 7 * Copyright (C) 2005-201 4Oracle Corporation7 * Copyright (C) 2005-2015 Oracle Corporation 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 351 351 ULONG aMaxDowntime, 352 352 ComPtr<IProgress> &aProgress); 353 HRESULT addDiskEncryptionPassword(const com::Utf8Str &aId, const com::Utf8Str &aPassword, 354 BOOL aClearOnSuspend); 355 HRESULT removeDiskEncryptionPassword(const com::Utf8Str &aId); 356 HRESULT clearAllDiskEncryptionPasswords(); 353 357 354 358 void notifyNatDnsChange(PUVM pUVM, const char *pszDevice, ULONG ulInstanceMax); … … 585 589 SecretKey() { } 586 590 587 SecretKey(uint8_t *pbKey, size_t cbKey )591 SecretKey(uint8_t *pbKey, size_t cbKey, bool fRemoveOnSuspend) 588 592 : m_cRefs(0), 589 593 m_pbKey(pbKey), 590 m_cbKey(cbKey) 594 m_cbKey(cbKey), 595 m_fRemoveOnSuspend(fRemoveOnSuspend) 591 596 { } 592 597 … … 597 602 m_pbKey = NULL; 598 603 m_cbKey = 0; 604 m_fRemoveOnSuspend = false; 599 605 } 600 606 … … 605 611 /** Size of the key in bytes. */ 606 612 size_t m_cbKey; 613 /** Flag whether to remove the key on suspend. */ 614 bool m_fRemoveOnSuspend; 607 615 }; 608 616 … … 810 818 size_t *pcbKey); 811 819 static DECLCALLBACK(int) i_pdmIfSecKey_KeyRelease(PPDMISECKEY pInterface, const char *pszId); 820 static DECLCALLBACK(int) i_pdmIfSecKey_PasswordRetain(PPDMISECKEY pInterface, const char *pszId, const char **ppszPassword); 821 static DECLCALLBACK(int) i_pdmIfSecKey_PasswordRelease(PPDMISECKEY pInterface, const char *pszId); 812 822 813 823 static DECLCALLBACK(int) i_pdmIfSecKeyHlp_KeyMissingNotify(PPDMISECKEYHLP pInterface); … … 852 862 * @{ */ 853 863 HRESULT i_consoleParseDiskEncryption(const char *psz, const char **ppszEnd); 854 HRESULT i_configureEncryptionForDisk(const char *pszUuid);864 HRESULT i_configureEncryptionForDisk(const Utf8Str &aId); 855 865 HRESULT i_clearDiskEncryptionKeysOnAllAttachments(void); 856 866 int i_consoleParseKeyValue(const char *psz, const char **ppszEnd, -
trunk/src/VBox/Main/include/MediumImpl.h
r54486 r54591 7 7 8 8 /* 9 * Copyright (C) 2008-201 4Oracle Corporation9 * Copyright (C) 2008-2015 Oracle Corporation 10 10 * 11 11 * This file is part of VirtualBox Open Source Edition (OSE), as … … 276 276 HRESULT reset(ComPtr<IProgress> &aProgress); 277 277 HRESULT changeEncryption(const com::Utf8Str &aNewPassword, const com::Utf8Str &aOldPassword, 278 const com::Utf8Str &aCipher, ComPtr<IProgress> &aProgress);278 const com::Utf8Str &aCipher, const com::Utf8Str &aNewPasswordId, ComPtr<IProgress> &aProgress); 279 279 280 280 // Private internal nmethods … … 324 324 const uint8_t **ppbKey, size_t *pcbKey); 325 325 static DECLCALLBACK(int) i_vdCryptoKeyRelease(void *pvUser, const char *pszId); 326 static DECLCALLBACK(int) i_vdCryptoKeyStoreGetPassword(void *pvUser, const char **ppszPassword); 326 static DECLCALLBACK(int) i_vdCryptoKeyStorePasswordRetain(void *pvUser, const char *pszId, const char **ppszPassword); 327 static DECLCALLBACK(int) i_vdCryptoKeyStorePasswordRelease(void *pvUser, const char *pszId); 327 328 static DECLCALLBACK(int) i_vdCryptoKeyStoreSave(void *pvUser, const void *pvKeyStore, size_t cbKeyStore); 328 329 static DECLCALLBACK(int) i_vdCryptoKeyStoreReturnParameters(void *pvUser, const char *pszCipher, -
trunk/src/VBox/Main/src-client/ConsoleImpl.cpp
r54230 r54591 5 5 6 6 /* 7 * Copyright (C) 2005-201 4Oracle Corporation7 * Copyright (C) 2005-2015 Oracle Corporation 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 474 474 pIfSecKey->pfnKeyRetain = Console::i_pdmIfSecKey_KeyRetain; 475 475 pIfSecKey->pfnKeyRelease = Console::i_pdmIfSecKey_KeyRelease; 476 pIfSecKey->pfnPasswordRetain = Console::i_pdmIfSecKey_PasswordRetain; 477 pIfSecKey->pfnPasswordRelease = Console::i_pdmIfSecKey_PasswordRelease; 476 478 pIfSecKey->pConsole = this; 477 479 mpIfSecKey = pIfSecKey; … … 3354 3356 3355 3357 i_setMachineStateLocally(machineState); 3358 return S_OK; 3359 } 3360 3361 HRESULT Console::addDiskEncryptionPassword(const com::Utf8Str &aId, const com::Utf8Str &aPassword, 3362 BOOL aClearOnSuspend) 3363 { 3364 if ( aId.isEmpty() 3365 || aPassword.isEmpty()) 3366 return setError(E_FAIL, tr("The ID and password must be both valid")); 3367 3368 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS); 3369 3370 /* Check that the ID is not existing already. */ 3371 SecretKeyMap::const_iterator it = m_mapSecretKeys.find(aId); 3372 if (it != m_mapSecretKeys.end()) 3373 return setError(VBOX_E_OBJECT_IN_USE, tr("A password with the given ID already exists")); 3374 3375 HRESULT hrc = S_OK; 3376 size_t cbKey = aPassword.length() + 1; /* Include terminator */ 3377 uint8_t *pbKey = NULL; 3378 int rc = RTMemSaferAllocZEx((void **)&pbKey, cbKey, RTMEMSAFER_F_REQUIRE_NOT_PAGABLE); 3379 if (RT_SUCCESS(rc)) 3380 { 3381 memcpy(pbKey, aPassword.c_str(), cbKey); 3382 SecretKey *pKey = new SecretKey(pbKey, cbKey, !!aClearOnSuspend); 3383 /* Add the key to the map */ 3384 m_mapSecretKeys.insert(std::make_pair(aId, pKey)); 3385 hrc = i_configureEncryptionForDisk(aId); 3386 if (FAILED(hrc)) 3387 m_mapSecretKeys.erase(aId); 3388 } 3389 else 3390 return setError(E_FAIL, tr("Failed to allocate secure memory for the password (%Rrc)"), rc); 3391 3392 return hrc; 3393 } 3394 3395 HRESULT Console::removeDiskEncryptionPassword(const com::Utf8Str &aId) 3396 { 3397 if (aId.isEmpty()) 3398 return setError(E_FAIL, tr("The ID must be valid")); 3399 3400 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS); 3401 3402 SecretKeyMap::const_iterator it = m_mapSecretKeys.find(aId); 3403 if (it == m_mapSecretKeys.end()) 3404 return setError(VBOX_E_OBJECT_NOT_FOUND, tr("A password with the given ID does not exist")); 3405 3406 SecretKey *pKey = it->second; 3407 if (pKey->m_cRefs) 3408 return setError(VBOX_E_OBJECT_IN_USE, tr("The password is still in use by the VM")); 3409 3410 m_mapSecretKeys.erase(it); 3411 delete pKey; 3412 3413 return S_OK; 3414 } 3415 3416 HRESULT Console::clearAllDiskEncryptionPasswords() 3417 { 3418 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS); 3419 3420 /* First check whether a password is still in use. */ 3421 for (SecretKeyMap::iterator it = m_mapSecretKeys.begin(); 3422 it != m_mapSecretKeys.end(); 3423 it++) 3424 { 3425 SecretKey *pKey = it->second; 3426 if (pKey->m_cRefs) 3427 return setError(VBOX_E_OBJECT_IN_USE, tr("The password with ID \"%s\" is still in use by the VM"), 3428 it->first.c_str()); 3429 } 3430 3431 for (SecretKeyMap::iterator it = m_mapSecretKeys.begin(); 3432 it != m_mapSecretKeys.end(); 3433 it++) 3434 delete it->second; 3435 m_mapSecretKeys.clear(); 3436 3356 3437 return S_OK; 3357 3438 } … … 4549 4630 4550 4631 /** 4551 * Configures the encryption support for the disk identified by the gien UUID with4552 * the givenkey.4632 * Configures the encryption support for the disk which have encryption conigured 4633 * with the configured key. 4553 4634 * 4554 4635 * @returns COM status code. 4555 * @param pszUuid The UUID of the disk to configure encryption for.4636 * @param aId The ID of the password. 4556 4637 */ 4557 HRESULT Console::i_configureEncryptionForDisk(const c har *pszUuid)4638 HRESULT Console::i_configureEncryptionForDisk(const com::Utf8Str &strId) 4558 4639 { 4559 4640 HRESULT hrc = S_OK; … … 4580 4661 ComPtr<IMedium> pMedium; 4581 4662 ComPtr<IMedium> pBase; 4582 Bstr uuid;4663 Bstr bstrKeyId; 4583 4664 4584 4665 hrc = pAtt->COMGETTER(Medium)(pMedium.asOutParam()); … … 4595 4676 break; 4596 4677 4597 hrc = pBase->COMGETTER(Id)(uuid.asOutParam()); 4598 if (FAILED(hrc)) 4678 hrc = pBase->GetProperty(Bstr("CRYPT/KeyId").raw(), bstrKeyId.asOutParam()); 4679 if (hrc == VBOX_E_OBJECT_NOT_FOUND) 4680 continue; 4681 else if (FAILED(hrc)) 4599 4682 break; 4600 4683 4601 if ( !RTUuidCompare2Strs(Utf8Str(uuid).c_str(), pszUuid))4684 if (strId.equals(Utf8Str(bstrKeyId))) 4602 4685 { 4603 4686 /* … … 4737 4820 if (RT_SUCCESS(rc)) 4738 4821 { 4739 SecretKey *pKey = new SecretKey(pbKey, cbKey );4822 SecretKey *pKey = new SecretKey(pbKey, cbKey, true /* fRemoveOnSuspend */); 4740 4823 /* Add the key to the map */ 4741 4824 m_mapSecretKeys.insert(std::make_pair(Utf8Str(pszUuid), pKey)); 4742 hrc = i_configureEncryptionForDisk( pszUuid);4825 hrc = i_configureEncryptionForDisk(Utf8Str(pszUuid)); 4743 4826 if (FAILED(hrc)) 4744 4827 { … … 10328 10411 Console *pConsole = ((MYPDMISECKEY *)pInterface)->pConsole; 10329 10412 10413 AutoReadLock thatLock(pConsole COMMA_LOCKVAL_SRC_POS); 10330 10414 SecretKeyMap::const_iterator it = pConsole->m_mapSecretKeys.find(Utf8Str(pszId)); 10331 10415 if (it != pConsole->m_mapSecretKeys.end()) … … 10349 10433 { 10350 10434 Console *pConsole = ((MYPDMISECKEY *)pInterface)->pConsole; 10435 10436 AutoReadLock thatLock(pConsole COMMA_LOCKVAL_SRC_POS); 10437 SecretKeyMap::const_iterator it = pConsole->m_mapSecretKeys.find(Utf8Str(pszId)); 10438 if (it != pConsole->m_mapSecretKeys.end()) 10439 { 10440 SecretKey *pKey = (*it).second; 10441 ASMAtomicDecU32(&pKey->m_cRefs); 10442 return VINF_SUCCESS; 10443 } 10444 10445 return VERR_NOT_FOUND; 10446 } 10447 10448 /** 10449 * @interface_method_impl{PDMISECKEY,pfnPasswordRetain} 10450 */ 10451 /*static*/ DECLCALLBACK(int) 10452 Console::i_pdmIfSecKey_PasswordRetain(PPDMISECKEY pInterface, const char *pszId, const char **ppszPassword) 10453 { 10454 Console *pConsole = ((MYPDMISECKEY *)pInterface)->pConsole; 10455 10456 AutoReadLock thatLock(pConsole COMMA_LOCKVAL_SRC_POS); 10457 SecretKeyMap::const_iterator it = pConsole->m_mapSecretKeys.find(Utf8Str(pszId)); 10458 if (it != pConsole->m_mapSecretKeys.end()) 10459 { 10460 SecretKey *pKey = (*it).second; 10461 10462 ASMAtomicIncU32(&pKey->m_cRefs); 10463 *ppszPassword = (const char *)pKey->m_pbKey; 10464 return VINF_SUCCESS; 10465 } 10466 10467 return VERR_NOT_FOUND; 10468 } 10469 10470 /** 10471 * @interface_method_impl{PDMISECKEY,pfnPasswordRelease} 10472 */ 10473 /*static*/ DECLCALLBACK(int) 10474 Console::i_pdmIfSecKey_PasswordRelease(PPDMISECKEY pInterface, const char *pszId) 10475 { 10476 Console *pConsole = ((MYPDMISECKEY *)pInterface)->pConsole; 10477 10478 AutoReadLock thatLock(pConsole COMMA_LOCKVAL_SRC_POS); 10351 10479 SecretKeyMap::const_iterator it = pConsole->m_mapSecretKeys.find(Utf8Str(pszId)); 10352 10480 if (it != pConsole->m_mapSecretKeys.end()) -
trunk/src/VBox/Main/src-server/MediumImpl.cpp
r54486 r54591 678 678 const com::Utf8Str &strOldPassword, 679 679 const com::Utf8Str &strCipher, 680 const com::Utf8Str &strNewPasswordId, 680 681 Progress *aProgress, 681 682 MediumLockList *aMediumLockList) … … 684 685 mstrOldPassword(strOldPassword), 685 686 mstrCipher(strCipher), 687 mstrNewPasswordId(strNewPasswordId), 686 688 mpMediumLockList(aMediumLockList) 687 689 { … … 707 709 Utf8Str mstrOldPassword; 708 710 Utf8Str mstrCipher; 711 Utf8Str mstrNewPasswordId; 709 712 MediumLockList *mpMediumLockList; 710 713 PVDINTERFACE mVDImageIfaces; … … 3027 3030 3028 3031 HRESULT Medium::changeEncryption(const com::Utf8Str &aNewPassword, const com::Utf8Str &aOldPassword, 3029 const com::Utf8Str &aCipher, ComPtr<IProgress> &aProgress) 3032 const com::Utf8Str &aCipher, const com::Utf8Str &aNewPasswordId, 3033 ComPtr<IProgress> &aProgress) 3030 3034 { 3031 3035 HRESULT rc = S_OK; … … 3100 3104 /* setup task object to carry out the operation asynchronously */ 3101 3105 pTask = new Medium::EncryptTask(this, aNewPassword, aOldPassword, 3102 aCipher, pProgress, pMediumLockList);3106 aCipher, aNewPasswordId, pProgress, pMediumLockList); 3103 3107 rc = pTask->rc(); 3104 3108 AssertComRC(rc); … … 6802 6806 if (!strcmp(pszName, "Algorithm")) 6803 6807 cbValue = strlen(pSettings->pszCipher) + 1; 6808 else if (!strcmp(pszName, "KeyId")) 6809 cbValue = sizeof("irrelevant"); 6804 6810 else if (!strcmp(pszName, "KeyStore")) 6805 cbValue = RTBase64DecodedSize(pSettings->pszKeyStoreLoad, NULL) + 1; 6811 { 6812 if (!pSettings->pszKeyStoreLoad) 6813 return VERR_CFGM_VALUE_NOT_FOUND; 6814 cbValue = strlen(pSettings->pszKeyStoreLoad) + 1; 6815 } 6806 6816 else if (!strcmp(pszName, "CreateKeyStore")) 6807 6817 cbValue = 2; /* Single digit + terminator. */ … … 6821 6831 AssertReturn(VALID_PTR(pszValue), VERR_INVALID_POINTER); 6822 6832 6823 if (!strcmp(pszName, "KeyStore")) 6824 return RTBase64Decode(pSettings->pszKeyStoreLoad, pszValue, cchValue, NULL, NULL); 6833 const char *psz = NULL; 6834 if (!strcmp(pszName, "Algorithm")) 6835 psz = pSettings->pszCipher; 6836 else if (!strcmp(pszName, "KeyId")) 6837 psz = "irrelevant"; 6838 else if (!strcmp(pszName, "KeyStore")) 6839 psz = pSettings->pszKeyStoreLoad; 6840 else if (!strcmp(pszName, "CreateKeyStore")) 6841 { 6842 if (pSettings->fCreateKeyStore) 6843 psz = "1"; 6844 else 6845 psz = "0"; 6846 } 6825 6847 else 6826 { 6827 const char *psz = NULL; 6828 if (!strcmp(pszName, "Algorithm")) 6829 psz = pSettings->pszCipher; 6830 else if (!strcmp(pszName, "CreateKeyStore")) 6831 { 6832 if (pSettings->fCreateKeyStore) 6833 psz = "1"; 6834 else 6835 psz = "0"; 6836 } 6837 else 6838 return VERR_CFGM_VALUE_NOT_FOUND; 6839 6840 size_t cch = strlen(psz); 6841 if (cch >= cchValue) 6842 return VERR_CFGM_NOT_ENOUGH_SPACE; 6843 6844 memcpy(pszValue, psz, cch + 1); 6845 } 6846 6848 return VERR_CFGM_VALUE_NOT_FOUND; 6849 6850 size_t cch = strlen(psz); 6851 if (cch >= cchValue) 6852 return VERR_CFGM_NOT_ENOUGH_SPACE; 6853 6854 memcpy(pszValue, psz, cch + 1); 6847 6855 return VINF_SUCCESS; 6848 6856 } … … 6863 6871 } 6864 6872 6865 DECLCALLBACK(int) Medium::i_vdCryptoKeyStore GetPassword(void *pvUser, const char **ppszPassword)6873 DECLCALLBACK(int) Medium::i_vdCryptoKeyStorePasswordRetain(void *pvUser, const char *pszId, const char **ppszPassword) 6866 6874 { 6867 6875 Medium::CryptoFilterSettings *pSettings = (Medium::CryptoFilterSettings *)pvUser; … … 6872 6880 } 6873 6881 6874 DECLCALLBACK(int) Medium::i_vdCryptoKeyStore Save(void *pvUser, const void *pvKeyStore, size_t cbKeyStore)6882 DECLCALLBACK(int) Medium::i_vdCryptoKeyStorePasswordRelease(void *pvUser, const char *pszId) 6875 6883 { 6876 6884 Medium::CryptoFilterSettings *pSettings = (Medium::CryptoFilterSettings *)pvUser; 6877 6885 AssertPtrReturn(pSettings, VERR_GENERAL_FAILURE); 6878 6879 size_t cbEnc = RTBase64EncodedLength(cbKeyStore); 6880 pSettings->pszKeyStore = (char *)RTMemAllocZ(cbEnc + 1); 6886 return VINF_SUCCESS; 6887 } 6888 6889 DECLCALLBACK(int) Medium::i_vdCryptoKeyStoreSave(void *pvUser, const void *pvKeyStore, size_t cbKeyStore) 6890 { 6891 Medium::CryptoFilterSettings *pSettings = (Medium::CryptoFilterSettings *)pvUser; 6892 AssertPtrReturn(pSettings, VERR_GENERAL_FAILURE); 6893 6894 pSettings->pszKeyStore = (char *)RTMemAllocZ(cbKeyStore); 6881 6895 if (!pSettings->pszKeyStore) 6882 6896 return VERR_NO_MEMORY; 6883 6897 6884 int rc = RTBase64Encode(pvKeyStore, cbKeyStore, pSettings->pszKeyStore, cbEnc + 1, NULL); 6885 if (RT_FAILURE(rc)) 6886 { 6887 RTMemFree(pSettings->pszKeyStore); 6888 pSettings->pszKeyStore = NULL; 6889 } 6890 6891 return rc; 6898 memcpy(pSettings->pszKeyStore, pvKeyStore, cbKeyStore); 6899 return VINF_SUCCESS; 6892 6900 } 6893 6901 … … 8727 8735 pSettings->vdIfCrypto.pfnKeyRetain = i_vdCryptoKeyRetain; 8728 8736 pSettings->vdIfCrypto.pfnKeyRelease = i_vdCryptoKeyRelease; 8729 pSettings->vdIfCrypto.pfnKeyStoreGetPassword = i_vdCryptoKeyStoreGetPassword; 8737 pSettings->vdIfCrypto.pfnKeyStorePasswordRetain = i_vdCryptoKeyStorePasswordRetain; 8738 pSettings->vdIfCrypto.pfnKeyStorePasswordRelease = i_vdCryptoKeyStorePasswordRelease; 8730 8739 pSettings->vdIfCrypto.pfnKeyStoreSave = i_vdCryptoKeyStoreSave; 8731 8740 pSettings->vdIfCrypto.pfnKeyStoreReturnParameters = i_vdCryptoKeyStoreReturnParameters; … … 8745 8754 8746 8755 /** 8747 * Implementation code for the " compact" task.8756 * Implementation code for the "encrypt" task. 8748 8757 * 8749 8758 * @param task … … 8836 8845 tr("No valid cipher identifier was given for encryption")); 8837 8846 8847 if (task.mstrNewPasswordId.isEmpty()) 8848 throw setError(VBOX_E_INVALID_OBJECT_STATE, 8849 tr("A new password must always have a valid identifier")); 8850 8838 8851 i_taskEncryptSettingsSetup(&CryptoSettingsWrite, task.mstrCipher.c_str(), NULL, 8839 8852 task.mstrNewPassword.c_str(), true /* fCreateKeyStore */); … … 8844 8857 i_vdError(vrc).c_str()); 8845 8858 } 8859 else if (task.mstrNewPasswordId.isNotEmpty()) 8860 throw setError(VBOX_E_INVALID_OBJECT_STATE, 8861 tr("The password identifier must be empty if there is no new password set for encryption")); 8846 8862 8847 8863 /* Open all media in the chain. */ … … 8931 8947 m->mapProperties.erase(it); 8932 8948 8949 it = m->mapProperties.find("CRYPT/KeyId"); 8950 if (it != m->mapProperties.end()) 8951 m->mapProperties.erase(it); 8952 8933 8953 if (CryptoSettingsWrite.pszKeyStore) 8954 { 8934 8955 m->mapProperties["CRYPT/KeyStore"] = Utf8Str(CryptoSettingsWrite.pszKeyStore); 8956 m->mapProperties["CRYPT/KeyId"] = task.mstrNewPasswordId; 8957 } 8935 8958 8936 8959 thisLock.release(); -
trunk/src/VBox/Storage/VD.cpp
r54430 r54591 5 5 6 6 /* 7 * Copyright (C) 2006-201 4Oracle Corporation7 * Copyright (C) 2006-2015 Oracle Corporation 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 8827 8827 AssertMsg(pDisk->u32Signature == VBOXHDDDISK_SIGNATURE, ("u32Signature=%08x\n", pDisk->u32Signature)); 8828 8828 8829 AssertMsgBreakStmt(!(fFlags & VD_FILTER_FLAGS_MASK),8829 AssertMsgBreakStmt(!(fFlags & ~VD_FILTER_FLAGS_MASK), 8830 8830 ("Invalid flags set (fFlags=%#x)\n", fFlags), 8831 8831 rc = VERR_INVALID_PARAMETER);
Note:
See TracChangeset
for help on using the changeset viewer.