VirtualBox

Changeset 39878 in vbox for trunk/src/VBox/Main


Ignore:
Timestamp:
Jan 25, 2012 4:30:07 PM (13 years ago)
Author:
vboxsync
Message:

Main,QtGui: Implemented that hashing todo, extending it all the way to the gui for good measure.

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

Legend:

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

    r39822 r39878  
    1621416214      </desc>
    1621516215      <param name="path" type="wstring" dir="in">
    16216         <desc>The path of the extension pack tarball.</desc>
     16216        <desc>The path of the extension pack tarball.  This can optionally be
     16217        followed by a "::SHA-256=hex-digit" of the tarball. </desc>
    1621716218      </param>
    1621816219      <param name="file" type="IExtPackFile" dir="return">
  • trunk/src/VBox/Main/include/ExtPackManagerImpl.h

    r39661 r39878  
    4444    HRESULT     FinalConstruct();
    4545    void        FinalRelease();
    46     HRESULT     initWithFile(const char *a_pszFile, class ExtPackManager *a_pExtPackMgr, VirtualBox *a_pVirtualBox);
     46    HRESULT     initWithFile(const char *a_pszFile, const char *a_pszDigest, class ExtPackManager *a_pExtPackMgr, VirtualBox *a_pVirtualBox);
    4747    void        uninit();
    4848    RTMEMEF_NEW_AND_DELETE_OPERATORS();
  • trunk/src/VBox/Main/include/ExtPackUtil.h

    r39661 r39878  
    127127
    128128int                 VBoxExtPackValidateMember(const char *pszName, RTVFSOBJTYPE enmType, RTVFSOBJ hVfsObj, char *pszError, size_t cbError);
    129 int                 VBoxExtPackOpenTarFss(RTFILE hTarballFile, char *pszError, size_t cbError, PRTVFSFSSTREAM phTarFss);
    130 int                 VBoxExtPackValidateTarball(RTFILE hTarballFile, const char *pszExtPackName, const char *pszTarball,
    131                                                char *pszError, size_t cbError, PRTMANIFEST phValidManifest, PRTVFSFILE phXmlFile);
     129int                 VBoxExtPackOpenTarFss(RTFILE hTarballFile, char *pszError, size_t cbError, PRTVFSFSSTREAM phTarFss, PRTMANIFEST phFileManifest);
     130int                 VBoxExtPackValidateTarball(RTFILE hTarballFile, const char *pszExtPackName,
     131                                               const char *pszTarball, const char *pszTarballDigest,
     132                                               char *pszError, size_t cbError,
     133                                               PRTMANIFEST phValidManifest, PRTVFSFILE phXmlFile, RTCString *pStrDigest);
    132134
    133135
  • trunk/src/VBox/Main/src-all/ExtPackManagerImpl.cpp

    r39661 r39878  
    8989    /** The path to the tarball. */
    9090    Utf8Str             strExtPackFile;
     91    /** The SHA-256 hash of the file (as string). */
     92    Utf8Str             strDigest;
    9193    /** The file handle of the extension pack file. */
    9294    RTFILE              hExtPackFile;
     
    220222 * @returns COM status code.
    221223 * @param   a_pszFile       The path to the extension pack file.
     224 * @param   a_pszDigest     The SHA-256 digest of the file. Or an empty string.
    222225 * @param   a_pExtPackMgr   Pointer to the extension pack manager.
    223226 * @param   a_pVirtualBox   Pointer to the VirtualBox object.
    224227 */
    225 HRESULT ExtPackFile::initWithFile(const char *a_pszFile, ExtPackManager *a_pExtPackMgr, VirtualBox *a_pVirtualBox)
     228HRESULT ExtPackFile::initWithFile(const char *a_pszFile, const char *a_pszDigest, ExtPackManager *a_pExtPackMgr, VirtualBox *a_pVirtualBox)
    226229{
    227230    AutoInitSpan autoInitSpan(this);
     
    237240    m->strWhyUnusable               = tr("ExtPack::init failed");
    238241    m->strExtPackFile               = a_pszFile;
     242    m->strDigest                    = a_pszDigest;
    239243    m->hExtPackFile                 = NIL_RTFILE;
    240244    m->hOurManifest                 = NIL_RTMANIFEST;
     
    276280    char        szError[8192];
    277281    RTVFSFILE   hXmlFile;
    278     vrc = VBoxExtPackValidateTarball(m->hExtPackFile, NULL /*pszExtPackName*/, a_pszFile,
    279                                      szError, sizeof(szError), &m->hOurManifest, &hXmlFile);
     282    vrc = VBoxExtPackValidateTarball(m->hExtPackFile, NULL /*pszExtPackName*/, a_pszFile, a_pszDigest,
     283                                     szError, sizeof(szError), &m->hOurManifest, &hXmlFile, &m->strDigest);
    280284    if (RT_FAILURE(vrc))
    281285        return initFailed(tr("%s"), szError);
     
    549553                RTVFSFSSTREAM   hTarFss;
    550554                char            szError[8192];
    551                 int vrc = VBoxExtPackOpenTarFss(m->hExtPackFile, szError, sizeof(szError), &hTarFss);
     555                int vrc = VBoxExtPackOpenTarFss(m->hExtPackFile, szError, sizeof(szError), &hTarFss, NULL);
    552556                if (RT_SUCCESS(vrc))
    553557                {
     
    20252029}
    20262030
    2027 STDMETHODIMP ExtPackManager::OpenExtPackFile(IN_BSTR a_bstrTarball, IExtPackFile **a_ppExtPackFile)
    2028 {
    2029     CheckComArgNotNull(a_bstrTarball);
     2031STDMETHODIMP ExtPackManager::OpenExtPackFile(IN_BSTR a_bstrTarballAndDigest, IExtPackFile **a_ppExtPackFile)
     2032{
     2033    CheckComArgNotNull(a_bstrTarballAndDigest);
    20302034    CheckComArgOutPointerValid(a_ppExtPackFile);
    2031     Utf8Str strTarball(a_bstrTarball);
    20322035    AssertReturn(m->enmContext == VBOXEXTPACKCTX_PER_USER_DAEMON, E_UNEXPECTED);
     2036
     2037    /* The API can optionally take a ::SHA-256=<hex-digest> attribute at the
     2038       end of the file name.  This is just a temporary measure for
     2039       backporting, in 4.2 we'll add another parameter to the method. */
     2040    Utf8Str strTarball;
     2041    Utf8Str strDigest;
     2042    Utf8Str strTarballAndDigest(a_bstrTarballAndDigest);
     2043    size_t offSha256 = Utf8Str::npos;
     2044    const char *pszFilename = RTPathFilename(strTarballAndDigest.c_str());
     2045    if (pszFilename)
     2046        offSha256 = strTarballAndDigest.find("::SHA-256=", pszFilename - strTarballAndDigest.c_str());
     2047    if (offSha256 == Utf8Str::npos)
     2048        strTarball = strTarballAndDigest;
     2049    else
     2050    {
     2051        strTarball = strTarballAndDigest.substr(0, offSha256);
     2052        strDigest  = strTarballAndDigest.substr(offSha256 + sizeof("::SHA-256=") - 1);
     2053    }
    20332054
    20342055    ComObjPtr<ExtPackFile> NewExtPackFile;
    20352056    HRESULT hrc = NewExtPackFile.createObject();
    20362057    if (SUCCEEDED(hrc))
    2037         hrc = NewExtPackFile->initWithFile(strTarball.c_str(), this, m->pVirtualBox);
     2058        hrc = NewExtPackFile->initWithFile(strTarball.c_str(), strDigest.c_str(), this, m->pVirtualBox);
    20382059    if (SUCCEEDED(hrc))
    20392060        NewExtPackFile.queryInterfaceTo(a_ppExtPackFile);
     
    25992620{
    26002621    AssertReturn(m->enmContext == VBOXEXTPACKCTX_PER_USER_DAEMON, E_UNEXPECTED);
    2601     RTCString const * const pStrName     = &a_pExtPackFile->m->Desc.strName;
    2602     RTCString const * const pStrTarball  = &a_pExtPackFile->m->strExtPackFile;
     2622    RTCString const * const pStrName          = &a_pExtPackFile->m->Desc.strName;
     2623    RTCString const * const pStrTarball       = &a_pExtPackFile->m->strExtPackFile;
     2624    RTCString const * const pStrTarballDigest = &a_pExtPackFile->m->strDigest;
    26032625
    26042626    AutoCaller autoCaller(this);
     
    26312653             * even on failure, to be on the safe side).
    26322654             */
    2633             /** @todo add a hash (SHA-256) of the tarball or maybe just the manifest. */
    26342655            hrc = runSetUidToRootHelper(a_pstrDisplayInfo,
    26352656                                        "install",
     
    26382659                                        "--name",       pStrName->c_str(),
    26392660                                        "--tarball",    pStrTarball->c_str(),
     2661                                        "--sha-256",    pStrTarballDigest->c_str(),
    26402662                                        pExtPack ? "--replace" : (const char *)NULL,
    26412663                                        (const char *)NULL);
  • trunk/src/VBox/Main/src-all/ExtPackUtil.cpp

    r39180 r39878  
    55
    66/*
    7  * Copyright (C) 2010-2011 Oracle Corporation
     7 * Copyright (C) 2010-2012 Oracle Corporation
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    2828#include <iprt/param.h>
    2929#include <iprt/path.h>
     30#include <iprt/sha.h>
    3031#include <iprt/string.h>
    3132#include <iprt/vfs.h>
     
    784785    return rc;
    785786}
     787
     788
     789/**
     790 * Verifies the file digest (if specified) and returns the SHA-256 of the file.
     791 *
     792 * @returns
     793 * @param   hFileManifest       Manifest containing a SHA-256 digest of the file
     794 *                              that was calculated as the file was processed.
     795 * @param   pszFileDigest       SHA-256 digest of the file.
     796 * @param   pStrDigest          Where to return the SHA-256 digest. Optional.
     797 * @param   pszError            Where to write an error message on failure.
     798 * @param   cbError             The size of the @a pszError buffer.
     799 */
     800static int vboxExtPackVerifyFileDigest(RTMANIFEST hFileManifest, const char *pszFileDigest,
     801                                       RTCString *pStrDigest, char *pszError, size_t cbError)
     802{
     803    /*
     804     * Extract the SHA-256 entry for the extpack file.
     805     */
     806    char szCalculatedDigest[RTSHA256_DIGEST_LEN + 1];
     807    int rc = RTManifestEntryQueryAttr(hFileManifest, "extpack", NULL /*no name*/, RTMANIFEST_ATTR_SHA256,
     808                                      szCalculatedDigest, sizeof(szCalculatedDigest), NULL);
     809    if (RT_SUCCESS(rc))
     810    {
     811        /*
     812         * Convert the two strings to binary form before comparing.
     813         * We convert the calculated hash even if we don't have anything to
     814         * compare with, just to validate it.
     815         */
     816        uint8_t abCalculatedHash[RTSHA256_HASH_SIZE];
     817        rc = RTSha256FromString(szCalculatedDigest, abCalculatedHash);
     818        if (RT_SUCCESS(rc))
     819        {
     820            if (   pszFileDigest
     821                && *pszFileDigest != '\0')
     822            {
     823                uint8_t abFileHash[RTSHA256_HASH_SIZE];
     824                rc = RTSha256FromString(pszFileDigest, abFileHash);
     825                if (RT_SUCCESS(rc))
     826                {
     827                    if (memcmp(abFileHash, abCalculatedHash, sizeof(abFileHash)))
     828                    {
     829                        vboxExtPackSetError(pszError, cbError, "The extension pack file has changed (SHA-256 mismatch)");
     830                        rc = VERR_NOT_EQUAL;
     831                    }
     832                }
     833                else
     834                    vboxExtPackSetError(pszError, cbError, "Bad SHA-256 '%s': %Rrc", szCalculatedDigest, rc);
     835            }
     836
     837            /*
     838             * Set the output hash on success.
     839             */
     840            if (pStrDigest && RT_SUCCESS(rc))
     841            {
     842                try
     843                {
     844                    *pStrDigest = szCalculatedDigest;
     845                }
     846                catch (std::bad_alloc)
     847                {
     848                    rc = VERR_NO_MEMORY;
     849                }
     850            }
     851        }
     852        else
     853            vboxExtPackSetError(pszError, cbError, "Bad SHA-256 '%s': %Rrc", szCalculatedDigest, rc);
     854    }
     855    else
     856        vboxExtPackSetError(pszError, cbError, "RTManifestEntryGetAttr: %Rrc", rc);
     857    return rc;
     858}
     859
    786860
    787861
     
    10441118 * @param   cbError             The size of the buffer @a pszError points to.
    10451119 * @param   phTarFss            Where to return the filesystem stream handle.
    1046  */
    1047 int VBoxExtPackOpenTarFss(RTFILE hTarballFile, char *pszError, size_t cbError, PRTVFSFSSTREAM phTarFss)
     1120 * @param   phFileManifest      Where to return a manifest where the tarball is
     1121 *                              gettting hashed.  The entry will be called
     1122 *                              "extpack" and be ready when the file system
     1123 *                              stream is at an end.  Optional.
     1124 */
     1125int VBoxExtPackOpenTarFss(RTFILE hTarballFile, char *pszError, size_t cbError, PRTVFSFSSTREAM phTarFss, PRTMANIFEST phFileManifest)
    10481126{
    10491127    Assert(cbError > 0);
     
    10641142        return vboxExtPackReturnError(rc, pszError, cbError, "RTVfsIoStrmFromRTFile failed: %Rrc", rc);
    10651143
    1066     RTVFSIOSTREAM hGunzipIos;
    1067     rc = RTZipGzipDecompressIoStream(hTarballIos, 0 /*fFlags*/, &hGunzipIos);
     1144    RTMANIFEST hFileManifest = NIL_RTMANIFEST;
     1145    rc = RTManifestCreate(0 /*fFlags*/, &hFileManifest);
    10681146    if (RT_SUCCESS(rc))
    10691147    {
    1070         RTVFSFSSTREAM hTarFss;
    1071         rc = RTZipTarFsStreamFromIoStream(hGunzipIos, 0 /*fFlags*/, &hTarFss);
     1148        RTVFSIOSTREAM hPtIos;
     1149        rc = RTManifestEntryAddPassthruIoStream(hFileManifest, hTarballIos, "extpack", RTMANIFEST_ATTR_SHA256, true /*read*/, &hPtIos);
    10721150        if (RT_SUCCESS(rc))
    10731151        {
    1074             RTVfsIoStrmRelease(hGunzipIos);
    1075             RTVfsIoStrmRelease(hTarballIos);
    1076             *phTarFss = hTarFss;
    1077             return VINF_SUCCESS;
    1078         }
    1079         vboxExtPackSetError(pszError, cbError, "RTZipTarFsStreamFromIoStream failed: %Rrc", rc);
    1080         RTVfsIoStrmRelease(hGunzipIos);
     1152            RTVFSIOSTREAM hGunzipIos;
     1153            rc = RTZipGzipDecompressIoStream(hPtIos, 0 /*fFlags*/, &hGunzipIos);
     1154            if (RT_SUCCESS(rc))
     1155            {
     1156                RTVFSFSSTREAM hTarFss;
     1157                rc = RTZipTarFsStreamFromIoStream(hGunzipIos, 0 /*fFlags*/, &hTarFss);
     1158                if (RT_SUCCESS(rc))
     1159                {
     1160                    RTVfsIoStrmRelease(hPtIos);
     1161                    RTVfsIoStrmRelease(hGunzipIos);
     1162                    RTVfsIoStrmRelease(hTarballIos);
     1163                    *phTarFss = hTarFss;
     1164                    if (phFileManifest)
     1165                        *phFileManifest = hFileManifest;
     1166                    else
     1167                        RTManifestRelease(hFileManifest);
     1168                    return VINF_SUCCESS;
     1169                }
     1170
     1171                vboxExtPackSetError(pszError, cbError, "RTZipTarFsStreamFromIoStream failed: %Rrc", rc);
     1172                RTVfsIoStrmRelease(hGunzipIos);
     1173            }
     1174            else
     1175                vboxExtPackSetError(pszError, cbError, "RTZipGzipDecompressIoStream failed: %Rrc", rc);
     1176            RTVfsIoStrmRelease(hPtIos);
     1177        }
     1178        else
     1179            vboxExtPackSetError(pszError, cbError, "RTManifestEntryAddPassthruIoStream failed: %Rrc", rc);
     1180        RTManifestRelease(hFileManifest);
    10811181    }
    10821182    else
    1083         vboxExtPackSetError(pszError, cbError, "RTZipGzipDecompressIoStream failed: %Rrc", rc);
     1183        vboxExtPackSetError(pszError, cbError, "RTManifestCreate failed: %Rrc", rc);
     1184
    10841185    RTVfsIoStrmRelease(hTarballIos);
    10851186    return rc;
     
    11021203 * @param   pszTarball          The name of the tarball in case we have to
    11031204 *                              complain about something.
     1205 * @param   pszTarballDigest    The SHA-256 digest of the tarball.  Empty string
     1206 *                              if no digest available.
    11041207 * @param   pszError            Where to store an error message on failure.
    11051208 * @param   cbError             The size of the buffer @a pszError points to.
     
    11091212 * @param   phXmlFile           Where to optionally return the memorized XML
    11101213 *                              file.
    1111  *
    1112  * @todo    This function is a bit too long and should be split up if possible.
    1113  */
    1114 int VBoxExtPackValidateTarball(RTFILE hTarballFile, const char *pszExtPackName, const char *pszTarball,
    1115                                char *pszError, size_t cbError, PRTMANIFEST phValidManifest, PRTVFSFILE phXmlFile)
     1214 * @param   pStrDigest          Where to return the digest of the file.
     1215 *                              Optional.
     1216 */
     1217int VBoxExtPackValidateTarball(RTFILE hTarballFile, const char *pszExtPackName,
     1218                               const char *pszTarball, const char *pszTarballDigest,
     1219                               char *pszError, size_t cbError,
     1220                               PRTMANIFEST phValidManifest, PRTVFSFILE phXmlFile, RTCString *pStrDigest)
    11161221{
    11171222    /*
     
    11291234     * Open the tar.gz filesystem stream and set up an manifest in-memory file.
    11301235     */
    1131     RTVFSFSSTREAM hTarFss;
    1132     int rc = VBoxExtPackOpenTarFss(hTarballFile, pszError, cbError, &hTarFss);
     1236    RTMANIFEST      hFileManifest;
     1237    RTVFSFSSTREAM   hTarFss;
     1238    int rc = VBoxExtPackOpenTarFss(hTarballFile, pszError, cbError, &hTarFss, &hFileManifest);
    11331239    if (RT_FAILURE(rc))
    11341240        return rc;
     
    11411247         * Process the tarball (would be nice to move this to a function).
    11421248         */
    1143         RTVFSFILE hXmlFile      = NIL_RTVFSFILE;
    1144         RTVFSFILE hManifestFile = NIL_RTVFSFILE;
    1145         RTVFSFILE hSignatureFile= NIL_RTVFSFILE;
     1249        RTVFSFILE hXmlFile       = NIL_RTVFSFILE;
     1250        RTVFSFILE hManifestFile  = NIL_RTVFSFILE;
     1251        RTVFSFILE hSignatureFile = NIL_RTVFSFILE;
    11461252        for (;;)
    11471253        {
     
    12101316
    12111317        /*
     1318         * Check the integrity of the tarball file.
     1319         */
     1320        if (RT_SUCCESS(rc))
     1321        {
     1322            RTVfsFsStrmRelease(hTarFss);
     1323            hTarFss = NIL_RTVFSFSSTREAM;
     1324            rc = vboxExtPackVerifyFileDigest(hFileManifest, pszTarballDigest, pStrDigest, pszError, cbError);
     1325        }
     1326
     1327        /*
    12121328         * If we've successfully processed the tarball, verify that the
    12131329         * mandatory files are present.
     
    12631379        vboxExtPackSetError(pszError, cbError, "RTManifestCreate failed: %Rrc", rc);
    12641380    RTVfsFsStrmRelease(hTarFss);
     1381    RTManifestRelease(hFileManifest);
    12651382
    12661383    return rc;
  • trunk/src/VBox/Main/src-helper-apps/VBoxExtPackHelperApp.cpp

    r39612 r39878  
    55
    66/*
    7  * Copyright (C) 2010-2011 Oracle Corporation
     7 * Copyright (C) 2010-2012 Oracle Corporation
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    3434#include <iprt/path.h>
    3535#include <iprt/process.h>
     36#include <iprt/sha.h>
    3637#include <iprt/string.h>
    3738#include <iprt/stream.h>
     
    254255{
    255256    char szError[8192];
    256     int rc = VBoxExtPackOpenTarFss(hTarballFile, szError, sizeof(szError), phTarFss);
     257    int rc = VBoxExtPackOpenTarFss(hTarballFile, szError, sizeof(szError), phTarFss, NULL);
    257258    if (RT_FAILURE(rc))
    258259    {
     
    597598 * @param   pszTarball          The name of the tarball in case we have to
    598599 *                              complain about something.
     600 * @param   pszTarballDigest    The SHA-256 digest of the tarball.
    599601 * @param   phValidManifest     Where to return the handle to fully validated
    600602 *                              the manifest for the extension pack.  This
     
    602604 */
    603605static RTEXITCODE ValidateExtPackTarball(RTFILE hTarballFile, const char *pszExtPackName, const char *pszTarball,
    604                                          PRTMANIFEST phValidManifest)
     606                                         const char *pszTarballDigest, PRTMANIFEST phValidManifest)
    605607{
    606608    *phValidManifest = NIL_RTMANIFEST;
    607609    RTMsgInfo("Validating extension pack '%s' ('%s')...", pszTarball, pszExtPackName);
     610    Assert(pszTarballDigest && *pszTarballDigest);
    608611
    609612    char szError[8192];
    610     int rc = VBoxExtPackValidateTarball(hTarballFile, pszExtPackName, pszTarball,
    611                                         szError, sizeof(szError), phValidManifest, NULL /*phXmlFile*/);
     613    int rc = VBoxExtPackValidateTarball(hTarballFile, pszExtPackName, pszTarball, pszTarballDigest,
     614                                        szError, sizeof(szError), phValidManifest, NULL /*phXmlFile*/, NULL /*pStrDigest*/);
    612615    if (RT_FAILURE(rc))
    613616    {
     
    627630 * @param   pszCertDir          The certificat directory.
    628631 * @param   pszTarball          The tarball name.
     632 * @param   pszTarballDigest    The SHA-256 digest of the tarball.  Empty string
     633 *                              if no digest available.
    629634 * @param   hTarballFile        The handle to open the @a pszTarball file.
    630635 * @param   hTarballFileOpt     The tarball file handle (optional).
     
    634639 */
    635640static RTEXITCODE DoInstall2(const char *pszBaseDir, const char *pszCertDir, const char *pszTarball,
    636                              RTFILE hTarballFile, RTFILE hTarballFileOpt,
     641                             const char *pszTarballDigest, RTFILE hTarballFile, RTFILE hTarballFileOpt,
    637642                             const char *pszName, const char *pszMangledName, bool fReplace)
    638643{
     
    719724
    720725    RTMANIFEST hValidManifest = NIL_RTMANIFEST;
    721     RTEXITCODE rcExit = ValidateExtPackTarball(hTarballFile, pszName, pszTarball, &hValidManifest);
     726    RTEXITCODE rcExit = ValidateExtPackTarball(hTarballFile, pszName, pszTarball, pszTarballDigest, &hValidManifest);
    722727    if (rcExit == RTEXITCODE_SUCCESS)
    723728        rcExit = UnpackExtPack(hTarballFile, szTmpPath, hValidManifest, pszTarball);
     
    783788        { "--tarball",      't',   RTGETOPT_REQ_STRING  },
    784789        { "--tarball-fd",   'd',   RTGETOPT_REQ_UINT64  },
    785         { "--replace",      'r',   RTGETOPT_REQ_NOTHING }
     790        { "--replace",      'r',   RTGETOPT_REQ_NOTHING },
     791        { "--sha-256",      's',   RTGETOPT_REQ_STRING  }
    786792    };
    787793    RTGETOPTSTATE   GetState;
     
    790796        return RTMsgErrorExit(RTEXITCODE_FAILURE, "RTGetOptInit failed: %Rrc\n", rc);
    791797
    792     const char     *pszBaseDir      = NULL;
    793     const char     *pszCertDir      = NULL;
    794     const char     *pszName         = NULL;
    795     const char     *pszTarball      = NULL;
    796     RTFILE          hTarballFileOpt = NIL_RTFILE;
    797     bool            fReplace        = false;
     798    const char     *pszBaseDir          = NULL;
     799    const char     *pszCertDir          = NULL;
     800    const char     *pszName             = NULL;
     801    const char     *pszTarball          = NULL;
     802    const char     *pszTarballDigest    = NULL;
     803    RTFILE          hTarballFileOpt     = NIL_RTFILE;
     804    bool            fReplace            = false;
    798805    RTGETOPTUNION   ValueUnion;
    799806    int             ch;
     
    849856                break;
    850857
     858            case 's':
     859            {
     860                if (pszTarballDigest)
     861                    return RTMsgErrorExit(RTEXITCODE_SYNTAX, "Too many --sha-256 options");
     862                pszTarballDigest = ValueUnion.psz;
     863
     864                uint8_t abDigest[RTSHA256_HASH_SIZE];
     865                rc = RTSha256FromString(pszTarballDigest, abDigest);
     866                if (RT_FAILURE(rc))
     867                    return RTMsgErrorExit(RTEXITCODE_SYNTAX, "Bad SHA-256 string: %Rrc", rc);
     868                break;
     869            }
     870
    851871            case 'h':
    852872            case 'V':
     
    865885    if (!pszTarball)
    866886        return RTMsgErrorExit(RTEXITCODE_SYNTAX, "Missing --tarball option");
     887    if (!pszTarballDigest)
     888        return RTMsgErrorExit(RTEXITCODE_SYNTAX, "Missing --sha-256 option");
    867889
    868890    /*
     
    878900    if (RT_SUCCESS(rc))
    879901    {
    880         rcExit = DoInstall2(pszBaseDir, pszCertDir, pszTarball, hTarballFile, hTarballFileOpt,
     902        rcExit = DoInstall2(pszBaseDir, pszCertDir, pszTarball, pszTarballDigest, hTarballFile, hTarballFileOpt,
    881903                            pszName, pstrMangledName->c_str(), fReplace);
    882904        RTFileClose(hTarballFile);
Note: See TracChangeset for help on using the changeset viewer.

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