Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(308)

Side by Side Diff: remoting/host/setup/me2me_native_messaging_host_main.cc

Issue 143303007: Enable pairing registry in me2me native messaging host on Windows (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@pairing
Patch Set: Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « remoting/host/setup/me2me_native_messaging_host.cc ('k') | remoting/remoting_host.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "base/at_exit.h" 5 #include "base/at_exit.h"
6 #include "base/command_line.h" 6 #include "base/command_line.h"
7 #include "base/message_loop/message_loop.h" 7 #include "base/message_loop/message_loop.h"
8 #include "base/run_loop.h" 8 #include "base/run_loop.h"
9 #include "base/strings/string_number_conversions.h" 9 #include "base/strings/string_number_conversions.h"
10 #include "net/url_request/url_fetcher.h" 10 #include "net/url_request/url_fetcher.h"
11 #include "remoting/host/host_exit_codes.h" 11 #include "remoting/host/host_exit_codes.h"
12 #include "remoting/host/logging.h" 12 #include "remoting/host/logging.h"
13 #include "remoting/host/pairing_registry_delegate.h" 13 #include "remoting/host/pairing_registry_delegate.h"
14 #include "remoting/host/setup/me2me_native_messaging_host.h" 14 #include "remoting/host/setup/me2me_native_messaging_host.h"
15 15
16 #if defined(OS_WIN) 16 #if defined(OS_WIN)
17 #include "base/win/registry.h"
17 #include "base/win/windows_version.h" 18 #include "base/win/windows_version.h"
19 #include "remoting/host/pairing_registry_delegate_win.h"
18 #endif // defined(OS_WIN) 20 #endif // defined(OS_WIN)
19 21
22 using remoting::protocol::PairingRegistry;
23
20 namespace { 24 namespace {
21 25
22 const char kParentWindowSwitchName[] = "parent-window"; 26 const char kParentWindowSwitchName[] = "parent-window";
23 27
24 } // namespace 28 } // namespace
25 29
26 namespace remoting { 30 namespace remoting {
27 31
28 #if defined(OS_WIN) 32 #if defined(OS_WIN)
29 bool IsProcessElevated() { 33 bool IsProcessElevated() {
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 #endif 137 #endif
134 138
135 // OAuth client (for credential requests). 139 // OAuth client (for credential requests).
136 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter( 140 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter(
137 new URLRequestContextGetter(io_thread.message_loop_proxy())); 141 new URLRequestContextGetter(io_thread.message_loop_proxy()));
138 scoped_ptr<OAuthClient> oauth_client( 142 scoped_ptr<OAuthClient> oauth_client(
139 new OAuthClient(url_request_context_getter)); 143 new OAuthClient(url_request_context_getter));
140 144
141 net::URLFetcher::SetIgnoreCertificateRequests(true); 145 net::URLFetcher::SetIgnoreCertificateRequests(true);
142 146
143 // Create the pairing registry and native messaging host. 147 // Create the pairing registry.
144 scoped_refptr<protocol::PairingRegistry> pairing_registry = 148 scoped_refptr<PairingRegistry> pairing_registry;
149
150 #if defined(OS_WIN)
151 base::win::RegKey root;
152 LONG result = root.Open(HKEY_LOCAL_MACHINE, kPairingRegistryKeyName,
153 KEY_READ);
154 if (result != ERROR_SUCCESS) {
155 SetLastError(result);
156 PLOG(ERROR) << "Failed to open HKLM\\" << kPairingRegistryKeyName;
157 return kInitializationFailed;
158 }
159
160 base::win::RegKey unprivileged;
161 result = unprivileged.Open(root.Handle(), kPairingRegistrySecretsKeyName,
162 needs_elevation ? KEY_READ : KEY_READ | KEY_WRITE);
163 if (result != ERROR_SUCCESS) {
164 SetLastError(result);
165 PLOG(ERROR) << "Failed to open HKLM\\" << kPairingRegistrySecretsKeyName
166 << "\\" << kPairingRegistrySecretsKeyName;
167 return kInitializationFailed;
168 }
169
170 // Only try to open the privileged key if the current process is elevated.
171 base::win::RegKey privileged;
172 if (!needs_elevation) {
173 result = privileged.Open(root.Handle(), kPairingRegistryClientsKeyName,
174 KEY_READ | KEY_WRITE);
175 if (result != ERROR_SUCCESS) {
176 SetLastError(result);
177 PLOG(ERROR) << "Failed to open HKLM\\" << kPairingRegistryKeyName << "\\"
178 << kPairingRegistryClientsKeyName;
179 return kInitializationFailed;
180 }
181 }
182
183 // Initialize the pairing registry delegate and set the root keys.
184 scoped_ptr<PairingRegistryDelegateWin> delegate(
185 new PairingRegistryDelegateWin());
186 if (!delegate->SetRootKeys(privileged.Take(), unprivileged.Take()))
187 return kInitializationFailed;
188
189 pairing_registry = new PairingRegistry(
190 io_thread.message_loop_proxy(),
191 delegate.PassAs<PairingRegistry::Delegate>());
192 #else // defined(OS_WIN)
193 pairing_registry =
145 CreatePairingRegistry(io_thread.message_loop_proxy()); 194 CreatePairingRegistry(io_thread.message_loop_proxy());
195 #endif // !defined(OS_WIN)
146 196
147 // Set up the native messaging channel. 197 // Set up the native messaging channel.
148 scoped_ptr<NativeMessagingChannel> channel( 198 scoped_ptr<NativeMessagingChannel> channel(
149 new NativeMessagingChannel(read_file, write_file)); 199 new NativeMessagingChannel(read_file, write_file));
150 200
201 // Create the native messaging host.
151 scoped_ptr<Me2MeNativeMessagingHost> host( 202 scoped_ptr<Me2MeNativeMessagingHost> host(
152 new Me2MeNativeMessagingHost( 203 new Me2MeNativeMessagingHost(
153 needs_elevation, 204 needs_elevation,
154 channel.Pass(), 205 channel.Pass(),
155 daemon_controller, 206 daemon_controller,
156 pairing_registry, 207 pairing_registry,
157 oauth_client.Pass())); 208 oauth_client.Pass()));
158 host->Start(run_loop.QuitClosure()); 209 host->Start(run_loop.QuitClosure());
159 210
160 // Run the loop until channel is alive. 211 // Run the loop until channel is alive.
161 run_loop.Run(); 212 run_loop.Run();
162 return kSuccessExitCode; 213 return kSuccessExitCode;
163 } 214 }
164 215
165 } // namespace remoting 216 } // namespace remoting
166 217
167 int main(int argc, char** argv) { 218 int main(int argc, char** argv) {
168 // This object instance is required by Chrome code (such as MessageLoop). 219 // This object instance is required by Chrome code (such as MessageLoop).
169 base::AtExitManager exit_manager; 220 base::AtExitManager exit_manager;
170 221
171 CommandLine::Init(argc, argv); 222 CommandLine::Init(argc, argv);
172 remoting::InitHostLogging(); 223 remoting::InitHostLogging();
173 224
174 return remoting::Me2MeNativeMessagingHostMain(); 225 return remoting::Me2MeNativeMessagingHostMain();
175 } 226 }
OLDNEW
« no previous file with comments | « remoting/host/setup/me2me_native_messaging_host.cc ('k') | remoting/remoting_host.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698