VirtualBox

Changeset 94747 in vbox


Ignore:
Timestamp:
Apr 28, 2022 6:29:45 PM (3 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
151129
Message:

Main/MachineImpl: Implement a few more APIs for full VM encryption, bugref:9955

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

Legend:

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

    r94735 r94747  
    13021302    HRESULT authenticateExternal(const std::vector<com::Utf8Str> &aAuthParams,
    13031303                                 com::Utf8Str &aResult);
     1304
     1305#ifdef VBOX_WITH_FULL_VM_ENCRYPTION
     1306    HRESULT i_setInaccessible(void);
     1307#endif
    13041308};
    13051309
  • trunk/src/VBox/Main/src-server/MachineImpl.cpp

    r94735 r94747  
    1592915929    return setError(VBOX_E_NOT_SUPPORTED, tr("Full VM encryption is not available with this build"));
    1593015930#else
    15931     RT_NOREF(aCipher, aPasswordId);
    15932     /** @todo */
    15933     return E_NOTIMPL;
     15931    AutoLimitedCaller autoCaller(this);
     15932    AssertComRCReturn(autoCaller.rc(), autoCaller.rc());
     15933
     15934    PCVBOXCRYPTOIF pCryptoIf = NULL;
     15935    HRESULT hrc = mParent->i_retainCryptoIf(&pCryptoIf);
     15936    if (FAILED(hrc)) return hrc; /* Error is set */
     15937
     15938    AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
     15939
     15940    if (mData->mstrKeyStore.isNotEmpty())
     15941    {
     15942        char *pszCipher = NULL;
     15943        int vrc = pCryptoIf->pfnCryptoKeyStoreGetDekFromEncoded(mData->mstrKeyStore.c_str(), NULL /*pszPassword*/,
     15944                                                                NULL /*ppbKey*/, NULL /*pcbKey*/, &pszCipher);
     15945        if (RT_SUCCESS(vrc))
     15946        {
     15947            aCipher = getCipherStringWithoutMode(pszCipher);
     15948            RTStrFree(pszCipher);
     15949            aPasswordId = mData->mstrKeyId;
     15950        }
     15951        else
     15952            hrc = setErrorBoth(VBOX_E_IPRT_ERROR, vrc,
     15953                               tr("Failed to query the encryption settings with %Rrc"),
     15954                               vrc);
     15955    }
     15956    else
     15957        hrc = setError(VBOX_E_NOT_SUPPORTED, tr("This VM is not encrypted"));
     15958
     15959    mParent->i_releaseCryptoIf(pCryptoIf);
     15960
     15961    return hrc;
    1593415962#endif
    1593515963}
     
    1594115969    return setError(VBOX_E_NOT_SUPPORTED, tr("Full VM encryption is not available with this build"));
    1594215970#else
    15943     RT_NOREF(aPassword);
    15944     /** @todo */
    15945     return E_NOTIMPL;
     15971    AutoLimitedCaller autoCaller(this);
     15972    AssertComRCReturn(autoCaller.rc(), autoCaller.rc());
     15973
     15974    PCVBOXCRYPTOIF pCryptoIf = NULL;
     15975    HRESULT hrc = mParent->i_retainCryptoIf(&pCryptoIf);
     15976    if (FAILED(hrc)) return hrc; /* Error is set */
     15977
     15978    AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
     15979
     15980    if (mData->mstrKeyStore.isNotEmpty())
     15981    {
     15982        char *pszCipher = NULL;
     15983        uint8_t *pbDek  = NULL;
     15984        size_t   cbDek  = 0;
     15985        int vrc = pCryptoIf->pfnCryptoKeyStoreGetDekFromEncoded(mData->mstrKeyStore.c_str(), aPassword.c_str(),
     15986                                                                &pbDek, &cbDek, &pszCipher);
     15987        if (RT_SUCCESS(vrc))
     15988        {
     15989            RTStrFree(pszCipher);
     15990            RTMemSaferFree(pbDek, cbDek);
     15991        }
     15992        else
     15993            hrc = setErrorBoth(VBOX_E_PASSWORD_INCORRECT, vrc,
     15994                               tr("The password supplied for the encrypted machine is incorrect"));
     15995    }
     15996    else
     15997        hrc = setError(VBOX_E_NOT_SUPPORTED, tr("This VM is not encrypted"));
     15998
     15999    mParent->i_releaseCryptoIf(pCryptoIf);
     16000
     16001    return hrc;
    1594616002#endif
    1594716003}
     
    1595416010    return setError(VBOX_E_NOT_SUPPORTED, tr("Full VM encryption is not available with this build"));
    1595516011#else
    15956     RT_NOREF(aId, aPassword);
    15957     /** @todo */
    15958     return E_NOTIMPL;
     16012    AutoLimitedCaller autoCaller(this);
     16013    AssertComRCReturn(autoCaller.rc(), autoCaller.rc());
     16014
     16015    AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
     16016
     16017    size_t   cbPassword = aPassword.length() + 1;
     16018    uint8_t *pbPassword = (uint8_t *)aPassword.c_str();
     16019
     16020    mData->mpKeyStore->addSecretKey(aId, pbPassword, cbPassword);
     16021
     16022    if (   mData->mAccessible
     16023        && mData->mSession.mState == SessionState_Locked
     16024        && mData->mSession.mLockType == LockType_VM
     16025        && mData->mSession.mDirectControl != NULL)
     16026    {
     16027        /* get the console from the direct session */
     16028        ComPtr<IConsole> console;
     16029        HRESULT rc = mData->mSession.mDirectControl->COMGETTER(RemoteConsole)(console.asOutParam());
     16030        ComAssertComRC(rc);
     16031        /* send passsword to console */
     16032        console->AddEncryptionPassword(Bstr(aId).raw(),
     16033                                       Bstr(aPassword).raw(),
     16034                                       TRUE);
     16035    }
     16036
     16037    if (mData->mstrKeyId == aId)
     16038    {
     16039        HRESULT hrc = checkEncryptionPassword(aPassword);
     16040        if (FAILED(hrc))
     16041            return hrc;
     16042
     16043        if (SUCCEEDED(hrc))
     16044        {
     16045            /*
     16046             * Encryption is used and password is correct,
     16047             * Reinit the machine if required.
     16048             */
     16049            BOOL fAccessible;
     16050            alock.release();
     16051            getAccessible(&fAccessible);
     16052            alock.acquire();
     16053        }
     16054    }
     16055
     16056    /*
     16057     * Add the password into the NvramStore only after
     16058     * the machine becomes accessible and the NvramStore
     16059     * contains key id and key store.
     16060     */
     16061    if (mNvramStore.isNotNull())
     16062        mNvramStore->i_addPassword(aId, aPassword);
     16063
     16064    return S_OK;
    1595916065#endif
    1596016066}
     
    1596716073    return setError(VBOX_E_NOT_SUPPORTED, tr("Full VM encryption is not available with this build"));
    1596816074#else
    15969     RT_NOREF(aIds, aPasswords);
    15970     /** @todo */
    15971     return E_NOTIMPL;
     16075    if (aIds.size() != aPasswords.size())
     16076        return setError(E_INVALIDARG, tr("Id and passwords arrays must have the same size"));
     16077
     16078    HRESULT hrc = S_OK;
     16079    for (size_t i = 0; i < aIds.size() && SUCCEEDED(hrc); ++i)
     16080        hrc = addEncryptionPassword(aIds[i], aPasswords[i]);
     16081
     16082    return hrc;
    1597216083#endif
    1597316084}
     
    1597916090    return setError(VBOX_E_NOT_SUPPORTED, tr("Full VM encryption is not available with this build"));
    1598016091#else
    15981     RT_NOREF(autoCaller, aId);
    15982     /** @todo */
    15983     return E_NOTIMPL;
     16092    AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
     16093
     16094    if (   mData->mAccessible
     16095        && mData->mSession.mState == SessionState_Locked
     16096        && mData->mSession.mLockType == LockType_VM
     16097        && mData->mSession.mDirectControl != NULL)
     16098    {
     16099        /* get the console from the direct session */
     16100        ComPtr<IConsole> console;
     16101        HRESULT rc = mData->mSession.mDirectControl->COMGETTER(RemoteConsole)(console.asOutParam());
     16102        ComAssertComRC(rc);
     16103        /* send passsword to console */
     16104        console->RemoveEncryptionPassword(Bstr(aId).raw());
     16105    }
     16106
     16107    if (mData->mAccessible && mData->mstrKeyStore.isNotEmpty() && mData->mstrKeyId == aId)
     16108    {
     16109        if (Global::IsOnlineOrTransient(mData->mMachineState))
     16110            return setError(VBOX_E_INVALID_VM_STATE, tr("The machine is in online or transient state"));
     16111        alock.release();
     16112        autoCaller.release();
     16113        /* return because all passwords are purged when machine becomes inaccessible; */
     16114        return i_setInaccessible();
     16115    }
     16116
     16117    if (mNvramStore.isNotNull())
     16118        mNvramStore->i_removePassword(aId);
     16119    mData->mpKeyStore->deleteSecretKey(aId);
     16120    return S_OK;
    1598416121#endif
    1598516122}
     
    1599116128    return setError(VBOX_E_NOT_SUPPORTED, tr("Full VM encryption is not available with this build"));
    1599216129#else
    15993     RT_NOREF(autoCaller);
    15994     /** @todo */
    15995     return E_NOTIMPL;
     16130    AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
     16131
     16132    if (mData->mAccessible && mData->mstrKeyStore.isNotEmpty())
     16133    {
     16134        if (Global::IsOnlineOrTransient(mData->mMachineState))
     16135            return setError(VBOX_E_INVALID_VM_STATE, tr("The machine is in online or transient state"));
     16136        alock.release();
     16137        autoCaller.release();
     16138        /* return because all passwords are purged when machine becomes inaccessible; */
     16139        return i_setInaccessible();
     16140    }
     16141
     16142    mNvramStore->i_removeAllPasswords();
     16143    mData->mpKeyStore->deleteAllSecretKeys(false, true);
     16144    return S_OK;
    1599616145#endif
    1599716146}
     16147
     16148#ifdef VBOX_WITH_FULL_VM_ENCRYPTION
     16149HRESULT Machine::i_setInaccessible()
     16150{
     16151    if (!mData->mAccessible)
     16152        return S_OK;
     16153
     16154    AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
     16155    VirtualBox   *pParent = mParent;
     16156    com::Utf8Str strConfigFile = mData->m_strConfigFile;
     16157    Guid         id(i_getId());
     16158
     16159    alock.release();
     16160
     16161    uninit();
     16162    HRESULT rc = initFromSettings(pParent, strConfigFile, &id, com::Utf8Str());
     16163
     16164    alock.acquire();
     16165    mParent->i_onMachineStateChanged(mData->mUuid, mData->mMachineState);
     16166    return rc;
     16167}
     16168#endif
    1599816169
    1599916170/* This isn't handled entirely by the wrapper generator yet. */
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