Commit d6cfe11e authored by Christos Froussios's avatar Christos Froussios Committed by Commit Bot

[OSCrypt] Use general threading implemention for KeyStorageKeyring

We now have a general implementation for dedicated TaskRunners for
OSCrypt's backends. The custom threading implementation for
KeyStorageKeyring can be removed and replaced with the general one.

Bug: 782851
Change-Id: I61b0df8568504d4160bbcce7301e99fbdb86609a
Reviewed-on: https://chromium-review.googlesource.com/804094Reviewed-by: default avatarVaclav Brozek <vabr@chromium.org>
Commit-Queue: Christos Froussios <cfroussios@chromium.org>
Cr-Commit-Position: refs/heads/master@{#521014}
parent 2049eab9
...@@ -9,8 +9,6 @@ ...@@ -9,8 +9,6 @@
#include "base/rand_util.h" #include "base/rand_util.h"
#include "base/single_thread_task_runner.h" #include "base/single_thread_task_runner.h"
#include "base/strings/string_number_conversions.h" #include "base/strings/string_number_conversions.h"
#include "base/synchronization/waitable_event.h"
#include "base/threading/thread.h"
#include "components/os_crypt/keyring_util_linux.h" #include "components/os_crypt/keyring_util_linux.h"
namespace { namespace {
...@@ -33,50 +31,34 @@ KeyStorageKeyring::KeyStorageKeyring( ...@@ -33,50 +31,34 @@ KeyStorageKeyring::KeyStorageKeyring(
KeyStorageKeyring::~KeyStorageKeyring() {} KeyStorageKeyring::~KeyStorageKeyring() {}
base::SequencedTaskRunner* KeyStorageKeyring::GetTaskRunner() {
return main_thread_runner_.get();
}
bool KeyStorageKeyring::Init() { bool KeyStorageKeyring::Init() {
DCHECK(main_thread_runner_->RunsTasksInCurrentSequence());
return GnomeKeyringLoader::LoadGnomeKeyring(); return GnomeKeyringLoader::LoadGnomeKeyring();
} }
std::string KeyStorageKeyring::GetKeyImpl() { std::string KeyStorageKeyring::GetKeyImpl() {
std::string password; DCHECK(main_thread_runner_->RunsTasksInCurrentSequence());
// Ensure GetKeyDelegate() is executed on the main thread.
if (main_thread_runner_->BelongsToCurrentThread()) {
GetKeyDelegate(&password, nullptr);
} else {
base::WaitableEvent password_loaded(
base::WaitableEvent::ResetPolicy::MANUAL,
base::WaitableEvent::InitialState::NOT_SIGNALED);
main_thread_runner_->PostTask(
FROM_HERE,
base::Bind(&KeyStorageKeyring::GetKeyDelegate, base::Unretained(this),
&password, &password_loaded));
password_loaded.Wait();
}
return password; std::string password;
} gchar* password_c = nullptr;
void KeyStorageKeyring::GetKeyDelegate(
std::string* password_ptr,
base::WaitableEvent* password_loaded_ptr) {
gchar* password = nullptr;
GnomeKeyringResult result = GnomeKeyringResult result =
GnomeKeyringLoader::gnome_keyring_find_password_sync_ptr( GnomeKeyringLoader::gnome_keyring_find_password_sync_ptr(
&kSchema, &password, "application", kApplicationName, nullptr); &kSchema, &password_c, "application", kApplicationName, nullptr);
if (result == GNOME_KEYRING_RESULT_OK) { if (result == GNOME_KEYRING_RESULT_OK) {
*password_ptr = password; password = password_c;
GnomeKeyringLoader::gnome_keyring_free_password_ptr(password); GnomeKeyringLoader::gnome_keyring_free_password_ptr(password_c);
} else if (result == GNOME_KEYRING_RESULT_NO_MATCH) { } else if (result == GNOME_KEYRING_RESULT_NO_MATCH) {
*password_ptr = KeyStorageKeyring::AddRandomPasswordInKeyring(); password = KeyStorageKeyring::AddRandomPasswordInKeyring();
VLOG(1) << "OSCrypt generated a new password"; VLOG(1) << "OSCrypt generated a new password";
} else { } else {
password_ptr->clear();
VLOG(1) << "OSCrypt failed to use gnome-keyring"; VLOG(1) << "OSCrypt failed to use gnome-keyring";
} }
if (password_loaded_ptr) return password;
password_loaded_ptr->Signal();
} }
std::string KeyStorageKeyring::AddRandomPasswordInKeyring() { std::string KeyStorageKeyring::AddRandomPasswordInKeyring() {
......
...@@ -13,7 +13,6 @@ ...@@ -13,7 +13,6 @@
namespace base { namespace base {
class SingleThreadTaskRunner; class SingleThreadTaskRunner;
class WaitableEvent;
} // namespace base } // namespace base
// Specialisation of KeyStorageLinux that uses Libsecret. // Specialisation of KeyStorageLinux that uses Libsecret.
...@@ -25,17 +24,11 @@ class KeyStorageKeyring : public KeyStorageLinux { ...@@ -25,17 +24,11 @@ class KeyStorageKeyring : public KeyStorageLinux {
protected: protected:
// KeyStorageLinux // KeyStorageLinux
base::SequencedTaskRunner* GetTaskRunner() override;
bool Init() override; bool Init() override;
std::string GetKeyImpl() override; std::string GetKeyImpl() override;
private: private:
// Gnome keyring requires calls to originate from the main thread.
// This is the part of GetKey() that gets dispatched to the main thread.
// The password is stored in |password_ptr|. If |password_loaded_ptr| is not
// null, it will be signaled when |password_ptr| is safe to read.
void GetKeyDelegate(std::string* password_ptr,
base::WaitableEvent* password_loaded_ptr);
// Generate a random string and store it as OScrypt's new password. // Generate a random string and store it as OScrypt's new password.
std::string AddRandomPasswordInKeyring(); std::string AddRandomPasswordInKeyring();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment