| 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 d9925cc52a74d23f982de09c6cf1bc09280e5794..a287abb9723bcf429f1ed66d0f305210b6d9dba5 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
|
| @@ -49,15 +49,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,
|
| + 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)) {
|
| @@ -411,6 +432,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,
|
| @@ -545,6 +597,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.reset(WiFiPassphraseGetter::Create(
|
| + base::Bind(
|
| + &NetworkingPrivateServiceClient::AfterGetAndEncryptCredentials,
|
| + weak_factory_.GetWeakPtr(),
|
| + service_callbacks->id),
|
| + callback_id,
|
| + *network_guid,
|
| + *public_key));
|
| + // This will call StartProcessOnIOThread;
|
| + 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,
|
|
|