1*5f12c8d7Swinesync #ifdef __REACTOS__ 2*5f12c8d7Swinesync #include "precomp.h" 3*5f12c8d7Swinesync #else 4c2c66affSColin Finck /* 5c2c66affSColin Finck * Wininet 6c2c66affSColin Finck * 7c2c66affSColin Finck * Copyright 2003 Mike McCormack for CodeWeavers Inc. 8c2c66affSColin Finck * 9c2c66affSColin Finck * This library is free software; you can redistribute it and/or 10c2c66affSColin Finck * modify it under the terms of the GNU Lesser General Public 11c2c66affSColin Finck * License as published by the Free Software Foundation; either 12c2c66affSColin Finck * version 2.1 of the License, or (at your option) any later version. 13c2c66affSColin Finck * 14c2c66affSColin Finck * This library is distributed in the hope that it will be useful, 15c2c66affSColin Finck * but WITHOUT ANY WARRANTY; without even the implied warranty of 16c2c66affSColin Finck * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17c2c66affSColin Finck * Lesser General Public License for more details. 18c2c66affSColin Finck * 19c2c66affSColin Finck * You should have received a copy of the GNU Lesser General Public 20c2c66affSColin Finck * License along with this library; if not, write to the Free Software 21c2c66affSColin Finck * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA 22c2c66affSColin Finck */ 23c2c66affSColin Finck 24bc01cef0SAmine Khaldi #include "ws2tcpip.h" 25bc01cef0SAmine Khaldi 26bc01cef0SAmine Khaldi #include <stdarg.h> 27bc01cef0SAmine Khaldi 28bc01cef0SAmine Khaldi #include "windef.h" 29bc01cef0SAmine Khaldi #include "winbase.h" 30bc01cef0SAmine Khaldi #include "winuser.h" 31bc01cef0SAmine Khaldi #include "winreg.h" 32bc01cef0SAmine Khaldi #include "wininet.h" 33bc01cef0SAmine Khaldi #include "winnetwk.h" 34bc01cef0SAmine Khaldi #include "wine/debug.h" 35bc01cef0SAmine Khaldi #include "winerror.h" 36bc01cef0SAmine Khaldi #define NO_SHLWAPI_STREAM 37bc01cef0SAmine Khaldi #include "shlwapi.h" 38bc01cef0SAmine Khaldi #include "cryptuiapi.h" 39bc01cef0SAmine Khaldi 40c2c66affSColin Finck #include "internet.h" 41bc01cef0SAmine Khaldi #include "resource.h" 42*5f12c8d7Swinesync #endif /* defined(__REACTOS__) */ 43c2c66affSColin Finck 44c2c66affSColin Finck #define MAX_STRING_LEN 1024 45c2c66affSColin Finck 46bc01cef0SAmine Khaldi WINE_DEFAULT_DEBUG_CHANNEL(wininet); 47bc01cef0SAmine Khaldi 48c2c66affSColin Finck struct WININET_ErrorDlgParams 49c2c66affSColin Finck { 50c2c66affSColin Finck http_request_t *req; 51c2c66affSColin Finck HWND hWnd; 52c2c66affSColin Finck DWORD dwError; 53c2c66affSColin Finck DWORD dwFlags; 54c2c66affSColin Finck LPVOID* lppvData; 55c2c66affSColin Finck }; 56c2c66affSColin Finck 57c2c66affSColin Finck /*********************************************************************** 58c2c66affSColin Finck * WININET_GetAuthRealm 59c2c66affSColin Finck * 60c2c66affSColin Finck * Determine the name of the (basic) Authentication realm 61c2c66affSColin Finck */ 62c2c66affSColin Finck static BOOL WININET_GetAuthRealm( HINTERNET hRequest, LPWSTR szBuf, DWORD sz, BOOL proxy ) 63c2c66affSColin Finck { 64c2c66affSColin Finck LPWSTR p, q; 65c2c66affSColin Finck DWORD index, query; 66c2c66affSColin Finck static const WCHAR szRealm[] = { 'r','e','a','l','m','=',0 }; 67c2c66affSColin Finck 68c2c66affSColin Finck if (proxy) 69c2c66affSColin Finck query = HTTP_QUERY_PROXY_AUTHENTICATE; 70c2c66affSColin Finck else 71c2c66affSColin Finck query = HTTP_QUERY_WWW_AUTHENTICATE; 72c2c66affSColin Finck 73c2c66affSColin Finck /* extract the Realm from the response and show it */ 74c2c66affSColin Finck index = 0; 75c2c66affSColin Finck if( !HttpQueryInfoW( hRequest, query, szBuf, &sz, &index) ) 76c2c66affSColin Finck return FALSE; 77c2c66affSColin Finck 78c2c66affSColin Finck /* 79c2c66affSColin Finck * FIXME: maybe we should check that we're 80c2c66affSColin Finck * dealing with 'Basic' Authentication 81c2c66affSColin Finck */ 82*5f12c8d7Swinesync p = wcschr( szBuf, ' ' ); 83*5f12c8d7Swinesync if( !p || wcsncmp( p+1, szRealm, lstrlenW(szRealm) ) ) 84c2c66affSColin Finck { 85c2c66affSColin Finck ERR("response wrong? (%s)\n", debugstr_w(szBuf)); 86c2c66affSColin Finck return FALSE; 87c2c66affSColin Finck } 88c2c66affSColin Finck 89c2c66affSColin Finck /* remove quotes */ 90c2c66affSColin Finck p += 7; 91c2c66affSColin Finck if( *p == '"' ) 92c2c66affSColin Finck { 93c2c66affSColin Finck p++; 94*5f12c8d7Swinesync q = wcsrchr( p, '"' ); 95c2c66affSColin Finck if( q ) 96c2c66affSColin Finck *q = 0; 97c2c66affSColin Finck } 98*5f12c8d7Swinesync lstrcpyW( szBuf, p ); 99c2c66affSColin Finck 100c2c66affSColin Finck return TRUE; 101c2c66affSColin Finck } 102c2c66affSColin Finck 103c2c66affSColin Finck /* These two are not defined in the public headers */ 104c2c66affSColin Finck extern DWORD WINAPI WNetCachePassword(LPSTR,WORD,LPSTR,WORD,BYTE,WORD); 105c2c66affSColin Finck extern DWORD WINAPI WNetGetCachedPassword(LPSTR,WORD,LPSTR,LPWORD,BYTE); 106c2c66affSColin Finck 107c2c66affSColin Finck /*********************************************************************** 108c2c66affSColin Finck * WININET_GetSetPassword 109c2c66affSColin Finck */ 110c2c66affSColin Finck static BOOL WININET_GetSetPassword( HWND hdlg, LPCWSTR szServer, 111c2c66affSColin Finck LPCWSTR szRealm, BOOL bSet ) 112c2c66affSColin Finck { 113c2c66affSColin Finck WCHAR szResource[0x80], szUserPass[0x40]; 114c2c66affSColin Finck LPWSTR p; 115c2c66affSColin Finck HWND hUserItem, hPassItem; 116c2c66affSColin Finck DWORD r, dwMagic = 19; 117c2c66affSColin Finck UINT r_len, u_len; 118c2c66affSColin Finck WORD sz; 119c2c66affSColin Finck static const WCHAR szColon[] = { ':',0 }; 120c2c66affSColin Finck static const WCHAR szbs[] = { '/', 0 }; 121c2c66affSColin Finck 122c2c66affSColin Finck hUserItem = GetDlgItem( hdlg, IDC_USERNAME ); 123c2c66affSColin Finck hPassItem = GetDlgItem( hdlg, IDC_PASSWORD ); 124c2c66affSColin Finck 125c2c66affSColin Finck /* now try fetch the username and password */ 126c2c66affSColin Finck lstrcpyW( szResource, szServer); 127c2c66affSColin Finck lstrcatW( szResource, szbs); 128c2c66affSColin Finck lstrcatW( szResource, szRealm); 129c2c66affSColin Finck 130c2c66affSColin Finck /* 131c2c66affSColin Finck * WNetCachePassword is only concerned with the length 132c2c66affSColin Finck * of the data stored (which we tell it) and it does 133c2c66affSColin Finck * not use strlen() internally so we can add WCHAR data 134c2c66affSColin Finck * instead of ASCII data and get it back the same way. 135c2c66affSColin Finck */ 136c2c66affSColin Finck if( bSet ) 137c2c66affSColin Finck { 138c2c66affSColin Finck szUserPass[0] = 0; 139c239cdd4SAmine Khaldi GetWindowTextW( hUserItem, szUserPass, ARRAY_SIZE( szUserPass ) - 1 ); 140c2c66affSColin Finck lstrcatW(szUserPass, szColon); 141*5f12c8d7Swinesync u_len = lstrlenW( szUserPass ); 142c239cdd4SAmine Khaldi GetWindowTextW( hPassItem, szUserPass+u_len, ARRAY_SIZE( szUserPass ) - u_len ); 143c2c66affSColin Finck 144*5f12c8d7Swinesync r_len = (lstrlenW( szResource ) + 1)*sizeof(WCHAR); 145*5f12c8d7Swinesync u_len = (lstrlenW( szUserPass ) + 1)*sizeof(WCHAR); 146c2c66affSColin Finck r = WNetCachePassword( (CHAR*)szResource, r_len, 147c2c66affSColin Finck (CHAR*)szUserPass, u_len, dwMagic, 0 ); 148c2c66affSColin Finck 149c2c66affSColin Finck return ( r == WN_SUCCESS ); 150c2c66affSColin Finck } 151c2c66affSColin Finck 152c2c66affSColin Finck sz = sizeof szUserPass; 153*5f12c8d7Swinesync r_len = (lstrlenW( szResource ) + 1)*sizeof(WCHAR); 154c2c66affSColin Finck r = WNetGetCachedPassword( (CHAR*)szResource, r_len, 155c2c66affSColin Finck (CHAR*)szUserPass, &sz, dwMagic ); 156c2c66affSColin Finck if( r != WN_SUCCESS ) 157c2c66affSColin Finck return FALSE; 158c2c66affSColin Finck 159*5f12c8d7Swinesync p = wcschr( szUserPass, ':' ); 160c2c66affSColin Finck if( p ) 161c2c66affSColin Finck { 162c2c66affSColin Finck *p = 0; 163c2c66affSColin Finck SetWindowTextW( hUserItem, szUserPass ); 164c2c66affSColin Finck SetWindowTextW( hPassItem, p+1 ); 165c2c66affSColin Finck } 166c2c66affSColin Finck 167c2c66affSColin Finck return TRUE; 168c2c66affSColin Finck } 169c2c66affSColin Finck 170c2c66affSColin Finck /*********************************************************************** 171c2c66affSColin Finck * WININET_SetAuthorization 172c2c66affSColin Finck */ 173c2c66affSColin Finck static BOOL WININET_SetAuthorization( http_request_t *request, LPWSTR username, 174c2c66affSColin Finck LPWSTR password, BOOL proxy ) 175c2c66affSColin Finck { 176c2c66affSColin Finck http_session_t *session = request->session; 177c2c66affSColin Finck LPWSTR p, q; 178c2c66affSColin Finck 179c2c66affSColin Finck p = heap_strdupW(username); 180c2c66affSColin Finck if( !p ) 181c2c66affSColin Finck return FALSE; 182c2c66affSColin Finck 183c2c66affSColin Finck q = heap_strdupW(password); 184c2c66affSColin Finck if( !q ) 185c2c66affSColin Finck { 186c2c66affSColin Finck heap_free(p); 187c2c66affSColin Finck return FALSE; 188c2c66affSColin Finck } 189c2c66affSColin Finck 190c2c66affSColin Finck if (proxy) 191c2c66affSColin Finck { 192c2c66affSColin Finck appinfo_t *hIC = session->appInfo; 193c2c66affSColin Finck 194c2c66affSColin Finck heap_free(hIC->proxyUsername); 195c2c66affSColin Finck hIC->proxyUsername = p; 196c2c66affSColin Finck 197c2c66affSColin Finck heap_free(hIC->proxyPassword); 198c2c66affSColin Finck hIC->proxyPassword = q; 199c2c66affSColin Finck } 200c2c66affSColin Finck else 201c2c66affSColin Finck { 202c2c66affSColin Finck heap_free(session->userName); 203c2c66affSColin Finck session->userName = p; 204c2c66affSColin Finck 205c2c66affSColin Finck heap_free(session->password); 206c2c66affSColin Finck session->password = q; 207c2c66affSColin Finck } 208c2c66affSColin Finck 209c2c66affSColin Finck return TRUE; 210c2c66affSColin Finck } 211c2c66affSColin Finck 212c2c66affSColin Finck /*********************************************************************** 213c2c66affSColin Finck * WININET_ProxyPasswordDialog 214c2c66affSColin Finck */ 215c2c66affSColin Finck static INT_PTR WINAPI WININET_ProxyPasswordDialog( 216c2c66affSColin Finck HWND hdlg, UINT uMsg, WPARAM wParam, LPARAM lParam ) 217c2c66affSColin Finck { 218c2c66affSColin Finck HWND hitem; 219c2c66affSColin Finck struct WININET_ErrorDlgParams *params; 220c239cdd4SAmine Khaldi WCHAR szRealm[0x80]; 221c2c66affSColin Finck 222c2c66affSColin Finck if( uMsg == WM_INITDIALOG ) 223c2c66affSColin Finck { 224c2c66affSColin Finck TRACE("WM_INITDIALOG (%08lx)\n", lParam); 225c2c66affSColin Finck 226c2c66affSColin Finck /* save the parameter list */ 227c2c66affSColin Finck params = (struct WININET_ErrorDlgParams*) lParam; 228c2c66affSColin Finck SetWindowLongPtrW( hdlg, GWLP_USERDATA, lParam ); 229c2c66affSColin Finck 230c2c66affSColin Finck /* extract the Realm from the proxy response and show it */ 231c2c66affSColin Finck if( WININET_GetAuthRealm( params->req->hdr.hInternet, 232c239cdd4SAmine Khaldi szRealm, ARRAY_SIZE( szRealm ), TRUE ) ) 233c2c66affSColin Finck { 234c2c66affSColin Finck hitem = GetDlgItem( hdlg, IDC_REALM ); 235c2c66affSColin Finck SetWindowTextW( hitem, szRealm ); 236c2c66affSColin Finck } 237c2c66affSColin Finck 238c2c66affSColin Finck hitem = GetDlgItem( hdlg, IDC_PROXY ); 239c2c66affSColin Finck SetWindowTextW( hitem, params->req->session->appInfo->proxy ); 240c2c66affSColin Finck 241c239cdd4SAmine Khaldi WININET_GetSetPassword( hdlg, params->req->session->appInfo->proxy, szRealm, FALSE ); 242c2c66affSColin Finck 243c2c66affSColin Finck return TRUE; 244c2c66affSColin Finck } 245c2c66affSColin Finck 246c2c66affSColin Finck params = (struct WININET_ErrorDlgParams*) 247c2c66affSColin Finck GetWindowLongPtrW( hdlg, GWLP_USERDATA ); 248c2c66affSColin Finck 249c2c66affSColin Finck switch( uMsg ) 250c2c66affSColin Finck { 251c2c66affSColin Finck case WM_COMMAND: 252c2c66affSColin Finck if( wParam == IDOK ) 253c2c66affSColin Finck { 254c2c66affSColin Finck WCHAR username[0x20], password[0x20]; 255c2c66affSColin Finck 256c2c66affSColin Finck username[0] = 0; 257c2c66affSColin Finck hitem = GetDlgItem( hdlg, IDC_USERNAME ); 258c2c66affSColin Finck if( hitem ) 259c239cdd4SAmine Khaldi GetWindowTextW( hitem, username, ARRAY_SIZE( username )); 260c2c66affSColin Finck 261c2c66affSColin Finck password[0] = 0; 262c2c66affSColin Finck hitem = GetDlgItem( hdlg, IDC_PASSWORD ); 263c2c66affSColin Finck if( hitem ) 264c239cdd4SAmine Khaldi GetWindowTextW( hitem, password, ARRAY_SIZE( password )); 265c2c66affSColin Finck 266c2c66affSColin Finck hitem = GetDlgItem( hdlg, IDC_SAVEPASSWORD ); 267c2c66affSColin Finck if( hitem && 268c2c66affSColin Finck SendMessageW( hitem, BM_GETSTATE, 0, 0 ) && 269c2c66affSColin Finck WININET_GetAuthRealm( params->req->hdr.hInternet, 270c239cdd4SAmine Khaldi szRealm, ARRAY_SIZE( szRealm ), TRUE) ) 271c2c66affSColin Finck WININET_GetSetPassword( hdlg, params->req->session->appInfo->proxy, szRealm, TRUE ); 272c2c66affSColin Finck WININET_SetAuthorization( params->req, username, password, TRUE ); 273c2c66affSColin Finck 274c2c66affSColin Finck EndDialog( hdlg, ERROR_INTERNET_FORCE_RETRY ); 275c2c66affSColin Finck return TRUE; 276c2c66affSColin Finck } 277c2c66affSColin Finck if( wParam == IDCANCEL ) 278c2c66affSColin Finck { 279c2c66affSColin Finck EndDialog( hdlg, 0 ); 280c2c66affSColin Finck return TRUE; 281c2c66affSColin Finck } 282c2c66affSColin Finck break; 283c2c66affSColin Finck } 284c2c66affSColin Finck return FALSE; 285c2c66affSColin Finck } 286c2c66affSColin Finck 287c2c66affSColin Finck /*********************************************************************** 288c2c66affSColin Finck * WININET_PasswordDialog 289c2c66affSColin Finck */ 290c2c66affSColin Finck static INT_PTR WINAPI WININET_PasswordDialog( 291c2c66affSColin Finck HWND hdlg, UINT uMsg, WPARAM wParam, LPARAM lParam ) 292c2c66affSColin Finck { 293c2c66affSColin Finck HWND hitem; 294c2c66affSColin Finck struct WININET_ErrorDlgParams *params; 295c239cdd4SAmine Khaldi WCHAR szRealm[0x80]; 296c2c66affSColin Finck 297c2c66affSColin Finck if( uMsg == WM_INITDIALOG ) 298c2c66affSColin Finck { 299c2c66affSColin Finck TRACE("WM_INITDIALOG (%08lx)\n", lParam); 300c2c66affSColin Finck 301c2c66affSColin Finck /* save the parameter list */ 302c2c66affSColin Finck params = (struct WININET_ErrorDlgParams*) lParam; 303c2c66affSColin Finck SetWindowLongPtrW( hdlg, GWLP_USERDATA, lParam ); 304c2c66affSColin Finck 305c2c66affSColin Finck /* extract the Realm from the response and show it */ 306c2c66affSColin Finck if( WININET_GetAuthRealm( params->req->hdr.hInternet, 307c239cdd4SAmine Khaldi szRealm, ARRAY_SIZE( szRealm ), FALSE ) ) 308c2c66affSColin Finck { 309c2c66affSColin Finck hitem = GetDlgItem( hdlg, IDC_REALM ); 310c2c66affSColin Finck SetWindowTextW( hitem, szRealm ); 311c2c66affSColin Finck } 312c2c66affSColin Finck 313c2c66affSColin Finck hitem = GetDlgItem( hdlg, IDC_SERVER ); 314c2c66affSColin Finck SetWindowTextW( hitem, params->req->session->hostName ); 315c2c66affSColin Finck 316c239cdd4SAmine Khaldi WININET_GetSetPassword( hdlg, params->req->session->hostName, szRealm, FALSE ); 317c2c66affSColin Finck 318c2c66affSColin Finck return TRUE; 319c2c66affSColin Finck } 320c2c66affSColin Finck 321c2c66affSColin Finck params = (struct WININET_ErrorDlgParams*) 322c2c66affSColin Finck GetWindowLongPtrW( hdlg, GWLP_USERDATA ); 323c2c66affSColin Finck 324c2c66affSColin Finck switch( uMsg ) 325c2c66affSColin Finck { 326c2c66affSColin Finck case WM_COMMAND: 327c2c66affSColin Finck if( wParam == IDOK ) 328c2c66affSColin Finck { 329c2c66affSColin Finck WCHAR username[0x20], password[0x20]; 330c2c66affSColin Finck 331c2c66affSColin Finck username[0] = 0; 332c2c66affSColin Finck hitem = GetDlgItem( hdlg, IDC_USERNAME ); 333c2c66affSColin Finck if( hitem ) 334c239cdd4SAmine Khaldi GetWindowTextW( hitem, username, ARRAY_SIZE( username )); 335c2c66affSColin Finck 336c2c66affSColin Finck password[0] = 0; 337c2c66affSColin Finck hitem = GetDlgItem( hdlg, IDC_PASSWORD ); 338c2c66affSColin Finck if( hitem ) 339c239cdd4SAmine Khaldi GetWindowTextW( hitem, password, ARRAY_SIZE( password )); 340c2c66affSColin Finck 341c2c66affSColin Finck hitem = GetDlgItem( hdlg, IDC_SAVEPASSWORD ); 342c2c66affSColin Finck if( hitem && 343c2c66affSColin Finck SendMessageW( hitem, BM_GETSTATE, 0, 0 ) && 344c2c66affSColin Finck WININET_GetAuthRealm( params->req->hdr.hInternet, 345c239cdd4SAmine Khaldi szRealm, ARRAY_SIZE( szRealm ), FALSE )) 346c2c66affSColin Finck { 347c2c66affSColin Finck WININET_GetSetPassword( hdlg, params->req->session->hostName, szRealm, TRUE ); 348c2c66affSColin Finck } 349c2c66affSColin Finck WININET_SetAuthorization( params->req, username, password, FALSE ); 350c2c66affSColin Finck 351c2c66affSColin Finck EndDialog( hdlg, ERROR_INTERNET_FORCE_RETRY ); 352c2c66affSColin Finck return TRUE; 353c2c66affSColin Finck } 354c2c66affSColin Finck if( wParam == IDCANCEL ) 355c2c66affSColin Finck { 356c2c66affSColin Finck EndDialog( hdlg, 0 ); 357c2c66affSColin Finck return TRUE; 358c2c66affSColin Finck } 359c2c66affSColin Finck break; 360c2c66affSColin Finck } 361c2c66affSColin Finck return FALSE; 362c2c66affSColin Finck } 363c2c66affSColin Finck 364c2c66affSColin Finck /*********************************************************************** 365c2c66affSColin Finck * WININET_InvalidCertificateDialog 366c2c66affSColin Finck */ 367c2c66affSColin Finck static INT_PTR WINAPI WININET_InvalidCertificateDialog( 368c2c66affSColin Finck HWND hdlg, UINT uMsg, WPARAM wParam, LPARAM lParam ) 369c2c66affSColin Finck { 370c2c66affSColin Finck struct WININET_ErrorDlgParams *params; 371c2c66affSColin Finck HWND hitem; 372c2c66affSColin Finck WCHAR buf[1024]; 373c2c66affSColin Finck 374c2c66affSColin Finck if( uMsg == WM_INITDIALOG ) 375c2c66affSColin Finck { 376c2c66affSColin Finck TRACE("WM_INITDIALOG (%08lx)\n", lParam); 377c2c66affSColin Finck 378c2c66affSColin Finck /* save the parameter list */ 379c2c66affSColin Finck params = (struct WININET_ErrorDlgParams*) lParam; 380c2c66affSColin Finck SetWindowLongPtrW( hdlg, GWLP_USERDATA, lParam ); 381c2c66affSColin Finck 382c2c66affSColin Finck switch( params->dwError ) 383c2c66affSColin Finck { 384c2c66affSColin Finck case ERROR_INTERNET_INVALID_CA: 385c2c66affSColin Finck LoadStringW( WININET_hModule, IDS_CERT_CA_INVALID, buf, 1024 ); 386c2c66affSColin Finck break; 387c2c66affSColin Finck case ERROR_INTERNET_SEC_CERT_DATE_INVALID: 388c2c66affSColin Finck LoadStringW( WININET_hModule, IDS_CERT_DATE_INVALID, buf, 1024 ); 389c2c66affSColin Finck break; 390c2c66affSColin Finck case ERROR_INTERNET_SEC_CERT_CN_INVALID: 391c2c66affSColin Finck LoadStringW( WININET_hModule, IDS_CERT_CN_INVALID, buf, 1024 ); 392c2c66affSColin Finck break; 393c2c66affSColin Finck case ERROR_INTERNET_SEC_CERT_ERRORS: 394c2c66affSColin Finck /* FIXME: We should fetch information about the 395c2c66affSColin Finck * certificate here and show all the relevant errors. 396c2c66affSColin Finck */ 397c2c66affSColin Finck LoadStringW( WININET_hModule, IDS_CERT_ERRORS, buf, 1024 ); 398c2c66affSColin Finck break; 399c2c66affSColin Finck default: 400c2c66affSColin Finck FIXME( "No message for error %d\n", params->dwError ); 401c2c66affSColin Finck buf[0] = '\0'; 402c2c66affSColin Finck } 403c2c66affSColin Finck 404c2c66affSColin Finck hitem = GetDlgItem( hdlg, IDC_CERT_ERROR ); 405c2c66affSColin Finck SetWindowTextW( hitem, buf ); 406c2c66affSColin Finck 407c2c66affSColin Finck return TRUE; 408c2c66affSColin Finck } 409c2c66affSColin Finck 410c2c66affSColin Finck params = (struct WININET_ErrorDlgParams*) 411c2c66affSColin Finck GetWindowLongPtrW( hdlg, GWLP_USERDATA ); 412c2c66affSColin Finck 413c2c66affSColin Finck switch( uMsg ) 414c2c66affSColin Finck { 415c2c66affSColin Finck case WM_COMMAND: 416c2c66affSColin Finck if( wParam == IDOK ) 417c2c66affSColin Finck { 418c2c66affSColin Finck if( params->dwFlags & FLAGS_ERROR_UI_FLAGS_CHANGE_OPTIONS ) 419c2c66affSColin Finck { 420c2c66affSColin Finck http_request_t *req = params->req; 421c2c66affSColin Finck DWORD flags, size = sizeof(flags); 422c2c66affSColin Finck 423c2c66affSColin Finck InternetQueryOptionW( req->hdr.hInternet, INTERNET_OPTION_SECURITY_FLAGS, &flags, &size ); 424c2c66affSColin Finck switch( params->dwError ) 425c2c66affSColin Finck { 426c2c66affSColin Finck case ERROR_INTERNET_INVALID_CA: 427c2c66affSColin Finck flags |= SECURITY_FLAG_IGNORE_UNKNOWN_CA; 428c2c66affSColin Finck break; 429c2c66affSColin Finck case ERROR_INTERNET_SEC_CERT_DATE_INVALID: 430c2c66affSColin Finck flags |= SECURITY_FLAG_IGNORE_CERT_DATE_INVALID; 431c2c66affSColin Finck break; 432c2c66affSColin Finck case ERROR_INTERNET_SEC_CERT_CN_INVALID: 433c2c66affSColin Finck flags |= SECURITY_FLAG_IGNORE_CERT_CN_INVALID; 434c2c66affSColin Finck break; 435c2c66affSColin Finck case ERROR_INTERNET_SEC_CERT_REV_FAILED: 436c2c66affSColin Finck flags |= SECURITY_FLAG_IGNORE_REVOCATION; 437c2c66affSColin Finck break; 438c2c66affSColin Finck case ERROR_INTERNET_SEC_CERT_ERRORS: 439c2c66affSColin Finck if(flags & _SECURITY_FLAG_CERT_REV_FAILED) 440c2c66affSColin Finck flags |= SECURITY_FLAG_IGNORE_REVOCATION; 441c2c66affSColin Finck if(flags & _SECURITY_FLAG_CERT_INVALID_CA) 442c2c66affSColin Finck flags |= SECURITY_FLAG_IGNORE_UNKNOWN_CA; 443c2c66affSColin Finck if(flags & _SECURITY_FLAG_CERT_INVALID_CN) 444c2c66affSColin Finck flags |= SECURITY_FLAG_IGNORE_CERT_CN_INVALID; 445c2c66affSColin Finck if(flags & _SECURITY_FLAG_CERT_INVALID_DATE) 446c2c66affSColin Finck flags |= SECURITY_FLAG_IGNORE_CERT_DATE_INVALID; 447c2c66affSColin Finck break; 448c2c66affSColin Finck } 449c2c66affSColin Finck /* FIXME: Use helper function */ 450c2c66affSColin Finck flags |= SECURITY_FLAG_SECURE; 451c2c66affSColin Finck req->security_flags |= flags; 452c2c66affSColin Finck if(is_valid_netconn(req->netconn)) 453c2c66affSColin Finck req->netconn->security_flags |= flags; 454c2c66affSColin Finck } 455c2c66affSColin Finck 456c2c66affSColin Finck EndDialog( hdlg, ERROR_SUCCESS ); 457c2c66affSColin Finck return TRUE; 458c2c66affSColin Finck } 459c2c66affSColin Finck if( wParam == IDCANCEL ) 460c2c66affSColin Finck { 461c2c66affSColin Finck TRACE("Pressed cancel.\n"); 462c2c66affSColin Finck 463c2c66affSColin Finck EndDialog( hdlg, ERROR_CANCELLED ); 464c2c66affSColin Finck return TRUE; 465c2c66affSColin Finck } 466c2c66affSColin Finck break; 467c2c66affSColin Finck } 468c2c66affSColin Finck 469c2c66affSColin Finck return FALSE; 470c2c66affSColin Finck } 471c2c66affSColin Finck 472c2c66affSColin Finck /*********************************************************************** 473c2c66affSColin Finck * InternetErrorDlg 474c2c66affSColin Finck */ 475c2c66affSColin Finck DWORD WINAPI InternetErrorDlg(HWND hWnd, HINTERNET hRequest, 476c2c66affSColin Finck DWORD dwError, DWORD dwFlags, LPVOID* lppvData) 477c2c66affSColin Finck { 478c2c66affSColin Finck struct WININET_ErrorDlgParams params; 479c2c66affSColin Finck http_request_t *req = NULL; 480c2c66affSColin Finck DWORD res = ERROR_SUCCESS; 481c2c66affSColin Finck 482c2c66affSColin Finck TRACE("%p %p %d %08x %p\n", hWnd, hRequest, dwError, dwFlags, lppvData); 483c2c66affSColin Finck 484c2c66affSColin Finck if( !hWnd && !(dwFlags & FLAGS_ERROR_UI_FLAGS_NO_UI) ) 485c2c66affSColin Finck return ERROR_INVALID_HANDLE; 486c2c66affSColin Finck 487c2c66affSColin Finck if(hRequest) { 488c2c66affSColin Finck req = (http_request_t*)get_handle_object(hRequest); 489c2c66affSColin Finck if(!req) 490c2c66affSColin Finck return ERROR_INVALID_HANDLE; 491c2c66affSColin Finck if(req->hdr.htype != WH_HHTTPREQ) 492c2c66affSColin Finck return ERROR_SUCCESS; /* Yes, that was tested */ 493c2c66affSColin Finck } 494c2c66affSColin Finck 495c2c66affSColin Finck params.req = req; 496c2c66affSColin Finck params.hWnd = hWnd; 497c2c66affSColin Finck params.dwError = dwError; 498c2c66affSColin Finck params.dwFlags = dwFlags; 499c2c66affSColin Finck params.lppvData = lppvData; 500c2c66affSColin Finck 501c2c66affSColin Finck switch( dwError ) 502c2c66affSColin Finck { 503c2c66affSColin Finck case ERROR_SUCCESS: 504c2c66affSColin Finck case ERROR_INTERNET_INCORRECT_PASSWORD: { 505c2c66affSColin Finck if( !dwError && !(dwFlags & FLAGS_ERROR_UI_FILTER_FOR_ERRORS ) ) 506c2c66affSColin Finck break; 507c2c66affSColin Finck if(!req) 508c2c66affSColin Finck return ERROR_INVALID_HANDLE; 509c2c66affSColin Finck 510c2c66affSColin Finck switch(req->status_code) { 511c2c66affSColin Finck case HTTP_STATUS_PROXY_AUTH_REQ: 512c2c66affSColin Finck res = DialogBoxParamW( WININET_hModule, MAKEINTRESOURCEW( IDD_PROXYDLG ), 513c2c66affSColin Finck hWnd, WININET_ProxyPasswordDialog, (LPARAM) ¶ms ); 514c2c66affSColin Finck break; 515c2c66affSColin Finck case HTTP_STATUS_DENIED: 516c2c66affSColin Finck res = DialogBoxParamW( WININET_hModule, MAKEINTRESOURCEW( IDD_AUTHDLG ), 517c2c66affSColin Finck hWnd, WININET_PasswordDialog, (LPARAM) ¶ms ); 518c2c66affSColin Finck break; 519c2c66affSColin Finck default: 520c2c66affSColin Finck WARN("unhandled status %u\n", req->status_code); 521c2c66affSColin Finck } 522c2c66affSColin Finck break; 523c2c66affSColin Finck } 524c2c66affSColin Finck case ERROR_INTERNET_SEC_CERT_ERRORS: 525c2c66affSColin Finck case ERROR_INTERNET_SEC_CERT_CN_INVALID: 526c2c66affSColin Finck case ERROR_INTERNET_SEC_CERT_DATE_INVALID: 527c2c66affSColin Finck case ERROR_INTERNET_INVALID_CA: 528c2c66affSColin Finck case ERROR_INTERNET_SEC_CERT_REV_FAILED: 529c2c66affSColin Finck if( dwFlags & FLAGS_ERROR_UI_FLAGS_NO_UI ) { 530c2c66affSColin Finck res = ERROR_CANCELLED; 531c2c66affSColin Finck break; 532c2c66affSColin Finck } 533c2c66affSColin Finck if(!req) 534c2c66affSColin Finck return ERROR_INVALID_HANDLE; 535c2c66affSColin Finck 536c2c66affSColin Finck 537c2c66affSColin Finck if( dwFlags & ~FLAGS_ERROR_UI_FLAGS_CHANGE_OPTIONS ) 538c2c66affSColin Finck FIXME("%08x contains unsupported flags.\n", dwFlags); 539c2c66affSColin Finck 540c2c66affSColin Finck res = DialogBoxParamW( WININET_hModule, MAKEINTRESOURCEW( IDD_INVCERTDLG ), 541c2c66affSColin Finck hWnd, WININET_InvalidCertificateDialog, (LPARAM) ¶ms ); 542c2c66affSColin Finck break; 543c2c66affSColin Finck case ERROR_INTERNET_HTTP_TO_HTTPS_ON_REDIR: 544c2c66affSColin Finck case ERROR_INTERNET_POST_IS_NON_SECURE: 545c2c66affSColin Finck FIXME("Need to display dialog for error %d\n", dwError); 546c2c66affSColin Finck res = ERROR_SUCCESS; 547c2c66affSColin Finck break; 548c2c66affSColin Finck default: 549c2c66affSColin Finck res = ERROR_NOT_SUPPORTED; 550c2c66affSColin Finck } 551c2c66affSColin Finck 552c2c66affSColin Finck if(req) 553c2c66affSColin Finck WININET_Release(&req->hdr); 554c2c66affSColin Finck return res; 555c2c66affSColin Finck } 556c2c66affSColin Finck 557c2c66affSColin Finck /*********************************************************************** 558c2c66affSColin Finck * InternetShowSecurityInfoByURLA (@) 559c2c66affSColin Finck */ 560c2c66affSColin Finck BOOL WINAPI InternetShowSecurityInfoByURLA(LPCSTR url, HWND window) 561c2c66affSColin Finck { 562c2c66affSColin Finck FIXME("stub: %s %p\n", url, window); 563c2c66affSColin Finck return FALSE; 564c2c66affSColin Finck } 565c2c66affSColin Finck 566c2c66affSColin Finck /*********************************************************************** 567c2c66affSColin Finck * InternetShowSecurityInfoByURLW (@) 568c2c66affSColin Finck */ 569c2c66affSColin Finck BOOL WINAPI InternetShowSecurityInfoByURLW(LPCWSTR url, HWND window) 570c2c66affSColin Finck { 571c2c66affSColin Finck FIXME("stub: %s %p\n", debugstr_w(url), window); 572c2c66affSColin Finck return FALSE; 573c2c66affSColin Finck } 574c2c66affSColin Finck 575c2c66affSColin Finck /*********************************************************************** 576bc01cef0SAmine Khaldi * ParseX509EncodedCertificateForListBoxEntry (@) 577bc01cef0SAmine Khaldi */ 578bc01cef0SAmine Khaldi DWORD WINAPI ParseX509EncodedCertificateForListBoxEntry(LPBYTE cert, DWORD len, LPSTR szlistbox, LPDWORD listbox) 579bc01cef0SAmine Khaldi { 580bc01cef0SAmine Khaldi FIXME("stub: %p %d %s %p\n", cert, len, debugstr_a(szlistbox), listbox); 581bc01cef0SAmine Khaldi return ERROR_CALL_NOT_IMPLEMENTED; 582bc01cef0SAmine Khaldi } 583bc01cef0SAmine Khaldi 584bc01cef0SAmine Khaldi /*********************************************************************** 585c2c66affSColin Finck * ShowX509EncodedCertificate (@) 586c2c66affSColin Finck */ 587c2c66affSColin Finck DWORD WINAPI ShowX509EncodedCertificate(HWND parent, LPBYTE cert, DWORD len) 588c2c66affSColin Finck { 589c2c66affSColin Finck PCCERT_CONTEXT certContext = CertCreateCertificateContext(X509_ASN_ENCODING, 590c2c66affSColin Finck cert, len); 591c2c66affSColin Finck DWORD ret; 592c2c66affSColin Finck 593c2c66affSColin Finck if (certContext) 594c2c66affSColin Finck { 595c2c66affSColin Finck CRYPTUI_VIEWCERTIFICATE_STRUCTW view; 596c2c66affSColin Finck 597c2c66affSColin Finck memset(&view, 0, sizeof(view)); 598c2c66affSColin Finck view.hwndParent = parent; 599c2c66affSColin Finck view.pCertContext = certContext; 600c2c66affSColin Finck if (CryptUIDlgViewCertificateW(&view, NULL)) 601c2c66affSColin Finck ret = ERROR_SUCCESS; 602c2c66affSColin Finck else 603c2c66affSColin Finck ret = GetLastError(); 604c2c66affSColin Finck CertFreeCertificateContext(certContext); 605c2c66affSColin Finck } 606c2c66affSColin Finck else 607c2c66affSColin Finck ret = GetLastError(); 608c2c66affSColin Finck return ret; 609c2c66affSColin Finck } 610