Using <urlmon.h> and URLDownloadToFile to get HTTPS Web Resources

5.6k Views Asked by At

I am making a program that will be able to download content from various websites on and off of my local network.To do this, I must use the <urlmon.h> libs and C++ for compatibility reasons. So far I have been able to successfully access a normal HTTP page, and an HTTPS page on the web. Example:

 HRESULT res = URLDownloadToFile( NULL,
          LPCTSTR(CString("https://www.google.com/")),
          LPCTSTR(CString("websitecontent.txt")),
          0,
          NULL);

There are two things I am unable to do:

  1. Access a local network resource that uses a local CA cert.

  2. Access a local network resource that uses a local CA cert and requests client authentication via client certificate.

In the first case I think that windows is disallowing the connection because it is not on a windows list of trusted CA's.

In the second I think I need to figure out a way to integrate a client cert/private key into the call to URLDownloadToFile but I don't know how to accomplish this. In addition, I would also have to tell windows to trust the local CA.

1

There are 1 best solutions below

1
On

just call CoInternetSetFeatureEnabled(FEATURE_SSLUX, SET_FEATURE_ON_PROCESS, TRUE) before URLDownloadToFile