Changeset 72948 in vbox for trunk/src/VBox/Main/src-server
- Timestamp:
- Jul 7, 2018 4:20:42 PM (7 years ago)
- svn:sync-xref-src-repo-rev:
- 123500
- Location:
- trunk/src/VBox/Main/src-server
- Files:
-
- 1 added
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/src-server/MediumImpl.cpp
r72883 r72948 16 16 */ 17 17 #include "MediumImpl.h" 18 #include "MediumIOImpl.h" 18 19 #include "TokenImpl.h" 19 20 #include "ProgressImpl.h" … … 768 769 HRESULT executeTask(); 769 770 AutoCaller mParentCaller; 770 };771 772 /**773 * Settings for a crypto filter instance.774 */775 struct Medium::CryptoFilterSettings776 {777 CryptoFilterSettings()778 : fCreateKeyStore(false),779 pszPassword(NULL),780 pszKeyStore(NULL),781 pszKeyStoreLoad(NULL),782 pbDek(NULL),783 cbDek(0),784 pszCipher(NULL),785 pszCipherReturned(NULL)786 { }787 788 bool fCreateKeyStore;789 const char *pszPassword;790 char *pszKeyStore;791 const char *pszKeyStoreLoad;792 793 const uint8_t *pbDek;794 size_t cbDek;795 const char *pszCipher;796 797 /** The cipher returned by the crypto filter. */798 char *pszCipherReturned;799 800 PVDINTERFACE vdFilterIfaces;801 802 VDINTERFACECONFIG vdIfCfg;803 VDINTERFACECRYPTO vdIfCrypto;804 771 }; 805 772 … … 3661 3628 ComAssertRCThrow(vrc, E_FAIL); 3662 3629 3663 Medium ::CryptoFilterSettings CryptoSettings;3630 MediumCryptoFilterSettings CryptoSettings; 3664 3631 3665 3632 i_taskEncryptSettingsSetup(&CryptoSettings, NULL, it->second.c_str(), NULL, false /* fCreateKeyStore */); … … 3737 3704 ComAssertRCThrow(vrc, E_FAIL); 3738 3705 3739 Medium ::CryptoFilterSettings CryptoSettings;3706 MediumCryptoFilterSettings CryptoSettings; 3740 3707 3741 3708 i_taskEncryptSettingsSetup(&CryptoSettings, NULL, it->second.c_str(), aPassword.c_str(), … … 3760 3727 return rc; 3761 3728 } 3729 3730 HRESULT Medium::openForIO(BOOL aWritable, com::Utf8Str const &aPassword, ComPtr<IMediumIO> &aMediumIO) 3731 { 3732 /* 3733 * Input validation. 3734 */ 3735 if (aWritable && i_isReadOnly()) 3736 return setError(E_ACCESSDENIED, tr("Write access denied: read-only")); 3737 3738 com::Utf8Str const strKeyId = i_getKeyId(); 3739 if (strKeyId.isEmpty() && aPassword.isNotEmpty()) 3740 return setError(E_INVALIDARG, tr("Password given for unencrypted medium")); 3741 if (strKeyId.isNotEmpty() && aPassword.isEmpty()) 3742 return setError(E_INVALIDARG, tr("Password needed for encrypted medium")); 3743 3744 /* 3745 * Create IO object and return it. 3746 */ 3747 ComObjPtr<MediumIO> ptrIO; 3748 HRESULT hrc = ptrIO.createObject(); 3749 if (SUCCEEDED(hrc)) 3750 { 3751 hrc = ptrIO->initForMedium(this, aWritable != FALSE, strKeyId, aPassword); 3752 if (SUCCEEDED(hrc)) 3753 ptrIO.queryInterfaceTo(aMediumIO.asOutParam()); 3754 } 3755 return hrc; 3756 } 3757 3762 3758 3763 3759 //////////////////////////////////////////////////////////////////////////////// … … 6116 6112 * Get a readonly hdd for this medium. 6117 6113 */ 6118 Medium ::CryptoFilterSettingsCryptoSettingsRead;6114 MediumCryptoFilterSettings CryptoSettingsRead; 6119 6115 MediumLockList SourceMediumLockList; 6120 6116 PVDISK pHdd; … … 6204 6200 * Get a readonly hdd for this medium (source). 6205 6201 */ 6206 Medium ::CryptoFilterSettingsCryptoSettingsRead;6202 MediumCryptoFilterSettings CryptoSettingsRead; 6207 6203 MediumLockList SourceMediumLockList; 6208 6204 PVDISK pSrcHdd; … … 6545 6541 return it->second; 6546 6542 } 6543 6544 /** 6545 * This method is intended for MediumIO::initForMedium(). 6546 * 6547 * @note Caller should not hold any medium related locks as this method will 6548 * acquire the medium lock for writing and others (VirtualBox). 6549 * 6550 * @returns COM status code. 6551 * @param pKeyStore Keystore containing the KeyId+password for 6552 * an encrypted medium. 6553 * @param ppHdd Where to return the pointer to the VDISK on 6554 * success. 6555 * @param pMediumLockList The lock list to populate and lock. Caller 6556 * is responsible for calling the destructor or 6557 * MediumLockList::Clear() after destroying 6558 * @a *ppHdd 6559 * @param pCryptoSettings The crypto settings to use for setting up 6560 * decryption of the VDISK. This object must 6561 * be alive until the VDISK is destroyed! 6562 * 6563 * @note Using a keystore here for the KeyId+password so we can share code 6564 * with appliance. Not quite sure if that's a great idea or not... 6565 */ 6566 HRESULT Medium::i_openHddForIO(bool fWritable, SecretKeyStore *pKeyStore, PVDISK *ppHdd, MediumLockList *pMediumLockList, 6567 MediumCryptoFilterSettings *pCryptoSettings) 6568 { 6569 *ppHdd = NULL; 6570 if (!fWritable) 6571 return i_openHddForReading(pKeyStore, ppHdd, pMediumLockList, pCryptoSettings); 6572 /** @todo implement opening for writing. */ 6573 return E_NOTIMPL; 6574 } 6575 6547 6576 6548 6577 /** … … 7859 7888 DECLCALLBACK(int) Medium::i_vdCryptoConfigQuerySize(void *pvUser, const char *pszName, size_t *pcbValue) 7860 7889 { 7861 Medium ::CryptoFilterSettings *pSettings = (Medium::CryptoFilterSettings *)pvUser;7890 MediumCryptoFilterSettings *pSettings = (MediumCryptoFilterSettings *)pvUser; 7862 7891 AssertPtrReturn(pSettings, VERR_GENERAL_FAILURE); 7863 7892 AssertReturn(VALID_PTR(pcbValue), VERR_INVALID_POINTER); … … 7887 7916 char *pszValue, size_t cchValue) 7888 7917 { 7889 Medium ::CryptoFilterSettings *pSettings = (Medium::CryptoFilterSettings *)pvUser;7918 MediumCryptoFilterSettings *pSettings = (MediumCryptoFilterSettings *)pvUser; 7890 7919 AssertPtrReturn(pSettings, VERR_GENERAL_FAILURE); 7891 7920 AssertReturn(VALID_PTR(pszValue), VERR_INVALID_POINTER); … … 7919 7948 const uint8_t **ppbKey, size_t *pcbKey) 7920 7949 { 7921 Medium ::CryptoFilterSettings *pSettings = (Medium::CryptoFilterSettings *)pvUser;7950 MediumCryptoFilterSettings *pSettings = (MediumCryptoFilterSettings *)pvUser; 7922 7951 NOREF(pszId); 7923 7952 NOREF(ppbKey); … … 7929 7958 DECLCALLBACK(int) Medium::i_vdCryptoKeyRelease(void *pvUser, const char *pszId) 7930 7959 { 7931 Medium ::CryptoFilterSettings *pSettings = (Medium::CryptoFilterSettings *)pvUser;7960 MediumCryptoFilterSettings *pSettings = (MediumCryptoFilterSettings *)pvUser; 7932 7961 NOREF(pszId); 7933 7962 AssertPtrReturn(pSettings, VERR_GENERAL_FAILURE); … … 7937 7966 DECLCALLBACK(int) Medium::i_vdCryptoKeyStorePasswordRetain(void *pvUser, const char *pszId, const char **ppszPassword) 7938 7967 { 7939 Medium ::CryptoFilterSettings *pSettings = (Medium::CryptoFilterSettings *)pvUser;7968 MediumCryptoFilterSettings *pSettings = (MediumCryptoFilterSettings *)pvUser; 7940 7969 AssertPtrReturn(pSettings, VERR_GENERAL_FAILURE); 7941 7970 … … 7947 7976 DECLCALLBACK(int) Medium::i_vdCryptoKeyStorePasswordRelease(void *pvUser, const char *pszId) 7948 7977 { 7949 Medium ::CryptoFilterSettings *pSettings = (Medium::CryptoFilterSettings *)pvUser;7978 MediumCryptoFilterSettings *pSettings = (MediumCryptoFilterSettings *)pvUser; 7950 7979 AssertPtrReturn(pSettings, VERR_GENERAL_FAILURE); 7951 7980 NOREF(pszId); … … 7955 7984 DECLCALLBACK(int) Medium::i_vdCryptoKeyStoreSave(void *pvUser, const void *pvKeyStore, size_t cbKeyStore) 7956 7985 { 7957 Medium ::CryptoFilterSettings *pSettings = (Medium::CryptoFilterSettings *)pvUser;7986 MediumCryptoFilterSettings *pSettings = (MediumCryptoFilterSettings *)pvUser; 7958 7987 AssertPtrReturn(pSettings, VERR_GENERAL_FAILURE); 7959 7988 … … 7969 7998 const uint8_t *pbDek, size_t cbDek) 7970 7999 { 7971 Medium ::CryptoFilterSettings *pSettings = (Medium::CryptoFilterSettings *)pvUser;8000 MediumCryptoFilterSettings *pSettings = (MediumCryptoFilterSettings *)pvUser; 7972 8001 AssertPtrReturn(pSettings, VERR_GENERAL_FAILURE); 7973 8002 … … 7998 8027 */ 7999 8028 HRESULT Medium::i_openHddForReading(SecretKeyStore *pKeyStore, PVDISK *ppHdd, MediumLockList *pMediumLockList, 8000 Medium ::CryptoFilterSettings *pCryptoSettingsRead)8029 MediumCryptoFilterSettings *pCryptoSettingsRead) 8001 8030 { 8002 8031 /* … … 8079 8108 vrc = pKeyStore->retainSecretKey(itKeyId->second, &pKey); 8080 8109 if (RT_FAILURE(vrc)) 8081 throw setError (VBOX_E_INVALID_OBJECT_STATE,8082 tr("Failed to retrieve the secret key with ID \"%s\" from the store (%Rrc)"),8083 itKeyId->second.c_str(), vrc);8110 throw setErrorBoth(VBOX_E_INVALID_OBJECT_STATE, vrc, 8111 tr("Failed to retrieve the secret key with ID \"%s\" from the store (%Rrc)"), 8112 itKeyId->second.c_str(), vrc); 8084 8113 8085 8114 i_taskEncryptSettingsSetup(pCryptoSettingsRead, NULL, itKeyStore->second.c_str(), (const char *)pKey->getKeyBuffer(), … … 10021 10050 * Sets up the encryption settings for a filter. 10022 10051 */ 10023 void Medium::i_taskEncryptSettingsSetup( CryptoFilterSettings *pSettings, const char *pszCipher,10052 void Medium::i_taskEncryptSettingsSetup(MediumCryptoFilterSettings *pSettings, const char *pszCipher, 10024 10053 const char *pszKeyStore, const char *pszPassword, 10025 10054 bool fCreateKeyStore) … … 10108 10137 ComAssertRCThrow(vrc, E_FAIL); 10109 10138 10110 Medium ::CryptoFilterSettings CryptoSettingsRead;10111 Medium ::CryptoFilterSettings CryptoSettingsWrite;10139 MediumCryptoFilterSettings CryptoSettingsRead; 10140 MediumCryptoFilterSettings CryptoSettingsWrite; 10112 10141 10113 10142 void *pvBuf = NULL;
Note:
See TracChangeset
for help on using the changeset viewer.