VirtualBox

Changeset 51925 in vbox


Ignore:
Timestamp:
Jul 8, 2014 11:13:51 AM (11 years ago)
Author:
vboxsync
Message:

Console,DrvVD: Clear the encryption keys on suspend

Location:
trunk/src/VBox/Main
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/include/ConsoleImpl.h

    r51753 r51925  
    844844    HRESULT i_consoleParseDiskEncryption(const char *psz, const char **ppszEnd);
    845845    HRESULT i_configureEncryptionForDisk(const char *pszUuid);
     846    HRESULT i_clearDiskEncryptionKeysOnAllAttachments(void);
    846847    int i_consoleParseKeyValue(const char *psz, const char **ppszEnd,
    847848                               char **ppszKey, char **ppszVal);
  • trunk/src/VBox/Main/src-client/ConsoleImpl.cpp

    r51903 r51925  
    43804380
    43814381/**
     4382 * Removes the key interfaces from all disk attachments, useful when
     4383 * changing the key store or dropping it.
     4384 */
     4385HRESULT Console::i_clearDiskEncryptionKeysOnAllAttachments(void)
     4386{
     4387    HRESULT hrc = S_OK;
     4388    SafeIfaceArray<IMediumAttachment> sfaAttachments;
     4389
     4390    AutoCaller autoCaller(this);
     4391    AssertComRCReturnRC(autoCaller.rc());
     4392
     4393    /* Get the VM - must be done before the read-locking. */
     4394    SafeVMPtr ptrVM(this);
     4395    if (!ptrVM.isOk())
     4396        return ptrVM.rc();
     4397
     4398    AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
     4399
     4400    hrc = mMachine->COMGETTER(MediumAttachments)(ComSafeArrayAsOutParam(sfaAttachments));
     4401    AssertComRCReturnRC(hrc);
     4402
     4403    /* Find the correct attachment. */
     4404    for (unsigned i = 0; i < sfaAttachments.size(); i++)
     4405    {
     4406        const ComPtr<IMediumAttachment> &pAtt = sfaAttachments[i];
     4407
     4408        /*
     4409         * Query storage controller, port and device
     4410         * to identify the correct driver.
     4411         */
     4412        ComPtr<IStorageController> pStorageCtrl;
     4413        Bstr storageCtrlName;
     4414        LONG lPort, lDev;
     4415        ULONG ulStorageCtrlInst;
     4416
     4417        hrc = pAtt->COMGETTER(Controller)(storageCtrlName.asOutParam());
     4418        AssertComRC(hrc);
     4419
     4420        hrc = pAtt->COMGETTER(Port)(&lPort);
     4421        AssertComRC(hrc);
     4422
     4423        hrc = pAtt->COMGETTER(Device)(&lDev);
     4424        AssertComRC(hrc);
     4425
     4426        hrc = mMachine->GetStorageControllerByName(storageCtrlName.raw(), pStorageCtrl.asOutParam());
     4427        AssertComRC(hrc);
     4428
     4429        hrc = pStorageCtrl->COMGETTER(Instance)(&ulStorageCtrlInst);
     4430        AssertComRC(hrc);
     4431
     4432        StorageControllerType_T enmCtrlType;
     4433        hrc = pStorageCtrl->COMGETTER(ControllerType)(&enmCtrlType);
     4434        AssertComRC(hrc);
     4435        const char *pcszDevice = i_convertControllerTypeToDev(enmCtrlType);
     4436
     4437        StorageBus_T enmBus;
     4438        hrc = pStorageCtrl->COMGETTER(Bus)(&enmBus);
     4439        AssertComRC(hrc);
     4440
     4441        unsigned uLUN;
     4442        hrc = Console::i_convertBusPortDeviceToLun(enmBus, lPort, lDev, uLUN);
     4443        AssertComRC(hrc);
     4444
     4445        PPDMIBASE pIBase = NULL;
     4446        PPDMIMEDIA pIMedium = NULL;
     4447        int rc = PDMR3QueryDriverOnLun(ptrVM.rawUVM(), pcszDevice, ulStorageCtrlInst, uLUN, "VD", &pIBase);
     4448        if (RT_SUCCESS(rc))
     4449        {
     4450            if (pIBase)
     4451            {
     4452                pIMedium = (PPDMIMEDIA)pIBase->pfnQueryInterface(pIBase, PDMIMEDIA_IID);
     4453                if (pIMedium)
     4454                {
     4455                    rc = pIMedium->pfnSetSecKeyIf(pIMedium, NULL);
     4456                    Assert(RT_SUCCESS(rc) || rc == VERR_NOT_SUPPORTED);
     4457                }
     4458            }
     4459        }
     4460    }
     4461
     4462    return hrc;
     4463}
     4464
     4465/**
    43824466 * Configures the encryption support for the disk identified by the gien UUID with
    43834467 * the given key.
     
    44844568                    if (!pIMedium)
    44854569                        return setError(E_FAIL, tr("could not query medium interface of controller"));
     4570                    else
     4571                    {
     4572                        rc = pIMedium->pfnSetSecKeyIf(pIMedium, mpIfSecKey);
     4573                        if (RT_FAILURE(rc))
     4574                            return setError(E_FAIL, tr("Failed to set the encryption key (%Rrc)"), rc);
     4575                    }
    44864576                }
    44874577                else
    44884578                    return setError(E_FAIL, tr("could not query base interface of controller"));
    44894579            }
    4490 
    4491             rc = pIMedium->pfnSetSecKeyIf(pIMedium, mpIfSecKey);
    4492             if (RT_FAILURE(rc))
    4493                 return setError(E_FAIL, tr("Failed to set the encryption key (%Rrc)"), rc);
    44944580        }
    44954581    }
     
    59656051    if (RT_FAILURE(vrc))
    59666052        hrc = setError(VBOX_E_VM_ERROR, tr("Could not suspend the machine execution (%Rrc)"), vrc);
     6053    else
     6054    {
     6055        /* Unconfigure disk encryption from all attachments. */
     6056        i_clearDiskEncryptionKeysOnAllAttachments();
     6057
     6058        /* Clear any keys we have stored. */
     6059        for (SecretKeyMap::iterator it = m_mapSecretKeys.begin();
     6060            it != m_mapSecretKeys.end();
     6061            it++)
     6062            delete it->second;
     6063        m_mapSecretKeys.clear();
     6064    }
    59676065
    59686066    LogFlowThisFunc(("hrc=%Rhrc\n", hrc));
Note: See TracChangeset for help on using the changeset viewer.

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