#include "base/base64.h"
#include "base/bind.h"
-#include "base/memory/scoped_handle.h"
#include "base/message_loop/message_loop.h"
#include "base/threading/sequenced_worker_pool.h"
-#include "chrome/common/chrome_utility_messages.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"
class CredentialsGetterHostClient : public content::UtilityProcessHostClient {
public:
- CredentialsGetterHostClient();
+ explicit CredentialsGetterHostClient(const std::string& public_key);
virtual ~CredentialsGetterHostClient();
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_;
DISALLOW_COPY_AND_ASSIGN(CredentialsGetterHostClient);
};
-CredentialsGetterHostClient::CredentialsGetterHostClient() {}
+CredentialsGetterHostClient::CredentialsGetterHostClient(
+ const std::string& public_key)
+ : public_key_(public_key.begin(), public_key.end()) {
+}
CredentialsGetterHostClient::~CredentialsGetterHostClient() {}
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;
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 {
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
BrowserThread::IO,
FROM_HERE,
base::Bind(&CredentialsGetterHostClient::StartProcessOnIOThread,
- new CredentialsGetterHostClient(),
+ new CredentialsGetterHostClient(public_key),
network_guid,
- public_key,
callback));
}