QString Downloader::inputPassword(HINTERNET hConnectHandle, DWORD dwStatus) { QString result; QString username, password; if (dwStatus == HTTP_STATUS_PROXY_AUTH_REQ) { WPMUtils::writeln("\r\n" + QObject::tr("The HTTP proxy requires authentication.")); WPMUtils::outputTextConsole(QObject::tr("Username") + ": "); username = WPMUtils::inputTextConsole(); WPMUtils::outputTextConsole(QObject::tr("Password") + ": "); password = WPMUtils::inputPasswordConsole(); if (!InternetSetOptionW(hConnectHandle, INTERNET_OPTION_PROXY_USERNAME, (void*) username.utf16(), username.length() + 1)) { WPMUtils::formatMessage(GetLastError(), &result); } if (result.isEmpty() && !InternetSetOptionW(hConnectHandle, INTERNET_OPTION_PROXY_PASSWORD, (void*) password.utf16(), password.length() + 1)) { WPMUtils::formatMessage(GetLastError(), &result); } } else if (dwStatus == HTTP_STATUS_DENIED) { WPMUtils::writeln("\r\n" + QObject::tr("The HTTP server requires authentication.") ); WPMUtils::outputTextConsole(QObject::tr("Username") + ": "); username = WPMUtils::inputTextConsole(); WPMUtils::outputTextConsole(QObject::tr("Password") + ": "); password = WPMUtils::inputPasswordConsole(); if (!InternetSetOptionW(hConnectHandle, INTERNET_OPTION_USERNAME, (void*) username.utf16(), username.length() + 1)) { WPMUtils::formatMessage(GetLastError(), &result); } if (result.isEmpty() && !InternetSetOptionW(hConnectHandle, INTERNET_OPTION_PASSWORD, (void*) password.utf16(), password.length() + 1)) { WPMUtils::formatMessage(GetLastError(), &result); } } else { result = QString(QObject::tr("Cannot handle HTTP status code %1")). arg(dwStatus); } return result; }
/*! * @brief Prepare a wininet request with the given context. * @param ctx Pointer to the HTTP transport context to prepare the request from. * @param isGet Indication of whether this request is a GET request, otherwise POST is used. * @param direction String representing the direction of the communications (for debug). * @return An Internet request handle. */ static HINTERNET get_request_wininet(HttpTransportContext *ctx, BOOL isGet, const char *direction) { HINTERNET hReq = NULL; DWORD flags = INTERNET_FLAG_RELOAD | INTERNET_FLAG_NO_CACHE_WRITE | INTERNET_FLAG_KEEP_CONNECTION | INTERNET_FLAG_NO_AUTO_REDIRECT | INTERNET_FLAG_NO_UI; if (ctx->ssl) { flags |= INTERNET_FLAG_SECURE | INTERNET_FLAG_IGNORE_CERT_CN_INVALID | INTERNET_FLAG_IGNORE_CERT_DATE_INVALID; dprintf("[%s] Setting secure request flag..", direction); } do { vdprintf("[%s] opening request on connection %x to %S", direction, ctx->connection, ctx->uri); hReq = HttpOpenRequestW(ctx->connection, isGet ? L"GET" : L"POST", ctx->uri, NULL, NULL, NULL, flags, 0); if (hReq == NULL) { dprintf("[%s] Failed HttpOpenRequestW: %d", direction, GetLastError()); SetLastError(ERROR_NOT_FOUND); break; } if (ctx->ssl) { DWORD secureFlags = SECURITY_FLAG_IGNORE_CERT_CN_INVALID | SECURITY_FLAG_IGNORE_CERT_DATE_INVALID | SECURITY_FLAG_IGNORE_WRONG_USAGE | SECURITY_FLAG_IGNORE_UNKNOWN_CA | SECURITY_FLAG_IGNORE_REVOCATION; dprintf("[%s] Setting secure option flags", direction); if (!InternetSetOptionW(hReq, INTERNET_OPTION_SECURITY_FLAGS, &secureFlags, sizeof(secureFlags))) { dprintf("[%s] Failed InternetSetOptionW: %d", direction, GetLastError()); SetLastError(ERROR_NOT_FOUND); break; } } return hReq; } while (0); if (hReq != NULL) { InternetCloseHandle(hReq); } return NULL; }
static inline BOOL set_security_flag(HttpProtocol *This, DWORD flags) { BOOL res; res = InternetSetOptionW(This->base.request, INTERNET_OPTION_SECURITY_FLAGS, &flags, sizeof(flags)); if(!res) ERR("Failed to set security flags: %x\n", flags); return res; }
/* Routine Description: Supports Yes/No,Ok/Cancel decisions for the authentication UI. Arguments: hwnd - standard dialog params msg - " wparam - " lparam - " Return Value: BOOL TRUE - we handled message FALSE - Windows should handle message */ INT_PTR CALLBACK OkCancelDialogProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) { BOOL fRet = FALSE; PERRORINFODLGTYPE pDlgInfo; if ( msg != WM_INITDIALOG ) { pDlgInfo = (PERRORINFODLGTYPE) GetWindowLongW(hwnd,DWL_USER); fRet = SHRCMLDialogProc( HINST_RESDLL, MAKEINTRESOURCE(pDlgInfo->dwDlgId), hwnd, msg, wparam, lparam ); } switch(msg) { case WM_INITDIALOG: ASSERT(lparam); SetWindowLongW(hwnd,DWL_USER,lparam); pDlgInfo = (PERRORINFODLGTYPE)lparam; SHRCMLDialogProc( HINST_RESDLL, MAKEINTRESOURCE(pDlgInfo->dwDlgId), hwnd, msg, wparam, lparam ); SHINITDLGINFO shidi; SHMENUBARINFO mbi; // Some of these dialogs need a scrollbar shidi.dwMask = SHIDIM_FLAGS; shidi.dwFlags = SHIDIF_SIZEDLGFULLSCREEN | SHIDIF_WANTSCROLLBAR; shidi.hDlg = hwnd; SHInitDialog(&shidi); // softkeys memset(&mbi, 0, sizeof(SHMENUBARINFO)); mbi.cbSize = sizeof(SHMENUBARINFO); mbi.hwndParent = hwnd; mbi.nToolBarId = IDR_INETUI_DIALOGYESNO; mbi.hInstRes = HINST_RESDLL; SHCreateMenuBar(&mbi); SHSetWindowBits(hwnd, GWL_STYLE, WS_NONAVDONEBUTTON, WS_NONAVDONEBUTTON); if(IDD_SEC_CERT_ERRORS == pDlgInfo->dwDlgId) { InitSecCertErrorsDlg(hwnd,pDlgInfo); } else if(IDD_REVOCATION_PROBLEM == pDlgInfo->dwDlgId) { DWORD dwFlags = 0, dwSize = sizeof(dwFlags); if(pDlgInfo->hInternetMapped) { InternetQueryOption(pDlgInfo->hInternetMapped, INTERNET_OPTION_SECURITY_FLAGS, &dwFlags, &dwSize); } if(dwFlags & DLG_FLAGS_SEC_CERT_REV_FAILED) pDlgInfo->dwDlgFlags |= DLG_FLAGS_IGNORE_FAILED_REVOCATION; } fRet = TRUE; // set this dialog as foreground if necessary if(pDlgInfo->dwDlgFlags & DLG_FLAGS_BRING_TO_FOREGROUND) SetForegroundWindow(hwnd); break; case WM_COMMAND: { WORD wID = LOWORD(wparam); pDlgInfo = (PERRORINFODLGTYPE) GetWindowLongW(hwnd,DWL_USER); switch(wID) { case IDOK: case IDYES: ASSERT(pDlgInfo); ASSERT(pDlgInfo->dwDlgId != 0); // Save flags,and change any global vars,and registry values if needed. if(pDlgInfo->hInternetMapped) { VERIFY(InternetSetOptionW(pDlgInfo->hInternetMapped, INTERNET_OPTION_SECURITY_FLAGS, &(pDlgInfo->dwDlgFlags), sizeof(pDlgInfo->dwDlgFlags))); } // If the user checked the "overide" check-box // let us map it,and force a general // override of all errors of this type. if(SendDlgItemMessageW(hwnd,IDC_DONT_WANT_WARNING,BM_GETCHECK,(WPARAM)0,(LPARAM)0)==BST_CHECKED) UpdateGlobalSecuritySettings(pDlgInfo->dwDlgId,pDlgInfo->dwDlgFlags); EndDialog(hwnd,TRUE); break; case IDCANCEL: case IDNO: EndDialog(hwnd,FALSE); break; } fRet = TRUE; break; } } return fRet; }
static HRESULT HttpProtocol_open_request(Protocol *prot, LPCWSTR url, DWORD request_flags, HINTERNET internet_session, IInternetBindInfo *bind_info) { HttpProtocol *This = ASYNCPROTOCOL_THIS(prot); LPWSTR addl_header = NULL, post_cookie = NULL, optional = NULL; IServiceProvider *service_provider = NULL; IHttpNegotiate2 *http_negotiate2 = NULL; LPWSTR host, user, pass, path; LPOLESTR accept_mimes[257]; URL_COMPONENTSW url_comp; BYTE security_id[512]; DWORD len = 0; ULONG num; BOOL res, b; HRESULT hres; static const WCHAR wszBindVerb[BINDVERB_CUSTOM][5] = {{'G','E','T',0}, {'P','O','S','T',0}, {'P','U','T',0}}; memset(&url_comp, 0, sizeof(url_comp)); url_comp.dwStructSize = sizeof(url_comp); url_comp.dwSchemeLength = url_comp.dwHostNameLength = url_comp.dwUrlPathLength = url_comp.dwExtraInfoLength = url_comp.dwUserNameLength = url_comp.dwPasswordLength = 1; if (!InternetCrackUrlW(url, 0, 0, &url_comp)) return MK_E_SYNTAX; if(!url_comp.nPort) url_comp.nPort = This->https ? INTERNET_DEFAULT_HTTPS_PORT : INTERNET_DEFAULT_HTTP_PORT; host = heap_strndupW(url_comp.lpszHostName, url_comp.dwHostNameLength); user = heap_strndupW(url_comp.lpszUserName, url_comp.dwUserNameLength); pass = heap_strndupW(url_comp.lpszPassword, url_comp.dwPasswordLength); This->base.connection = InternetConnectW(internet_session, host, url_comp.nPort, user, pass, INTERNET_SERVICE_HTTP, This->https ? INTERNET_FLAG_SECURE : 0, (DWORD_PTR)&This->base); heap_free(pass); heap_free(user); heap_free(host); if(!This->base.connection) { WARN("InternetConnect failed: %d\n", GetLastError()); return INET_E_CANNOT_CONNECT; } num = sizeof(accept_mimes)/sizeof(accept_mimes[0])-1; hres = IInternetBindInfo_GetBindString(bind_info, BINDSTRING_ACCEPT_MIMES, accept_mimes, num, &num); if(hres != S_OK) { WARN("GetBindString BINDSTRING_ACCEPT_MIMES failed: %08x\n", hres); return INET_E_NO_VALID_MEDIA; } accept_mimes[num] = 0; path = heap_alloc((url_comp.dwUrlPathLength+url_comp.dwExtraInfoLength+1)*sizeof(WCHAR)); if(url_comp.dwUrlPathLength) memcpy(path, url_comp.lpszUrlPath, url_comp.dwUrlPathLength*sizeof(WCHAR)); if(url_comp.dwExtraInfoLength) memcpy(path+url_comp.dwUrlPathLength, url_comp.lpszExtraInfo, url_comp.dwExtraInfoLength*sizeof(WCHAR)); path[url_comp.dwUrlPathLength+url_comp.dwExtraInfoLength] = 0; if(This->https) request_flags |= INTERNET_FLAG_SECURE; This->base.request = HttpOpenRequestW(This->base.connection, This->base.bind_info.dwBindVerb < BINDVERB_CUSTOM ? wszBindVerb[This->base.bind_info.dwBindVerb] : This->base.bind_info.szCustomVerb, path, NULL, NULL, (LPCWSTR *)accept_mimes, request_flags, (DWORD_PTR)&This->base); heap_free(path); while(num--) CoTaskMemFree(accept_mimes[num]); if (!This->base.request) { WARN("HttpOpenRequest failed: %d\n", GetLastError()); return INET_E_RESOURCE_NOT_FOUND; } hres = IInternetProtocolSink_QueryInterface(This->base.protocol_sink, &IID_IServiceProvider, (void **)&service_provider); if (hres != S_OK) { WARN("IInternetProtocolSink_QueryInterface IID_IServiceProvider failed: %08x\n", hres); return hres; } hres = IServiceProvider_QueryService(service_provider, &IID_IHttpNegotiate, &IID_IHttpNegotiate, (void **)&This->http_negotiate); if (hres != S_OK) { WARN("IServiceProvider_QueryService IID_IHttpNegotiate failed: %08x\n", hres); return hres; } hres = IHttpNegotiate_BeginningTransaction(This->http_negotiate, url, wszHeaders, 0, &addl_header); if(hres != S_OK) { WARN("IHttpNegotiate_BeginningTransaction failed: %08x\n", hres); IServiceProvider_Release(service_provider); return hres; } if(addl_header) { int len_addl_header = strlenW(addl_header); This->full_header = heap_alloc(len_addl_header*sizeof(WCHAR)+sizeof(wszHeaders)); lstrcpyW(This->full_header, addl_header); lstrcpyW(&This->full_header[len_addl_header], wszHeaders); CoTaskMemFree(addl_header); }else { This->full_header = (LPWSTR)wszHeaders; } hres = IServiceProvider_QueryService(service_provider, &IID_IHttpNegotiate2, &IID_IHttpNegotiate2, (void **)&http_negotiate2); IServiceProvider_Release(service_provider); if(hres != S_OK) { WARN("IServiceProvider_QueryService IID_IHttpNegotiate2 failed: %08x\n", hres); /* No goto done as per native */ }else { len = sizeof(security_id)/sizeof(security_id[0]); hres = IHttpNegotiate2_GetRootSecurityId(http_negotiate2, security_id, &len, 0); IHttpNegotiate2_Release(http_negotiate2); if (hres != S_OK) WARN("IHttpNegotiate2_GetRootSecurityId failed: %08x\n", hres); } /* FIXME: Handle security_id. Native calls undocumented function IsHostInProxyBypassList. */ if(This->base.bind_info.dwBindVerb == BINDVERB_POST) { num = 0; hres = IInternetBindInfo_GetBindString(bind_info, BINDSTRING_POST_COOKIE, &post_cookie, 1, &num); if(hres == S_OK && num) { if(!InternetSetOptionW(This->base.request, INTERNET_OPTION_SECONDARY_CACHE_KEY, post_cookie, lstrlenW(post_cookie))) WARN("InternetSetOption INTERNET_OPTION_SECONDARY_CACHE_KEY failed: %d\n", GetLastError()); CoTaskMemFree(post_cookie); } } if(This->base.bind_info.dwBindVerb != BINDVERB_GET) { /* Native does not use GlobalLock/GlobalUnlock, so we won't either */ if (This->base.bind_info.stgmedData.tymed != TYMED_HGLOBAL) WARN("Expected This->base.bind_info.stgmedData.tymed to be TYMED_HGLOBAL, not %d\n", This->base.bind_info.stgmedData.tymed); else optional = (LPWSTR)This->base.bind_info.stgmedData.u.hGlobal; } b = TRUE; res = InternetSetOptionW(This->base.request, INTERNET_OPTION_HTTP_DECODING, &b, sizeof(b)); if(!res) WARN("InternetSetOption(INTERNET_OPTION_HTTP_DECODING) failed: %08x\n", GetLastError()); res = HttpSendRequestW(This->base.request, This->full_header, lstrlenW(This->full_header), optional, optional ? This->base.bind_info.cbstgmedData : 0); if(!res && GetLastError() != ERROR_IO_PENDING) { WARN("HttpSendRequest failed: %d\n", GetLastError()); return INET_E_DOWNLOAD_FAILURE; } return S_OK; }
static HRESULT HttpProtocol_open_request(Protocol *prot, IUri *uri, DWORD request_flags, HINTERNET internet_session, IInternetBindInfo *bind_info) { HttpProtocol *This = impl_from_Protocol(prot); WCHAR *addl_header = NULL, *post_cookie = NULL, *rootdoc_url = NULL; IServiceProvider *service_provider = NULL; IHttpNegotiate2 *http_negotiate2 = NULL; BSTR url, host, user, pass, path; LPOLESTR accept_mimes[257]; const WCHAR **accept_types; BYTE security_id[512]; DWORD len, port, flags; ULONG num, error; BOOL res, b; HRESULT hres; static const WCHAR wszBindVerb[BINDVERB_CUSTOM][5] = {{'G','E','T',0}, {'P','O','S','T',0}, {'P','U','T',0}}; hres = IUri_GetPort(uri, &port); if(FAILED(hres)) return hres; hres = IUri_GetHost(uri, &host); if(FAILED(hres)) return hres; hres = IUri_GetUserName(uri, &user); if(SUCCEEDED(hres)) { hres = IUri_GetPassword(uri, &pass); if(SUCCEEDED(hres)) { This->base.connection = InternetConnectW(internet_session, host, port, user, pass, INTERNET_SERVICE_HTTP, This->https ? INTERNET_FLAG_SECURE : 0, (DWORD_PTR)&This->base); SysFreeString(pass); } SysFreeString(user); } SysFreeString(host); if(FAILED(hres)) return hres; if(!This->base.connection) { WARN("InternetConnect failed: %d\n", GetLastError()); return INET_E_CANNOT_CONNECT; } num = 0; hres = IInternetBindInfo_GetBindString(bind_info, BINDSTRING_ROOTDOC_URL, &rootdoc_url, 1, &num); if(hres == S_OK && num) { FIXME("Use root doc URL %s\n", debugstr_w(rootdoc_url)); CoTaskMemFree(rootdoc_url); } num = sizeof(accept_mimes)/sizeof(accept_mimes[0])-1; hres = IInternetBindInfo_GetBindString(bind_info, BINDSTRING_ACCEPT_MIMES, accept_mimes, num, &num); if(hres == INET_E_USE_DEFAULT_SETTING) { static const WCHAR default_accept_mimeW[] = {'*','/','*',0}; static const WCHAR *default_accept_mimes[] = {default_accept_mimeW, NULL}; accept_types = default_accept_mimes; num = 0; }else if(hres == S_OK) { accept_types = (const WCHAR**)accept_mimes; }else { WARN("GetBindString BINDSTRING_ACCEPT_MIMES failed: %08x\n", hres); return INET_E_NO_VALID_MEDIA; } accept_mimes[num] = 0; if(This->https) request_flags |= INTERNET_FLAG_SECURE; hres = IUri_GetPathAndQuery(uri, &path); if(SUCCEEDED(hres)) { This->base.request = HttpOpenRequestW(This->base.connection, This->base.bind_info.dwBindVerb < BINDVERB_CUSTOM ? wszBindVerb[This->base.bind_info.dwBindVerb] : This->base.bind_info.szCustomVerb, path, NULL, NULL, accept_types, request_flags, (DWORD_PTR)&This->base); SysFreeString(path); } while(num--) CoTaskMemFree(accept_mimes[num]); if(FAILED(hres)) return hres; if (!This->base.request) { WARN("HttpOpenRequest failed: %d\n", GetLastError()); return INET_E_RESOURCE_NOT_FOUND; } hres = IInternetProtocolSink_QueryInterface(This->base.protocol_sink, &IID_IServiceProvider, (void **)&service_provider); if (hres != S_OK) { WARN("IInternetProtocolSink_QueryInterface IID_IServiceProvider failed: %08x\n", hres); return hres; } hres = IServiceProvider_QueryService(service_provider, &IID_IHttpNegotiate, &IID_IHttpNegotiate, (void **)&This->http_negotiate); if (hres != S_OK) { WARN("IServiceProvider_QueryService IID_IHttpNegotiate failed: %08x\n", hres); IServiceProvider_Release(service_provider); return hres; } hres = IUri_GetAbsoluteUri(uri, &url); if(FAILED(hres)) { IServiceProvider_Release(service_provider); return hres; } hres = IHttpNegotiate_BeginningTransaction(This->http_negotiate, url, default_headersW, 0, &addl_header); SysFreeString(url); if(hres != S_OK) { WARN("IHttpNegotiate_BeginningTransaction failed: %08x\n", hres); IServiceProvider_Release(service_provider); return hres; } len = addl_header ? strlenW(addl_header) : 0; This->full_header = heap_alloc(len*sizeof(WCHAR)+sizeof(default_headersW)); if(!This->full_header) { IServiceProvider_Release(service_provider); return E_OUTOFMEMORY; } if(len) memcpy(This->full_header, addl_header, len*sizeof(WCHAR)); CoTaskMemFree(addl_header); memcpy(This->full_header+len, default_headersW, sizeof(default_headersW)); hres = IServiceProvider_QueryService(service_provider, &IID_IHttpNegotiate2, &IID_IHttpNegotiate2, (void **)&http_negotiate2); IServiceProvider_Release(service_provider); if(hres != S_OK) { WARN("IServiceProvider_QueryService IID_IHttpNegotiate2 failed: %08x\n", hres); /* No goto done as per native */ }else { len = sizeof(security_id)/sizeof(security_id[0]); hres = IHttpNegotiate2_GetRootSecurityId(http_negotiate2, security_id, &len, 0); IHttpNegotiate2_Release(http_negotiate2); if (hres != S_OK) WARN("IHttpNegotiate2_GetRootSecurityId failed: %08x\n", hres); } /* FIXME: Handle security_id. Native calls undocumented function IsHostInProxyBypassList. */ if(This->base.bind_info.dwBindVerb == BINDVERB_POST) { num = 0; hres = IInternetBindInfo_GetBindString(bind_info, BINDSTRING_POST_COOKIE, &post_cookie, 1, &num); if(hres == S_OK && num) { if(!InternetSetOptionW(This->base.request, INTERNET_OPTION_SECONDARY_CACHE_KEY, post_cookie, lstrlenW(post_cookie))) WARN("InternetSetOption INTERNET_OPTION_SECONDARY_CACHE_KEY failed: %d\n", GetLastError()); CoTaskMemFree(post_cookie); } } flags = INTERNET_ERROR_MASK_COMBINED_SEC_CERT; res = InternetSetOptionW(This->base.request, INTERNET_OPTION_ERROR_MASK, &flags, sizeof(flags)); if(!res) WARN("InternetSetOption(INTERNET_OPTION_ERROR_MASK) failed: %u\n", GetLastError()); b = TRUE; res = InternetSetOptionW(This->base.request, INTERNET_OPTION_HTTP_DECODING, &b, sizeof(b)); if(!res) WARN("InternetSetOption(INTERNET_OPTION_HTTP_DECODING) failed: %u\n", GetLastError()); do { error = send_http_request(This); switch(error) { case ERROR_IO_PENDING: return S_OK; case ERROR_SUCCESS: /* * If sending response ended synchronously, it means that we have the whole data * available locally (most likely in cache). */ return protocol_syncbinding(&This->base); default: hres = handle_http_error(This, error); } } while(hres == RPC_E_RETRY); WARN("HttpSendRequest failed: %d\n", error); return hres; }
/*********************************************************************** * WININET_InvalidCertificateDialog */ static INT_PTR WINAPI WININET_InvalidCertificateDialog( HWND hdlg, UINT uMsg, WPARAM wParam, LPARAM lParam ) { struct WININET_ErrorDlgParams *params; HWND hitem; WCHAR buf[1024]; if( uMsg == WM_INITDIALOG ) { TRACE("WM_INITDIALOG (%08lx)\n", lParam); /* save the parameter list */ params = (struct WININET_ErrorDlgParams*) lParam; SetWindowLongPtrW( hdlg, GWLP_USERDATA, lParam ); switch( params->dwError ) { case ERROR_INTERNET_INVALID_CA: LoadStringW( WININET_hModule, IDS_CERT_CA_INVALID, buf, 1024 ); break; case ERROR_INTERNET_SEC_CERT_DATE_INVALID: LoadStringW( WININET_hModule, IDS_CERT_DATE_INVALID, buf, 1024 ); break; case ERROR_INTERNET_SEC_CERT_CN_INVALID: LoadStringW( WININET_hModule, IDS_CERT_CN_INVALID, buf, 1024 ); break; case ERROR_INTERNET_SEC_CERT_ERRORS: /* FIXME: We should fetch information about the * certificate here and show all the relevant errors. */ LoadStringW( WININET_hModule, IDS_CERT_ERRORS, buf, 1024 ); break; default: FIXME( "No message for error %d\n", params->dwError ); buf[0] = '\0'; } hitem = GetDlgItem( hdlg, IDC_CERT_ERROR ); SetWindowTextW( hitem, buf ); return TRUE; } params = (struct WININET_ErrorDlgParams*) GetWindowLongPtrW( hdlg, GWLP_USERDATA ); switch( uMsg ) { case WM_COMMAND: if( wParam == IDOK ) { BOOL res = TRUE; if( params->dwFlags & FLAGS_ERROR_UI_FLAGS_CHANGE_OPTIONS ) { DWORD flags, size = sizeof(flags); InternetQueryOptionW( params->hRequest, INTERNET_OPTION_SECURITY_FLAGS, &flags, &size ); switch( params->dwError ) { case ERROR_INTERNET_INVALID_CA: flags |= SECURITY_FLAG_IGNORE_UNKNOWN_CA; break; case ERROR_INTERNET_SEC_CERT_DATE_INVALID: flags |= SECURITY_FLAG_IGNORE_CERT_DATE_INVALID; break; case ERROR_INTERNET_SEC_CERT_CN_INVALID: flags |= SECURITY_FLAG_IGNORE_CERT_CN_INVALID; break; case ERROR_INTERNET_SEC_CERT_ERRORS: FIXME("Should only add ignore flags as needed.\n"); flags |= SECURITY_FLAG_IGNORE_CERT_CN_INVALID | SECURITY_FLAG_IGNORE_CERT_DATE_INVALID | SECURITY_FLAG_IGNORE_UNKNOWN_CA; /* FIXME: ERROR_INTERNET_SEC_CERT_ERRORS also * seems to set the corresponding DLG_* flags. */ break; } res = InternetSetOptionW( params->hRequest, INTERNET_OPTION_SECURITY_FLAGS, &flags, size ); if(!res) WARN("InternetSetOption(INTERNET_OPTION_SECURITY_FLAGS) failed.\n"); } EndDialog( hdlg, res ? ERROR_SUCCESS : ERROR_NOT_SUPPORTED ); return TRUE; } if( wParam == IDCANCEL ) { TRACE("Pressed cancel.\n"); EndDialog( hdlg, ERROR_CANCELLED ); return TRUE; } break; } return FALSE; }
/*! * @brief Initialise the HTTP(S) connection. * @param remote Pointer to the remote instance with the HTTP(S) transport details wired in. * @param sock Reference to the original socket FD passed to metsrv (ignored); * @return Indication of success or failure. */ static BOOL server_init_wininet(Transport* transport) { URL_COMPONENTS bits; wchar_t tmpHostName[URL_SIZE]; wchar_t tmpUrlPath[URL_SIZE]; HttpTransportContext* ctx = (HttpTransportContext*)transport->ctx; dprintf("[WININET] Initialising ..."); // configure proxy if (ctx->proxy) { dprintf("[DISPATCH] Configuring with proxy: %S", ctx->proxy); ctx->internet = InternetOpenW(ctx->ua, INTERNET_OPEN_TYPE_PROXY, ctx->proxy, NULL, 0); } else { ctx->internet = InternetOpenW(ctx->ua, INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0); } if (!ctx->internet) { dprintf("[DISPATCH] Failed InternetOpenW: %d", GetLastError()); return FALSE; } dprintf("[DISPATCH] Configured hInternet: 0x%.8x", ctx->internet); // The InternetCrackUrl method was poorly designed... ZeroMemory(tmpHostName, sizeof(tmpHostName)); ZeroMemory(tmpUrlPath, sizeof(tmpUrlPath)); ZeroMemory(&bits, sizeof(bits)); bits.dwStructSize = sizeof(bits); bits.dwHostNameLength = URL_SIZE - 1; bits.lpszHostName = tmpHostName; bits.dwUrlPathLength = URL_SIZE - 1; bits.lpszUrlPath = tmpUrlPath; dprintf("[DISPATCH] About to crack URL: %S", transport->url); InternetCrackUrlW(transport->url, 0, 0, &bits); SAFE_FREE(ctx->uri); ctx->uri = _wcsdup(tmpUrlPath); transport->comms_last_packet = current_unix_timestamp(); dprintf("[DISPATCH] Configured URI: %S", ctx->uri); dprintf("[DISPATCH] Host: %S Port: %u", tmpHostName, bits.nPort); // Allocate the connection handle ctx->connection = InternetConnectW(ctx->internet, tmpHostName, bits.nPort, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0); if (!ctx->connection) { dprintf("[DISPATCH] Failed InternetConnect: %d", GetLastError()); return FALSE; } if (ctx->proxy) { if (ctx->proxy_user) { InternetSetOptionW(ctx->connection, INTERNET_OPTION_PROXY_USERNAME, ctx->proxy_user, (DWORD)wcslen(ctx->proxy_user)); } if (ctx->proxy_pass) { InternetSetOptionW(ctx->connection, INTERNET_OPTION_PROXY_PASSWORD, ctx->proxy_pass, (DWORD)wcslen(ctx->proxy_pass)); } } dprintf("[DISPATCH] Configured hConnection: 0x%.8x", ctx->connection); return TRUE; }