VirtualBox

Changeset 54885 in vbox


Ignore:
Timestamp:
Mar 20, 2015 5:38:27 PM (10 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
99100
Message:

Main: Add a method to check for the correct encryption password

Location:
trunk/src/VBox
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VBoxManage/VBoxManage.cpp

    r54487 r54885  
    492492            { "clonevdi",         USAGE_CLONEMEDIUM,       handleCloneMedium }, /* backward compatibility */
    493493            { "encryptmedium",    USAGE_ENCRYPTMEDIUM,     handleEncryptMedium},
     494            { "checkmediumpwd",   USAGE_MEDIUMENCCHKPWD,   handleCheckMediumPassword},
    494495            { "createvm",         USAGE_CREATEVM,          handleCreateVM },
    495496            { "modifyvm",         USAGE_MODIFYVM,          handleModifyVM },
  • trunk/src/VBox/Frontends/VBoxManage/VBoxManage.h

    r54487 r54885  
    106106#define USAGE_MEDIUMPROPERTY        RT_BIT_64(60)
    107107#define USAGE_ENCRYPTMEDIUM         RT_BIT_64(61)
     108#define USAGE_MEDIUMENCCHKPWD       RT_BIT_64(62)
    108109#define USAGE_ALL                   (~(uint64_t)0)
    109110/** @} */
     
    264265int handleMediumProperty(HandlerArg *a);
    265266int handleEncryptMedium(HandlerArg *a);
     267int handleCheckMediumPassword(HandlerArg *a);
    266268RTEXITCODE handleConvertFromRaw(int argc, char *argv[]);
    267269HRESULT showMediumInfo(const ComPtr<IVirtualBox> &pVirtualBox,
  • trunk/src/VBox/Frontends/VBoxManage/VBoxManageDisk.cpp

    r54854 r54885  
    18411841}
    18421842
     1843int handleCheckMediumPassword(HandlerArg *a)
     1844{
     1845    HRESULT rc;
     1846    int vrc;
     1847    ComPtr<IMedium> hardDisk;
     1848    const char *pszFilenameOrUuid = NULL;
     1849    Utf8Str strPassword;
     1850
     1851    if (a->argc != 2)
     1852        return errorSyntax(USAGE_MEDIUMENCCHKPWD, "Invalid number of arguments: %d", a->argc);
     1853
     1854    pszFilenameOrUuid = a->argv[0];
     1855
     1856    if (!RTStrCmp(a->argv[1], "-"))
     1857    {
     1858        /* Get password from console. */
     1859        vrc = getPassword("Enter password:", &strPassword);
     1860        if (RT_FAILURE(vrc))
     1861        {
     1862            RTMsgError("Failed to read password from standard input");
     1863            return 1;
     1864        }
     1865    }
     1866    else
     1867    {
     1868        RTEXITCODE rcExit = readPasswordFile(a->argv[1], &strPassword);
     1869        if (rcExit == RTEXITCODE_FAILURE)
     1870        {
     1871            RTMsgError("Failed to read password from file");
     1872            return rcExit;
     1873        }
     1874    }
     1875
     1876    /* Always open the medium if necessary, there is no other way. */
     1877    rc = openMedium(a, pszFilenameOrUuid, DeviceType_HardDisk,
     1878                    AccessMode_ReadWrite, hardDisk,
     1879                    false /* fForceNewUuidOnOpen */, false /* fSilent */);
     1880    if (FAILED(rc))
     1881        return 1;
     1882    if (hardDisk.isNull())
     1883    {
     1884        RTMsgError("Invalid hard disk reference, avoiding crash");
     1885        return 1;
     1886    }
     1887
     1888    CHECK_ERROR(hardDisk, CheckEncryptionPassword(Bstr(strPassword).raw()));
     1889    if (SUCCEEDED(rc))
     1890        RTPrintf("The given password is correct\n");
     1891    return SUCCEEDED(rc) ? 0 : 1;
     1892}
     1893
    18431894#endif /* !VBOX_ONLY_DOCS */
  • trunk/src/VBox/Frontends/VBoxManage/VBoxManageHelp.cpp

    r54725 r54885  
    645645                     "\n", SEP);
    646646
     647    if (fCategory & USAGE_MEDIUMENCCHKPWD)
     648        RTStrmPrintf(pStrm,
     649                           "%s checkmediumpwd %s  <uuid|filename>\n"
     650                     "                            <pwd file>|-\n"
     651                     "\n", SEP);
     652
    647653    if (fCategory & USAGE_CONVERTFROMRAW)
    648654        RTStrmPrintf(pStrm,
  • trunk/src/VBox/Main/idl/VirtualBox.xidl

    r54855 r54885  
    1348913489  <interface
    1349013490    name="IMedium" extends="$unknown"
    13491     uuid="9fae9ea1-c57c-4a3d-8992-cbb2b9b4b4a3"
     13491    uuid="9680d99b-3550-4e14-8fc4-82ad1426cbde"
    1349213492    wsmap="managed"
    1349313493    >
     
    1479314793      <param name="passwordId" type="wstring" dir="return">
    1479414794        <desc>The ID of the password when unlocking the medium.</desc>
     14795      </param>
     14796    </method>
     14797
     14798    <method name="checkEncryptionPassword" const="yes">
     14799      <desc>
     14800        Checks whether the supplied password is correct for the medium.
     14801
     14802        <result name="VBOX_E_NOT_SUPPORTED">
     14803          Encryption is not configured for this medium.
     14804        </result>
     14805        <result name="VBOX_E_PASSWORD_INCORRECT">
     14806          The given password is incorrect.
     14807        </result>
     14808      </desc>
     14809      <param name="password" type="wstring" dir="in">
     14810        <desc>The password to check.</desc>
    1479514811      </param>
    1479614812    </method>
  • trunk/src/VBox/Main/include/MediumImpl.h

    r54854 r54885  
    280280                             ComPtr<IProgress> &aProgress);
    281281    HRESULT getEncryptionSettings(com::Utf8Str &aCipher, com::Utf8Str &aPasswordId);
     282    HRESULT checkEncryptionPassword(const com::Utf8Str &aPassword);
    282283
    283284    // Private internal nmethods
  • trunk/src/VBox/Main/src-server/MediumImpl.cpp

    r54884 r54885  
    32303230        aCipher = CryptoSettings.pszCipherReturned;
    32313231        RTStrFree(CryptoSettings.pszCipherReturned);
     3232
     3233        VDDestroy(pDisk);
     3234# else
     3235        throw setError(VBOX_E_NOT_SUPPORTED,
     3236                       tr("Encryption is not supported because extension pack support is not built in"));
     3237# endif
     3238    }
     3239    catch (HRESULT aRC) { rc = aRC; }
     3240
     3241    return rc;
     3242}
     3243
     3244HRESULT Medium::checkEncryptionPassword(const com::Utf8Str &aPassword)
     3245{
     3246    HRESULT rc = S_OK;
     3247
     3248    try
     3249    {
     3250        ComObjPtr<Medium> pBase = i_getBase();
     3251        AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
     3252
     3253        settings::StringsMap::iterator it = pBase->m->mapProperties.find("CRYPT/KeyStore");
     3254        if (it == pBase->m->mapProperties.end())
     3255            throw setError(VBOX_E_NOT_SUPPORTED,
     3256                           tr("The image is not configured for encryption"));
     3257
     3258        if (aPassword.isEmpty())
     3259            throw setError(E_INVALIDARG,
     3260                           tr("The given password must not be empty"));
     3261
     3262# ifdef VBOX_WITH_EXTPACK
     3263        static const Utf8Str strExtPackPuel("Oracle VM VirtualBox Extension Pack");
     3264        static const char *s_pszVDPlugin = "VDPluginCrypt";
     3265        ExtPackManager *pExtPackManager = m->pVirtualBox->i_getExtPackManager();
     3266        if (pExtPackManager->i_isExtPackUsable(strExtPackPuel.c_str()))
     3267        {
     3268            /* Load the plugin */
     3269            Utf8Str strPlugin;
     3270            rc = pExtPackManager->i_getLibraryPathForExtPack(s_pszVDPlugin, &strExtPackPuel, &strPlugin);
     3271            if (SUCCEEDED(rc))
     3272            {
     3273                int vrc = VDPluginLoadFromFilename(strPlugin.c_str());
     3274                if (RT_FAILURE(vrc))
     3275                    throw setError(VBOX_E_NOT_SUPPORTED,
     3276                                   tr("Retrieving encryption settings of the image failed because the encryption plugin could not be loaded (%s)"),
     3277                                   i_vdError(vrc).c_str());
     3278            }
     3279            else
     3280                throw setError(VBOX_E_NOT_SUPPORTED,
     3281                               tr("Encryption is not supported because the extension pack '%s' is missing the encryption plugin (old extension pack installed?)"),
     3282                               strExtPackPuel.c_str());
     3283        }
     3284        else
     3285            throw setError(VBOX_E_NOT_SUPPORTED,
     3286                           tr("Encryption is not supported because the extension pack '%s' is missing"),
     3287                           strExtPackPuel.c_str());
     3288
     3289        PVBOXHDD pDisk = NULL;
     3290        int vrc = VDCreate(m->vdDiskIfaces, i_convertDeviceType(), &pDisk);
     3291        ComAssertRCThrow(vrc, E_FAIL);
     3292
     3293        Medium::CryptoFilterSettings CryptoSettings;
     3294
     3295        i_taskEncryptSettingsSetup(&CryptoSettings, NULL, it->second.c_str(), aPassword.c_str(),
     3296                                   false /* fCreateKeyStore */);
     3297        vrc = VDFilterAdd(pDisk, "CRYPT", VD_FILTER_FLAGS_READ, CryptoSettings.vdFilterIfaces);
     3298        if (vrc == VERR_VD_PASSWORD_INCORRECT)
     3299            throw setError(VBOX_E_PASSWORD_INCORRECT,
     3300                           tr("The given password is incorrect"));
     3301        else if (RT_FAILURE(vrc))
     3302            throw setError(VBOX_E_INVALID_OBJECT_STATE,
     3303                           tr("Failed to load the encryption filter: %s"),
     3304                           i_vdError(vrc).c_str());
    32323305
    32333306        VDDestroy(pDisk);
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