VirtualBox

Changeset 65268 in vbox


Ignore:
Timestamp:
Jan 12, 2017 7:05:49 PM (8 years ago)
Author:
vboxsync
Message:

FE/Qt: when downloading an Extension Pack or Guest Additions, verify the hash sum automatically

Location:
trunk/src/VBox/Frontends/VirtualBox/src
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/globals/UIMessageCenter.cpp

    r64429 r65268  
    21662166}
    21672167
     2168void UIMessageCenter::cannotValidateGuestAdditionsSHA256Sum(const QString &strUrl, const QString &strSrc) const
     2169{
     2170    alert(windowManager().networkManagerOrMainWindowShown(), MessageType_Error,
     2171          tr("<p>The <b>VirtualBox Guest Additions</b> disk image file has been successfully downloaded "
     2172             "from <nobr><a href=\"%1\">%1</a></nobr> "
     2173             "and saved locally as <nobr><b>%2</b>, </nobr>"
     2174             "but the SHA-256 checksum verification failed.</p>"
     2175             "<p>Please do the download, installation and verification manually.</p>")
     2176             .arg(strUrl, strSrc));
     2177}
     2178
    21682179void UIMessageCenter::cannotUpdateGuestAdditions(const CProgress &progress) const
    21692180{
     
    22712282                          0 /* auto-confirm id */,
    22722283                          tr("Delete", "extension pack"));
     2284}
     2285
     2286void UIMessageCenter::cannotValidateExtentionPackSHA256Sum(const QString &strExtPackName, const QString &strFrom, const QString &strTo) const
     2287{
     2288    alert(windowManager().networkManagerOrMainWindowShown(), MessageType_Error,
     2289          tr("<p>The <b><nobr>%1</nobr></b> has been successfully downloaded "
     2290             "from <nobr><a href=\"%2\">%2</a></nobr> "
     2291             "and saved locally as <nobr><b>%3</b>, </nobr>"
     2292             "but the SHA-256 checksum verification failed.</p>"
     2293             "<p>Please do the download, installation and verification manually.</p>")
     2294             .arg(strExtPackName, strFrom, strTo));
    22732295}
    22742296#endif /* VBOX_GUI_WITH_NETWORK_MANAGER */
  • trunk/src/VBox/Frontends/VirtualBox/src/globals/UIMessageCenter.h

    r63762 r65268  
    329329    void cannotSaveGuestAdditions(const QString &strURL, const QString &strTarget) const;
    330330    bool proposeMountGuestAdditions(const QString &strUrl, const QString &strSrc) const;
     331    void cannotValidateGuestAdditionsSHA256Sum(const QString &strUrl, const QString &strSrc) const;
    331332    void cannotUpdateGuestAdditions(const CProgress &progress) const;
    332333    bool cannotFindUserManual(const QString &strMissedLocation) const;
     
    338339    void cannotSaveExtensionPack(const QString &strExtPackName, const QString &strFrom, const QString &strTo) const;
    339340    bool proposeInstallExtentionPack(const QString &strExtPackName, const QString &strFrom, const QString &strTo) const;
     341    void cannotValidateExtentionPackSHA256Sum(const QString &strExtPackName, const QString &strFrom, const QString &strTo) const;
    340342    bool proposeDeleteExtentionPack(const QString &strTo) const;
    341343    bool proposeDeleteOldExtentionPacks(const QStringList &strFiles) const;
  • trunk/src/VBox/Frontends/VirtualBox/src/net/UIDownloader.cpp

    r62493 r65268  
    1515 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
    1616 */
     17
     18/// This class requires proper doxy.
     19/// For now I'm keeping the old style consistent.
    1720
    1821#ifdef VBOX_WITH_PRECOMPILED_HEADERS
     
    4952void UIDownloader::sltStartDownloading()
    5053{
    51     /* Set state to acknowledging: */
     54    /* Set state to downloading: */
    5255    m_state = UIDownloaderState_Downloading;
    5356
    5457    /* Send GET request: */
    5558    createNetworkRequest(UINetworkRequestType_GET, QList<QUrl>() << m_source);
     59}
     60
     61/* Verifying start: */
     62void UIDownloader::sltStartVerifying()
     63{
     64    /* Set state to verifying: */
     65    m_state = UIDownloaderState_Verifying;
     66
     67    /* Send GET request: */
     68    createNetworkRequest(UINetworkRequestType_GET, QList<QUrl>() << m_strPathSHA256SumsFile);
    5669}
    5770
     
    6376    connect(this, SIGNAL(sigToStartAcknowledging()), this, SLOT(sltStartAcknowledging()), Qt::QueuedConnection);
    6477    connect(this, SIGNAL(sigToStartDownloading()), this, SLOT(sltStartDownloading()), Qt::QueuedConnection);
     78    connect(this, SIGNAL(sigToStartVerifying()), this, SLOT(sltStartVerifying()), Qt::QueuedConnection);
    6579}
    6680
     
    7387        case UIDownloaderState_Acknowledging: return tr("Looking for %1...");
    7488        case UIDownloaderState_Downloading:   return tr("Downloading %1...");
     89        case UIDownloaderState_Verifying:     return tr("Verifying %1...");
    7590        default:                              break;
    7691    }
     
    113128            break;
    114129        }
     130        case UIDownloaderState_Verifying:
     131        {
     132            handleVerifyingResult(pNetworkReply);
     133            break;
     134        }
    115135        default:
    116136            break;
     
    143163    handleDownloadedObject(pNetworkReply);
    144164
     165    /* Check whether we should do verification: */
     166    if (!m_strPathSHA256SumsFile.isEmpty())
     167    {
     168        /* Start verifying: */
     169        startDelayedVerifying();
     170    }
     171    else
     172    {
     173        /* Delete downloader: */
     174        deleteLater();
     175    }
     176}
     177
     178void UIDownloader::handleVerifyingResult(UINetworkReply *pNetworkReply)
     179{
     180    /* Handle verified object: */
     181    handleVerifiedObject(pNetworkReply);
     182
    145183    /* Delete downloader: */
    146184    deleteLater();
  • trunk/src/VBox/Frontends/VirtualBox/src/net/UIDownloader.h

    r62493 r65268  
    1515 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
    1616 */
     17
     18/// This class requires proper doxy.
     19/// For now I'm keeping the old style consistent.
    1720
    1821#ifndef __UIDownloader_h__
     
    4245    /* Signal to start downloading: */
    4346    void sigToStartDownloading();
     47    /* Signal to start verifying: */
     48    void sigToStartVerifying();
    4449
    4550public:
     
    5459    /* Downloading part: */
    5560    void sltStartDownloading();
     61    /* Verifying part: */
     62    void sltStartVerifying();
    5663
    5764protected:
     
    6269        UIDownloaderState_Null,
    6370        UIDownloaderState_Acknowledging,
    64         UIDownloaderState_Downloading
     71        UIDownloaderState_Downloading,
     72        UIDownloaderState_Verifying,
    6573    };
    6674
     
    8088    const QString& target() const { return m_strTarget; }
    8189
     90    /* SHA-256 stuff,
     91     * allows to set/get SHA-256 sum dictionary file for downloaded source. */
     92    QString pathSHA256SumsFile() const { return m_strPathSHA256SumsFile; }
     93    void setPathSHA256SumsFile(const QString &strPathSHA256SumsFile) { m_strPathSHA256SumsFile = strPathSHA256SumsFile; }
     94
    8295    /** Returns description of the current network operation. */
    8396    virtual const QString description() const;
     
    87100    /* Start delayed downloading: */
    88101    void startDelayedDownloading() { emit sigToStartDownloading(); }
     102    /* Start delayed verifying: */
     103    void startDelayedVerifying() { emit sigToStartVerifying(); }
    89104
    90105    /* Network-reply progress handler: */
     
    99114    /* Handle downloading result: */
    100115    virtual void handleDownloadingResult(UINetworkReply *pNetworkReply);
     116    /* Handle verifying result: */
     117    virtual void handleVerifyingResult(UINetworkReply *pNetworkReply);
    101118
    102119    /* Pure virtual function to ask user about downloading confirmation: */
     
    104121    /* Pure virtual function to handle downloaded object: */
    105122    virtual void handleDownloadedObject(UINetworkReply *pNetworkReply) = 0;
     123    /* Base virtual function to handle verified object: */
     124    virtual void handleVerifiedObject(UINetworkReply * /* pNetworkReply */) {}
    106125
    107126private:
     
    112131    QUrl m_source;
    113132    QString m_strTarget;
     133    QString m_strPathSHA256SumsFile;
    114134};
    115135
  • trunk/src/VBox/Frontends/VirtualBox/src/net/UIDownloaderAdditions.cpp

    r62493 r65268  
    3434#endif /* !VBOX_WITH_PRECOMPILED_HEADERS */
    3535
     36#include <iprt/sha.h>
     37
    3638
    3739/* static */
     
    8183
    8284    /* Prepare source/target: */
    83     const QString &strName = QString("VBoxGuestAdditions_%1.iso").arg(strVersion);
    84     const QString &strSource = QString("http://download.virtualbox.org/virtualbox/%1/").arg(strVersion) + strName;
    85     const QString &strTarget = QDir(vboxGlobal().homeFolder()).absoluteFilePath(strName);
     85    const QString strSourceName = QString("VBoxGuestAdditions_%1.iso").arg(strVersion);
     86    const QString strSourceFolder = QString("http://download.virtualbox.org/virtualbox/%1/").arg(strVersion);
     87    const QString strSource = strSourceFolder + strSourceName;
     88    const QString strPathSHA256SumsFile = QString("https://www.virtualbox.org/download/hashes/%1/SHA256SUMS").arg(strVersion);
     89    const QString strTarget = QDir(vboxGlobal().homeFolder()).absoluteFilePath(strSourceName);
    8690
    8791    /* Set source/target: */
    8892    setSource(strSource);
    8993    setTarget(strTarget);
     94    setPathSHA256SumsFile(strPathSHA256SumsFile);
    9095}
    9196
     
    111116{
    112117    /* Read received data into the buffer: */
    113     QByteArray receivedData(pReply->readAll());
     118    m_receivedData = pReply->readAll();
     119}
     120
     121void UIDownloaderAdditions::handleVerifiedObject(UINetworkReply *pReply)
     122{
     123    /* Try to verify the SHA-256 checksum: */
     124    bool fSuccess = false;
     125    do
     126    {
     127        /* Read received data into the buffer: */
     128        const QByteArray receivedData(pReply->readAll());
     129        /* Make sure it's not empty: */
     130        if (receivedData.isEmpty())
     131            break;
     132
     133        /* Parse buffer contents to dictionary: */
     134        const QStringList dictionary(QString(receivedData).split("\n", QString::SkipEmptyParts));
     135        /* Make sure it's not empty: */
     136        if (dictionary.isEmpty())
     137            break;
     138
     139        /* Parse each record to tags, look for the required one: */
     140        foreach (const QString &strRecord, dictionary)
     141        {
     142            const QString strFileName = strRecord.section(" *", 1);
     143            const QString strDownloadedSumm = strRecord.section(" *", 0, 0);
     144            if (strFileName == QFileInfo(source().toString()).fileName())
     145            {
     146                /* Calculate the SHA-256 on the bytes, creating a string: */
     147                uint8_t abHash[RTSHA256_HASH_SIZE];
     148                RTSha256(m_receivedData.constData(), m_receivedData.length(), abHash);
     149                char szDigest[RTSHA256_DIGEST_LEN + 1];
     150                int rc = RTSha256ToString(abHash, szDigest, sizeof(szDigest));
     151                if (RT_FAILURE(rc))
     152                {
     153                    AssertRC(rc);
     154                    szDigest[0] = '\0';
     155                }
     156
     157                const QString strCalculatedSumm(szDigest);
     158                // printf("Downloaded SHA-256 summ: [%s]\n", strDownloadedSumm.toUtf8().constData());
     159                // printf("Calculated SHA-256 summ: [%s]\n", strCalculatedSumm.toUtf8().constData());
     160                /* Make sure checksum is valid: */
     161                fSuccess = strDownloadedSumm == strCalculatedSumm;
     162                break;
     163            }
     164        }
     165    }
     166    while (false);
     167
     168    /* If SHA-256 checksum verification failed: */
     169    if (!fSuccess)
     170    {
     171        /* Warn the user about additions-image was downloaded and saved but checksum is invalid: */
     172        msgCenter().cannotValidateGuestAdditionsSHA256Sum(source().toString(), QDir::toNativeSeparators(target()));
     173        return;
     174    }
     175
    114176    /* Serialize that buffer into the file: */
    115177    while (true)
     
    120182        {
    121183            /* Write buffer into the file: */
    122             file.write(receivedData);
     184            file.write(m_receivedData);
    123185            file.close();
    124186
  • trunk/src/VBox/Frontends/VirtualBox/src/net/UIDownloaderAdditions.h

    r62493 r65268  
    5050    bool askForDownloadingConfirmation(UINetworkReply *pReply);
    5151    void handleDownloadedObject(UINetworkReply *pReply);
     52    void handleVerifiedObject(UINetworkReply *pReply);
    5253
    5354    /* Variables: */
    5455    static UIDownloaderAdditions *m_spInstance;
     56    QByteArray m_receivedData;
    5557};
    5658
  • trunk/src/VBox/Frontends/VirtualBox/src/net/UIDownloaderExtensionPack.cpp

    r62493 r65268  
    6161
    6262    /* Prepare source/target: */
     63    QString strVersion = vboxGlobal().vboxVersionStringNormalized();
    6364    QString strExtPackUnderscoredName(QString(GUI_ExtPackName).replace(' ', '_'));
    6465    QString strTemplateSourcePath("http://download.virtualbox.org/virtualbox/%1/");
    6566    QString strTemplateSourceName(QString("%1-%2.vbox-extpack").arg(strExtPackUnderscoredName));
    66     QString strSourcePath(strTemplateSourcePath.arg(vboxGlobal().vboxVersionStringNormalized()));
    67     QString strSourceName(strTemplateSourceName.arg(vboxGlobal().vboxVersionStringNormalized()));
     67    QString strSourcePath(strTemplateSourcePath.arg(strVersion));
     68    QString strSourceName(strTemplateSourceName.arg(strVersion));
    6869    QString strSource(strSourcePath + strSourceName);
     70    QString strPathSHA256SumsFile = QString("https://www.virtualbox.org/download/hashes/%1/SHA256SUMS").arg(strVersion);
    6971    QString strTargetPath(vboxGlobal().homeFolder());
    7072    QString strTargetName(strSourceName);
     
    7476    setSource(strSource);
    7577    setTarget(strTarget);
     78    setPathSHA256SumsFile(strPathSHA256SumsFile);
    7679}
    7780
     
    97100{
    98101    /* Read received data into the buffer: */
    99     QByteArray receivedData(pReply->readAll());
     102    m_receivedData = pReply->readAll();
     103}
     104
     105void UIDownloaderExtensionPack::handleVerifiedObject(UINetworkReply *pReply)
     106{
     107    /* Try to verify the SHA-256 checksum: */
     108    bool fSuccess = false;
     109    do
     110    {
     111        /* Read received data into the buffer: */
     112        const QByteArray receivedData(pReply->readAll());
     113        /* Make sure it's not empty: */
     114        if (receivedData.isEmpty())
     115            break;
     116
     117        /* Parse buffer contents to dictionary: */
     118        const QStringList dictionary(QString(receivedData).split("\n", QString::SkipEmptyParts));
     119        /* Make sure it's not empty: */
     120        if (dictionary.isEmpty())
     121            break;
     122
     123        /* Parse each record to tags, look for the required one: */
     124        foreach (const QString &strRecord, dictionary)
     125        {
     126            const QString strFileName = strRecord.section(" *", 1);
     127            const QString strDownloadedSumm = strRecord.section(" *", 0, 0);
     128            if (strFileName == QFileInfo(source().toString()).fileName())
     129            {
     130                /* Calculate the SHA-256 on the bytes, creating a string: */
     131                uint8_t abHash[RTSHA256_HASH_SIZE];
     132                RTSha256(m_receivedData.constData(), m_receivedData.length(), abHash);
     133                char szDigest[RTSHA256_DIGEST_LEN + 1];
     134                int rc = RTSha256ToString(abHash, szDigest, sizeof(szDigest));
     135                if (RT_FAILURE(rc))
     136                {
     137                    AssertRC(rc);
     138                    szDigest[0] = '\0';
     139                }
     140
     141                const QString strCalculatedSumm(szDigest);
     142                // printf("Downloaded SHA-256 summ: [%s]\n", strDownloadedSumm.toUtf8().constData());
     143                // printf("Calculated SHA-256 summ: [%s]\n", strCalculatedSumm.toUtf8().constData());
     144                /* Make sure checksum is valid: */
     145                fSuccess = strDownloadedSumm == strCalculatedSumm;
     146                break;
     147            }
     148        }
     149    }
     150    while (false);
     151
     152    /* If SHA-256 checksum verification failed: */
     153    if (!fSuccess)
     154    {
     155        /* Warn the user about additions-image was downloaded and saved but checksum is invalid: */
     156        msgCenter().cannotValidateExtentionPackSHA256Sum(GUI_ExtPackName, source().toString(), QDir::toNativeSeparators(target()));
     157        return;
     158    }
     159
    100160    /* Serialize that buffer into the file: */
    101161    while (true)
     
    106166        {
    107167            /* Write buffer into the file: */
    108             file.write(receivedData);
     168            file.write(m_receivedData);
    109169            file.close();
    110170
    111171            /* Calc the SHA-256 on the bytes, creating a string: */
    112172            uint8_t abHash[RTSHA256_HASH_SIZE];
    113             RTSha256(receivedData.constData(), receivedData.length(), abHash);
     173            RTSha256(m_receivedData.constData(), m_receivedData.length(), abHash);
    114174            char szDigest[RTSHA256_DIGEST_LEN + 1];
    115175            int rc = RTSha256ToString(abHash, szDigest, sizeof(szDigest));
  • trunk/src/VBox/Frontends/VirtualBox/src/net/UIDownloaderExtensionPack.h

    r62493 r65268  
    5050    bool askForDownloadingConfirmation(UINetworkReply *pReply);
    5151    void handleDownloadedObject(UINetworkReply *pReply);
     52    void handleVerifiedObject(UINetworkReply *pReply);
    5253
    5354    /* Variables: */
    5455    static UIDownloaderExtensionPack *m_spInstance;
     56    QByteArray m_receivedData;
    5557};
    5658
  • trunk/src/VBox/Frontends/VirtualBox/src/net/UIUpdateManager.cpp

    r64772 r65268  
    5656
    5757
    58 #if 0
    5958/* enable to test the version update check */
    60 #define VBOX_NEW_VERSION_TEST "0.0.0_0 http://unknown.unknown.org/0.0.0/VirtualBox-0.0.0-0-unknown.pkg"
    61 #endif
     59//#define VBOX_NEW_VERSION_TEST "5.1.12_0 http://unknown.unknown.org/0.0.0/VirtualBox-0.0.0-0-unknown.pkg"
    6260
    6361/* Forward declarations: */
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