OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/public/browser/browser_main_runner.h" | 5 #include "content/public/browser/browser_main_runner.h" |
6 | 6 |
7 #include "base/allocator/allocator_shim.h" | 7 #include "base/allocator/allocator_shim.h" |
8 #include "base/base_switches.h" | 8 #include "base/base_switches.h" |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/debug/leak_annotations.h" | 10 #include "base/debug/leak_annotations.h" |
11 #include "base/debug/trace_event.h" | 11 #include "base/debug/trace_event.h" |
12 #include "base/logging.h" | 12 #include "base/logging.h" |
13 #include "base/metrics/histogram.h" | 13 #include "base/metrics/histogram.h" |
14 #include "base/metrics/statistics_recorder.h" | 14 #include "base/metrics/statistics_recorder.h" |
15 #include "content/browser/browser_main_loop.h" | 15 #include "content/browser/browser_main_loop.h" |
16 #include "content/browser/browser_shutdown_profile_dumper.h" | 16 #include "content/browser/browser_shutdown_profile_dumper.h" |
17 #include "content/browser/notification_service_impl.h" | 17 #include "content/browser/notification_service_impl.h" |
18 #include "content/public/common/content_switches.h" | 18 #include "content/public/common/content_switches.h" |
19 #include "content/public/common/main_function_params.h" | 19 #include "content/public/common/main_function_params.h" |
20 #include "ui/base/ime/input_method_initializer.h" | 20 #include "ui/base/ime/input_method_initializer.h" |
21 | 21 |
22 #if defined(OS_WIN) | 22 #if defined(OS_WIN) |
| 23 #include "base/win/win_util.h" |
23 #include "base/win/windows_version.h" | 24 #include "base/win/windows_version.h" |
| 25 #include "net/cert/sha256_legacy_support_win.h" |
| 26 #include "sandbox/win/src/sidestep/preamble_patcher.h" |
24 #include "ui/base/win/scoped_ole_initializer.h" | 27 #include "ui/base/win/scoped_ole_initializer.h" |
25 #endif | 28 #endif |
26 | 29 |
27 bool g_exited_main_message_loop = false; | 30 bool g_exited_main_message_loop = false; |
28 | 31 |
29 namespace content { | 32 namespace content { |
30 | 33 |
| 34 #if defined(OS_WIN) |
| 35 namespace { |
| 36 |
| 37 // Pointer to the original CryptVerifyCertificateSignatureEx function. |
| 38 net::sha256_interception::CryptVerifyCertificateSignatureExFunc |
| 39 g_real_crypt_verify_signature_stub = NULL; |
| 40 |
| 41 // Stub function that is called whenever the Crypt32 function |
| 42 // CryptVerifyCertificateSignatureEx is called. It just defers to net to perform |
| 43 // the actual verification. |
| 44 BOOL WINAPI CryptVerifyCertificateSignatureExStub( |
| 45 HCRYPTPROV_LEGACY provider, |
| 46 DWORD encoding_type, |
| 47 DWORD subject_type, |
| 48 void* subject_data, |
| 49 DWORD issuer_type, |
| 50 void* issuer_data, |
| 51 DWORD flags, |
| 52 void* extra) { |
| 53 return net::sha256_interception::CryptVerifyCertificateSignatureExHook( |
| 54 g_real_crypt_verify_signature_stub, provider, encoding_type, subject_type, |
| 55 subject_data, issuer_type, issuer_data, flags, extra); |
| 56 } |
| 57 |
| 58 // If necessary, install an interception |
| 59 void InstallSha256LegacyHooks() { |
| 60 #if defined(_WIN64) |
| 61 // Interception on x64 is not supported. |
| 62 return; |
| 63 #else |
| 64 if (base::win::MaybeHasSHA256Support()) |
| 65 return; |
| 66 |
| 67 net::sha256_interception::CryptVerifyCertificateSignatureExFunc |
| 68 cert_verify_signature_ptr = reinterpret_cast< |
| 69 net::sha256_interception::CryptVerifyCertificateSignatureExFunc>( |
| 70 ::GetProcAddress(::GetModuleHandle(L"crypt32.dll"), |
| 71 "CryptVerifyCertificateSignatureEx")); |
| 72 CHECK(cert_verify_signature_ptr); |
| 73 |
| 74 DWORD old_protect = 0; |
| 75 if (!::VirtualProtect(cert_verify_signature_ptr, 5, PAGE_EXECUTE_READWRITE, |
| 76 &old_protect)) { |
| 77 return; |
| 78 } |
| 79 |
| 80 g_real_crypt_verify_signature_stub = |
| 81 reinterpret_cast< |
| 82 net::sha256_interception::CryptVerifyCertificateSignatureExFunc>( |
| 83 VirtualAllocEx(::GetCurrentProcess(), NULL, |
| 84 sidestep::kMaxPreambleStubSize, MEM_COMMIT, |
| 85 PAGE_EXECUTE_READWRITE)); |
| 86 if (g_real_crypt_verify_signature_stub == NULL) { |
| 87 CHECK(::VirtualProtect(cert_verify_signature_ptr, 5, old_protect, |
| 88 &old_protect)); |
| 89 return; |
| 90 } |
| 91 |
| 92 sidestep::SideStepError patch_result = |
| 93 sidestep::PreamblePatcher::Patch( |
| 94 cert_verify_signature_ptr, CryptVerifyCertificateSignatureExStub, |
| 95 g_real_crypt_verify_signature_stub, sidestep::kMaxPreambleStubSize); |
| 96 if (patch_result != sidestep::SIDESTEP_SUCCESS) { |
| 97 CHECK(::VirtualFreeEx(::GetCurrentProcess(), |
| 98 g_real_crypt_verify_signature_stub, 0, |
| 99 MEM_RELEASE)); |
| 100 CHECK(::VirtualProtect(cert_verify_signature_ptr, 5, old_protect, |
| 101 &old_protect)); |
| 102 return; |
| 103 } |
| 104 |
| 105 DWORD dummy = 0; |
| 106 CHECK(::VirtualProtect(cert_verify_signature_ptr, 5, old_protect, &dummy)); |
| 107 CHECK(::VirtualProtect(g_real_crypt_verify_signature_stub, |
| 108 sidestep::kMaxPreambleStubSize, old_protect, |
| 109 &old_protect)); |
| 110 #endif // _WIN64 |
| 111 } |
| 112 |
| 113 } // namespace |
| 114 |
| 115 #endif // OS_WIN |
| 116 |
31 class BrowserMainRunnerImpl : public BrowserMainRunner { | 117 class BrowserMainRunnerImpl : public BrowserMainRunner { |
32 public: | 118 public: |
33 BrowserMainRunnerImpl() | 119 BrowserMainRunnerImpl() |
34 : initialization_started_(false), is_shutdown_(false) {} | 120 : initialization_started_(false), is_shutdown_(false) {} |
35 | 121 |
36 virtual ~BrowserMainRunnerImpl() { | 122 virtual ~BrowserMainRunnerImpl() { |
37 if (initialization_started_ && !is_shutdown_) | 123 if (initialization_started_ && !is_shutdown_) |
38 Shutdown(); | 124 Shutdown(); |
39 } | 125 } |
40 | 126 |
(...skipping 16 matching lines...) Expand all Loading... |
57 // When "Extend support of advanced text services to all programs" | 143 // When "Extend support of advanced text services to all programs" |
58 // (a.k.a. Cicero Unaware Application Support; CUAS) is enabled on | 144 // (a.k.a. Cicero Unaware Application Support; CUAS) is enabled on |
59 // Windows XP and handwriting modules shipped with Office 2003 are | 145 // Windows XP and handwriting modules shipped with Office 2003 are |
60 // installed, "penjpn.dll" and "skchui.dll" will be loaded and then | 146 // installed, "penjpn.dll" and "skchui.dll" will be loaded and then |
61 // crash unless a user installs Office 2003 SP3. To prevent these | 147 // crash unless a user installs Office 2003 SP3. To prevent these |
62 // modules from being loaded, disable TSF entirely. crbug.com/160914. | 148 // modules from being loaded, disable TSF entirely. crbug.com/160914. |
63 // TODO(yukawa): Add a high-level wrapper for this instead of calling | 149 // TODO(yukawa): Add a high-level wrapper for this instead of calling |
64 // Win32 API here directly. | 150 // Win32 API here directly. |
65 ImmDisableTextFrameService(static_cast<DWORD>(-1)); | 151 ImmDisableTextFrameService(static_cast<DWORD>(-1)); |
66 } | 152 } |
| 153 InstallSha256LegacyHooks(); |
67 #endif // OS_WIN | 154 #endif // OS_WIN |
68 | 155 |
69 base::StatisticsRecorder::Initialize(); | 156 base::StatisticsRecorder::Initialize(); |
70 | 157 |
71 notification_service_.reset(new NotificationServiceImpl); | 158 notification_service_.reset(new NotificationServiceImpl); |
72 | 159 |
73 #if defined(OS_WIN) | 160 #if defined(OS_WIN) |
74 // Ole must be initialized before starting message pump, so that TSF | 161 // Ole must be initialized before starting message pump, so that TSF |
75 // (Text Services Framework) module can interact with the message pump | 162 // (Text Services Framework) module can interact with the message pump |
76 // on Windows 8 Metro mode. | 163 // on Windows 8 Metro mode. |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
194 | 281 |
195 DISALLOW_COPY_AND_ASSIGN(BrowserMainRunnerImpl); | 282 DISALLOW_COPY_AND_ASSIGN(BrowserMainRunnerImpl); |
196 }; | 283 }; |
197 | 284 |
198 // static | 285 // static |
199 BrowserMainRunner* BrowserMainRunner::Create() { | 286 BrowserMainRunner* BrowserMainRunner::Create() { |
200 return new BrowserMainRunnerImpl(); | 287 return new BrowserMainRunnerImpl(); |
201 } | 288 } |
202 | 289 |
203 } // namespace content | 290 } // namespace content |
OLD | NEW |