OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "crypto/nss_util.h" | 5 #include "crypto/nss_util.h" |
6 #include "crypto/nss_util_internal.h" | 6 #include "crypto/nss_util_internal.h" |
7 | 7 |
8 #include <nss.h> | 8 #include <nss.h> |
9 #include <pk11pub.h> | 9 #include <pk11pub.h> |
10 #include <plarena.h> | 10 #include <plarena.h> |
11 #include <prerror.h> | 11 #include <prerror.h> |
12 #include <prinit.h> | 12 #include <prinit.h> |
13 #include <prtime.h> | 13 #include <prtime.h> |
14 #include <secmod.h> | 14 #include <secmod.h> |
15 | 15 |
16 #if defined(OS_OPENBSD) | 16 #if defined(OS_OPENBSD) |
17 #include <sys/mount.h> | 17 #include <sys/mount.h> |
18 #include <sys/param.h> | 18 #include <sys/param.h> |
19 #endif | 19 #endif |
20 | 20 |
21 #include <map> | 21 #include <map> |
22 #include <vector> | 22 #include <vector> |
23 | 23 |
24 #include "base/bind.h" | 24 #include "base/bind.h" |
25 #include "base/callback.h" | |
26 #include "base/cpu.h" | 25 #include "base/cpu.h" |
27 #include "base/debug/alias.h" | 26 #include "base/debug/alias.h" |
28 #include "base/debug/stack_trace.h" | 27 #include "base/debug/stack_trace.h" |
29 #include "base/environment.h" | 28 #include "base/environment.h" |
30 #include "base/file_util.h" | 29 #include "base/file_util.h" |
31 #include "base/files/file_path.h" | 30 #include "base/files/file_path.h" |
32 #include "base/lazy_instance.h" | 31 #include "base/lazy_instance.h" |
33 #include "base/logging.h" | 32 #include "base/logging.h" |
34 #include "base/memory/scoped_ptr.h" | 33 #include "base/memory/scoped_ptr.h" |
35 #include "base/message_loop/message_loop.h" | 34 #include "base/message_loop/message_loop.h" |
36 #include "base/metrics/histogram.h" | 35 #include "base/metrics/histogram.h" |
37 #include "base/native_library.h" | 36 #include "base/native_library.h" |
38 #include "base/stl_util.h" | 37 #include "base/stl_util.h" |
39 #include "base/strings/stringprintf.h" | 38 #include "base/strings/stringprintf.h" |
40 #include "base/threading/thread_checker.h" | 39 #include "base/threading/thread_checker.h" |
41 #include "base/threading/thread_restrictions.h" | 40 #include "base/threading/thread_restrictions.h" |
| 41 #include "base/threading/worker_pool.h" |
42 #include "build/build_config.h" | 42 #include "build/build_config.h" |
43 | 43 |
44 // USE_NSS means we use NSS for everything crypto-related. If USE_NSS is not | 44 // USE_NSS means we use NSS for everything crypto-related. If USE_NSS is not |
45 // defined, such as on Mac and Windows, we use NSS for SSL only -- we don't | 45 // defined, such as on Mac and Windows, we use NSS for SSL only -- we don't |
46 // use NSS for crypto or certificate verification, and we don't use the NSS | 46 // use NSS for crypto or certificate verification, and we don't use the NSS |
47 // certificate and key databases. | 47 // certificate and key databases. |
48 #if defined(USE_NSS) | 48 #if defined(USE_NSS) |
49 #include "base/synchronization/lock.h" | 49 #include "base/synchronization/lock.h" |
50 #include "crypto/nss_crypto_module_delegate.h" | 50 #include "crypto/nss_crypto_module_delegate.h" |
51 #endif // defined(USE_NSS) | 51 #endif // defined(USE_NSS) |
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
258 | 258 |
259 typedef std::vector<base::Callback<void(ScopedPK11Slot)> > | 259 typedef std::vector<base::Callback<void(ScopedPK11Slot)> > |
260 SlotReadyCallbackList; | 260 SlotReadyCallbackList; |
261 SlotReadyCallbackList tpm_ready_callback_list_; | 261 SlotReadyCallbackList tpm_ready_callback_list_; |
262 }; | 262 }; |
263 #endif // defined(OS_CHROMEOS) | 263 #endif // defined(OS_CHROMEOS) |
264 | 264 |
265 class NSSInitSingleton { | 265 class NSSInitSingleton { |
266 public: | 266 public: |
267 #if defined(OS_CHROMEOS) | 267 #if defined(OS_CHROMEOS) |
| 268 // Used with PostTaskAndReply to pass handles to worker thread and back. |
| 269 struct TPMModuleAndSlot { |
| 270 explicit TPMModuleAndSlot(SECMODModule* init_chaps_module) |
| 271 : chaps_module(init_chaps_module), tpm_slot(NULL) {} |
| 272 SECMODModule* chaps_module; |
| 273 PK11SlotInfo* tpm_slot; |
| 274 }; |
| 275 |
268 void OpenPersistentNSSDB() { | 276 void OpenPersistentNSSDB() { |
269 DCHECK(thread_checker_.CalledOnValidThread()); | 277 DCHECK(thread_checker_.CalledOnValidThread()); |
270 | 278 |
271 if (!chromeos_user_logged_in_) { | 279 if (!chromeos_user_logged_in_) { |
272 // GetDefaultConfigDirectory causes us to do blocking IO on UI thread. | 280 // GetDefaultConfigDirectory causes us to do blocking IO on UI thread. |
273 // Temporarily allow it until we fix http://crbug.com/70119 | 281 // Temporarily allow it until we fix http://crbug.com/70119 |
274 base::ThreadRestrictions::ScopedAllowIO allow_io; | 282 base::ThreadRestrictions::ScopedAllowIO allow_io; |
275 chromeos_user_logged_in_ = true; | 283 chromeos_user_logged_in_ = true; |
276 | 284 |
277 // This creates another DB slot in NSS that is read/write, unlike | 285 // This creates another DB slot in NSS that is read/write, unlike |
(...skipping 27 matching lines...) Expand all Loading... |
305 // private keys, otherwise we'll fall back to the software | 313 // private keys, otherwise we'll fall back to the software |
306 // implementation. | 314 // implementation. |
307 tpm_token_enabled_for_nss_ = true; | 315 tpm_token_enabled_for_nss_ = true; |
308 } | 316 } |
309 | 317 |
310 bool IsTPMTokenEnabledForNSS() { | 318 bool IsTPMTokenEnabledForNSS() { |
311 DCHECK(thread_checker_.CalledOnValidThread()); | 319 DCHECK(thread_checker_.CalledOnValidThread()); |
312 return tpm_token_enabled_for_nss_; | 320 return tpm_token_enabled_for_nss_; |
313 } | 321 } |
314 | 322 |
315 bool InitializeTPMToken(int token_slot_id) { | 323 void InitializeTPMToken(int token_slot_id, |
| 324 const base::Callback<void(bool)>& callback) { |
316 DCHECK(thread_checker_.CalledOnValidThread()); | 325 DCHECK(thread_checker_.CalledOnValidThread()); |
317 | 326 // Should not be called while there is already an initialization in |
| 327 // progress. |
| 328 DCHECK(!initializing_tpm_token_); |
318 // If EnableTPMTokenForNSS hasn't been called, return false. | 329 // If EnableTPMTokenForNSS hasn't been called, return false. |
319 if (!tpm_token_enabled_for_nss_) | 330 if (!tpm_token_enabled_for_nss_) { |
320 return false; | 331 base::MessageLoop::current()->PostTask(FROM_HERE, |
| 332 base::Bind(callback, false)); |
| 333 return; |
| 334 } |
321 | 335 |
322 // If everything is already initialized, then return true. | 336 // If everything is already initialized, then return true. |
323 if (chaps_module_ && tpm_slot_) | 337 // Note that only |tpm_slot_| is checked, since |chaps_module_| could be |
324 return true; | 338 // NULL in tests while |tpm_slot_| has been set to the test DB. |
| 339 if (tpm_slot_) { |
| 340 base::MessageLoop::current()->PostTask(FROM_HERE, |
| 341 base::Bind(callback, true)); |
| 342 return; |
| 343 } |
325 | 344 |
| 345 // Note that a reference is not taken to chaps_module_. This is safe since |
| 346 // NSSInitSingleton is Leaky, so the reference it holds is never released. |
| 347 scoped_ptr<TPMModuleAndSlot> tpm_args(new TPMModuleAndSlot(chaps_module_)); |
| 348 TPMModuleAndSlot* tpm_args_ptr = tpm_args.get(); |
| 349 if (base::WorkerPool::PostTaskAndReply( |
| 350 FROM_HERE, |
| 351 base::Bind(&NSSInitSingleton::InitializeTPMTokenOnWorkerThread, |
| 352 token_slot_id, |
| 353 tpm_args_ptr), |
| 354 base::Bind(&NSSInitSingleton::OnInitializedTPMToken, |
| 355 base::Unretained(this), // NSSInitSingleton is leaky |
| 356 callback, |
| 357 base::Passed(&tpm_args)), |
| 358 true /* task_is_slow */ |
| 359 )) { |
| 360 initializing_tpm_token_ = true; |
| 361 } else { |
| 362 base::MessageLoop::current()->PostTask(FROM_HERE, |
| 363 base::Bind(callback, false)); |
| 364 } |
| 365 } |
| 366 |
| 367 static void InitializeTPMTokenOnWorkerThread(CK_SLOT_ID token_slot_id, |
| 368 TPMModuleAndSlot* tpm_args) { |
326 // This tries to load the Chaps module so NSS can talk to the hardware | 369 // This tries to load the Chaps module so NSS can talk to the hardware |
327 // TPM. | 370 // TPM. |
328 if (!chaps_module_) { | 371 if (!tpm_args->chaps_module) { |
329 chaps_module_ = LoadModule( | 372 DVLOG(3) << "Loading chaps..."; |
| 373 tpm_args->chaps_module = LoadModule( |
330 kChapsModuleName, | 374 kChapsModuleName, |
331 kChapsPath, | 375 kChapsPath, |
332 // For more details on these parameters, see: | 376 // For more details on these parameters, see: |
333 // https://developer.mozilla.org/en/PKCS11_Module_Specs | 377 // https://developer.mozilla.org/en/PKCS11_Module_Specs |
334 // slotFlags=[PublicCerts] -- Certificates and public keys can be | 378 // slotFlags=[PublicCerts] -- Certificates and public keys can be |
335 // read from this slot without requiring a call to C_Login. | 379 // read from this slot without requiring a call to C_Login. |
336 // askpw=only -- Only authenticate to the token when necessary. | 380 // askpw=only -- Only authenticate to the token when necessary. |
337 "NSS=\"slotParams=(0={slotFlags=[PublicCerts] askpw=only})\""); | 381 "NSS=\"slotParams=(0={slotFlags=[PublicCerts] askpw=only})\""); |
338 if (!chaps_module_ && test_slot_) { | |
339 // chromeos_unittests try to test the TPM initialization process. If we | |
340 // have a test DB open, pretend that it is the TPM slot. | |
341 tpm_slot_ = PK11_ReferenceSlot(test_slot_); | |
342 return true; | |
343 } | |
344 } | 382 } |
345 if (chaps_module_){ | 383 if (tpm_args->chaps_module) { |
346 tpm_slot_ = GetTPMSlotForId(token_slot_id); | 384 tpm_args->tpm_slot = |
| 385 GetTPMSlotForIdOnWorkerThread(tpm_args->chaps_module, token_slot_id); |
| 386 } |
| 387 } |
347 | 388 |
348 if (!tpm_slot_) | 389 void OnInitializedTPMToken(const base::Callback<void(bool)>& callback, |
349 return false; | 390 scoped_ptr<TPMModuleAndSlot> tpm_args) { |
| 391 DCHECK(thread_checker_.CalledOnValidThread()); |
| 392 DVLOG(2) << "Loaded chaps: " << !!tpm_args->chaps_module |
| 393 << ", got tpm slot: " << !!tpm_args->tpm_slot; |
350 | 394 |
| 395 chaps_module_ = tpm_args->chaps_module; |
| 396 tpm_slot_ = tpm_args->tpm_slot; |
| 397 if (!chaps_module_ && test_slot_) { |
| 398 // chromeos_unittests try to test the TPM initialization process. If we |
| 399 // have a test DB open, pretend that it is the TPM slot. |
| 400 tpm_slot_ = PK11_ReferenceSlot(test_slot_); |
| 401 } |
| 402 initializing_tpm_token_ = false; |
| 403 |
| 404 if (tpm_slot_) { |
351 TPMReadyCallbackList callback_list; | 405 TPMReadyCallbackList callback_list; |
352 callback_list.swap(tpm_ready_callback_list_); | 406 callback_list.swap(tpm_ready_callback_list_); |
353 for (TPMReadyCallbackList::iterator i = | 407 for (TPMReadyCallbackList::iterator i = callback_list.begin(); |
354 callback_list.begin(); | |
355 i != callback_list.end(); | 408 i != callback_list.end(); |
356 ++i) { | 409 ++i) { |
357 (*i).Run(); | 410 (*i).Run(); |
358 } | 411 } |
| 412 } |
359 | 413 |
360 return true; | 414 callback.Run(!!tpm_slot_); |
361 } | |
362 return false; | |
363 } | 415 } |
364 | 416 |
365 bool IsTPMTokenReady(const base::Closure& callback) { | 417 bool IsTPMTokenReady(const base::Closure& callback) { |
366 if (!callback.is_null()) { | 418 if (!callback.is_null()) { |
367 // Cannot DCHECK in the general case yet, but since the callback is | 419 // Cannot DCHECK in the general case yet, but since the callback is |
368 // a new addition to the API, DCHECK to make sure at least the new uses | 420 // a new addition to the API, DCHECK to make sure at least the new uses |
369 // don't regress. | 421 // don't regress. |
370 DCHECK(thread_checker_.CalledOnValidThread()); | 422 DCHECK(thread_checker_.CalledOnValidThread()); |
371 } else if (!thread_checker_.CalledOnValidThread()) { | 423 } else if (!thread_checker_.CalledOnValidThread()) { |
372 // TODO(mattm): Change to DCHECK when callers have been fixed. | 424 // TODO(mattm): Change to DCHECK when callers have been fixed. |
373 DVLOG(1) << "Called on wrong thread.\n" | 425 DVLOG(1) << "Called on wrong thread.\n" |
374 << base::debug::StackTrace().ToString(); | 426 << base::debug::StackTrace().ToString(); |
375 } | 427 } |
376 | 428 |
377 if (tpm_slot_ != NULL) | 429 if (tpm_slot_ != NULL) |
378 return true; | 430 return true; |
379 | 431 |
380 if (!callback.is_null()) | 432 if (!callback.is_null()) |
381 tpm_ready_callback_list_.push_back(callback); | 433 tpm_ready_callback_list_.push_back(callback); |
382 | 434 |
383 return false; | 435 return false; |
384 } | 436 } |
385 | 437 |
386 // Note that CK_SLOT_ID is an unsigned long, but cryptohome gives us the slot | 438 // Note that CK_SLOT_ID is an unsigned long, but cryptohome gives us the slot |
387 // id as an int. This should be safe since this is only used with chaps, which | 439 // id as an int. This should be safe since this is only used with chaps, which |
388 // we also control. | 440 // we also control. |
389 PK11SlotInfo* GetTPMSlotForId(CK_SLOT_ID slot_id) { | 441 static PK11SlotInfo* GetTPMSlotForIdOnWorkerThread(SECMODModule* chaps_module, |
390 DCHECK(thread_checker_.CalledOnValidThread()); | 442 CK_SLOT_ID slot_id) { |
391 | 443 DCHECK(chaps_module); |
392 if (!chaps_module_) | |
393 return NULL; | |
394 | 444 |
395 DVLOG(3) << "Poking chaps module."; | 445 DVLOG(3) << "Poking chaps module."; |
396 SECStatus rv = SECMOD_UpdateSlotList(chaps_module_); | 446 SECStatus rv = SECMOD_UpdateSlotList(chaps_module); |
397 if (rv != SECSuccess) | 447 if (rv != SECSuccess) |
398 PLOG(ERROR) << "SECMOD_UpdateSlotList failed: " << PORT_GetError(); | 448 PLOG(ERROR) << "SECMOD_UpdateSlotList failed: " << PORT_GetError(); |
399 | 449 |
400 PK11SlotInfo* slot = SECMOD_LookupSlot(chaps_module_->moduleID, slot_id); | 450 PK11SlotInfo* slot = SECMOD_LookupSlot(chaps_module->moduleID, slot_id); |
401 if (!slot) | 451 if (!slot) |
402 LOG(ERROR) << "TPM slot " << slot_id << " not found."; | 452 LOG(ERROR) << "TPM slot " << slot_id << " not found."; |
403 return slot; | 453 return slot; |
404 } | 454 } |
405 | 455 |
406 bool InitializeNSSForChromeOSUser( | 456 bool InitializeNSSForChromeOSUser( |
407 const std::string& email, | 457 const std::string& email, |
408 const std::string& username_hash, | 458 const std::string& username_hash, |
409 bool is_primary_user, | 459 bool is_primary_user, |
410 const base::FilePath& path) { | 460 const base::FilePath& path) { |
(...skipping 13 matching lines...) Expand all Loading... |
424 } | 474 } |
425 chromeos_user_map_[username_hash] = | 475 chromeos_user_map_[username_hash] = |
426 new ChromeOSUserData(public_slot.Pass(), is_primary_user); | 476 new ChromeOSUserData(public_slot.Pass(), is_primary_user); |
427 return true; | 477 return true; |
428 } | 478 } |
429 | 479 |
430 void InitializeTPMForChromeOSUser(const std::string& username_hash, | 480 void InitializeTPMForChromeOSUser(const std::string& username_hash, |
431 CK_SLOT_ID slot_id) { | 481 CK_SLOT_ID slot_id) { |
432 DCHECK(thread_checker_.CalledOnValidThread()); | 482 DCHECK(thread_checker_.CalledOnValidThread()); |
433 DCHECK(chromeos_user_map_.find(username_hash) != chromeos_user_map_.end()); | 483 DCHECK(chromeos_user_map_.find(username_hash) != chromeos_user_map_.end()); |
434 chromeos_user_map_[username_hash] | 484 |
435 ->SetPrivateSlot(ScopedPK11Slot(GetTPMSlotForId(slot_id))); | 485 if (!chaps_module_) |
| 486 return; |
| 487 |
| 488 // Note that a reference is not taken to chaps_module_. This is safe since |
| 489 // NSSInitSingleton is Leaky, so the reference it holds is never released. |
| 490 scoped_ptr<TPMModuleAndSlot> tpm_args(new TPMModuleAndSlot(chaps_module_)); |
| 491 TPMModuleAndSlot* tpm_args_ptr = tpm_args.get(); |
| 492 base::WorkerPool::PostTaskAndReply( |
| 493 FROM_HERE, |
| 494 base::Bind(&NSSInitSingleton::InitializeTPMTokenOnWorkerThread, |
| 495 slot_id, |
| 496 tpm_args_ptr), |
| 497 base::Bind(&NSSInitSingleton::OnInitializedTPMForChromeOSUser, |
| 498 base::Unretained(this), // NSSInitSingleton is leaky |
| 499 username_hash, |
| 500 base::Passed(&tpm_args)), |
| 501 true /* task_is_slow */ |
| 502 ); |
| 503 } |
| 504 |
| 505 void OnInitializedTPMForChromeOSUser(const std::string& username_hash, |
| 506 scoped_ptr<TPMModuleAndSlot> tpm_args) { |
| 507 DCHECK(thread_checker_.CalledOnValidThread()); |
| 508 DVLOG(2) << "Got tpm slot for " << username_hash << " " |
| 509 << !!tpm_args->tpm_slot; |
| 510 chromeos_user_map_[username_hash]->SetPrivateSlot( |
| 511 ScopedPK11Slot(tpm_args->tpm_slot)); |
436 } | 512 } |
437 | 513 |
438 void InitializePrivateSoftwareSlotForChromeOSUser( | 514 void InitializePrivateSoftwareSlotForChromeOSUser( |
439 const std::string& username_hash) { | 515 const std::string& username_hash) { |
440 DCHECK(thread_checker_.CalledOnValidThread()); | 516 DCHECK(thread_checker_.CalledOnValidThread()); |
441 VLOG(1) << "using software private slot for " << username_hash; | 517 VLOG(1) << "using software private slot for " << username_hash; |
442 DCHECK(chromeos_user_map_.find(username_hash) != chromeos_user_map_.end()); | 518 DCHECK(chromeos_user_map_.find(username_hash) != chromeos_user_map_.end()); |
443 chromeos_user_map_[username_hash]->SetPrivateSlot( | 519 chromeos_user_map_[username_hash]->SetPrivateSlot( |
444 chromeos_user_map_[username_hash]->GetPublicSlot()); | 520 chromeos_user_map_[username_hash]->GetPublicSlot()); |
445 } | 521 } |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
583 // Call this method before NSSInitSingleton() is constructed. | 659 // Call this method before NSSInitSingleton() is constructed. |
584 static void ForceNoDBInit() { | 660 static void ForceNoDBInit() { |
585 force_nodb_init_ = true; | 661 force_nodb_init_ = true; |
586 } | 662 } |
587 | 663 |
588 private: | 664 private: |
589 friend struct base::DefaultLazyInstanceTraits<NSSInitSingleton>; | 665 friend struct base::DefaultLazyInstanceTraits<NSSInitSingleton>; |
590 | 666 |
591 NSSInitSingleton() | 667 NSSInitSingleton() |
592 : tpm_token_enabled_for_nss_(false), | 668 : tpm_token_enabled_for_nss_(false), |
| 669 initializing_tpm_token_(false), |
593 chaps_module_(NULL), | 670 chaps_module_(NULL), |
594 software_slot_(NULL), | 671 software_slot_(NULL), |
595 test_slot_(NULL), | 672 test_slot_(NULL), |
596 tpm_slot_(NULL), | 673 tpm_slot_(NULL), |
597 root_(NULL), | 674 root_(NULL), |
598 chromeos_user_logged_in_(false) { | 675 chromeos_user_logged_in_(false) { |
599 base::TimeTicks start_time = base::TimeTicks::Now(); | 676 base::TimeTicks start_time = base::TimeTicks::Now(); |
600 | 677 |
601 // It's safe to construct on any thread, since LazyInstance will prevent any | 678 // It's safe to construct on any thread, since LazyInstance will prevent any |
602 // other threads from accessing until the constructor is done. | 679 // other threads from accessing until the constructor is done. |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
747 if (root) | 824 if (root) |
748 return root; | 825 return root; |
749 | 826 |
750 // Aw, snap. Can't find/load root cert shared library. | 827 // Aw, snap. Can't find/load root cert shared library. |
751 // This will make it hard to talk to anybody via https. | 828 // This will make it hard to talk to anybody via https. |
752 // TODO(mattm): Re-add the NOTREACHED here when crbug.com/310972 is fixed. | 829 // TODO(mattm): Re-add the NOTREACHED here when crbug.com/310972 is fixed. |
753 return NULL; | 830 return NULL; |
754 } | 831 } |
755 | 832 |
756 // Load the given module for this NSS session. | 833 // Load the given module for this NSS session. |
757 SECMODModule* LoadModule(const char* name, | 834 static SECMODModule* LoadModule(const char* name, |
758 const char* library_path, | 835 const char* library_path, |
759 const char* params) { | 836 const char* params) { |
760 std::string modparams = base::StringPrintf( | 837 std::string modparams = base::StringPrintf( |
761 "name=\"%s\" library=\"%s\" %s", | 838 "name=\"%s\" library=\"%s\" %s", |
762 name, library_path, params ? params : ""); | 839 name, library_path, params ? params : ""); |
763 | 840 |
764 // Shouldn't need to const_cast here, but SECMOD doesn't properly | 841 // Shouldn't need to const_cast here, but SECMOD doesn't properly |
765 // declare input string arguments as const. Bug | 842 // declare input string arguments as const. Bug |
766 // https://bugzilla.mozilla.org/show_bug.cgi?id=642546 was filed | 843 // https://bugzilla.mozilla.org/show_bug.cgi?id=642546 was filed |
767 // on NSS codebase to address this. | 844 // on NSS codebase to address this. |
768 SECMODModule* module = SECMOD_LoadUserModule( | 845 SECMODModule* module = SECMOD_LoadUserModule( |
769 const_cast<char*>(modparams.c_str()), NULL, PR_FALSE); | 846 const_cast<char*>(modparams.c_str()), NULL, PR_FALSE); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
811 if (cpu.has_avx_hardware() && !cpu.has_avx()) { | 888 if (cpu.has_avx_hardware() && !cpu.has_avx()) { |
812 base::Environment::Create()->SetVar("NSS_DISABLE_HW_AES", "1"); | 889 base::Environment::Create()->SetVar("NSS_DISABLE_HW_AES", "1"); |
813 } | 890 } |
814 } | 891 } |
815 } | 892 } |
816 | 893 |
817 // If this is set to true NSS is forced to be initialized without a DB. | 894 // If this is set to true NSS is forced to be initialized without a DB. |
818 static bool force_nodb_init_; | 895 static bool force_nodb_init_; |
819 | 896 |
820 bool tpm_token_enabled_for_nss_; | 897 bool tpm_token_enabled_for_nss_; |
| 898 bool initializing_tpm_token_; |
821 typedef std::vector<base::Closure> TPMReadyCallbackList; | 899 typedef std::vector<base::Closure> TPMReadyCallbackList; |
822 TPMReadyCallbackList tpm_ready_callback_list_; | 900 TPMReadyCallbackList tpm_ready_callback_list_; |
823 SECMODModule* chaps_module_; | 901 SECMODModule* chaps_module_; |
824 PK11SlotInfo* software_slot_; | 902 PK11SlotInfo* software_slot_; |
825 PK11SlotInfo* test_slot_; | 903 PK11SlotInfo* test_slot_; |
826 PK11SlotInfo* tpm_slot_; | 904 PK11SlotInfo* tpm_slot_; |
827 SECMODModule* root_; | 905 SECMODModule* root_; |
828 bool chromeos_user_logged_in_; | 906 bool chromeos_user_logged_in_; |
829 #if defined(OS_CHROMEOS) | 907 #if defined(OS_CHROMEOS) |
830 typedef std::map<std::string, ChromeOSUserData*> ChromeOSUserMap; | 908 typedef std::map<std::string, ChromeOSUserData*> ChromeOSUserMap; |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
998 } | 1076 } |
999 | 1077 |
1000 bool IsTPMTokenEnabledForNSS() { | 1078 bool IsTPMTokenEnabledForNSS() { |
1001 return g_nss_singleton.Get().IsTPMTokenEnabledForNSS(); | 1079 return g_nss_singleton.Get().IsTPMTokenEnabledForNSS(); |
1002 } | 1080 } |
1003 | 1081 |
1004 bool IsTPMTokenReady(const base::Closure& callback) { | 1082 bool IsTPMTokenReady(const base::Closure& callback) { |
1005 return g_nss_singleton.Get().IsTPMTokenReady(callback); | 1083 return g_nss_singleton.Get().IsTPMTokenReady(callback); |
1006 } | 1084 } |
1007 | 1085 |
1008 bool InitializeTPMToken(int token_slot_id) { | 1086 void InitializeTPMToken(int token_slot_id, |
1009 return g_nss_singleton.Get().InitializeTPMToken(token_slot_id); | 1087 const base::Callback<void(bool)>& callback) { |
| 1088 g_nss_singleton.Get().InitializeTPMToken(token_slot_id, callback); |
1010 } | 1089 } |
1011 | 1090 |
1012 ScopedTestNSSChromeOSUser::ScopedTestNSSChromeOSUser( | 1091 ScopedTestNSSChromeOSUser::ScopedTestNSSChromeOSUser( |
1013 const std::string& username_hash) | 1092 const std::string& username_hash) |
1014 : username_hash_(username_hash), constructed_successfully_(false) { | 1093 : username_hash_(username_hash), constructed_successfully_(false) { |
1015 if (!temp_dir_.CreateUniqueTempDir()) | 1094 if (!temp_dir_.CreateUniqueTempDir()) |
1016 return; | 1095 return; |
1017 constructed_successfully_ = | 1096 constructed_successfully_ = |
1018 InitializeNSSForChromeOSUser(username_hash, | 1097 InitializeNSSForChromeOSUser(username_hash, |
1019 username_hash, | 1098 username_hash, |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1070 | 1149 |
1071 PK11SlotInfo* GetPublicNSSKeySlot() { | 1150 PK11SlotInfo* GetPublicNSSKeySlot() { |
1072 return g_nss_singleton.Get().GetPublicNSSKeySlot(); | 1151 return g_nss_singleton.Get().GetPublicNSSKeySlot(); |
1073 } | 1152 } |
1074 | 1153 |
1075 PK11SlotInfo* GetPrivateNSSKeySlot() { | 1154 PK11SlotInfo* GetPrivateNSSKeySlot() { |
1076 return g_nss_singleton.Get().GetPrivateNSSKeySlot(); | 1155 return g_nss_singleton.Get().GetPrivateNSSKeySlot(); |
1077 } | 1156 } |
1078 | 1157 |
1079 } // namespace crypto | 1158 } // namespace crypto |
OLD | NEW |