[PATCH 0/1] MR10390: winhttp: Support Qyuery option WINHTTP_OPTION_SECURITY_INFO
From: Alistair Leslie-Hughes <leslie_alistair@hotmail.com> --- dlls/winhttp/session.c | 18 ++++++++++++++++++ dlls/winhttp/tests/winhttp.c | 21 +++++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/dlls/winhttp/session.c b/dlls/winhttp/session.c index 6348ec67b82..3c231d0708a 100644 --- a/dlls/winhttp/session.c +++ b/dlls/winhttp/session.c @@ -23,6 +23,7 @@ #include "winsock2.h" #include "ws2ipdef.h" #include "ws2tcpip.h" +#include "schannel.h" #include "winhttp.h" #include "winreg.h" #include "winternl.h" @@ -821,6 +822,23 @@ static BOOL request_query_option( struct object_header *hdr, DWORD option, void *buflen = sizeof(flags); return TRUE; } + case WINHTTP_OPTION_SECURITY_INFO: + { + WINHTTP_SECURITY_INFO *info = (WINHTTP_SECURITY_INFO *)buffer; + SECURITY_STATUS res; + + if (!validate_buffer( buffer, buflen, sizeof(WINHTTP_SECURITY_INFO) )) return FALSE; + + memset(info, 0 , sizeof(WINHTTP_SECURITY_INFO)); + if (!request->netconn->secure) return TRUE; + res = QueryContextAttributesW(&request->netconn->ssl_ctx, SECPKG_ATTR_CONNECTION_INFO, (void*)&info->ConnectionInfo); + if(res != SEC_E_OK) + WARN( "QueryContextAttributesW failed: %#lx\n", res ); + res = QueryContextAttributesW(&request->netconn->ssl_ctx, SECPKG_ATTR_CIPHER_INFO, (void*)&info->CipherInfo); + if(res != SEC_E_OK) + WARN( "QueryContextAttributesW failed: %#lx\n", res ); + return TRUE; + } case WINHTTP_OPTION_SERVER_CERT_CONTEXT: { const CERT_CONTEXT *cert; diff --git a/dlls/winhttp/tests/winhttp.c b/dlls/winhttp/tests/winhttp.c index b4ad4a67803..9b1f3a74026 100644 --- a/dlls/winhttp/tests/winhttp.c +++ b/dlls/winhttp/tests/winhttp.c @@ -24,6 +24,7 @@ #include <windef.h> #include <winsock2.h> #include <ws2tcpip.h> +#include <schannel.h> #include <winhttp.h> #include <wincrypt.h> #include <winreg.h> @@ -69,6 +70,7 @@ static void test_WinHttpQueryOption(void) BOOL ret; HINTERNET session, request, connection; DWORD feature, size; + WINHTTP_SECURITY_INFO info; SetLastError(0xdeadbeef); session = WinHttpOpen(L"winetest", 0, 0, 0, 0); @@ -283,6 +285,15 @@ static void test_WinHttpQueryOption(void) ok(!ret, "should fail to query option\n"); ok( GetLastError() == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER, got %lu\n", GetLastError() ); + size = sizeof(info); + ret = WinHttpQueryOption(request, WINHTTP_OPTION_SECURITY_INFO, &info, &size); + ok(ret, "got %lu\n", GetLastError()); + if (ret) + { + ok(info.ConnectionInfo.dwProtocol == 0, "got %lu\n", info.ConnectionInfo.dwProtocol); + ok(info.ConnectionInfo.dwCipherStrength == 0, "got %lu\n", info.ConnectionInfo.dwCipherStrength); + } + SetLastError(0xdeadbeef); ret = WinHttpCloseHandle(request); ok(ret, "WinHttpCloseHandle failed on closing request: %lu\n", GetLastError()); @@ -1088,6 +1099,7 @@ static void test_secure_connection(void) BOOL ret; CERT_CONTEXT *cert; WINHTTP_CERTIFICATE_INFO info; + WINHTTP_SECURITY_INFO secinfo; char buffer[32]; ses = WinHttpOpen(L"winetest", 0, NULL, NULL, 0); @@ -1213,6 +1225,15 @@ static void test_secure_connection(void) LocalFree( info.lpszIssuerInfo ); } + size = sizeof(secinfo); + ret = WinHttpQueryOption(req, WINHTTP_OPTION_SECURITY_INFO, &secinfo, &size); + ok(ret, "got %lu\n", GetLastError()); + if (ret) + { + ok(secinfo.ConnectionInfo.dwProtocol == SP_PROT_TLS1_2_CLIENT, "got %lu\n", secinfo.ConnectionInfo.dwProtocol); + ok(secinfo.ConnectionInfo.dwCipherStrength == info.dwKeySize, "got %lu\n", secinfo.ConnectionInfo.dwCipherStrength); + } + ret = WinHttpReceiveResponse(req, NULL); if (!ret && GetLastError() == ERROR_WINHTTP_CONNECTION_ERROR) { -- GitLab https://gitlab.winehq.org/wine/wine/-/merge_requests/10390
Hans Leidekker (@hans) commented about dlls/winhttp/tests/winhttp.c:
ok(!ret, "should fail to query option\n"); ok( GetLastError() == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER, got %lu\n", GetLastError() );
+ size = sizeof(info); + ret = WinHttpQueryOption(request, WINHTTP_OPTION_SECURITY_INFO, &info, &size); + ok(ret, "got %lu\n", GetLastError()); + if (ret) + { + ok(info.ConnectionInfo.dwProtocol == 0, "got %lu\n", info.ConnectionInfo.dwProtocol); + ok(info.ConnectionInfo.dwCipherStrength == 0, "got %lu\n", info.ConnectionInfo.dwCipherStrength); + }
Please set these fields to 0xdeadbeef to prove that they are zeroed. -- https://gitlab.winehq.org/wine/wine/-/merge_requests/10390#note_132946
Hans Leidekker (@hans) commented about dlls/winhttp/session.c:
*buflen = sizeof(flags); return TRUE; } + case WINHTTP_OPTION_SECURITY_INFO: + { + WINHTTP_SECURITY_INFO *info = (WINHTTP_SECURITY_INFO *)buffer; + SECURITY_STATUS res; + + if (!validate_buffer( buffer, buflen, sizeof(WINHTTP_SECURITY_INFO) )) return FALSE; + + memset(info, 0 , sizeof(WINHTTP_SECURITY_INFO)); + if (!request->netconn->secure) return TRUE;
request->netconn is not guaranteed to be valid so this should be: ``` if (!request->netconn || !request->netconn->secure) return TRUE; ``` -- https://gitlab.winehq.org/wine/wine/-/merge_requests/10390#note_132948
Hans Leidekker (@hans) commented about dlls/winhttp/session.c:
*buflen = sizeof(flags); return TRUE; } + case WINHTTP_OPTION_SECURITY_INFO: + { + WINHTTP_SECURITY_INFO *info = (WINHTTP_SECURITY_INFO *)buffer; + SECURITY_STATUS res; + + if (!validate_buffer( buffer, buflen, sizeof(WINHTTP_SECURITY_INFO) )) return FALSE; + + memset(info, 0 , sizeof(WINHTTP_SECURITY_INFO)); + if (!request->netconn->secure) return TRUE; + res = QueryContextAttributesW(&request->netconn->ssl_ctx, SECPKG_ATTR_CONNECTION_INFO, (void*)&info->ConnectionInfo); + if(res != SEC_E_OK) + WARN( "QueryContextAttributesW failed: %#lx\n", res );
Please conform to surrounding style. ``` res = QueryContextAttributesW( &request->netconn->ssl_ctx, SECPKG_ATTR_CONNECTION_INFO, (void *)&info->ConnectionInfo ); if (res != SEC_E_OK) WARN( "QueryContextAttributesW failed: %#lx\n", res ); ``` -- https://gitlab.winehq.org/wine/wine/-/merge_requests/10390#note_132947
Please also fix the commit subject. -- https://gitlab.winehq.org/wine/wine/-/merge_requests/10390#note_132950
participants (3)
-
Alistair Leslie-Hughes -
Alistair Leslie-Hughes (@alesliehughes) -
Hans Leidekker (@hans)