VirtualBox

Changeset 54976 in vbox


Ignore:
Timestamp:
Mar 26, 2015 7:32:11 PM (10 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
99235
Message:

Main/Console: Add method to add multiple disk encryption passwords with a single call

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

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/idl/VirtualBox.xidl

    r54911 r54976  
    75547554  <interface
    75557555    name="IConsole" extends="$unknown"
    7556     uuid="a0059bfc-04e8-4ff0-93d9-2e4d5257d9ee"
     7556    uuid="080505f4-bca9-45aa-ab95-030036b665e6"
    75577557    wsmap="managed"
    75587558    >
     
    84008400          Flag whether to clear the password on VM suspend (due to a suspending host
    84018401          for example). The password must be supplied again before the VM can resume.
     8402        </desc>
     8403      </param>
     8404    </method>
     8405
     8406    <method name="addDiskEncryptionPasswords">
     8407      <desc>
     8408        Adds a password used for hard disk encryption/decryption.
     8409
     8410        <result name="VBOX_E_PASSWORD_INCORRECT">
     8411          The password provided wasn't correct for at least one disk using the provided
     8412          ID.
     8413        </result>
     8414      </desc>
     8415      <param name="ids" type="wstring" dir="in" safearray="yes">
     8416        <desc>
     8417          List of identifiers for the passwords. Must match the identifier
     8418          used when the encrypted medium was created.
     8419        </desc>
     8420      </param>
     8421      <param name="passwords" type="wstring" dir="in" safearray="yes">
     8422        <desc>List of passwords.</desc>
     8423      </param>
     8424      <param name="clearOnSuspend" type="boolean" dir="in">
     8425        <desc>
     8426          Flag whether to clear the given passwords on VM suspend (due to a suspending host
     8427          for example). The passwords must be supplied again before the VM can resume.
    84028428        </desc>
    84038429      </param>
  • trunk/src/VBox/Main/include/ConsoleImpl.h

    r54798 r54976  
    352352                     ComPtr<IProgress> &aProgress);
    353353    HRESULT addDiskEncryptionPassword(const com::Utf8Str &aId, const com::Utf8Str &aPassword,
     354                                      BOOL aClearOnSuspend);
     355    HRESULT addDiskEncryptionPasswords(const std::vector<com::Utf8Str> &aIds, const std::vector<com::Utf8Str> &aPasswords,
    354356                                      BOOL aClearOnSuspend);
    355357    HRESULT removeDiskEncryptionPassword(const com::Utf8Str &aId);
  • trunk/src/VBox/Main/src-client/ConsoleImpl.cpp

    r54809 r54976  
    34123412    else
    34133413        return setError(E_FAIL, tr("Failed to allocate secure memory for the password (%Rrc)"), rc);
     3414
     3415    return hrc;
     3416}
     3417
     3418HRESULT Console::addDiskEncryptionPasswords(const std::vector<com::Utf8Str> &aIds, const std::vector<com::Utf8Str> &aPasswords,
     3419                                            BOOL aClearOnSuspend)
     3420{
     3421    HRESULT hrc = S_OK;
     3422
     3423    if (   !aIds.size()
     3424        || !aPasswords.size())
     3425        return setError(E_FAIL, tr("IDs and passwords must not be empty"));
     3426
     3427    if (aIds.size() != aPasswords.size())
     3428        return setError(E_FAIL, tr("The number of entries in the id and password arguments must match"));
     3429
     3430    AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
     3431
     3432    /* Check that the IDs do not exist already before changing anything. */
     3433    for (unsigned i = 0; i < aIds.size(); i++)
     3434    {
     3435        SecretKeyMap::const_iterator it = m_mapSecretKeys.find(aIds[i]);
     3436        if (it != m_mapSecretKeys.end())
     3437            return setError(VBOX_E_OBJECT_IN_USE, tr("A password with the given ID already exists"));
     3438    }
     3439
     3440    for (unsigned i = 0; i < aIds.size(); i++)
     3441    {
     3442        size_t cbKey = aPasswords[i].length() + 1; /* Include terminator */
     3443        uint8_t *pbKey = NULL;
     3444        int rc = RTMemSaferAllocZEx((void **)&pbKey, cbKey, RTMEMSAFER_F_REQUIRE_NOT_PAGABLE);
     3445        if (RT_SUCCESS(rc))
     3446        {
     3447            memcpy(pbKey, aPasswords[i].c_str(), cbKey);
     3448
     3449            /* Scramble content to make retrieving the key more difficult. */
     3450            rc = RTMemSaferScramble(pbKey, cbKey);
     3451            AssertRC(rc);
     3452            SecretKey *pKey = new SecretKey(pbKey, cbKey, !!aClearOnSuspend);
     3453            /* Add the key to the map */
     3454            m_mapSecretKeys.insert(std::make_pair(aIds[i], pKey));
     3455            hrc = i_configureEncryptionForDisk(aIds[i]);
     3456            if (FAILED(hrc))
     3457                m_mapSecretKeys.erase(aIds[i]);
     3458        }
     3459        else
     3460            hrc = setError(E_FAIL, tr("Failed to allocate secure memory for the password (%Rrc)"), rc);
     3461
     3462        if (FAILED(hrc))
     3463        {
     3464            /*
     3465             * Try to remove already successfully added passwords from the map to not
     3466             * change the state of the Console object.
     3467             */
     3468            for (unsigned ii = 0; ii < i; ii++)
     3469                removeDiskEncryptionPassword(aIds[ii]);
     3470
     3471            break;
     3472        }
     3473    }
     3474
     3475    if (   SUCCEEDED(hrc)
     3476        && m_mapSecretKeys.size() == m_cDisksEncrypted
     3477        && mMachineState == MachineState_Paused)
     3478    {
     3479        /* get the VM handle. */
     3480        SafeVMPtr ptrVM(this);
     3481        if (!ptrVM.isOk())
     3482            return ptrVM.rc();
     3483
     3484        alock.release();
     3485        int vrc = VMR3Resume(ptrVM.rawUVM(), VMRESUMEREASON_RECONFIG);
     3486
     3487        hrc = RT_SUCCESS(vrc) ? S_OK :
     3488                setError(VBOX_E_VM_ERROR,
     3489                         tr("Could not resume the machine execution (%Rrc)"), vrc);
     3490    }
    34143491
    34153492    return hrc;
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