summaryrefslogtreecommitdiffstats
path: root/remoting
diff options
context:
space:
mode:
authorrmsousa@chromium.org <rmsousa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-08-16 22:29:52 +0000
committerrmsousa@chromium.org <rmsousa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-08-16 22:29:52 +0000
commit1aec34523835ab4dafcd3f24ee808e3f6c34f230 (patch)
treea5eedc945e1dd5aa4a1f289d81aa165e273e00b9 /remoting
parentf4c6ad8b98692604c8de80df46367bec479fe5ce (diff)
downloadchromium_src-1aec34523835ab4dafcd3f24ee808e3f6c34f230.zip
chromium_src-1aec34523835ab4dafcd3f24ee808e3f6c34f230.tar.gz
chromium_src-1aec34523835ab4dafcd3f24ee808e3f6c34f230.tar.bz2
Service account setup for headless Linux hosts
BUG=224742 Review URL: https://chromiumcodereview.appspot.com/22992002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@218106 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'remoting')
-rw-r--r--remoting/host/setup/host_starter.cc60
-rw-r--r--remoting/host/setup/host_starter.h8
-rw-r--r--remoting/host/setup/service_client.cc51
-rw-r--r--remoting/host/setup/service_client.h3
4 files changed, 95 insertions, 27 deletions
diff --git a/remoting/host/setup/host_starter.cc b/remoting/host/setup/host_starter.cc
index d16137b..3a0646b 100644
--- a/remoting/host/setup/host_starter.cc
+++ b/remoting/host/setup/host_starter.cc
@@ -95,30 +95,72 @@ void HostStarter::OnRefreshTokenResponse(
NOTREACHED();
}
+// This function is called twice: once with the host owner credentials, and once
+// with the service account credentials.
void HostStarter::OnGetUserEmailResponse(const std::string& user_email) {
if (!main_task_runner_->BelongsToCurrentThread()) {
main_task_runner_->PostTask(FROM_HERE, base::Bind(
&HostStarter::OnGetUserEmailResponse, weak_ptr_, user_email));
return;
}
- user_email_ = user_email;
- // Register the host.
- host_id_ = base::GenerateGUID();
- key_pair_ = RsaKeyPair::Generate();
- service_client_->RegisterHost(
- host_id_, host_name_, key_pair_->GetPublicKey(), access_token_, this);
+
+ if (host_owner_.empty()) {
+ // This is the first callback, with the host owner credentials. Store the
+ // owner's email, and register the host.
+ host_owner_ = user_email;
+ host_id_ = base::GenerateGUID();
+ key_pair_ = RsaKeyPair::Generate();
+
+ std::string host_client_id;
+ host_client_id = google_apis::GetOAuth2ClientID(
+ google_apis::CLIENT_REMOTING_HOST);
+
+ service_client_->RegisterHost(
+ host_id_, host_name_, key_pair_->GetPublicKey(), host_client_id,
+ access_token_, this);
+ } else {
+ // This is the second callback, with the service account credentials.
+ // This email is the service account's email, used to login to XMPP.
+ xmpp_login_ = user_email;
+ StartHostProcess();
+ }
}
-void HostStarter::OnHostRegistered() {
+void HostStarter::OnHostRegistered(const std::string& authorization_code) {
if (!main_task_runner_->BelongsToCurrentThread()) {
main_task_runner_->PostTask(FROM_HERE, base::Bind(
- &HostStarter::OnHostRegistered, weak_ptr_));
+ &HostStarter::OnHostRegistered, weak_ptr_, authorization_code));
+ return;
+ }
+
+ if (authorization_code.empty()) {
+ // No service account code, start the host with the owner's credentials.
+ xmpp_login_ = host_owner_;
+ StartHostProcess();
return;
}
+
+ // Received a service account authorization code, update oauth_client_info_
+ // to use the service account client keys, and get service account tokens.
+ oauth_client_info_.client_id =
+ google_apis::GetOAuth2ClientID(
+ google_apis::CLIENT_REMOTING_HOST);
+ oauth_client_info_.client_secret =
+ google_apis::GetOAuth2ClientSecret(
+ google_apis::CLIENT_REMOTING_HOST);
+ oauth_client_info_.redirect_uri = "oob";
+ oauth_client_->GetTokensFromAuthCode(
+ oauth_client_info_, authorization_code, kMaxGetTokensRetries, this);
+}
+
+void HostStarter::StartHostProcess() {
// Start the host.
std::string host_secret_hash = remoting::MakeHostPinHash(host_id_, host_pin_);
scoped_ptr<base::DictionaryValue> config(new base::DictionaryValue());
- config->SetString("xmpp_login", user_email_);
+ if (host_owner_ != xmpp_login_) {
+ config->SetString("host_owner", host_owner_);
+ }
+ config->SetString("xmpp_login", xmpp_login_);
config->SetString("oauth_refresh_token", refresh_token_);
config->SetString("host_id", host_id_);
config->SetString("host_name", host_name_);
diff --git a/remoting/host/setup/host_starter.h b/remoting/host/setup/host_starter.h
index a51f299..3bb2e3e 100644
--- a/remoting/host/setup/host_starter.h
+++ b/remoting/host/setup/host_starter.h
@@ -55,7 +55,7 @@ class HostStarter : public gaia::GaiaOAuthClient::Delegate,
virtual void OnGetUserEmailResponse(const std::string& user_email) OVERRIDE;
// remoting::ServiceClient::Delegate
- virtual void OnHostRegistered() OVERRIDE;
+ virtual void OnHostRegistered(const std::string& authorization_code) OVERRIDE;
virtual void OnHostUnregistered() OVERRIDE;
// TODO(sergeyu): Following methods are members of all three delegate
@@ -70,6 +70,8 @@ class HostStarter : public gaia::GaiaOAuthClient::Delegate,
scoped_ptr<remoting::ServiceClient> service_client,
scoped_ptr<remoting::DaemonController> daemon_controller);
+ void StartHostProcess();
+
void OnHostStarted(DaemonController::AsyncResult result);
scoped_ptr<gaia::GaiaOAuthClient> oauth_client_;
@@ -83,9 +85,11 @@ class HostStarter : public gaia::GaiaOAuthClient::Delegate,
scoped_refptr<base::SingleThreadTaskRunner> main_task_runner_;
std::string refresh_token_;
std::string access_token_;
- std::string user_email_;
+ std::string host_owner_;
+ std::string xmpp_login_;
scoped_refptr<remoting::RsaKeyPair> key_pair_;
std::string host_id_;
+ bool use_service_account_;
base::WeakPtrFactory<HostStarter> weak_ptr_factory_;
base::WeakPtr<HostStarter> weak_ptr_;
diff --git a/remoting/host/setup/service_client.cc b/remoting/host/setup/service_client.cc
index c7bc22e..215b04e 100644
--- a/remoting/host/setup/service_client.cc
+++ b/remoting/host/setup/service_client.cc
@@ -4,6 +4,7 @@
#include "remoting/host/setup/service_client.h"
+#include "base/json/json_reader.h"
#include "base/json/json_writer.h"
#include "base/memory/scoped_ptr.h"
#include "base/values.h"
@@ -30,6 +31,7 @@ class ServiceClient::Core
void RegisterHost(const std::string& host_id,
const std::string& host_name,
const std::string& public_key,
+ const std::string& host_client_id,
const std::string& oauth_access_token,
ServiceClient::Delegate* delegate);
@@ -50,7 +52,7 @@ class ServiceClient::Core
PENDING_REQUEST_UNREGISTER_HOST
};
- void MakeGaiaRequest(net::URLFetcher::RequestType request_type,
+ void MakeChromotingRequest(net::URLFetcher::RequestType request_type,
const std::string& post_body,
const std::string& url_suffix,
const std::string& oauth_access_token,
@@ -68,6 +70,7 @@ void ServiceClient::Core::RegisterHost(
const std::string& host_id,
const std::string& host_name,
const std::string& public_key,
+ const std::string& host_client_id,
const std::string& oauth_access_token,
Delegate* delegate) {
DCHECK(pending_request_type_ == PENDING_REQUEST_NONE);
@@ -76,13 +79,16 @@ void ServiceClient::Core::RegisterHost(
post_body.SetString("data.hostId", host_id);
post_body.SetString("data.hostName", host_name);
post_body.SetString("data.publicKey", public_key);
+ std::string url_suffix;
+ if (!host_client_id.empty())
+ url_suffix = "?hostClientId=" + host_client_id;
std::string post_body_str;
base::JSONWriter::Write(&post_body, &post_body_str);
- MakeGaiaRequest(net::URLFetcher::POST,
- std::string(),
- post_body_str,
- oauth_access_token,
- delegate);
+ MakeChromotingRequest(net::URLFetcher::POST,
+ url_suffix,
+ post_body_str,
+ oauth_access_token,
+ delegate);
}
void ServiceClient::Core::UnregisterHost(
@@ -91,14 +97,14 @@ void ServiceClient::Core::UnregisterHost(
Delegate* delegate) {
DCHECK(pending_request_type_ == PENDING_REQUEST_NONE);
pending_request_type_ = PENDING_REQUEST_UNREGISTER_HOST;
- MakeGaiaRequest(net::URLFetcher::DELETE_REQUEST,
- host_id,
- std::string(),
- oauth_access_token,
- delegate);
+ MakeChromotingRequest(net::URLFetcher::DELETE_REQUEST,
+ host_id,
+ std::string(),
+ oauth_access_token,
+ delegate);
}
-void ServiceClient::Core::MakeGaiaRequest(
+void ServiceClient::Core::MakeChromotingRequest(
net::URLFetcher::RequestType request_type,
const std::string& url_suffix,
const std::string& request_body,
@@ -133,7 +139,21 @@ void ServiceClient::Core::HandleResponse(const net::URLFetcher* source) {
case PENDING_REQUEST_NONE:
break;
case PENDING_REQUEST_REGISTER_HOST:
- delegate_->OnHostRegistered();
+ {
+ std::string data;
+ source->GetResponseAsString(&data);
+ scoped_ptr<Value> message_value(base::JSONReader::Read(data));
+ DictionaryValue *dict;
+ std::string code;
+ if (message_value.get() &&
+ message_value->IsType(Value::TYPE_DICTIONARY) &&
+ message_value->GetAsDictionary(&dict) &&
+ dict->GetString("data.authorizationCode", &code)) {
+ delegate_->OnHostRegistered(code);
+ } else {
+ delegate_->OnHostRegistered(std::string());
+ }
+ }
break;
case PENDING_REQUEST_UNREGISTER_HOST:
delegate_->OnHostUnregistered();
@@ -156,10 +176,11 @@ void ServiceClient::RegisterHost(
const std::string& host_id,
const std::string& host_name,
const std::string& public_key,
+ const std::string& host_client_id,
const std::string& oauth_access_token,
Delegate* delegate) {
- return core_->RegisterHost(host_id, host_name, public_key, oauth_access_token,
- delegate);
+ return core_->RegisterHost(host_id, host_name, public_key, host_client_id,
+ oauth_access_token, delegate);
}
void ServiceClient::UnregisterHost(
diff --git a/remoting/host/setup/service_client.h b/remoting/host/setup/service_client.h
index 5ae2144..eaa26ab 100644
--- a/remoting/host/setup/service_client.h
+++ b/remoting/host/setup/service_client.h
@@ -22,7 +22,7 @@ class ServiceClient {
class Delegate {
public:
// Invoked when a host has been registered.
- virtual void OnHostRegistered() = 0;
+ virtual void OnHostRegistered(const std::string& authorization_code) = 0;
// Invoked when a host has been unregistered.
virtual void OnHostUnregistered() = 0;
// Invoked when there is an OAuth error.
@@ -42,6 +42,7 @@ class ServiceClient {
void RegisterHost(const std::string& host_id,
const std::string& host_name,
const std::string& public_key,
+ const std::string& host_client_id,
const std::string& oauth_access_token,
Delegate* delegate);
// Unregister a host.