VirtualBox

Changeset 72948 in vbox for trunk/src/VBox/Main/src-server


Ignore:
Timestamp:
Jul 7, 2018 4:20:42 PM (7 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
123500
Message:

Main: Introducing IMediumIO for accessing the content of a medium. The new IMedium::openForIO method instantiates and returns this interface. N.B. Write access hasn't been implemented yet.

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  
    1616 */
    1717#include "MediumImpl.h"
     18#include "MediumIOImpl.h"
    1819#include "TokenImpl.h"
    1920#include "ProgressImpl.h"
     
    768769    HRESULT executeTask();
    769770    AutoCaller mParentCaller;
    770 };
    771 
    772 /**
    773  * Settings for a crypto filter instance.
    774  */
    775 struct Medium::CryptoFilterSettings
    776 {
    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;
    804771};
    805772
     
    36613628        ComAssertRCThrow(vrc, E_FAIL);
    36623629
    3663         Medium::CryptoFilterSettings CryptoSettings;
     3630        MediumCryptoFilterSettings CryptoSettings;
    36643631
    36653632        i_taskEncryptSettingsSetup(&CryptoSettings, NULL, it->second.c_str(), NULL, false /* fCreateKeyStore */);
     
    37373704        ComAssertRCThrow(vrc, E_FAIL);
    37383705
    3739         Medium::CryptoFilterSettings CryptoSettings;
     3706        MediumCryptoFilterSettings CryptoSettings;
    37403707
    37413708        i_taskEncryptSettingsSetup(&CryptoSettings, NULL, it->second.c_str(), aPassword.c_str(),
     
    37603727    return rc;
    37613728}
     3729
     3730HRESULT 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
    37623758
    37633759////////////////////////////////////////////////////////////////////////////////
     
    61166112         * Get a readonly hdd for this medium.
    61176113         */
    6118         Medium::CryptoFilterSettings    CryptoSettingsRead;
     6114        MediumCryptoFilterSettings      CryptoSettingsRead;
    61196115        MediumLockList                  SourceMediumLockList;
    61206116        PVDISK                          pHdd;
     
    62046200                 * Get a readonly hdd for this medium (source).
    62056201                 */
    6206                 Medium::CryptoFilterSettings    CryptoSettingsRead;
     6202                MediumCryptoFilterSettings      CryptoSettingsRead;
    62076203                MediumLockList                  SourceMediumLockList;
    62086204                PVDISK                          pSrcHdd;
     
    65456541    return it->second;
    65466542}
     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 */
     6566HRESULT 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
    65476576
    65486577/**
     
    78597888DECLCALLBACK(int) Medium::i_vdCryptoConfigQuerySize(void *pvUser, const char *pszName, size_t *pcbValue)
    78607889{
    7861     Medium::CryptoFilterSettings *pSettings = (Medium::CryptoFilterSettings *)pvUser;
     7890    MediumCryptoFilterSettings *pSettings = (MediumCryptoFilterSettings *)pvUser;
    78627891    AssertPtrReturn(pSettings, VERR_GENERAL_FAILURE);
    78637892    AssertReturn(VALID_PTR(pcbValue), VERR_INVALID_POINTER);
     
    78877916                                                char *pszValue, size_t cchValue)
    78887917{
    7889     Medium::CryptoFilterSettings *pSettings = (Medium::CryptoFilterSettings *)pvUser;
     7918    MediumCryptoFilterSettings *pSettings = (MediumCryptoFilterSettings *)pvUser;
    78907919    AssertPtrReturn(pSettings, VERR_GENERAL_FAILURE);
    78917920    AssertReturn(VALID_PTR(pszValue), VERR_INVALID_POINTER);
     
    79197948                                              const uint8_t **ppbKey, size_t *pcbKey)
    79207949{
    7921     Medium::CryptoFilterSettings *pSettings = (Medium::CryptoFilterSettings *)pvUser;
     7950    MediumCryptoFilterSettings *pSettings = (MediumCryptoFilterSettings *)pvUser;
    79227951    NOREF(pszId);
    79237952    NOREF(ppbKey);
     
    79297958DECLCALLBACK(int) Medium::i_vdCryptoKeyRelease(void *pvUser, const char *pszId)
    79307959{
    7931     Medium::CryptoFilterSettings *pSettings = (Medium::CryptoFilterSettings *)pvUser;
     7960    MediumCryptoFilterSettings *pSettings = (MediumCryptoFilterSettings *)pvUser;
    79327961    NOREF(pszId);
    79337962    AssertPtrReturn(pSettings, VERR_GENERAL_FAILURE);
     
    79377966DECLCALLBACK(int) Medium::i_vdCryptoKeyStorePasswordRetain(void *pvUser, const char *pszId, const char **ppszPassword)
    79387967{
    7939     Medium::CryptoFilterSettings *pSettings = (Medium::CryptoFilterSettings *)pvUser;
     7968    MediumCryptoFilterSettings *pSettings = (MediumCryptoFilterSettings *)pvUser;
    79407969    AssertPtrReturn(pSettings, VERR_GENERAL_FAILURE);
    79417970
     
    79477976DECLCALLBACK(int) Medium::i_vdCryptoKeyStorePasswordRelease(void *pvUser, const char *pszId)
    79487977{
    7949     Medium::CryptoFilterSettings *pSettings = (Medium::CryptoFilterSettings *)pvUser;
     7978    MediumCryptoFilterSettings *pSettings = (MediumCryptoFilterSettings *)pvUser;
    79507979    AssertPtrReturn(pSettings, VERR_GENERAL_FAILURE);
    79517980    NOREF(pszId);
     
    79557984DECLCALLBACK(int) Medium::i_vdCryptoKeyStoreSave(void *pvUser, const void *pvKeyStore, size_t cbKeyStore)
    79567985{
    7957     Medium::CryptoFilterSettings *pSettings = (Medium::CryptoFilterSettings *)pvUser;
     7986    MediumCryptoFilterSettings *pSettings = (MediumCryptoFilterSettings *)pvUser;
    79587987    AssertPtrReturn(pSettings, VERR_GENERAL_FAILURE);
    79597988
     
    79697998                                                             const uint8_t *pbDek, size_t cbDek)
    79707999{
    7971     Medium::CryptoFilterSettings *pSettings = (Medium::CryptoFilterSettings *)pvUser;
     8000    MediumCryptoFilterSettings *pSettings = (MediumCryptoFilterSettings *)pvUser;
    79728001    AssertPtrReturn(pSettings, VERR_GENERAL_FAILURE);
    79738002
     
    79988027 */
    79998028HRESULT Medium::i_openHddForReading(SecretKeyStore *pKeyStore, PVDISK *ppHdd, MediumLockList *pMediumLockList,
    8000                                     Medium::CryptoFilterSettings *pCryptoSettingsRead)
     8029                                    MediumCryptoFilterSettings *pCryptoSettingsRead)
    80018030{
    80028031    /*
     
    80798108            vrc = pKeyStore->retainSecretKey(itKeyId->second, &pKey);
    80808109            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);
    80848113
    80858114            i_taskEncryptSettingsSetup(pCryptoSettingsRead, NULL, itKeyStore->second.c_str(), (const char *)pKey->getKeyBuffer(),
     
    1002110050 * Sets up the encryption settings for a filter.
    1002210051 */
    10023 void Medium::i_taskEncryptSettingsSetup(CryptoFilterSettings *pSettings, const char *pszCipher,
     10052void Medium::i_taskEncryptSettingsSetup(MediumCryptoFilterSettings *pSettings, const char *pszCipher,
    1002410053                                        const char *pszKeyStore, const char *pszPassword,
    1002510054                                        bool fCreateKeyStore)
     
    1010810137        ComAssertRCThrow(vrc, E_FAIL);
    1010910138
    10110         Medium::CryptoFilterSettings CryptoSettingsRead;
    10111         Medium::CryptoFilterSettings CryptoSettingsWrite;
     10139        MediumCryptoFilterSettings CryptoSettingsRead;
     10140        MediumCryptoFilterSettings CryptoSettingsWrite;
    1011210141
    1011310142        void *pvBuf = NULL;
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette