VirtualBox

Changeset 78066 in vbox


Ignore:
Timestamp:
Apr 9, 2019 4:02:32 PM (5 years ago)
Author:
vboxsync
Message:

IPRT,GUI: Workaround for certificate downloads getting redirected to https.

Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/iprt/http.h

    r76585 r78066  
    319319
    320320/**
     321 * Gets the follow redirect setting.
     322 *
     323 * @returns cMaxRedirects value, 0 means not to follow.
     324 * @param   hHttp           The HTTP client handle.
     325 */
     326RTR3DECL(uint32_t) RTHttpGetFollowRedirects(RTHTTP hHttp);
     327
     328/**
    321329 * Set custom raw headers.
    322330 *
     
    468476 */
    469477RTR3DECL(int) RTHttpGatherCaCertsInFile(const char *pszCaFile, uint32_t fFlags, PRTERRINFO pErrInfo);
     478
     479/**
     480 * Set whether to verify the peer's SSL certificate.
     481 *
     482 * The default is to verify it.  It can however sometimes be useful or even
     483 * necessary to skip this.
     484 *
     485 * @returns iprt status code.
     486 *
     487 * @param   hHttp           The HTTP client handle.
     488 * @param   fVerify         Verify the certificate if @a true.
     489 */
     490RTR3DECL(int) RTHttpSetVerifyPeer(RTHTTP hHttp, bool fVerify);
     491
     492/**
     493 * Get the state of the peer's SSL certificate setting.
     494 *
     495 * @returns  true if we verify the SSL certificate, false if not.
     496 * @param   hHttp           The HTTP client handle.
     497 */
     498RTR3DECL(bool) RTHttpGetVerifyPeer(RTHTTP hHttp);
    470499
    471500/**
  • trunk/include/iprt/mangling.h

    r78048 r78066  
    11311131# define RTHeapSimpleSize                               RT_MANGLER(RTHeapSimpleSize)
    11321132# define RTHttpGetFile                                  RT_MANGLER(RTHttpGetFile)
     1133# define RTHttpGetFollowRedirects                       RT_MANGLER(RTHttpGetFollowRedirects)
    11331134# define RTHttpSetFollowRedirects                       RT_MANGLER(RTHttpSetFollowRedirects)
     1135# define RTHttpGetVerifyPeer                            RT_MANGLER(RTHttpGetVerifyPeer)
     1136# define RTHttpSetVerifyPeer                            RT_MANGLER(RTHttpSetVerifyPeer)
    11341137# define RTHttpUseSystemProxySettings                   RT_MANGLER(RTHttpUseSystemProxySettings)
    11351138# define RTIniFileCreateFromVfsFile                     RT_MANGLER(RTIniFileCreateFromVfsFile)
  • trunk/src/VBox/Frontends/VirtualBox/src/net/UINetworkReply.cpp

    r76606 r78066  
    777777    NOREF(pStaticErrInfo);
    778778    int rc;
     779
     780    /*
     781     * Must disable SSL certification verification here as we cannot use the
     782     * SSL certificates before we've downloaded them.   We must also enable
     783     * redirections in case the certificates moves around.
     784     */
     785    bool const     fSavedVerifyPeer   = RTHttpGetVerifyPeer(hHttp);
     786    uint32_t const cSavedMaxRedirects = RTHttpGetFollowRedirects(hHttp);
     787    RTHttpSetVerifyPeer(hHttp, false);
     788    RTHttpSetFollowRedirects(hHttp, 8);
    779789
    780790    /*
     
    810820                                {
    811821                                    RTHttpFreeResponse(pvRootsZip);
     822                                    RTHttpSetVerifyPeer(hHttp, fSavedVerifyPeer);
     823                                    RTHttpSetFollowRedirects(hHttp, cSavedMaxRedirects);
    812824                                    return;
    813825                                }
     
    845857                }
    846858        }
     859
     860    RTHttpSetVerifyPeer(hHttp, fSavedVerifyPeer);
     861    RTHttpSetFollowRedirects(hHttp, cSavedMaxRedirects);
    847862}
    848863
  • trunk/src/VBox/Frontends/VirtualBox/src/net/tstSSLCertDownloads.cpp

    r76553 r78066  
    5757    int rc;
    5858
     59    bool const     fSavedVerifyPeer   = RTHttpGetVerifyPeer(TestObj.m_hHttp);
     60    uint32_t const cSavedMaxRedirects = RTHttpGetFollowRedirects(TestObj.m_hHttp);
     61    RTTESTI_CHECK_RC(RTHttpSetVerifyPeer(TestObj.m_hHttp, false), VINF_SUCCESS);
     62    RTTESTI_CHECK_RC(RTHttpSetFollowRedirects(TestObj.m_hHttp, 8), VINF_SUCCESS);
     63    RTTESTI_CHECK(RTHttpGetVerifyPeer(TestObj.m_hHttp) == false);
     64    RTTESTI_CHECK(RTHttpGetFollowRedirects(TestObj.m_hHttp) == 8);
     65
    5966    /* ZIP files: */
    6067    for (uint32_t iUrl = 0; iUrl < RT_ELEMENTS(s_apszRootsZipUrls); iUrl++)
     
    113120    RTTESTI_CHECK(RTCrStoreRelease(hStore) == 0);
    114121
     122    RTTESTI_CHECK_RC(RTHttpSetVerifyPeer(TestObj.m_hHttp, fSavedVerifyPeer), VINF_SUCCESS);
     123    RTTESTI_CHECK_RC(RTHttpSetFollowRedirects(TestObj.m_hHttp, cSavedMaxRedirects), VINF_SUCCESS);
     124
    115125    /*
    116126     * Now check the gathering of certificates on the system doesn't crash.
  • trunk/src/VBox/Runtime/generic/http-curl.cpp

    r76553 r78066  
    188188     * Zero if not automatically following (default). */
    189189    uint32_t            cMaxRedirects;
     190    /** Whether to check if Peer lies about his SSL certificate. */
     191    bool                fVerifyPeer;
    190192    /** @} */
    191193
     
    384386                pThis->fUseSystemProxySettings  = true;
    385387                pThis->cMaxRedirects            = 0; /* no automatic redir following */
     388                pThis->fVerifyPeer              = true;
    386389                pThis->BodyOutput.pHttp         = pThis;
    387390                pThis->HeadersOutput.pHttp      = pThis;
     
    418421    curl_easy_reset(pThis->pCurl);
    419422
     423    /** @todo check if CURLOPT_SSL_VERIFYPEER is affected by curl_easy_reset. */
     424
    420425    if (!(fFlags & RTHTTP_RESET_F_KEEP_HEADERS))
    421426        rtHttpFreeHeaders(pThis);
     
    523528    }
    524529    return VINF_SUCCESS;
     530}
     531
     532
     533RTR3DECL(uint32_t) RTHttpGetFollowRedirects(RTHTTP hHttp)
     534{
     535    PRTHTTPINTERNAL pThis = hHttp;
     536    RTHTTP_VALID_RETURN_RC(pThis, 0);
     537    return pThis->cMaxRedirects;
    525538}
    526539
     
    26152628    RT_NOREF_PV(fFlags);
    26162629
    2617 
    26182630    /*
    26192631     * Add the user store, quitely ignoring any errors.
     
    26712683    }
    26722684    return rc;
     2685}
     2686
     2687
     2688RTR3DECL(bool) RTHttpGetVerifyPeer(RTHTTP hHttp)
     2689{
     2690    PRTHTTPINTERNAL pThis = hHttp;
     2691    RTHTTP_VALID_RETURN_RC(pThis, false);
     2692    return pThis->fVerifyPeer;
     2693}
     2694
     2695
     2696RTR3DECL(int) RTHttpSetVerifyPeer(RTHTTP hHttp, bool fVerify)
     2697{
     2698    PRTHTTPINTERNAL pThis = hHttp;
     2699    RTHTTP_VALID_RETURN(pThis);
     2700    AssertReturn(!pThis->fBusy, VERR_WRONG_ORDER);
     2701
     2702    if (pThis->fVerifyPeer != fVerify)
     2703    {
     2704        int rcCurl = curl_easy_setopt(pThis->pCurl, CURLOPT_SSL_VERIFYPEER, (long)fVerify);
     2705        AssertMsgReturn(rcCurl == CURLE_OK, ("CURLOPT_SSL_VERIFYPEER=%RTbool: %d (%#x)\n", fVerify, rcCurl, rcCurl),
     2706                        VERR_HTTP_CURL_ERROR);
     2707        pThis->fVerifyPeer = fVerify;
     2708    }
     2709
     2710    return VINF_SUCCESS;
    26732711}
    26742712
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