VirtualBox

忽略:
時間撮記:
2014-6-27 下午08:59:43 (10 年 以前)
作者:
vboxsync
訊息:

Storage,DrvVD,Main: Redo the way secret keys are passed from Main to encryption filters in DrvVD. Instead of using the config interface in VD use a distinct interface for retrieving secret keys which directly talks to the entity storing the keys in Console. Avoids copying sensitive data into probably insecure buffers. Key consumers only get a reference to the key which they can use and don't have to worry about allocating secure key memory.

檔案:
修改 1 筆資料

圖例:

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

    r51687 r51752  
    421421#endif
    422422    , mBusMgr(NULL)
     423    , mpIfSecKey(NULL)
    423424    , mVMStateChangeCallbackDisabled(false)
    424425    , mfUseHostClipboard(true)
     
    457458    pVmm2UserMethods->pConsole          = this;
    458459    mpVmm2UserMethods = pVmm2UserMethods;
     460
     461    MYPDMISECKEY *pIfSecKey = (MYPDMISECKEY *)RTMemAllocZ(sizeof(*mpIfSecKey) + sizeof(Console *));
     462    if (!pIfSecKey)
     463        return E_OUTOFMEMORY;
     464    pIfSecKey->pfnKeyRetain             = Console::i_pdmIfSecKey_KeyRetain;
     465    pIfSecKey->pfnKeyRelease            = Console::i_pdmIfSecKey_KeyRelease;
     466    pIfSecKey->pConsole                 = this;
     467    mpIfSecKey = pIfSecKey;
    459468
    460469    return BaseFinalConstruct();
     
    687696    }
    688697
     698    if (mpIfSecKey)
     699    {
     700        RTMemFree((void *)mpIfSecKey);
     701        mpIfSecKey = NULL;
     702    }
     703
    689704    if (mNvram)
    690705    {
     
    727742    mRemoteUSBDevices.clear();
    728743    mUSBDevices.clear();
     744
     745    for (SecretKeyMap::iterator it = m_mapSecretKeys.begin();
     746         it != m_mapSecretKeys.end();
     747         it++)
     748        delete it->second;
     749    m_mapSecretKeys.clear();
    729750
    730751    if (mVRDEServerInfo)
     
    43614382 * @returns COM status code.
    43624383 * @param   pszUuid   The UUID of the disk to configure encryption for.
    4363  * @param   pbKey     The key to use
    4364  * @param   cbKey     Size of the key in bytes.
    43654384 */
    4366 HRESULT Console::i_configureEncryptionForDisk(const char *pszUuid, const uint8_t *pbKey, size_t cbKey)
     4385HRESULT Console::i_configureEncryptionForDisk(const char *pszUuid)
    43674386{
    43684387    HRESULT hrc = S_OK;
     
    44674486            }
    44684487
    4469             rc = pIMedium->pfnSetKey(pIMedium, pbKey, cbKey);
     4488            rc = pIMedium->pfnSetSecKeyIf(pIMedium, mpIfSecKey);
    44704489            if (RT_FAILURE(rc))
    44714490                return setError(E_FAIL, tr("Failed to set the encryption key (%Rrc)"), rc);
     
    45424561                rc = RTBase64Decode(pszKeyEnc, pbKey, cbKey, NULL, NULL);
    45434562                if (RT_SUCCESS(rc))
    4544                     hrc = i_configureEncryptionForDisk(pszUuid, pbKey, cbKey);
     4563                {
     4564                    SecretKey *pKey = new SecretKey(pbKey, cbKey);
     4565                    /* Add the key to the map */
     4566                    m_mapSecretKeys.insert(std::make_pair(Utf8Str(pszUuid), pKey));
     4567                    hrc = i_configureEncryptionForDisk(pszUuid);
     4568                }
    45454569                else
    45464570                    hrc = setError(E_FAIL,
    45474571                                   tr("Failed to decode the key (%Rrc)"),
    45484572                                   rc);
    4549 
    4550                 RTMemWipeThoroughly(pbKey, cbKey, 10 /* cMinPasses */);
    4551                 RTMemLockedFree(pbKey);
    45524573            }
    45534574            else
     
    1013410155
    1013510156    pConsole->mfPowerOffCausedByReset = true;
     10157}
     10158
     10159
     10160
     10161
     10162/**
     10163 * @interface_method_impl{PDMISECKEY,pfnKeyRetain}
     10164 */
     10165/*static*/ DECLCALLBACK(int)
     10166Console::i_pdmIfSecKey_KeyRetain(PPDMISECKEY pInterface, const char *pszId, const uint8_t **ppbKey,
     10167                                 size_t *pcbKey)
     10168{
     10169    Console *pConsole = ((MYPDMISECKEY *)pInterface)->pConsole;
     10170
     10171    SecretKeyMap::const_iterator it = pConsole->m_mapSecretKeys.find(Utf8Str(pszId));
     10172    if (it != pConsole->m_mapSecretKeys.end())
     10173    {
     10174        SecretKey *pKey = (*it).second;
     10175
     10176        ASMAtomicIncU32(&pKey->m_cRefs);
     10177        *ppbKey = pKey->m_pbKey;
     10178        *pcbKey = pKey->m_cbKey;
     10179        return VINF_SUCCESS;
     10180    }
     10181
     10182    return VERR_NOT_FOUND;
     10183}
     10184
     10185/**
     10186 * @interface_method_impl{PDMISECKEY,pfnKeyRelease}
     10187 */
     10188/*static*/ DECLCALLBACK(int)
     10189Console::i_pdmIfSecKey_KeyRelease(PPDMISECKEY pInterface, const char *pszId)
     10190{
     10191    Console *pConsole = ((MYPDMISECKEY *)pInterface)->pConsole;
     10192    SecretKeyMap::const_iterator it = pConsole->m_mapSecretKeys.find(Utf8Str(pszId));
     10193    if (it != pConsole->m_mapSecretKeys.end())
     10194    {
     10195        SecretKey *pKey = (*it).second;
     10196        ASMAtomicDecU32(&pKey->m_cRefs);
     10197        return VINF_SUCCESS;
     10198    }
     10199
     10200    return VERR_NOT_FOUND;
    1013610201}
    1013710202
注意: 瀏覽 TracChangeset 來幫助您使用更動檢視器

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