Commit 82065f2b authored by pneubeck's avatar pneubeck Committed by Commit bot

Handle empty username_hash in ClientCertFilterChromeOS.

The Init() function did never call back if the username_hash was empty, because GetPrivateSlotForChromeOSUser would return a nullptr and InitIfSlotsAvailable returning consistently false.

Now the callback will be called once GetPrivateSlotForChromeOSUser returned.

This change is on purpose kept minimal to allow merging to M40.

BUG=434205

Review URL: https://codereview.chromium.org/802433002

Cr-Commit-Position: refs/heads/master@{#308191}
parent 30ee9094
...@@ -16,6 +16,7 @@ ClientCertFilterChromeOS::ClientCertFilterChromeOS( ...@@ -16,6 +16,7 @@ ClientCertFilterChromeOS::ClientCertFilterChromeOS(
: init_called_(false), : init_called_(false),
use_system_slot_(use_system_slot), use_system_slot_(use_system_slot),
username_hash_(username_hash), username_hash_(username_hash),
waiting_for_private_slot_(false),
weak_ptr_factory_(this) { weak_ptr_factory_(this) {
} }
...@@ -26,16 +27,25 @@ bool ClientCertFilterChromeOS::Init(const base::Closure& callback) { ...@@ -26,16 +27,25 @@ bool ClientCertFilterChromeOS::Init(const base::Closure& callback) {
DCHECK(!init_called_); DCHECK(!init_called_);
init_called_ = true; init_called_ = true;
waiting_for_private_slot_ = true;
if (use_system_slot_) { if (use_system_slot_) {
system_slot_ = crypto::GetSystemNSSKeySlot( system_slot_ = crypto::GetSystemNSSKeySlot(
base::Bind(&ClientCertFilterChromeOS::GotSystemSlot, base::Bind(&ClientCertFilterChromeOS::GotSystemSlot,
weak_ptr_factory_.GetWeakPtr())).Pass(); weak_ptr_factory_.GetWeakPtr())).Pass();
} }
private_slot_ = private_slot_ =
crypto::GetPrivateSlotForChromeOSUser( crypto::GetPrivateSlotForChromeOSUser(
username_hash_, base::Bind(&ClientCertFilterChromeOS::GotPrivateSlot, username_hash_, base::Bind(&ClientCertFilterChromeOS::GotPrivateSlot,
weak_ptr_factory_.GetWeakPtr())).Pass(); weak_ptr_factory_.GetWeakPtr())).Pass();
// If the returned slot is null, GotPrivateSlot will be called back
// eventually. If it is not null, the private slot was available synchronously
// and the callback will not be called.
if (private_slot_)
waiting_for_private_slot_ = false;
// Do not call back if we initialized synchronously. // Do not call back if we initialized synchronously.
if (InitIfSlotsAvailable()) if (InitIfSlotsAvailable())
return true; return true;
...@@ -60,6 +70,7 @@ void ClientCertFilterChromeOS::GotSystemSlot( ...@@ -60,6 +70,7 @@ void ClientCertFilterChromeOS::GotSystemSlot(
void ClientCertFilterChromeOS::GotPrivateSlot( void ClientCertFilterChromeOS::GotPrivateSlot(
crypto::ScopedPK11Slot private_slot) { crypto::ScopedPK11Slot private_slot) {
waiting_for_private_slot_ = false;
private_slot_ = private_slot.Pass(); private_slot_ = private_slot.Pass();
if (InitIfSlotsAvailable() && !init_callback_.is_null()) { if (InitIfSlotsAvailable() && !init_callback_.is_null()) {
init_callback_.Run(); init_callback_.Run();
...@@ -68,7 +79,7 @@ void ClientCertFilterChromeOS::GotPrivateSlot( ...@@ -68,7 +79,7 @@ void ClientCertFilterChromeOS::GotPrivateSlot(
} }
bool ClientCertFilterChromeOS::InitIfSlotsAvailable() { bool ClientCertFilterChromeOS::InitIfSlotsAvailable() {
if ((use_system_slot_ && !system_slot_) || !private_slot_) if ((use_system_slot_ && !system_slot_) || waiting_for_private_slot_)
return false; return false;
nss_profile_filter_.Init(crypto::GetPublicSlotForChromeOSUser(username_hash_), nss_profile_filter_.Init(crypto::GetPublicSlotForChromeOSUser(username_hash_),
private_slot_.Pass(), private_slot_.Pass(),
......
...@@ -23,6 +23,7 @@ class ClientCertFilterChromeOS ...@@ -23,6 +23,7 @@ class ClientCertFilterChromeOS
// The internal NSSProfileFilterChromeOS will be initialized with the public // The internal NSSProfileFilterChromeOS will be initialized with the public
// and private slot of the user with |username_hash| and with the system slot // and private slot of the user with |username_hash| and with the system slot
// if |use_system_slot| is true. // if |use_system_slot| is true.
// If |username_hash| is empty, no public and no private slot will be used.
ClientCertFilterChromeOS(bool use_system_slot, ClientCertFilterChromeOS(bool use_system_slot,
const std::string& username_hash); const std::string& username_hash);
~ClientCertFilterChromeOS() override; ~ClientCertFilterChromeOS() override;
...@@ -64,6 +65,11 @@ class ClientCertFilterChromeOS ...@@ -64,6 +65,11 @@ class ClientCertFilterChromeOS
// filter is initialized. // filter is initialized.
crypto::ScopedPK11Slot private_slot_; crypto::ScopedPK11Slot private_slot_;
// If a private slot is requested but the slot, maybe null, is not obtained
// yet, this is equal true. As long as this is true, the NSSProfileFilter will
// not be initialized.
bool waiting_for_private_slot_;
net::NSSProfileFilterChromeOS nss_profile_filter_; net::NSSProfileFilterChromeOS nss_profile_filter_;
base::WeakPtrFactory<ClientCertFilterChromeOS> weak_ptr_factory_; base::WeakPtrFactory<ClientCertFilterChromeOS> weak_ptr_factory_;
}; };
......
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