VirtualBox

忽略:
時間撮記:
2015-3-4 下午02:36:39 (10 年 以前)
作者:
vboxsync
訊息:

Main: Fixes for disk encryption support and make use of the optimized filter preparation when encrypting images for the first time

檔案:
修改 1 筆資料

圖例:

未更動
新增
刪除
  • trunk/src/VBox/Main/src-client/ConsoleImpl.cpp

    r54592 r54625  
    33803380    {
    33813381        memcpy(pbKey, aPassword.c_str(), cbKey);
     3382
     3383        /* Scramble content to make retrieving the key more difficult. */
     3384        rc = RTMemSaferScramble(pbKey, cbKey);
     3385        AssertRC(rc);
    33823386        SecretKey *pKey = new SecretKey(pbKey, cbKey, !!aClearOnSuspend);
    33833387        /* Add the key to the map */
     
    45464550
    45474551/**
    4548  * Removes the key interfaces from all disk attachments, useful when
    4549  * changing the key store or dropping it.
     4552 * Initializes the secret key interface on all configured attachments.
     4553 *
     4554 * @returns COM status code.
    45504555 */
    4551 HRESULT Console::i_clearDiskEncryptionKeysOnAllAttachments(void)
     4556HRESULT Console::i_initSecretKeyIfOnAllAttachments(void)
    45524557{
    45534558    HRESULT hrc = S_OK;
     
    45714576    {
    45724577        const ComPtr<IMediumAttachment> &pAtt = sfaAttachments[i];
    4573 
    45744578        /*
    45754579         * Query storage controller, port and device
     
    46304634
    46314635/**
    4632  * Configures the encryption support for the disk which have encryption conigured
    4633  * with the configured key.
     4636 * Removes the key interfaces from all disk attachments with the given key ID.
     4637 * Useful when changing the key store or dropping it.
    46344638 *
    46354639 * @returns COM status code.
    4636  * @param   aId    The ID of the password.
     4640 * @param   aId    The ID to look for.
    46374641 */
    4638 HRESULT Console::i_configureEncryptionForDisk(const com::Utf8Str &strId)
     4642HRESULT Console::i_clearDiskEncryptionKeysOnAllAttachmentsWithKeyId(const Utf8Str &strId)
    46394643{
    46404644    HRESULT hrc = S_OK;
     
    46524656
    46534657    hrc = mMachine->COMGETTER(MediumAttachments)(ComSafeArrayAsOutParam(sfaAttachments));
    4654     if (FAILED(hrc))
    4655         return hrc;
     4658    AssertComRCReturnRC(hrc);
    46564659
    46574660    /* Find the correct attachment. */
     
    46784681        hrc = pBase->GetProperty(Bstr("CRYPT/KeyId").raw(), bstrKeyId.asOutParam());
    46794682        if (hrc == VBOX_E_OBJECT_NOT_FOUND)
     4683        {
     4684            hrc = S_OK;
    46804685            continue;
     4686        }
     4687        else if (FAILED(hrc))
     4688            break;
     4689
     4690        if (strId.equals(Utf8Str(bstrKeyId)))
     4691        {
     4692
     4693            /*
     4694             * Query storage controller, port and device
     4695             * to identify the correct driver.
     4696             */
     4697            ComPtr<IStorageController> pStorageCtrl;
     4698            Bstr storageCtrlName;
     4699            LONG lPort, lDev;
     4700            ULONG ulStorageCtrlInst;
     4701
     4702            hrc = pAtt->COMGETTER(Controller)(storageCtrlName.asOutParam());
     4703            AssertComRC(hrc);
     4704
     4705            hrc = pAtt->COMGETTER(Port)(&lPort);
     4706            AssertComRC(hrc);
     4707
     4708            hrc = pAtt->COMGETTER(Device)(&lDev);
     4709            AssertComRC(hrc);
     4710
     4711            hrc = mMachine->GetStorageControllerByName(storageCtrlName.raw(), pStorageCtrl.asOutParam());
     4712            AssertComRC(hrc);
     4713
     4714            hrc = pStorageCtrl->COMGETTER(Instance)(&ulStorageCtrlInst);
     4715            AssertComRC(hrc);
     4716
     4717            StorageControllerType_T enmCtrlType;
     4718            hrc = pStorageCtrl->COMGETTER(ControllerType)(&enmCtrlType);
     4719            AssertComRC(hrc);
     4720            const char *pcszDevice = i_convertControllerTypeToDev(enmCtrlType);
     4721
     4722            StorageBus_T enmBus;
     4723            hrc = pStorageCtrl->COMGETTER(Bus)(&enmBus);
     4724            AssertComRC(hrc);
     4725
     4726            unsigned uLUN;
     4727            hrc = Console::i_convertBusPortDeviceToLun(enmBus, lPort, lDev, uLUN);
     4728            AssertComRC(hrc);
     4729
     4730            PPDMIBASE pIBase = NULL;
     4731            PPDMIMEDIA pIMedium = NULL;
     4732            int rc = PDMR3QueryDriverOnLun(ptrVM.rawUVM(), pcszDevice, ulStorageCtrlInst, uLUN, "VD", &pIBase);
     4733            if (RT_SUCCESS(rc))
     4734            {
     4735                if (pIBase)
     4736                {
     4737                    pIMedium = (PPDMIMEDIA)pIBase->pfnQueryInterface(pIBase, PDMIMEDIA_IID);
     4738                    if (pIMedium)
     4739                    {
     4740                        rc = pIMedium->pfnSetSecKeyIf(pIMedium, NULL, mpIfSecKeyHlp);
     4741                        Assert(RT_SUCCESS(rc) || rc == VERR_NOT_SUPPORTED);
     4742                    }
     4743                }
     4744            }
     4745        }
     4746    }
     4747
     4748    return hrc;
     4749}
     4750
     4751/**
     4752 * Configures the encryption support for the disk which have encryption conigured
     4753 * with the configured key.
     4754 *
     4755 * @returns COM status code.
     4756 * @param   strId    The ID of the password.
     4757 */
     4758HRESULT Console::i_configureEncryptionForDisk(const com::Utf8Str &strId)
     4759{
     4760    HRESULT hrc = S_OK;
     4761    SafeIfaceArray<IMediumAttachment> sfaAttachments;
     4762
     4763    AutoCaller autoCaller(this);
     4764    AssertComRCReturnRC(autoCaller.rc());
     4765
     4766    /* Get the VM - must be done before the read-locking. */
     4767    SafeVMPtr ptrVM(this);
     4768    if (!ptrVM.isOk())
     4769        return ptrVM.rc();
     4770
     4771    AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
     4772
     4773    hrc = mMachine->COMGETTER(MediumAttachments)(ComSafeArrayAsOutParam(sfaAttachments));
     4774    if (FAILED(hrc))
     4775        return hrc;
     4776
     4777    /* Find the correct attachment. */
     4778    for (unsigned i = 0; i < sfaAttachments.size(); i++)
     4779    {
     4780        const ComPtr<IMediumAttachment> &pAtt = sfaAttachments[i];
     4781        ComPtr<IMedium> pMedium;
     4782        ComPtr<IMedium> pBase;
     4783        Bstr bstrKeyId;
     4784
     4785        hrc = pAtt->COMGETTER(Medium)(pMedium.asOutParam());
     4786        if (FAILED(hrc))
     4787            break;
     4788
     4789        /* Skip non hard disk attachments. */
     4790        if (pMedium.isNull())
     4791            continue;
     4792
     4793        /* Get the UUID of the base medium and compare. */
     4794        hrc = pMedium->COMGETTER(Base)(pBase.asOutParam());
     4795        if (FAILED(hrc))
     4796            break;
     4797
     4798        hrc = pBase->GetProperty(Bstr("CRYPT/KeyId").raw(), bstrKeyId.asOutParam());
     4799        if (hrc == VBOX_E_OBJECT_NOT_FOUND)
     4800        {
     4801            hrc = S_OK;
     4802            continue;
     4803        }
    46814804        else if (FAILED(hrc))
    46824805            break;
     
    62586381    else
    62596382    {
    6260         /* Unconfigure disk encryption from all attachments. */
    6261         i_clearDiskEncryptionKeysOnAllAttachments();
    6262 
    6263         /* Clear any keys we have stored. */
    6264         for (SecretKeyMap::iterator it = m_mapSecretKeys.begin();
    6265             it != m_mapSecretKeys.end();
    6266             it++)
    6267             delete it->second;
    6268         m_mapSecretKeys.clear();
     6383        /* Remove keys which are supposed to be removed on a VM suspend. */
     6384        SecretKeyMap::iterator it = m_mapSecretKeys.begin();
     6385        while (it != m_mapSecretKeys.end())
     6386        {
     6387            SecretKey *pKey = it->second;
     6388            if (pKey->m_fRemoveOnSuspend)
     6389            {
     6390                /* Unconfigure disk encryption from all attachments associated with this key. */
     6391                i_clearDiskEncryptionKeysOnAllAttachmentsWithKeyId(it->first);
     6392
     6393                AssertMsg(!pKey->m_cRefs, ("No one should access the stored key at this point anymore!\n"));
     6394                delete pKey;
     6395                m_mapSecretKeys.erase(it++);
     6396            }
     6397            else
     6398                it++;
     6399        }
    62696400    }
    62706401
     
    84268557             * get notified about missing keys.
    84278558             */
    8428             that->i_clearDiskEncryptionKeysOnAllAttachments();
     8559            that->i_initSecretKeyIfOnAllAttachments();
    84298560            break;
    84308561        }
     
    1046010591        SecretKey *pKey = (*it).second;
    1046110592
    10462         ASMAtomicIncU32(&pKey->m_cRefs);
     10593        uint32_t cRefs = ASMAtomicIncU32(&pKey->m_cRefs);
     10594        if (cRefs == 1)
     10595        {
     10596            int rc = RTMemSaferUnscramble(pKey->m_pbKey, pKey->m_cbKey);
     10597            AssertRC(rc);
     10598        }
    1046310599        *ppszPassword = (const char *)pKey->m_pbKey;
    1046410600        return VINF_SUCCESS;
     
    1048110617    {
    1048210618        SecretKey *pKey = (*it).second;
    10483         ASMAtomicDecU32(&pKey->m_cRefs);
     10619        uint32_t cRefs = ASMAtomicDecU32(&pKey->m_cRefs);
     10620        if (!cRefs)
     10621        {
     10622            int rc = RTMemSaferScramble(pKey->m_pbKey, pKey->m_cbKey);
     10623            AssertRC(rc);
     10624        }
    1048410625        return VINF_SUCCESS;
    1048510626    }
注意: 瀏覽 TracChangeset 來幫助您使用更動檢視器

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