VirtualBox

Changeset 84375 in vbox


Ignore:
Timestamp:
May 19, 2020 5:00:03 PM (5 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
138070
Message:

FE/Qt: Kicked out the long obsolete root.zip download code.

Location:
trunk/src/VBox/Frontends/VirtualBox
Files:
1 deleted
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/Makefile.kmk

    r84020 r84375  
    18981898
    18991899#
    1900 # Testcase for SSL certificate downloading.
    1901 #
    1902 if defined(VBOX_WITH_TESTCASES) && defined(VBOX_GUI_WITH_NETWORK_MANAGER)
    1903  PROGRAMS += tstSSLCertDownloads
    1904  tstSSLCertDownloads_TEMPLATE   = VBOXQTGUIEXE
    1905  tstSSLCertDownloads_USES       = qt5
    1906  tstSSLCertDownloads_QTTOOL     = QT5
    1907  tstSSLCertDownloads_QT_MODULES = Core Gui
    1908  tstSSLCertDownloads_DEFS = VBOX_GUI_IN_TST_SSL_CERT_DOWNLOADS
    1909  tstSSLCertDownloads_INCS = \
    1910         $(VBOX_GUI_INC_DIRS)
    1911  tstSSLCertDownloads_SOURCES = \
    1912         src/net/tstSSLCertDownloads.cpp
    1913 endif
    1914 
    1915 
    1916 #
    19171900# Doxygen documentation.
    19181901#
  • trunk/src/VBox/Frontends/VirtualBox/src/net/UINetworkReply.cpp

    r83801 r84375  
    134134
    135135        /** Refreshes the certificates.
    136           * @param  hHttp          Brings the HTTP client instance. (Can be NIL when running the testcase.)
    137136          * @param  phStore        On input, this holds the current store, so that we can fish out wanted
    138137          *                        certificates from it. On successful return, this is replaced with a new
     
    143142          * @param  pszCaCertFile  Where to write the refreshed certificates if we've managed to gather
    144143          *                        a collection that is at least as good as the old one. */
    145         static int refreshCertificates(RTHTTP hHttp, PRTCRSTORE phStore, bool *pafFoundCerts, const char *pszCaCertFile);
    146 
    147         /** Downloads missing certificates.
    148           * @param  hNewStore         On successful return, this store will contain newly downloaded certificates.
    149           * @param  pafNewFoundCerts  On successful return, this array parallel to s_aCerts will contain the
    150           *                           status of each newly downloaded certificate.
    151           * @param  hHttp             Brings the HTTP client instance.
    152           * @param  pStaticErrInfo    Unused currently. */
    153         static void downloadMissingCertificates(RTCRSTORE hNewStore, bool *pafNewFoundCerts, RTHTTP hHttp,
    154                                                 PRTERRINFOSTATIC pStaticErrInfo);
    155 
    156         /** Converts a PEM certificate, verifies it against @a pCertInfo and adds it to the given store.
    157           * @param  hStore       The store to add certificate to.
    158           * @param  pvResponse   The raw PEM certificate file bytes.
    159           * @param  cbResponse   The number of bytes.
    160           * @param  pWantedCert  The certificate info (we use hashes and encoded size). */
    161         static int convertVerifyAndAddPemCertificateToStore(RTCRSTORE hStore, void const *pvResponse,
    162                                                             size_t cbResponse, PCRTCRCERTWANTED pWantedCert);
     144        static int refreshCertificates(PRTCRSTORE phStore, bool *pafFoundCerts, const char *pszCaCertFile);
    163145
    164146        /** Redirects download progress callback to particular object which can handle it.
     
    170152        static DECLCALLBACK(void) handleProgressChange(RTHTTP hHttp, void *pvUser, uint64_t cbDownloadTotal, uint64_t cbDownloaded);
    171153    /** @} */
    172 
    173     /** Additinoal download nfo about wanted certificate. */
    174     typedef struct CERTINFO
    175     {
    176         /** Holds the filename of the zip file we download (PEM). */
    177         const char *pszZipFile;
    178         /** Lists direct URLs to PEM formatted files. */
    179         const char *apszUrls[4];
    180     } CERTINFO;
    181154
    182155    /** Holds the request type. */
     
    200173    UserDictionary m_headers;
    201174
    202     /** Holds the URLs to root zip files containing certificates we want. */
    203     static const char * const s_apszRootsZipUrls[];
    204     /** Holds the download details. */
    205     static const CERTINFO s_CertInfoPcaCls3Gen5;
    206     /** Holds the details on the certificates we are after.
    207       * The pvUser member points to a UINetworkReplyPrivateThread::CERTINFO. */
     175    /** Holds the details on the certificates we are after. */
    208176    static const RTCRCERTWANTED s_aCerts[];
    209177    /** Holds the certificate file name (no path). */
     
    280248*   Class UINetworkReplyPrivateThread implementation.                                                                            *
    281249*********************************************************************************************************************************/
    282 
    283 /* static */
    284 const char * const UINetworkReplyPrivateThread::s_apszRootsZipUrls[] =
    285 {
    286     "http://www.symantec.com/content/en/us/enterprise/verisign/roots/roots.zip"
    287 };
    288 
    289 /* static */
    290 const UINetworkReplyPrivateThread::CERTINFO UINetworkReplyPrivateThread::s_CertInfoPcaCls3Gen5 =
    291 {
    292     /*.pszZipFile     =*/
    293     "VeriSign Root Certificates/Generation 5 (G5) PCA/VeriSign Class 3 Public Primary Certification Authority - G5.pem",
    294     /*.apszUrls[]     =*/
    295     {
    296         "http://www.symantec.com/content/en/us/enterprise/verisign/roots/VeriSign-Class%203-Public-Primary-Certification-Authority-G5.pem",
    297         "http://www.symantec.com/content/en/us/enterprise/verisign/roots/VeriSign-Class-3-Public-Primary-Certification-Authority-G5.pem", /* (in case they correct above typo) */
    298         "http://www.verisign.com/repository/roots/root-certificates/PCA-3G5.pem", /* dead */
    299         NULL,
    300     }
    301 };
    302250
    303251/* static */
     
    328276            0xd2, 0x6b, 0xa8, 0x9a, 0xf0, 0xb3, 0x6a, 0x01
    329277        },
    330         /*.pvUser */ &UINetworkReplyPrivateThread::s_CertInfoPcaCls3Gen5
     278        /*.pvUser            =*/ NULL,
    331279    },
    332280};
     
    470418         */
    471419        if (fRefresh)
    472             refreshCertificates(m_hHttp, &hCurStore, afCertsFound, pszCaCertFile);
     420            refreshCertificates(&hCurStore, afCertsFound, pszCaCertFile);
    473421
    474422        RTCrStoreRelease(hCurStore);
     
    696644
    697645/* static */
    698 int UINetworkReplyPrivateThread::refreshCertificates(RTHTTP hHttp, PRTCRSTORE phStore, bool *pafFoundCerts,
    699                                                      const char *pszCaCertFile)
     646int UINetworkReplyPrivateThread::refreshCertificates(PRTCRSTORE phStore, bool *pafFoundCerts, const char *pszCaCertFile)
    700647{
    701648    /*
     
    753700
    754701            /*
    755              * If that didn't help, try download the certificates.
    756              */
    757             if (rc != VINF_SUCCESS && hHttp != NIL_RTHTTP)
    758                 downloadMissingCertificates(hNewStore, afNewFoundCerts, hHttp, &StaticErrInfo);
    759 
    760             /*
    761702             * If we've got the same or better hit rate than the old store,
    762703             * replace the CA certs file.
     
    792733
    793734/* static */
    794 void UINetworkReplyPrivateThread::downloadMissingCertificates(RTCRSTORE hNewStore, bool *pafNewFoundCerts, RTHTTP hHttp,
    795                                                               PRTERRINFOSTATIC pStaticErrInfo)
    796 {
    797     NOREF(pStaticErrInfo);
    798     int rc;
    799 
    800     /*
    801      * Must disable SSL certification verification here as we cannot use the
    802      * SSL certificates before we've downloaded them.   We must also enable
    803      * redirections in case the certificates moves around.
    804      */
    805     bool const     fSavedVerifyPeer   = RTHttpGetVerifyPeer(hHttp);
    806     uint32_t const cSavedMaxRedirects = RTHttpGetFollowRedirects(hHttp);
    807     RTHttpSetVerifyPeer(hHttp, false);
    808     RTHttpSetFollowRedirects(hHttp, 8);
    809 
    810     /*
    811      * Try get the roots.zip from symantec (or virtualbox.org) first.
    812      */
    813     for (uint32_t iUrl = 0; iUrl < RT_ELEMENTS(s_apszRootsZipUrls); iUrl++)
    814     {
    815         void   *pvRootsZip;
    816         size_t  cbRootsZip;
    817         rc = RTHttpGetBinary(hHttp, s_apszRootsZipUrls[iUrl], &pvRootsZip, &cbRootsZip);
    818         if (RT_SUCCESS(rc))
    819         {
    820             for (uint32_t i = 0; i < RT_ELEMENTS(s_aCerts); i++)
    821                 if (!pafNewFoundCerts[i])
    822                 {
    823                     CERTINFO const *pInfo = (CERTINFO const *)s_aCerts[i].pvUser;
    824                     if (pInfo->pszZipFile)
    825                     {
    826                         void  *pvFile;
    827                         size_t cbFile;
    828                         rc = RTZipPkzipMemDecompress(&pvFile, &cbFile, pvRootsZip, cbRootsZip, pInfo->pszZipFile);
    829                         if (RT_SUCCESS(rc))
    830                         {
    831                             rc = convertVerifyAndAddPemCertificateToStore(hNewStore, pvFile, cbFile, &s_aCerts[i]);
    832                             RTMemFree(pvFile);
    833                             if (RT_SUCCESS(rc))
    834                             {
    835                                 /*
    836                                  * Successfully added. Mark it as found and return if we've got them all.
    837                                  */
    838                                 pafNewFoundCerts[i] = true;
    839                                 if (areAllCertsFound(pafNewFoundCerts))
    840                                 {
    841                                     RTHttpFreeResponse(pvRootsZip);
    842                                     RTHttpSetVerifyPeer(hHttp, fSavedVerifyPeer);
    843                                     RTHttpSetFollowRedirects(hHttp, cSavedMaxRedirects);
    844                                     return;
    845                                 }
    846                             }
    847                         }
    848                     }
    849                 }
    850             RTHttpFreeResponse(pvRootsZip);
    851         }
    852     }
    853 
    854     /*
    855      * Try download certificates separately.
    856      */
    857     for (uint32_t i = 0; i < RT_ELEMENTS(s_aCerts); i++)
    858         if (!pafNewFoundCerts[i])
    859         {
    860             CERTINFO const *pInfo = (CERTINFO const *)s_aCerts[i].pvUser;
    861             for (uint32_t iUrl = 0; iUrl < RT_ELEMENTS(pInfo->apszUrls); iUrl++)
    862                 if (pInfo->apszUrls[iUrl])
    863                 {
    864                     void  *pvResponse;
    865                     size_t cbResponse;
    866                     rc = RTHttpGetBinary(hHttp, pInfo->apszUrls[iUrl], &pvResponse, &cbResponse);
    867                     if (RT_SUCCESS(rc))
    868                     {
    869                         rc = convertVerifyAndAddPemCertificateToStore(hNewStore, pvResponse, cbResponse, &s_aCerts[i]);
    870                         RTHttpFreeResponse(pvResponse);
    871                         if (RT_SUCCESS(rc))
    872                         {
    873                             pafNewFoundCerts[i] = true;
    874                             break;
    875                         }
    876                     }
    877                 }
    878         }
    879 
    880     RTHttpSetVerifyPeer(hHttp, fSavedVerifyPeer);
    881     RTHttpSetFollowRedirects(hHttp, cSavedMaxRedirects);
    882 }
    883 
    884 /* static */
    885 int UINetworkReplyPrivateThread::convertVerifyAndAddPemCertificateToStore(RTCRSTORE hStore,
    886                                                                           void const *pvResponse, size_t cbResponse,
    887                                                                           PCRTCRCERTWANTED pWantedCert)
    888 {
    889     /*
    890      * Convert the PEM certificate to its binary form so we can hash it.
    891      */
    892     static RTCRPEMMARKERWORD const s_aWords_Certificate[]  = { { RT_STR_TUPLE("CERTIFICATE") } };
    893     static RTCRPEMMARKER     const s_aCertificateMarkers[] = { { s_aWords_Certificate, RT_ELEMENTS(s_aWords_Certificate) }, };
    894     RTERRINFOSTATIC StaticErrInfo;
    895     PCRTCRPEMSECTION pSectionHead;
    896     int rc = RTCrPemParseContent(pvResponse, cbResponse, 0 /*fFlags*/,
    897                                  &s_aCertificateMarkers[0], RT_ELEMENTS(s_aCertificateMarkers),
    898                                  &pSectionHead, RTErrInfoInitStatic(&StaticErrInfo));
    899     if (RTErrInfoIsSet(&StaticErrInfo.Core))
    900         LogRel(("RTCrPemParseContent: %s\n", StaticErrInfo.Core.pszMsg));
    901     if (RT_SUCCESS(rc))
    902     {
    903         /*
    904          * Look at what we got back and hash it.
    905          */
    906         rc = VERR_NOT_FOUND;
    907         for (PCRTCRPEMSECTION pCur = pSectionHead; pCur; pCur = pCur->pNext)
    908             if (pCur->cbData == pWantedCert->cbEncoded)
    909             {
    910                 if (   RTSha1Check(pCur->pbData, pCur->cbData, pWantedCert->abSha1)
    911                     && RTSha512Check(pCur->pbData, pCur->cbData, pWantedCert->abSha512))
    912                 {
    913                     /*
    914                      * Matching, add it to the store.
    915                      */
    916                     rc = RTCrStoreCertAddEncoded(hStore,
    917                                                  RTCRCERTCTX_F_ENC_X509_DER | RTCRCERTCTX_F_ADD_IF_NOT_FOUND,
    918                                                  pCur->pbData, pCur->cbData,
    919                                                  RTErrInfoInitStatic(&StaticErrInfo));
    920                     if (RTErrInfoIsSet(&StaticErrInfo.Core))
    921                         LogRel(("RTCrStoreCertAddEncoded: %s\n", StaticErrInfo.Core.pszMsg));
    922                     else if (RT_FAILURE(rc))
    923                         LogRel(("RTCrStoreCertAddEncoded: %Rrc\n", rc));
    924                     if (RT_SUCCESS(rc))
    925                         break;
    926                 }
    927                 else
    928                     LogRel(("convertVerifyAndAddPemCertificateToStore: hash mismatch (cbData=%#zx)\n", pCur->cbData));
    929             }
    930             else
    931                 LogRel(("convertVerifyAndAddPemCertificateToStore: cbData=%#zx expected %#zx\n",
    932                         pCur->cbData, pWantedCert->cbEncoded));
    933 
    934         RTCrPemFreeSections(pSectionHead);
    935     }
    936     return rc;
    937 }
    938 
    939 /* static */
    940735DECLCALLBACK(void) UINetworkReplyPrivateThread::handleProgressChange(RTHTTP hHttp, void *pvUser, uint64_t cbDownloadTotal, uint64_t cbDownloaded)
    941736{
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