#include "remoting/host/setup/me2me_native_messaging_host.h"
#include <cstdint>
#include <memory>
#include <optional>
#include <string>
#include <utility>
#include "base/command_line.h"
#include "base/functional/bind.h"
#include "base/functional/callback.h"
#include "base/json/json_reader.h"
#include "base/json/json_writer.h"
#include "base/logging.h"
#include "base/strings/stringize_macros.h"
#include "base/task/single_thread_task_runner.h"
#include "base/time/time.h"
#include "base/values.h"
#include "build/build_config.h"
#include "google_apis/gaia/gaia_oauth_client.h"
#include "google_apis/google_api_keys.h"
#include "net/base/network_interfaces.h"
#include "remoting/base/auto_thread_task_runner.h"
#include "remoting/base/oauth_client.h"
#include "remoting/base/rsa_key_pair.h"
#include "remoting/host/chromoting_host_context.h"
#include "remoting/host/native_messaging/log_message_handler.h"
#include "remoting/host/pin_hash.h"
#include "remoting/protocol/pairing_registry.h"
#if BUILDFLAG(IS_WIN)
#include "remoting/host/win/elevated_native_messaging_host.h"
#endif
namespace {
#if BUILDFLAG(IS_WIN)
const int kElevatedHostTimeoutSeconds = 300;
#endif
const char* kSupportedFeatures[] = …;
std::optional<base::Value::Dict> ConfigDictionaryFromMessage(
base::Value::Dict message) { … }
}
namespace remoting {
Me2MeNativeMessagingHost::Me2MeNativeMessagingHost(
bool needs_elevation,
intptr_t parent_window_handle,
std::unique_ptr<ChromotingHostContext> host_context,
scoped_refptr<DaemonController> daemon_controller,
scoped_refptr<protocol::PairingRegistry> pairing_registry,
std::unique_ptr<OAuthClient> oauth_client)
: … { … }
Me2MeNativeMessagingHost::~Me2MeNativeMessagingHost() { … }
void Me2MeNativeMessagingHost::OnMessage(const std::string& message) { … }
void Me2MeNativeMessagingHost::Start(Client* client) { … }
scoped_refptr<base::SingleThreadTaskRunner>
Me2MeNativeMessagingHost::task_runner() const { … }
void Me2MeNativeMessagingHost::ProcessHello(base::Value::Dict message,
base::Value::Dict response) { … }
void Me2MeNativeMessagingHost::ProcessClearPairedClients(
base::Value::Dict message,
base::Value::Dict response) { … }
void Me2MeNativeMessagingHost::ProcessDeletePairedClient(
base::Value::Dict message,
base::Value::Dict response) { … }
void Me2MeNativeMessagingHost::ProcessGetHostName(base::Value::Dict message,
base::Value::Dict response) { … }
void Me2MeNativeMessagingHost::ProcessGetPinHash(base::Value::Dict message,
base::Value::Dict response) { … }
void Me2MeNativeMessagingHost::ProcessGenerateKeyPair(
base::Value::Dict message,
base::Value::Dict response) { … }
void Me2MeNativeMessagingHost::ProcessUpdateDaemonConfig(
base::Value::Dict message,
base::Value::Dict response) { … }
void Me2MeNativeMessagingHost::ProcessGetDaemonConfig(
base::Value::Dict message,
base::Value::Dict response) { … }
void Me2MeNativeMessagingHost::ProcessGetPairedClients(
base::Value::Dict message,
base::Value::Dict response) { … }
void Me2MeNativeMessagingHost::ProcessGetUsageStatsConsent(
base::Value::Dict message,
base::Value::Dict response) { … }
void Me2MeNativeMessagingHost::ProcessStartDaemon(base::Value::Dict message,
base::Value::Dict response) { … }
void Me2MeNativeMessagingHost::ProcessStopDaemon(base::Value::Dict message,
base::Value::Dict response) { … }
void Me2MeNativeMessagingHost::ProcessGetDaemonState(
base::Value::Dict message,
base::Value::Dict response) { … }
void Me2MeNativeMessagingHost::ProcessGetHostClientId(
base::Value::Dict message,
base::Value::Dict response) { … }
void Me2MeNativeMessagingHost::ProcessGetCredentialsFromAuthCode(
base::Value::Dict message,
base::Value::Dict response,
bool need_user_email) { … }
void Me2MeNativeMessagingHost::ProcessIt2mePermissionCheck(
base::Value::Dict message,
base::Value::Dict response) { … }
void Me2MeNativeMessagingHost::SendConfigResponse(
base::Value::Dict response,
std::optional<base::Value::Dict> config) { … }
void Me2MeNativeMessagingHost::SendPairedClientsResponse(
base::Value::Dict response,
base::Value::List pairings) { … }
void Me2MeNativeMessagingHost::SendUsageStatsConsentResponse(
base::Value::Dict response,
const DaemonController::UsageStatsConsent& consent) { … }
void Me2MeNativeMessagingHost::SendAsyncResult(
base::Value::Dict response,
DaemonController::AsyncResult result) { … }
void Me2MeNativeMessagingHost::SendBooleanResult(base::Value::Dict response,
bool result) { … }
void Me2MeNativeMessagingHost::SendCredentialsResponse(
base::Value::Dict response,
const std::string& user_email,
const std::string& refresh_token) { … }
void Me2MeNativeMessagingHost::SendMessageToClient(
base::Value::Dict message) const { … }
void Me2MeNativeMessagingHost::OnError(const std::string& error_message) { … }
#if BUILDFLAG(IS_WIN)
Me2MeNativeMessagingHost::DelegationResult
Me2MeNativeMessagingHost::DelegateToElevatedHost(base::Value::Dict message) {
DCHECK(task_runner()->BelongsToCurrentThread());
DCHECK(needs_elevation_);
if (!elevated_host_) {
elevated_host_ = std::make_unique<ElevatedNativeMessagingHost>(
base::CommandLine::ForCurrentProcess()->GetProgram(),
parent_window_handle_,
true, base::Seconds(kElevatedHostTimeoutSeconds),
client_);
}
ProcessLaunchResult result = elevated_host_->EnsureElevatedHostCreated();
if (result == PROCESS_LAUNCH_RESULT_SUCCESS) {
elevated_host_->SendMessage(message);
}
switch (result) {
case PROCESS_LAUNCH_RESULT_SUCCESS:
return DELEGATION_SUCCESS;
case PROCESS_LAUNCH_RESULT_CANCELLED:
return DELEGATION_CANCELLED;
case PROCESS_LAUNCH_RESULT_FAILED:
return DELEGATION_FAILED;
}
}
#else
Me2MeNativeMessagingHost::DelegationResult
Me2MeNativeMessagingHost::DelegateToElevatedHost(base::Value::Dict message) { … }
#endif
}