scoped_hinternet.cc 1.2 KB

12345678910111213141516171819202122232425262728293031
  1. // Copyright 2021 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include "components/winhttp/scoped_hinternet.h"
  5. #include <versionhelpers.h>
  6. #include <windows.h>
  7. namespace winhttp {
  8. ScopedHInternet CreateSessionHandle(const wchar_t* user_agent,
  9. int proxy_access_type) {
  10. ScopedHInternet session_handle(
  11. ::WinHttpOpen(user_agent, proxy_access_type, WINHTTP_NO_PROXY_NAME,
  12. WINHTTP_NO_PROXY_BYPASS, WINHTTP_FLAG_ASYNC));
  13. // Allow TLS1.2 on Windows 7 and Windows 8. See KB3140245. TLS 1.2 is enabled
  14. // by default on Windows 8.1 and Windows 10.
  15. if (session_handle.is_valid() && ::IsWindows7OrGreater() &&
  16. !::IsWindows8Point1OrGreater()) {
  17. DWORD protocols = WINHTTP_FLAG_SECURE_PROTOCOL_TLS1 |
  18. WINHTTP_FLAG_SECURE_PROTOCOL_TLS1_1 |
  19. WINHTTP_FLAG_SECURE_PROTOCOL_TLS1_2;
  20. ::WinHttpSetOption(session_handle.get(), WINHTTP_OPTION_SECURE_PROTOCOLS,
  21. &protocols, sizeof(protocols));
  22. }
  23. return session_handle;
  24. }
  25. } // namespace winhttp