VirtualBox

Ignore:
Timestamp:
Jun 26, 2014 9:28:58 AM (10 years ago)
Author:
vboxsync
Message:

FE/Qt: 7418: Network Manager: Save SSL certificates only if both downloaded/verified.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/net/UINetworkReply.cpp

    r51733 r51734  
    7777    static int checkCertificates(RTHTTP pHttp, const QString &strFullCertificateFileName);
    7878    static int downloadCertificates(RTHTTP pHttp, const QString &strFullCertificateFileName);
    79     static int downloadCertificatePca3G5(RTHTTP pHttp, QFile &file);
    80     static int downloadCertificatePca3(RTHTTP pHttp, QFile &file);
     79    static int downloadCertificatePca3G5(RTHTTP pHttp, QByteArray &certificate);
     80    static int downloadCertificatePca3(RTHTTP pHttp, QByteArray &certificate);
    8181    static int verifyCertificatePca3G5(RTHTTP pHttp, QByteArray &certificate);
    8282    static int verifyCertificatePca3(RTHTTP pHttp, QByteArray &certificate);
    8383    static int verifyCertificate(RTHTTP pHttp, QByteArray &certificate, const QByteArray &sha1, const QByteArray &sha512);
     84    static int saveCertificates(const QString &strFullCertificateFileName, const QByteArray &certificatePca3G5, const QByteArray &certificatePca3);
    8485    static int saveCertificate(QFile &file, const QByteArray &certificate);
    8586
     
    356357int UINetworkReplyPrivateThread::downloadCertificates(RTHTTP pHttp, const QString &strFullCertificateFileName)
    357358{
    358     /* Open certificates file: */
    359     QFile file(strFullCertificateFileName);
    360     bool fFileOpened = file.open(QIODevice::WriteOnly);
    361     int rc = fFileOpened ? VINF_SUCCESS : VERR_OPEN_FAILED;
     359    /* Prepare certificates: */
     360    QByteArray certificatePca3G5;
     361    QByteArray certificatePca3;
     362    /* Prepare result: */
     363    int rc = VINF_SUCCESS;
    362364
    363365    /* Download PCA-3G5 certificate: */
    364366    if (RT_SUCCESS(rc))
    365         rc = downloadCertificatePca3G5(pHttp, file);
     367        rc = downloadCertificatePca3G5(pHttp, certificatePca3G5);
    366368    /* Download PCA-3 certificate: */
    367369    if (RT_SUCCESS(rc))
    368         rc = downloadCertificatePca3(pHttp, file);
    369 
    370     /* Close certificates file: */
    371     if (fFileOpened)
    372         file.close();
     370        rc = downloadCertificatePca3(pHttp, certificatePca3);
     371
     372    /* Save certificates: */
     373    if (RT_SUCCESS(rc))
     374        saveCertificates(strFullCertificateFileName, certificatePca3G5, certificatePca3);
    373375
    374376    /* Return result-code: */
     
    377379
    378380/* static */
    379 int UINetworkReplyPrivateThread::downloadCertificatePca3G5(RTHTTP pHttp, QFile &file)
     381int UINetworkReplyPrivateThread::downloadCertificatePca3G5(RTHTTP pHttp, QByteArray &certificate)
    380382{
    381383    /* Receive certificate: */
    382     QByteArray certificate;
    383384    const QNetworkRequest address(QUrl("http://www.verisign.com/repository/roots/root-certificates/PCA-3G5.pem"));
    384385    int rc = performGetRequestForText(pHttp, address, certificate);
     
    388389        rc = verifyCertificatePca3G5(pHttp, certificate);
    389390
    390     /* Save certificate: */
    391     if (RT_SUCCESS(rc))
    392         rc = saveCertificate(file, certificate);
    393 
    394391    /* Return result-code: */
    395392    return rc;
     
    397394
    398395/* static */
    399 int UINetworkReplyPrivateThread::downloadCertificatePca3(RTHTTP pHttp, QFile &file)
     396int UINetworkReplyPrivateThread::downloadCertificatePca3(RTHTTP pHttp, QByteArray &certificate)
    400397{
    401398    /* Receive certificate: */
    402     QByteArray certificate;
    403399    const QNetworkRequest address(QUrl("http://www.verisign.com/repository/roots/root-certificates/PCA-3.pem"));
    404400    int rc = performGetRequestForText(pHttp, address, certificate);
     
    407403    if (RT_SUCCESS(rc))
    408404        rc = verifyCertificatePca3(pHttp, certificate);
    409 
    410     /* Save certificate: */
    411     if (RT_SUCCESS(rc))
    412         rc = saveCertificate(file, certificate);
    413405
    414406    /* Return result-code: */
     
    500492    RTMemFree(abSha1);
    501493    RTMemFree(abSha512);
     494
     495    /* Return result-code: */
     496    return rc;
     497}
     498
     499/* static */
     500int UINetworkReplyPrivateThread::saveCertificates(const QString &strFullCertificateFileName,
     501                                                  const QByteArray &certificatePca3G5,
     502                                                  const QByteArray &certificatePca3)
     503{
     504    /* Open certificates file: */
     505    QFile file(strFullCertificateFileName);
     506    bool fFileOpened = file.open(QIODevice::WriteOnly);
     507    int rc = fFileOpened ? VINF_SUCCESS : VERR_OPEN_FAILED;
     508
     509    /* Save certificates: */
     510    if (RT_SUCCESS(rc))
     511        rc = saveCertificate(file, certificatePca3G5);
     512    if (RT_SUCCESS(rc))
     513        rc = saveCertificate(file, certificatePca3);
     514
     515    /* Close certificates file: */
     516    if (fFileOpened)
     517        file.close();
    502518
    503519    /* Return result-code: */
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