| 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 77653d88c019ce554a92cfd588a9d51cf2464018..3436aec2d7f179f9a70d323e2309d100464bd2d1 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
|
| @@ -7,102 +7,43 @@
|
| #include "base/base64.h"
|
| #include "base/bind.h"
|
| #include "base/message_loop/message_loop.h"
|
| -#include "base/threading/sequenced_worker_pool.h"
|
| -#include "chrome/common/chrome_utility_messages.h"
|
| -#include "content/public/browser/browser_thread.h"
|
| -#include "content/public/browser/utility_process_host.h"
|
| +#include "chrome/browser/extensions/api/networking_private/networking_private_service_client.h"
|
| +#include "chrome/browser/local_discovery/wifi/credential_getter_win.h"
|
| +#include "chrome/common/extensions/api/networking_private/networking_private_crypto.h"
|
|
|
| -using content::BrowserThread;
|
| -using content::UtilityProcessHost;
|
| -using extensions::NetworkingPrivateCredentialsGetter;
|
| +using local_discovery::wifi::CredentialGetterWin;
|
|
|
| -namespace {
|
| -
|
| -class CredentialsGetterHostClient : public content::UtilityProcessHostClient {
|
| - public:
|
| - CredentialsGetterHostClient();
|
| -
|
| - virtual ~CredentialsGetterHostClient();
|
| -
|
| - // UtilityProcessHostClient
|
| - virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
|
| - virtual void OnProcessCrashed(int exit_code) OVERRIDE;
|
| - virtual void OnProcessLaunchFailed() OVERRIDE;
|
| -
|
| - // IPC message handlers.
|
| - void OnGotEncryptedCredentials(const std::vector<uint8>& 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:
|
| - // Callback for reporting the result.
|
| - extensions::NetworkingPrivateServiceClient::CryptoVerify::
|
| - VerifyAndEncryptCredentialsCallback callback_;
|
| -
|
| - DISALLOW_COPY_AND_ASSIGN(CredentialsGetterHostClient);
|
| -};
|
| -
|
| -CredentialsGetterHostClient::CredentialsGetterHostClient() {}
|
| -
|
| -CredentialsGetterHostClient::~CredentialsGetterHostClient() {}
|
| -
|
| -bool CredentialsGetterHostClient::OnMessageReceived(
|
| - const IPC::Message& message) {
|
| - bool handled = true;
|
| - IPC_BEGIN_MESSAGE_MAP(CredentialsGetterHostClient, message)
|
| - IPC_MESSAGE_HANDLER(ChromeUtilityHostMsg_GotEncryptedWiFiCredentials,
|
| - OnGotEncryptedCredentials)
|
| - IPC_MESSAGE_UNHANDLED(handled = false)
|
| - IPC_END_MESSAGE_MAP()
|
| - return handled;
|
| -}
|
| +namespace extensions {
|
|
|
| -void CredentialsGetterHostClient::OnProcessCrashed(int exit_code) {
|
| - callback_.Run("", "Process Crashed");
|
| -}
|
| +namespace {
|
|
|
| -void CredentialsGetterHostClient::OnProcessLaunchFailed() {
|
| - callback_.Run("", "Process Launch Failed");
|
| -}
|
| +void OnGotCredentials(const NetworkingPrivateServiceClient::CryptoVerify::
|
| + VerifyAndEncryptCredentialsCallback& callback,
|
| + const std::string& public_key,
|
| + bool success,
|
| + const std::string& key_data) {
|
| + std::string error;
|
| + std::string base64_encoded_ciphertext;
|
|
|
| -void CredentialsGetterHostClient::OnGotEncryptedCredentials(
|
| - const std::vector<uint8>& key_data,
|
| - bool success) {
|
| - if (success) {
|
| - std::string base64_encoded_key_data;
|
| - base::Base64Encode(std::string(key_data.begin(), key_data.end()),
|
| - &base64_encoded_key_data);
|
| - callback_.Run(base64_encoded_key_data, "");
|
| + if (!success) {
|
| + error = "Could not retrieve credentials";
|
| } else {
|
| - callback_.Run("", "Get Credentials Failed");
|
| + NetworkingPrivateCrypto crypto;
|
| + std::vector<uint8> public_key_data(public_key.begin(), public_key.end());
|
| + std::vector<uint8> ciphertext;
|
| + if (!crypto.EncryptByteString(public_key_data, key_data, &ciphertext)) {
|
| + error = "Encryption failed";
|
| + } else {
|
| + base::Base64Encode(std::string(ciphertext.begin(), ciphertext.end()),
|
| + &base64_encoded_ciphertext);
|
| + }
|
| }
|
| -}
|
|
|
| -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));
|
| + callback.Run(base64_encoded_ciphertext, error);
|
| }
|
|
|
| } // namespace
|
|
|
| -namespace extensions {
|
| -
|
| class NetworkingPrivateCredentialsGetterWin
|
| : public NetworkingPrivateCredentialsGetter {
|
| public:
|
| @@ -111,12 +52,14 @@ class NetworkingPrivateCredentialsGetterWin
|
| virtual void Start(
|
| const std::string& network_guid,
|
| const std::string& public_key,
|
| - const extensions::NetworkingPrivateServiceClient::CryptoVerify::
|
| + const NetworkingPrivateServiceClient::CryptoVerify::
|
| VerifyAndEncryptCredentialsCallback& callback) OVERRIDE;
|
|
|
| private:
|
| virtual ~NetworkingPrivateCredentialsGetterWin();
|
|
|
| + scoped_refptr<CredentialGetterWin> credentials_getter_;
|
| +
|
| DISALLOW_COPY_AND_ASSIGN(NetworkingPrivateCredentialsGetterWin);
|
| };
|
|
|
| @@ -126,16 +69,14 @@ NetworkingPrivateCredentialsGetterWin::NetworkingPrivateCredentialsGetterWin() {
|
| void NetworkingPrivateCredentialsGetterWin::Start(
|
| const std::string& network_guid,
|
| const std::string& public_key,
|
| - const extensions::NetworkingPrivateServiceClient::CryptoVerify::
|
| + const NetworkingPrivateServiceClient::CryptoVerify::
|
| VerifyAndEncryptCredentialsCallback& callback) {
|
| - BrowserThread::PostTask(
|
| - BrowserThread::IO,
|
| - FROM_HERE,
|
| - base::Bind(&CredentialsGetterHostClient::StartProcessOnIOThread,
|
| - new CredentialsGetterHostClient(),
|
| - network_guid,
|
| - public_key,
|
| - callback));
|
| + credentials_getter_ = new CredentialGetterWin();
|
| + credentials_getter_->SetCallbackRunner(
|
| + content::BrowserThread::GetMessageLoopProxyForThread(
|
| + content::BrowserThread::IO));
|
| + credentials_getter_->StartGetCredentials(
|
| + network_guid, base::Bind(&OnGotCredentials, callback, public_key));
|
| }
|
|
|
| NetworkingPrivateCredentialsGetterWin::
|
|
|