diff options
author | pneubeck@chromium.org <pneubeck@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-07-30 12:24:29 +0000 |
---|---|---|
committer | pneubeck@chromium.org <pneubeck@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-07-30 12:24:29 +0000 |
commit | 8edd721868328478de1543ad4ebe74e9ae03b92a (patch) | |
tree | b164a9887593e52014948153b06cb59d730678a8 /crypto | |
parent | f7c77e5270a14b4dbad074cf0a6cf7d7769d44df (diff) | |
download | chromium_src-8edd721868328478de1543ad4ebe74e9ae03b92a.zip chromium_src-8edd721868328478de1543ad4ebe74e9ae03b92a.tar.gz chromium_src-8edd721868328478de1543ad4ebe74e9ae03b92a.tar.bz2 |
Make crypto::GetSystemNSSKeySlot asynchronous.
The system slot is set asynchronously, so the getting the system slot should happen asynchronously as well.
BUG=210525
TBR=rsleevi@chromium.org
Review URL: https://codereview.chromium.org/426983002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@286493 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'crypto')
-rw-r--r-- | crypto/nss_util.cc | 30 | ||||
-rw-r--r-- | crypto/nss_util_internal.h | 8 |
2 files changed, 26 insertions, 12 deletions
diff --git a/crypto/nss_util.cc b/crypto/nss_util.cc index 64489dc..96c13e2 100644 --- a/crypto/nss_util.cc +++ b/crypto/nss_util.cc @@ -594,18 +594,29 @@ class NSSInitSingleton { #endif #if defined(OS_CHROMEOS) - PK11SlotInfo* GetSystemNSSKeySlot() { - DCHECK(thread_checker_.CalledOnValidThread()); + void GetSystemNSSKeySlotCallback( + const base::Callback<void(ScopedPK11Slot)>& callback) { + callback.Run(ScopedPK11Slot(PK11_ReferenceSlot(tpm_slot_))); + } + ScopedPK11Slot GetSystemNSSKeySlot( + const base::Callback<void(ScopedPK11Slot)>& callback) { + DCHECK(thread_checker_.CalledOnValidThread()); // TODO(mattm): chromeos::TPMTokenloader always calls // InitializeTPMTokenAndSystemSlot with slot 0. If the system slot is // disabled, tpm_slot_ will be the first user's slot instead. Can that be // detected and return NULL instead? - if (tpm_token_enabled_for_nss_ && IsTPMTokenReady(base::Closure())) - return PK11_ReferenceSlot(tpm_slot_); - // If we were supposed to get the hardware token, but were - // unable to, return NULL rather than fall back to sofware. - return NULL; + + base::Closure wrapped_callback; + if (!callback.is_null()) { + wrapped_callback = + base::Bind(&NSSInitSingleton::GetSystemNSSKeySlotCallback, + base::Unretained(this) /* singleton is leaky */, + callback); + } + if (IsTPMTokenReady(wrapped_callback)) + return ScopedPK11Slot(PK11_ReferenceSlot(tpm_slot_)); + return ScopedPK11Slot(); } #endif @@ -1000,8 +1011,9 @@ AutoSECMODListReadLock::~AutoSECMODListReadLock() { #endif // defined(USE_NSS) #if defined(OS_CHROMEOS) -PK11SlotInfo* GetSystemNSSKeySlot() { - return g_nss_singleton.Get().GetSystemNSSKeySlot(); +ScopedPK11Slot GetSystemNSSKeySlot( + const base::Callback<void(ScopedPK11Slot)>& callback) { + return g_nss_singleton.Get().GetSystemNSSKeySlot(callback); } void SetSystemKeySlotForTesting(ScopedPK11Slot slot) { diff --git a/crypto/nss_util_internal.h b/crypto/nss_util_internal.h index c40295f..cb1b9bd 100644 --- a/crypto/nss_util_internal.h +++ b/crypto/nss_util_internal.h @@ -47,9 +47,11 @@ class CRYPTO_EXPORT AutoSECMODListReadLock { }; #if defined(OS_CHROMEOS) -// Returns a reference to the system-wide TPM slot. Caller must release returned -// reference with PK11_FreeSlot. -CRYPTO_EXPORT PK11SlotInfo* GetSystemNSSKeySlot() WARN_UNUSED_RESULT; +// Returns a reference to the system-wide TPM slot if it is loaded. If it is not +// loaded and |callback| is non-null, the |callback| will be run once the slot +// is loaded. +CRYPTO_EXPORT ScopedPK11Slot GetSystemNSSKeySlot( + const base::Callback<void(ScopedPK11Slot)>& callback) WARN_UNUSED_RESULT; // Sets the test system slot. If this was called before // InitializeTPMTokenAndSystemSlot and no system token is provided by the Chaps |