| Index: chrome/browser/extensions/api/networking_private/networking_private_credentials_getter_win.cc
|
| diff --git a/chrome/browser/extensions/api/networking_private/networking_private_credentials_getter_win.cc b/chrome/browser/extensions/api/networking_private/networking_private_credentials_getter_win.cc
|
| index 20f95030ca39d78fc3b7b9540c9e4249a678beb7..4832eb68161b46c096598457f73ab64db2b3e01c 100644
|
| --- a/chrome/browser/extensions/api/networking_private/networking_private_credentials_getter_win.cc
|
| +++ b/chrome/browser/extensions/api/networking_private/networking_private_credentials_getter_win.cc
|
| @@ -8,6 +8,7 @@
|
| #include "base/bind.h"
|
| #include "base/message_loop/message_loop.h"
|
| #include "base/threading/sequenced_worker_pool.h"
|
| +#include "chrome/common/extensions/api/networking_private/networking_private_crypto.h"
|
| #include "chrome/common/extensions/chrome_utility_extensions_messages.h"
|
| #include "content/public/browser/browser_thread.h"
|
| #include "content/public/browser/utility_process_host.h"
|
| @@ -20,7 +21,7 @@ namespace {
|
|
|
| class CredentialsGetterHostClient : public content::UtilityProcessHostClient {
|
| public:
|
| - CredentialsGetterHostClient();
|
| + explicit CredentialsGetterHostClient(const std::string& public_key);
|
|
|
| virtual ~CredentialsGetterHostClient();
|
|
|
| @@ -30,17 +31,18 @@ class CredentialsGetterHostClient : public content::UtilityProcessHostClient {
|
| virtual void OnProcessLaunchFailed() OVERRIDE;
|
|
|
| // IPC message handlers.
|
| - void OnGotEncryptedCredentials(const std::vector<uint8>& key_data,
|
| - bool success);
|
| + void OnGotCredentials(const std::string& key_data, bool success);
|
|
|
| // Starts the utility process that gets wifi passphrase from system.
|
| void StartProcessOnIOThread(
|
| const std::string& network_guid,
|
| - const std::string& public_key,
|
| const extensions::NetworkingPrivateServiceClient::CryptoVerify::
|
| VerifyAndEncryptCredentialsCallback& callback);
|
|
|
| private:
|
| + // Public key used to encrypt results
|
| + std::vector<uint8> public_key_;
|
| +
|
| // Callback for reporting the result.
|
| extensions::NetworkingPrivateServiceClient::CryptoVerify::
|
| VerifyAndEncryptCredentialsCallback callback_;
|
| @@ -48,7 +50,10 @@ class CredentialsGetterHostClient : public content::UtilityProcessHostClient {
|
| DISALLOW_COPY_AND_ASSIGN(CredentialsGetterHostClient);
|
| };
|
|
|
| -CredentialsGetterHostClient::CredentialsGetterHostClient() {}
|
| +CredentialsGetterHostClient::CredentialsGetterHostClient(
|
| + const std::string& public_key)
|
| + : public_key_(public_key.begin(), public_key.end()) {
|
| +}
|
|
|
| CredentialsGetterHostClient::~CredentialsGetterHostClient() {}
|
|
|
| @@ -56,8 +61,7 @@ bool CredentialsGetterHostClient::OnMessageReceived(
|
| const IPC::Message& message) {
|
| bool handled = true;
|
| IPC_BEGIN_MESSAGE_MAP(CredentialsGetterHostClient, message)
|
| - IPC_MESSAGE_HANDLER(ChromeUtilityHostMsg_GotEncryptedWiFiCredentials,
|
| - OnGotEncryptedCredentials)
|
| + IPC_MESSAGE_HANDLER(ChromeUtilityHostMsg_GotWiFiCredentials, OnGotCredentials)
|
| IPC_MESSAGE_UNHANDLED(handled = false)
|
| IPC_END_MESSAGE_MAP()
|
| return handled;
|
| @@ -71,12 +75,18 @@ void CredentialsGetterHostClient::OnProcessLaunchFailed() {
|
| callback_.Run("", "Process Launch Failed");
|
| }
|
|
|
| -void CredentialsGetterHostClient::OnGotEncryptedCredentials(
|
| - const std::vector<uint8>& key_data,
|
| - bool success) {
|
| +void CredentialsGetterHostClient::OnGotCredentials(const std::string& key_data,
|
| + bool success) {
|
| if (success) {
|
| + std::vector<uint8> ciphertext;
|
| + if (!networking_private_crypto::EncryptByteString(
|
| + public_key_, key_data, &ciphertext)) {
|
| + callback_.Run("", "Encrypt Credentials Failed");
|
| + return;
|
| + }
|
| +
|
| std::string base64_encoded_key_data;
|
| - base::Base64Encode(std::string(key_data.begin(), key_data.end()),
|
| + base::Base64Encode(std::string(ciphertext.begin(), ciphertext.end()),
|
| &base64_encoded_key_data);
|
| callback_.Run(base64_encoded_key_data, "");
|
| } else {
|
| @@ -86,17 +96,14 @@ void CredentialsGetterHostClient::OnGotEncryptedCredentials(
|
|
|
| void CredentialsGetterHostClient::StartProcessOnIOThread(
|
| const std::string& network_guid,
|
| - const std::string& public_key,
|
| const extensions::NetworkingPrivateServiceClient::CryptoVerify::
|
| VerifyAndEncryptCredentialsCallback& callback) {
|
| DCHECK_CURRENTLY_ON(BrowserThread::IO);
|
| - std::vector<uint8> public_key_data(public_key.begin(), public_key.end());
|
| UtilityProcessHost* host =
|
| UtilityProcessHost::Create(this, base::MessageLoopProxy::current());
|
| callback_ = callback;
|
| host->ElevatePrivileges();
|
| - host->Send(new ChromeUtilityHostMsg_GetAndEncryptWiFiCredentials(
|
| - network_guid, public_key_data));
|
| + host->Send(new ChromeUtilityHostMsg_GetWiFiCredentials(network_guid));
|
| }
|
|
|
| } // namespace
|
| @@ -132,9 +139,8 @@ void NetworkingPrivateCredentialsGetterWin::Start(
|
| BrowserThread::IO,
|
| FROM_HERE,
|
| base::Bind(&CredentialsGetterHostClient::StartProcessOnIOThread,
|
| - new CredentialsGetterHostClient(),
|
| + new CredentialsGetterHostClient(public_key),
|
| network_guid,
|
| - public_key,
|
| callback));
|
| }
|
|
|
|
|