Commit b301e8f6 authored by weitaosu@chromium.org's avatar weitaosu@chromium.org

Enable pairing registry in me2me native messaging host on Windows:

1. Build a standalone remoting_native_messaging_host.exe. remoting_host.exe is a win32 application (as opposed to console application) thus not suitable as a native messaging host.
2. Initialize the pairing registry reg keys in the native messaging host.
3. GetPairdClients doesn't require elevation.
4. Add the native messaging host binary and manifest and the pairing reg keys to the installer.


Enable pairing registry in Me2Me native messaging host on Windows.

BUG=325567

Review URL: https://codereview.chromium.org/143303007

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@251137 0039d316-1c4b-4281-b951-d872f2087c98
parent e3c30797
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
#include "remoting/host/host_exit_codes.h" #include "remoting/host/host_exit_codes.h"
#include "remoting/host/host_main.h" #include "remoting/host/host_main.h"
#include "remoting/host/ipc_constants.h" #include "remoting/host/ipc_constants.h"
#include "remoting/host/pairing_registry_delegate_win.h"
#include "remoting/host/screen_resolution.h" #include "remoting/host/screen_resolution.h"
#include "remoting/host/win/launch_process_with_token.h" #include "remoting/host/win/launch_process_with_token.h"
#include "remoting/host/win/unprivileged_process_delegate.h" #include "remoting/host/win/unprivileged_process_delegate.h"
...@@ -38,17 +39,6 @@ using base::TimeDelta; ...@@ -38,17 +39,6 @@ using base::TimeDelta;
namespace { namespace {
#if defined(OFFICIAL_BUILD)
const wchar_t kPairingRegistryKeyName[] =
L"SOFTWARE\\Google\\Chrome Remote Desktop\\paired-clients";
#else
const wchar_t kPairingRegistryKeyName[] =
L"SOFTWARE\\Chromoting\\paired-clients";
#endif
const wchar_t kPrivilegedKeyName[] = L"secrets";
const wchar_t kUnprivilegedKeyName[] = L"clients";
// Duplicates |key| into |target_process| and returns the value that can be sent // Duplicates |key| into |target_process| and returns the value that can be sent
// over IPC. // over IPC.
IPC::PlatformFileForTransit GetRegistryKeyForTransit( IPC::PlatformFileForTransit GetRegistryKeyForTransit(
...@@ -318,22 +308,22 @@ bool DaemonProcessWin::OpenPairingRegistry() { ...@@ -318,22 +308,22 @@ bool DaemonProcessWin::OpenPairingRegistry() {
} }
base::win::RegKey privileged; base::win::RegKey privileged;
result = privileged.Open(root.Handle(), kPrivilegedKeyName, result = privileged.Open(root.Handle(), kPairingRegistryClientsKeyName,
KEY_READ | KEY_WRITE); KEY_READ | KEY_WRITE);
if (result != ERROR_SUCCESS) { if (result != ERROR_SUCCESS) {
SetLastError(result); SetLastError(result);
PLOG(ERROR) << "Failed to open HKLM\\" << kPairingRegistryKeyName << "\\" PLOG(ERROR) << "Failed to open HKLM\\" << kPairingRegistryKeyName << "\\"
<< kPrivilegedKeyName; << kPairingRegistryClientsKeyName;
return false; return false;
} }
base::win::RegKey unprivileged; base::win::RegKey unprivileged;
result = unprivileged.Open(root.Handle(), kUnprivilegedKeyName, result = unprivileged.Open(root.Handle(), kPairingRegistrySecretsKeyName,
KEY_READ | KEY_WRITE); KEY_READ | KEY_WRITE);
if (result != ERROR_SUCCESS) { if (result != ERROR_SUCCESS) {
SetLastError(result); SetLastError(result);
PLOG(ERROR) << "Failed to open HKLM\\" << kUnprivilegedKeyName << "\\" PLOG(ERROR) << "Failed to open HKLM\\" << kPairingRegistrySecretsKeyName
<< kUnprivilegedKeyName; << "\\" << kPairingRegistrySecretsKeyName;
return false; return false;
} }
......
...@@ -188,6 +188,22 @@ ...@@ -188,6 +188,22 @@
Vital="yes"/> Vital="yes"/>
</Component> </Component>
<Component Id="remoting_native_messaging_host" Guid="*">
<File Id="remoting_native_messaging_host.exe"
DiskId="1"
KeyPath="yes"
Name="remoting_native_messaging_host.exe"
Vital="yes"/>
</Component>
<Component Id="native_messaging_host_manifest" Guid="*">
<File Id="com.google.chrome.remote_desktop.json"
DiskId="1"
KeyPath="yes"
Name="com.google.chrome.remote_desktop.json"
Vital="yes"/>
</Component>
<Component Id="icudtl" Guid="*"> <Component Id="icudtl" Guid="*">
<File Id="icudtl.dat" <File Id="icudtl.dat"
DiskId="1" DiskId="1"
...@@ -492,9 +508,28 @@ ...@@ -492,9 +508,28 @@
Windows Installer version 4.5 or lower. Also Cannot use Windows Installer version 4.5 or lower. Also Cannot use
PermissionEx in WixUtilExtension because it automatically PermissionEx in WixUtilExtension because it automatically
inherits all the ACLs from the parent. --> inherits all the ACLs from the parent. -->
<Permission User="SYSTEM" GenericAll="yes" <Permission User="SYSTEM"
ChangePermission="yes" GenericAll="yes"
TakeOwnership="yes"/> ChangePermission="yes"
TakeOwnership="yes"/>
<Permission User="Administrators"
Domain="[LOCAL_MACHINE_NAME]"
GenericAll="yes"
ChangePermission="yes"
TakeOwnership="yes"/>
</RegistryKey>
</RegistryKey>
<CreateFolder/>
</Component>
<Component Id="native_messaging_host_registry" Guid="*">
<RegistryKey Root="HKLM"
Key="SOFTWARE\Google\chrome\NativeMessagingHosts"
Action="create">
<RegistryKey Key="com.google.chrome.remote_desktop" Action="create">
<RegistryValue
Type="string"
Value="[binaries]com.google.chrome.remote_desktop.json"/>
</RegistryKey> </RegistryKey>
</RegistryKey> </RegistryKey>
<CreateFolder/> <CreateFolder/>
...@@ -600,6 +635,9 @@ ...@@ -600,6 +635,9 @@
<ComponentRef Id="omaha_registration"/> <ComponentRef Id="omaha_registration"/>
<?endif?> <?endif?>
<ComponentRef Id="icudtl"/> <ComponentRef Id="icudtl"/>
<ComponentRef Id="remoting_native_messaging_host"/>
<ComponentRef Id="native_messaging_host_manifest"/>
<ComponentRef Id="native_messaging_host_registry"/>
<ComponentRef Id="remoting_core"/> <ComponentRef Id="remoting_core"/>
<ComponentRef Id="remoting_desktop"/> <ComponentRef Id="remoting_desktop"/>
<ComponentRef Id="remoting_host"/> <ComponentRef Id="remoting_host"/>
......
...@@ -19,6 +19,17 @@ class ListValue; ...@@ -19,6 +19,17 @@ class ListValue;
namespace remoting { namespace remoting {
#if defined(OFFICIAL_BUILD)
const wchar_t kPairingRegistryKeyName[] =
L"SOFTWARE\\Google\\Chrome Remote Desktop\\paired-clients";
#else
const wchar_t kPairingRegistryKeyName[] =
L"SOFTWARE\\Chromoting\\paired-clients";
#endif
const wchar_t kPairingRegistryClientsKeyName[] = L"secrets";
const wchar_t kPairingRegistrySecretsKeyName[] = L"clients";
// Stores client pairing information in Windows registry. Two separate registry // Stores client pairing information in Windows registry. Two separate registry
// keys are used: // keys are used:
// - |privileged| - contains the shared secrets of all pairings. This key must // - |privileged| - contains the shared secrets of all pairings. This key must
......
...@@ -289,11 +289,6 @@ void Me2MeNativeMessagingHost::ProcessGetPairedClients( ...@@ -289,11 +289,6 @@ void Me2MeNativeMessagingHost::ProcessGetPairedClients(
scoped_ptr<base::DictionaryValue> response) { scoped_ptr<base::DictionaryValue> response) {
DCHECK(thread_checker_.CalledOnValidThread()); DCHECK(thread_checker_.CalledOnValidThread());
if (needs_elevation_) {
DelegateToElevatedHost(message.Pass(), response.Pass());
return;
}
if (pairing_registry_) { if (pairing_registry_) {
pairing_registry_->GetAllPairings( pairing_registry_->GetAllPairings(
base::Bind(&Me2MeNativeMessagingHost::SendPairedClientsResponse, base::Bind(&Me2MeNativeMessagingHost::SendPairedClientsResponse,
......
...@@ -14,9 +14,13 @@ ...@@ -14,9 +14,13 @@
#include "remoting/host/setup/me2me_native_messaging_host.h" #include "remoting/host/setup/me2me_native_messaging_host.h"
#if defined(OS_WIN) #if defined(OS_WIN)
#include "base/win/registry.h"
#include "base/win/windows_version.h" #include "base/win/windows_version.h"
#include "remoting/host/pairing_registry_delegate_win.h"
#endif // defined(OS_WIN) #endif // defined(OS_WIN)
using remoting::protocol::PairingRegistry;
namespace { namespace {
const char kParentWindowSwitchName[] = "parent-window"; const char kParentWindowSwitchName[] = "parent-window";
...@@ -140,14 +144,61 @@ int Me2MeNativeMessagingHostMain() { ...@@ -140,14 +144,61 @@ int Me2MeNativeMessagingHostMain() {
net::URLFetcher::SetIgnoreCertificateRequests(true); net::URLFetcher::SetIgnoreCertificateRequests(true);
// Create the pairing registry and native messaging host. // Create the pairing registry.
scoped_refptr<protocol::PairingRegistry> pairing_registry = scoped_refptr<PairingRegistry> pairing_registry;
#if defined(OS_WIN)
base::win::RegKey root;
LONG result = root.Open(HKEY_LOCAL_MACHINE, kPairingRegistryKeyName,
KEY_READ);
if (result != ERROR_SUCCESS) {
SetLastError(result);
PLOG(ERROR) << "Failed to open HKLM\\" << kPairingRegistryKeyName;
return kInitializationFailed;
}
base::win::RegKey unprivileged;
result = unprivileged.Open(root.Handle(), kPairingRegistrySecretsKeyName,
needs_elevation ? KEY_READ : KEY_READ | KEY_WRITE);
if (result != ERROR_SUCCESS) {
SetLastError(result);
PLOG(ERROR) << "Failed to open HKLM\\" << kPairingRegistrySecretsKeyName
<< "\\" << kPairingRegistrySecretsKeyName;
return kInitializationFailed;
}
// Only try to open the privileged key if the current process is elevated.
base::win::RegKey privileged;
if (!needs_elevation) {
result = privileged.Open(root.Handle(), kPairingRegistryClientsKeyName,
KEY_READ | KEY_WRITE);
if (result != ERROR_SUCCESS) {
SetLastError(result);
PLOG(ERROR) << "Failed to open HKLM\\" << kPairingRegistryKeyName << "\\"
<< kPairingRegistryClientsKeyName;
return kInitializationFailed;
}
}
// Initialize the pairing registry delegate and set the root keys.
scoped_ptr<PairingRegistryDelegateWin> delegate(
new PairingRegistryDelegateWin());
if (!delegate->SetRootKeys(privileged.Take(), unprivileged.Take()))
return kInitializationFailed;
pairing_registry = new PairingRegistry(
io_thread.message_loop_proxy(),
delegate.PassAs<PairingRegistry::Delegate>());
#else // defined(OS_WIN)
pairing_registry =
CreatePairingRegistry(io_thread.message_loop_proxy()); CreatePairingRegistry(io_thread.message_loop_proxy());
#endif // !defined(OS_WIN)
// Set up the native messaging channel. // Set up the native messaging channel.
scoped_ptr<NativeMessagingChannel> channel( scoped_ptr<NativeMessagingChannel> channel(
new NativeMessagingChannel(read_file, write_file)); new NativeMessagingChannel(read_file, write_file));
// Create the native messaging host.
scoped_ptr<Me2MeNativeMessagingHost> host( scoped_ptr<Me2MeNativeMessagingHost> host(
new Me2MeNativeMessagingHost( new Me2MeNativeMessagingHost(
needs_elevation, needs_elevation,
......
...@@ -556,6 +556,28 @@ ...@@ -556,6 +556,28 @@
'host/it2me/it2me_native_messaging_host.h', 'host/it2me/it2me_native_messaging_host.h',
], ],
}, # end of target 'remoting_it2me_host_static' }, # end of target 'remoting_it2me_host_static'
{
'target_name': 'remoting_me2me_native_messaging_host',
'type': 'executable',
'product_name': 'remoting_native_messaging_host',
'variables': { 'enable_wexit_time_destructors': 1, },
'dependencies': [
'../base/base.gyp:base',
'remoting_host',
'remoting_host_setup_base',
'remoting_native_messaging_base',
],
'sources': [
'host/setup/me2me_native_messaging_host_main.cc',
],
'conditions': [
['OS=="linux" and linux_use_tcmalloc==1', {
'dependencies': [
'../base/allocator/allocator.gyp:allocator',
],
}],
],
}, # end of target 'remoting_me2me_native_messaging_host'
{ {
'target_name': 'remoting_it2me_native_messaging_host', 'target_name': 'remoting_it2me_native_messaging_host',
'type': 'executable', 'type': 'executable',
...@@ -610,7 +632,7 @@ ...@@ -610,7 +632,7 @@
'conditions': [ 'conditions': [
[ 'OS == "win"', { [ 'OS == "win"', {
'variables': { 'variables': {
'me2me_host_path': 'remoting_host.exe', 'me2me_host_path': 'remoting_native_messaging_host.exe',
'it2me_host_path': 'remoting_assistance_host.exe', 'it2me_host_path': 'remoting_assistance_host.exe',
}, },
}], }],
...@@ -789,28 +811,6 @@ ...@@ -789,28 +811,6 @@
}], # OS=linux }], # OS=linux
], # end of 'conditions' ], # end of 'conditions'
}, # end of target 'remoting_me2me_host' }, # end of target 'remoting_me2me_host'
{
'target_name': 'remoting_me2me_native_messaging_host',
'type': 'executable',
'product_name': 'remoting_native_messaging_host',
'variables': { 'enable_wexit_time_destructors': 1, },
'dependencies': [
'../base/base.gyp:base',
'remoting_host',
'remoting_host_setup_base',
'remoting_native_messaging_base',
],
'sources': [
'host/setup/me2me_native_messaging_host_main.cc',
],
'conditions': [
['OS=="linux" and linux_use_tcmalloc==1', {
'dependencies': [
'../base/allocator/allocator.gyp:allocator',
],
}],
],
}, # end of target 'remoting_me2me_native_messaging_host'
], # end of 'targets' ], # end of 'targets'
}], # OS!="win" }], # OS!="win"
......
...@@ -465,17 +465,20 @@ ...@@ -465,17 +465,20 @@
'remoting_core', 'remoting_core',
'remoting_desktop', 'remoting_desktop',
'remoting_host_exe', 'remoting_host_exe',
'remoting_me2me_native_messaging_host',
'remoting_native_messaging_manifests', 'remoting_native_messaging_manifests',
], ],
'compiled_inputs': [ 'compiled_inputs': [
'<(PRODUCT_DIR)/remoting_core.dll', '<(PRODUCT_DIR)/remoting_core.dll',
'<(PRODUCT_DIR)/remoting_desktop.exe', '<(PRODUCT_DIR)/remoting_desktop.exe',
'<(PRODUCT_DIR)/remoting_host.exe', '<(PRODUCT_DIR)/remoting_host.exe',
'<(PRODUCT_DIR)/remoting_native_messaging_host.exe',
], ],
'compiled_inputs_dst': [ 'compiled_inputs_dst': [
'files/remoting_core.dll', 'files/remoting_core.dll',
'files/remoting_desktop.exe', 'files/remoting_desktop.exe',
'files/remoting_host.exe', 'files/remoting_host.exe',
'files/remoting_native_messaging_host.exe',
], ],
'conditions': [ 'conditions': [
['buildtype == "Official"', { ['buildtype == "Official"', {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment