-
Notifications
You must be signed in to change notification settings - Fork 6.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[vcpkg] Add sources for TLS 1.2 downloader tool. #15516
[vcpkg] Add sources for TLS 1.2 downloader tool. #15516
Conversation
This passes in official signed builds but not here because here we try to build the program with the optimizer off, which means the optimizer doesn't eliminate all the references to the CRT, and for some reason a CRT isn't being linked with despite setting |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've written comments on the C code, but not the winhttp code; I don't understand winhttp, so I don't feel comfortable making suggestions on the code using it (at least without more deep study).
The other thing I'd like to see changed is the camelCase; this project uses snek_case, and I'd like to see this rewritten to use the project's style.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we need to do better proxy handling along the lines of
vcpkg/toolsrc/src/vcpkg/base/downloads.cpp
Lines 95 to 145 in 9c63f97
auto h = WinHttpOpen(L"vcpkg/1.0", | |
IsWindows8Point1OrGreater() ? WINHTTP_ACCESS_TYPE_AUTOMATIC_PROXY | |
: WINHTTP_ACCESS_TYPE_DEFAULT_PROXY, | |
WINHTTP_NO_PROXY_NAME, | |
WINHTTP_NO_PROXY_BYPASS, | |
0); | |
if (!h) return Strings::concat("WinHttpOpen() failed: ", GetLastError()); | |
WinHttpSession ret; | |
ret.m_hSession.reset(h); | |
// If the environment variable HTTPS_PROXY is set | |
// use that variable as proxy. This situation might exist when user is in a company network | |
// with restricted network/proxy settings | |
auto maybe_https_proxy_env = System::get_environment_variable("HTTPS_PROXY"); | |
if (auto p_https_proxy = maybe_https_proxy_env.get()) | |
{ | |
std::wstring env_proxy_settings = Strings::to_utf16(*p_https_proxy); | |
WINHTTP_PROXY_INFO proxy; | |
proxy.dwAccessType = WINHTTP_ACCESS_TYPE_NAMED_PROXY; | |
proxy.lpszProxy = env_proxy_settings.data(); | |
proxy.lpszProxyBypass = nullptr; | |
WinHttpSetOption(ret.m_hSession.get(), WINHTTP_OPTION_PROXY, &proxy, sizeof(proxy)); | |
} | |
// Win7 IE Proxy fallback | |
else if (IsWindows7OrGreater() && !IsWindows8Point1OrGreater()) | |
{ | |
// First check if any proxy has been found automatically | |
WINHTTP_PROXY_INFO proxyInfo; | |
DWORD proxyInfoSize = sizeof(WINHTTP_PROXY_INFO); | |
auto noProxyFound = | |
!WinHttpQueryOption(ret.m_hSession.get(), WINHTTP_OPTION_PROXY, &proxyInfo, &proxyInfoSize) || | |
proxyInfo.dwAccessType == WINHTTP_ACCESS_TYPE_NO_PROXY; | |
// If no proxy was found automatically, use IE's proxy settings, if any | |
if (noProxyFound) | |
{ | |
WINHTTP_CURRENT_USER_IE_PROXY_CONFIG ieProxy; | |
if (WinHttpGetIEProxyConfigForCurrentUser(&ieProxy) && ieProxy.lpszProxy != nullptr) | |
{ | |
WINHTTP_PROXY_INFO proxy; | |
proxy.dwAccessType = WINHTTP_ACCESS_TYPE_NAMED_PROXY; | |
proxy.lpszProxy = ieProxy.lpszProxy; | |
proxy.lpszProxyBypass = ieProxy.lpszProxyBypass; | |
WinHttpSetOption(ret.m_hSession.get(), WINHTTP_OPTION_PROXY, &proxy, sizeof(proxy)); | |
GlobalFree(ieProxy.lpszProxy); | |
GlobalFree(ieProxy.lpszProxyBypass); | |
GlobalFree(ieProxy.lpszAutoConfigUrl); | |
} | |
} | |
} |
toolsrc/src/tls12-download.c
Outdated
} | ||
|
||
write_message(hStdOut, L"\r\n"); | ||
FlushFileBuffers(hStdOut); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps it makes sense to add FlushFileBuffers()
to win32_abort()
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
abort
does not traditionally flush buffers; it's called in cases where e.g. memory corruption has occurred and attempting to flush is not safe.
toolsrc/src/tls12-download.c
Outdated
|
||
BOOL results = FALSE; | ||
const HINTERNET session = WinHttpOpen( | ||
L"tls12-download/1.0", WINHTTP_ACCESS_TYPE_DEFAULT_PROXY, WINHTTP_NO_PROXY_NAME, WINHTTP_NO_PROXY_BYPASS, 0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We probably need to do
IsWindows8Point1OrGreater() ? WINHTTP_ACCESS_TYPE_AUTOMATIC_PROXY |
L"tls12-download/1.0", WINHTTP_ACCESS_TYPE_DEFAULT_PROXY, WINHTTP_NO_PROXY_NAME, WINHTTP_NO_PROXY_BYPASS, 0); | |
L"tls12-download/1.0", IsWindows8Point1OrGreater() ? WINHTTP_ACCESS_TYPE_AUTOMATIC_PROXY : WINHTTP_ACCESS_TYPE_DEFAULT_PROXY, WINHTTP_NO_PROXY_NAME, WINHTTP_NO_PROXY_BYPASS, 0); |
for proxy support
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IsWindows8Point1OrGreater()
is false
the way this program is built. Certainly for the only platform on which we intend its use.
@ras0219 / @ras0219-msft Considering the absolute mess wpad proxy autodetection has been for cpprestsdk I don't think we want to add that; we certainly don't care about wpad on any other platform or anywhere else in vcpkg since we regularly use curl. |
I note that neither cmake nor curl.exe do WPAD. |
This also needs an update to --- a/scripts/azure-pipelines/Format-CxxCode.ps1
+++ b/scripts/azure-pipelines/Format-CxxCode.ps1
@@ -37,5 +37,6 @@ try
{
$files = Get-ChildItem -Recurse -LiteralPath "$toolsrc/src" -Filter "*.cpp"
+ $files += Get-ChildItem -Recurse -LiteralPath "$toolsrc/src" -Filter "*.c"
$files += Get-ChildItem -Recurse -LiteralPath "$toolsrc/include/vcpkg" -Filter '*.h'
$files += Get-ChildItem -Recurse -LiteralPath "$toolsrc/include/vcpkg-test" -Filter '*.h'
$files += Get-Item "$toolsrc/include/pch.h"
|
toolsrc/CMakeLists.txt
Outdated
@@ -198,3 +203,11 @@ if(CLANG_FORMAT) | |||
|
|||
COMMAND ${CLANG_FORMAT} -i -verbose ${VCPKG_FUZZ_SOURCES}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
COMMAND ${CLANG_FORMAT} -i -verbose ${VCPKG_FUZZ_SOURCES}) | |
COMMAND ${CLANG_FORMAT} -i -verbose ${VCPKG_FUZZ_SOURCES} | |
COMMAND ${CLANG_FORMAT} -i -verbose ${TLS12_DOWNLOAD_SOURCES}) |
toolsrc/src/tls12-download.c
Outdated
* hello world program that does link with the CRT is ~300kb) | ||
*/ | ||
|
||
void __declspec(noreturn) win32_abort() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's no reason for these to have external linkage; I'd prefer they be marked static
.
toolsrc/src/tls12-download.c
Outdated
} | ||
|
||
DWORD httpCode = 0; | ||
DWORD unused = sizeof(DWORD); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DWORD unused = sizeof(DWORD); | |
DWORD httpCodeSize = sizeof httpCode; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alternatively, see next comment.
toolsrc/src/tls12-download.c
Outdated
|
||
if (httpCode != 200) | ||
{ | ||
write_message(stdOut, L"Download failed, server returned HTTP status "); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
write_message(stdOut, L"Download failed, server returned HTTP status "); | |
write_message(stdOut, L"Download failed, server returned HTTP status: "); |
I'm ok with skipping WPAD if we add support for |
These are the sources for
tls12-download.exe
in #15474.