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

Unified Diff: chrome/browser/extensions/api/networking_private/networking_private_service_client.cc

Issue 102993002: Implement Networking Private API VerifyAndEncryptCredentials method (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Use utility process to get and encrypt wifi passphrase. Created 6 years, 11 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/extensions/api/networking_private/networking_private_service_client.cc
diff --git a/chrome/browser/extensions/api/networking_private/networking_private_service_client.cc b/chrome/browser/extensions/api/networking_private/networking_private_service_client.cc
index 9d5e47e5a60668e3461c40eb8e594fa6ef126413..a0278bd03312ef8f33b0969e4ba54b9a1024674a 100644
--- a/chrome/browser/extensions/api/networking_private/networking_private_service_client.cc
+++ b/chrome/browser/extensions/api/networking_private/networking_private_service_client.cc
@@ -50,15 +50,36 @@ class CryptoVerifyImpl : public NetworkingPrivateServiceClient::CryptoVerify {
virtual void VerifyDestination(scoped_ptr<base::ListValue> args,
bool* verified,
std::string* error) OVERRIDE {
- using extensions::api::networking_private::VerifyDestination::Params;
+ using api::networking_private::VerifyDestination::Params;
scoped_ptr<Params> params = Params::Create(*args);
*verified = VerifyDestination(params->properties);
}
+ virtual void VerifyAndEncryptCredentials(scoped_ptr<base::ListValue> args,
+ std::string* network_guid,
+ std::string* public_key,
+ std::string* ciphertext,
tbarzic 2014/02/07 19:25:00 arg names should match those in h file
mef 2014/02/07 19:53:31 Done.
+ std::string* error) OVERRIDE {
+ using api::networking_private::VerifyAndEncryptCredentials::Params;
+ scoped_ptr<Params> params = Params::Create(*args);
+
+ if (!VerifyDestination(params->properties)) {
+ *error = "VerifyError";
+ return;
+ }
+
+ if (!base::Base64Decode(params->properties.public_key, public_key)) {
+ *error = "DecodeError";
+ return;
+ }
+
+ *network_guid = params->guid;
+ }
+
virtual void VerifyAndEncryptData(scoped_ptr<base::ListValue> args,
std::string* base64_encoded_ciphertext,
std::string* error) OVERRIDE {
- using extensions::api::networking_private::VerifyAndEncryptData::Params;
+ using api::networking_private::VerifyAndEncryptData::Params;
scoped_ptr<Params> params = Params::Create(*args);
if (!VerifyDestination(params->properties)) {
@@ -402,6 +423,37 @@ void NetworkingPrivateServiceClient::VerifyDestination(
base::Owned(error)));
}
+void NetworkingPrivateServiceClient::VerifyAndEncryptCredentials(
+ scoped_ptr<base::ListValue> args,
+ const StringResultCallback& callback,
+ const CryptoErrorCallback& error_callback) {
+ ServiceCallbacks* service_callbacks = AddServiceCallbacks();
+ service_callbacks->crypto_error_callback = error_callback;
+ service_callbacks->verify_and_encrypt_credentials_callback = callback;
+
+ std::string* network_guid = new std::string;
+ std::string* public_key = new std::string;
+ std::string* result = new std::string;
+ std::string* error = new std::string;
+
+ task_runner_->PostTaskAndReply(
+ FROM_HERE,
+ base::Bind(&CryptoVerify::VerifyAndEncryptCredentials,
+ base::Unretained(crypto_verify_.get()),
+ base::Passed(&args),
+ network_guid,
+ public_key,
+ result,
+ error),
+ base::Bind(&NetworkingPrivateServiceClient::AfterVerifyGetWiFiPassword,
+ weak_factory_.GetWeakPtr(),
+ service_callbacks->id,
+ base::Owned(network_guid),
+ base::Owned(public_key),
+ base::Owned(result),
+ base::Owned(error)));
+}
+
void NetworkingPrivateServiceClient::VerifyAndEncryptData(
scoped_ptr<base::ListValue> args,
const StringResultCallback& callback,
@@ -536,6 +588,63 @@ void NetworkingPrivateServiceClient::AfterVerifyDestination(
RemoveServiceCallbacks(callback_id);
}
+void NetworkingPrivateServiceClient::AfterVerifyGetWiFiPassword(
+ ServiceCallbacksID callback_id,
+ const std::string* network_guid,
+ const std::string* public_key,
+ const std::string* encrypted_data,
+ const std::string* error) {
+ ServiceCallbacks* service_callbacks = callbacks_map_.Lookup(callback_id);
+ DCHECK(service_callbacks);
+ if (!error->empty()) {
+ DCHECK(!service_callbacks->crypto_error_callback.is_null());
+ service_callbacks->crypto_error_callback.Run(*error, *error);
+ } else {
+ // Credentials are fine. Now we need to launch elevated Utility Process
+ // to obtain WiFI passphrase encrypted by caller's public key.
+ // THIS is happening on UI thread!
+ // If encrypted data is not populated yet, use utility process to get it.
+ if (encrypted_data->empty()) {
+ service_callbacks->wifi_passphrase_getter = new WiFiPassphraseGetter(
+ base::Bind(
+ &NetworkingPrivateServiceClient::AfterGetAndEncryptCredentials,
+ weak_factory_.GetWeakPtr(),
+ service_callbacks->id),
+ callback_id,
+ *network_guid,
+ *public_key);
+ // This will call StartProcessOnIOThread;
mef 2014/01/28 17:51:26 After https://codereview.chromium.org/98603007/ la
+ service_callbacks->wifi_passphrase_getter->Start();
+ // Keep service_callbacks in the map until utility process returns.
+ return;
+ }
+
+ DCHECK(
+ !service_callbacks->verify_and_encrypt_credentials_callback.is_null());
+ service_callbacks->verify_and_encrypt_credentials_callback.Run(
+ *encrypted_data);
+ }
+ RemoveServiceCallbacks(callback_id);
+}
+
+void NetworkingPrivateServiceClient::AfterGetAndEncryptCredentials(
+ ServiceCallbacksID callback_id,
+ const std::string& encrypted_data,
+ const std::string& error) {
+ ServiceCallbacks* service_callbacks = callbacks_map_.Lookup(callback_id);
+ DCHECK(service_callbacks);
+ if (!error.empty()) {
+ DCHECK(!service_callbacks->crypto_error_callback.is_null());
+ service_callbacks->crypto_error_callback.Run(error, error);
+ } else {
+ DCHECK(
+ !service_callbacks->verify_and_encrypt_credentials_callback.is_null());
+ service_callbacks->verify_and_encrypt_credentials_callback.Run(
+ encrypted_data);
+ }
+ RemoveServiceCallbacks(callback_id);
+}
+
void NetworkingPrivateServiceClient::AfterVerifyAndEncryptData(
ServiceCallbacksID callback_id,
const std::string* result,

Powered by Google App Engine
This is Rietveld 408576698