VirtualBox

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

FE/Qt: 7418: Network Manager: Alternative way to get SSL certificate (from downloaded .zip package).

File:
1 edited

Legend:

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

    r51734 r51736  
    3434#include <iprt/http.h>
    3535#include <iprt/err.h>
     36#include <iprt/zip.h>
    3637
    3738/* Our network-reply thread: */
     
    7677    static int performGetRequestForBinary(RTHTTP pHttp, const QNetworkRequest &request, QByteArray &reply);
    7778    static int checkCertificates(RTHTTP pHttp, const QString &strFullCertificateFileName);
     79    static int decompressCertificate(const QByteArray &package, QByteArray &certificate, const QString &strName);
    7880    static int downloadCertificates(RTHTTP pHttp, const QString &strFullCertificateFileName);
    7981    static int downloadCertificatePca3G5(RTHTTP pHttp, QByteArray &certificate);
     
    355357
    356358/* static */
     359int UINetworkReplyPrivateThread::decompressCertificate(const QByteArray &package, QByteArray &certificate, const QString &strName)
     360{
     361    /* Decompress certificate: */
     362    void *pDecompressedBuffer;
     363    size_t cDecompressedSize;
     364    int rc = RTZipPkzipMemDecompress(&pDecompressedBuffer, &cDecompressedSize, package, package.size(), strName.toLatin1().constData());
     365    if (RT_SUCCESS(rc))
     366    {
     367        /* Copy certificate: */
     368        certificate = QByteArray((const char*)pDecompressedBuffer, (int)cDecompressedSize);
     369        /* Free decompressed buffer: */
     370        RTMemFree(pDecompressedBuffer);
     371    }
     372    /* Return result: */
     373    return rc;
     374}
     375
     376/* static */
    357377int UINetworkReplyPrivateThread::downloadCertificates(RTHTTP pHttp, const QString &strFullCertificateFileName)
    358378{
     
    360380    QByteArray certificatePca3G5;
    361381    QByteArray certificatePca3;
    362     /* Prepare result: */
    363     int rc = VINF_SUCCESS;
    364 
    365     /* Download PCA-3G5 certificate: */
    366     if (RT_SUCCESS(rc))
    367         rc = downloadCertificatePca3G5(pHttp, certificatePca3G5);
    368     /* Download PCA-3 certificate: */
    369     if (RT_SUCCESS(rc))
    370         rc = downloadCertificatePca3(pHttp, certificatePca3);
     382
     383    /* Receive certificate package: */
     384    QByteArray package;
     385    const QNetworkRequest address(QUrl("http://www.verisign.com/support/roots.zip"));
     386    int rc = performGetRequestForBinary(pHttp, address, package);
     387    /* UnZIP PCA-3G5 certificate: */
     388    if (RT_SUCCESS(rc))
     389    {
     390        rc = decompressCertificate(package, certificatePca3G5,
     391                                   "VeriSign Root Certificates/Generation 5 (G5) PCA/VeriSign Class 3 Public Primary Certification Authority - G5.pem");
     392        /* Verify PCA-3G5 certificate: */
     393        if (RT_SUCCESS(rc))
     394            rc = verifyCertificatePca3G5(pHttp, certificatePca3G5);
     395    }
     396    /* UnZIP PCA-3 certificate: */
     397    if (RT_SUCCESS(rc))
     398    {
     399        rc = decompressCertificate(package, certificatePca3,
     400                                   "VeriSign Root Certificates/Generation 1 (G1) PCAs/Class 3 Public Primary Certification Authority.pem");
     401        /* Verify PCA-3 certificate: */
     402        if (RT_SUCCESS(rc))
     403            rc = verifyCertificatePca3(pHttp, certificatePca3);
     404    }
     405
     406    /* Fallback.. download certificates separately: */
     407    if (!RT_SUCCESS(rc))
     408    {
     409        /* Reset result: */
     410        rc = VINF_SUCCESS;
     411        /* Download PCA-3G5 certificate: */
     412        if (RT_SUCCESS(rc))
     413            rc = downloadCertificatePca3G5(pHttp, certificatePca3G5);
     414        /* Download PCA-3 certificate: */
     415        if (RT_SUCCESS(rc))
     416            rc = downloadCertificatePca3(pHttp, certificatePca3);
     417    }
    371418
    372419    /* Save certificates: */
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