Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(394)

Side by Side Diff: crypto/nss_util.cc

Issue 317613004: Remove usage of singleton software_slot_ in nss on ChromeOS (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « crypto/nss_util.h ('k') | crypto/nss_util_internal.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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>
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 scoped_ptr<char[]> error_text(new char[PR_GetErrorTextLength() + 1]); 74 scoped_ptr<char[]> error_text(new char[PR_GetErrorTextLength() + 1]);
75 PRInt32 copied = PR_GetErrorText(error_text.get()); 75 PRInt32 copied = PR_GetErrorText(error_text.get());
76 result = std::string(error_text.get(), copied); 76 result = std::string(error_text.get(), copied);
77 } else { 77 } else {
78 result = base::StringPrintf("NSS error code: %d", PR_GetError()); 78 result = base::StringPrintf("NSS error code: %d", PR_GetError());
79 } 79 }
80 return result; 80 return result;
81 } 81 }
82 82
83 #if defined(USE_NSS) 83 #if defined(USE_NSS)
84 #if !defined(OS_CHROMEOS)
84 base::FilePath GetDefaultConfigDirectory() { 85 base::FilePath GetDefaultConfigDirectory() {
85 base::FilePath dir; 86 base::FilePath dir;
86 PathService::Get(base::DIR_HOME, &dir); 87 PathService::Get(base::DIR_HOME, &dir);
87 if (dir.empty()) { 88 if (dir.empty()) {
88 LOG(ERROR) << "Failed to get home directory."; 89 LOG(ERROR) << "Failed to get home directory.";
89 return dir; 90 return dir;
90 } 91 }
91 dir = dir.AppendASCII(".pki").AppendASCII("nssdb"); 92 dir = dir.AppendASCII(".pki").AppendASCII("nssdb");
92 if (!base::CreateDirectory(dir)) { 93 if (!base::CreateDirectory(dir)) {
93 LOG(ERROR) << "Failed to create " << dir.value() << " directory."; 94 LOG(ERROR) << "Failed to create " << dir.value() << " directory.";
94 dir.clear(); 95 dir.clear();
95 } 96 }
96 DVLOG(2) << "DefaultConfigDirectory: " << dir.value(); 97 DVLOG(2) << "DefaultConfigDirectory: " << dir.value();
97 return dir; 98 return dir;
98 } 99 }
100 #endif // !defined(IS_CHROMEOS)
99 101
100 // On non-Chrome OS platforms, return the default config directory. On Chrome OS 102 // On non-Chrome OS platforms, return the default config directory. On Chrome OS
101 // test images, return a read-only directory with fake root CA certs (which are 103 // test images, return a read-only directory with fake root CA certs (which are
102 // used by the local Google Accounts server mock we use when testing our login 104 // used by the local Google Accounts server mock we use when testing our login
103 // code). On Chrome OS non-test images (where the read-only directory doesn't 105 // code). On Chrome OS non-test images (where the read-only directory doesn't
104 // exist), return an empty path. 106 // exist), return an empty path.
105 base::FilePath GetInitialConfigDirectory() { 107 base::FilePath GetInitialConfigDirectory() {
106 #if defined(OS_CHROMEOS) 108 #if defined(OS_CHROMEOS)
107 base::FilePath database_dir = base::FilePath(kReadOnlyCertDB); 109 base::FilePath database_dir = base::FilePath(kReadOnlyCertDB);
108 if (!base::PathExists(database_dir)) 110 if (!base::PathExists(database_dir))
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 base::debug::Alias(&nss_error); 211 base::debug::Alias(&nss_error);
210 base::debug::Alias(&os_error); 212 base::debug::Alias(&os_error);
211 LOG(ERROR) << "Error initializing NSS without a persistent database: " 213 LOG(ERROR) << "Error initializing NSS without a persistent database: "
212 << GetNSSErrorMessage(); 214 << GetNSSErrorMessage();
213 LOG(FATAL) << "nss_error=" << nss_error << ", os_error=" << os_error; 215 LOG(FATAL) << "nss_error=" << nss_error << ", os_error=" << os_error;
214 } 216 }
215 217
216 #if defined(OS_CHROMEOS) 218 #if defined(OS_CHROMEOS)
217 class ChromeOSUserData { 219 class ChromeOSUserData {
218 public: 220 public:
219 ChromeOSUserData(ScopedPK11Slot public_slot, bool is_primary_user) 221 explicit ChromeOSUserData(ScopedPK11Slot public_slot)
220 : public_slot_(public_slot.Pass()), 222 : public_slot_(public_slot.Pass()),
221 is_primary_user_(is_primary_user) {} 223 private_slot_initialization_started_(false) {}
222 ~ChromeOSUserData() { 224 ~ChromeOSUserData() {
223 if (public_slot_ && !is_primary_user_) { 225 if (public_slot_) {
224 SECStatus status = SECMOD_CloseUserDB(public_slot_.get()); 226 SECStatus status = SECMOD_CloseUserDB(public_slot_.get());
225 if (status != SECSuccess) 227 if (status != SECSuccess)
226 PLOG(ERROR) << "SECMOD_CloseUserDB failed: " << PORT_GetError(); 228 PLOG(ERROR) << "SECMOD_CloseUserDB failed: " << PORT_GetError();
227 } 229 }
228 } 230 }
229 231
230 ScopedPK11Slot GetPublicSlot() { 232 ScopedPK11Slot GetPublicSlot() {
231 return ScopedPK11Slot( 233 return ScopedPK11Slot(
232 public_slot_ ? PK11_ReferenceSlot(public_slot_.get()) : NULL); 234 public_slot_ ? PK11_ReferenceSlot(public_slot_.get()) : NULL);
233 } 235 }
(...skipping 13 matching lines...) Expand all
247 249
248 SlotReadyCallbackList callback_list; 250 SlotReadyCallbackList callback_list;
249 callback_list.swap(tpm_ready_callback_list_); 251 callback_list.swap(tpm_ready_callback_list_);
250 for (SlotReadyCallbackList::iterator i = callback_list.begin(); 252 for (SlotReadyCallbackList::iterator i = callback_list.begin();
251 i != callback_list.end(); 253 i != callback_list.end();
252 ++i) { 254 ++i) {
253 (*i).Run(ScopedPK11Slot(PK11_ReferenceSlot(private_slot_.get()))); 255 (*i).Run(ScopedPK11Slot(PK11_ReferenceSlot(private_slot_.get())));
254 } 256 }
255 } 257 }
256 258
259 bool private_slot_initialization_started() const {
260 return private_slot_initialization_started_;
261 }
262
263 void set_private_slot_initialization_started() {
264 private_slot_initialization_started_ = true;
265 }
266
257 private: 267 private:
258 ScopedPK11Slot public_slot_; 268 ScopedPK11Slot public_slot_;
259 ScopedPK11Slot private_slot_; 269 ScopedPK11Slot private_slot_;
260 bool is_primary_user_; 270
271 bool private_slot_initialization_started_;
261 272
262 typedef std::vector<base::Callback<void(ScopedPK11Slot)> > 273 typedef std::vector<base::Callback<void(ScopedPK11Slot)> >
263 SlotReadyCallbackList; 274 SlotReadyCallbackList;
264 SlotReadyCallbackList tpm_ready_callback_list_; 275 SlotReadyCallbackList tpm_ready_callback_list_;
265 }; 276 };
266 #endif // defined(OS_CHROMEOS) 277 #endif // defined(OS_CHROMEOS)
267 278
268 class NSSInitSingleton { 279 class NSSInitSingleton {
269 public: 280 public:
270 #if defined(OS_CHROMEOS) 281 #if defined(OS_CHROMEOS)
271 // Used with PostTaskAndReply to pass handles to worker thread and back. 282 // Used with PostTaskAndReply to pass handles to worker thread and back.
272 struct TPMModuleAndSlot { 283 struct TPMModuleAndSlot {
273 explicit TPMModuleAndSlot(SECMODModule* init_chaps_module) 284 explicit TPMModuleAndSlot(SECMODModule* init_chaps_module)
274 : chaps_module(init_chaps_module), tpm_slot(NULL) {} 285 : chaps_module(init_chaps_module), tpm_slot(NULL) {}
275 SECMODModule* chaps_module; 286 SECMODModule* chaps_module;
276 PK11SlotInfo* tpm_slot; 287 PK11SlotInfo* tpm_slot;
277 }; 288 };
278 289
279 void OpenPersistentNSSDB() {
280 DCHECK(thread_checker_.CalledOnValidThread());
281
282 if (!chromeos_user_logged_in_) {
283 // GetDefaultConfigDirectory causes us to do blocking IO on UI thread.
284 // Temporarily allow it until we fix http://crbug.com/70119
285 base::ThreadRestrictions::ScopedAllowIO allow_io;
286 chromeos_user_logged_in_ = true;
287
288 // This creates another DB slot in NSS that is read/write, unlike
289 // the fake root CA cert DB and the "default" crypto key
290 // provider, which are still read-only (because we initialized
291 // NSS before we had a cryptohome mounted).
292 software_slot_ = OpenUserDB(GetDefaultConfigDirectory(),
293 kNSSDatabaseName);
294 }
295 }
296
297 PK11SlotInfo* OpenPersistentNSSDBForPath(const base::FilePath& path) { 290 PK11SlotInfo* OpenPersistentNSSDBForPath(const base::FilePath& path) {
298 DCHECK(thread_checker_.CalledOnValidThread()); 291 DCHECK(thread_checker_.CalledOnValidThread());
299 // NSS is allowed to do IO on the current thread since dispatching 292 // NSS is allowed to do IO on the current thread since dispatching
300 // to a dedicated thread would still have the affect of blocking 293 // to a dedicated thread would still have the affect of blocking
301 // the current thread, due to NSS's internal locking requirements 294 // the current thread, due to NSS's internal locking requirements
302 base::ThreadRestrictions::ScopedAllowIO allow_io; 295 base::ThreadRestrictions::ScopedAllowIO allow_io;
303 296
304 base::FilePath nssdb_path = path.AppendASCII(".pki").AppendASCII("nssdb"); 297 base::FilePath nssdb_path = path.AppendASCII(".pki").AppendASCII("nssdb");
305 if (!base::CreateDirectory(nssdb_path)) { 298 if (!base::CreateDirectory(nssdb_path)) {
306 LOG(ERROR) << "Failed to create " << nssdb_path.value() << " directory."; 299 LOG(ERROR) << "Failed to create " << nssdb_path.value() << " directory.";
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
452 445
453 PK11SlotInfo* slot = SECMOD_LookupSlot(chaps_module->moduleID, slot_id); 446 PK11SlotInfo* slot = SECMOD_LookupSlot(chaps_module->moduleID, slot_id);
454 if (!slot) 447 if (!slot)
455 LOG(ERROR) << "TPM slot " << slot_id << " not found."; 448 LOG(ERROR) << "TPM slot " << slot_id << " not found.";
456 return slot; 449 return slot;
457 } 450 }
458 451
459 bool InitializeNSSForChromeOSUser( 452 bool InitializeNSSForChromeOSUser(
460 const std::string& email, 453 const std::string& email,
461 const std::string& username_hash, 454 const std::string& username_hash,
462 bool is_primary_user,
463 const base::FilePath& path) { 455 const base::FilePath& path) {
464 DCHECK(thread_checker_.CalledOnValidThread()); 456 DCHECK(thread_checker_.CalledOnValidThread());
465 if (chromeos_user_map_.find(username_hash) != chromeos_user_map_.end()) { 457 if (chromeos_user_map_.find(username_hash) != chromeos_user_map_.end()) {
466 // This user already exists in our mapping. 458 // This user already exists in our mapping.
467 DVLOG(2) << username_hash << " already initialized."; 459 DVLOG(2) << username_hash << " already initialized.";
468 return false; 460 return false;
469 } 461 }
470 ScopedPK11Slot public_slot; 462
471 if (is_primary_user) { 463 // If test slot is set, slot getter methods will short circuit
472 DVLOG(2) << "Primary user, using GetPublicNSSKeySlot()"; 464 // checking |chromeos_user_map_|, so there is nothing left to be
473 public_slot.reset(GetPublicNSSKeySlot()); 465 // initialized.
474 } else { 466 if (test_slot_)
475 DVLOG(2) << "Opening NSS DB " << path.value(); 467 return false;
476 public_slot.reset(OpenPersistentNSSDBForPath(path)); 468
477 } 469 DVLOG(2) << "Opening NSS DB " << path.value();
470 ScopedPK11Slot public_slot(OpenPersistentNSSDBForPath(path));
478 chromeos_user_map_[username_hash] = 471 chromeos_user_map_[username_hash] =
479 new ChromeOSUserData(public_slot.Pass(), is_primary_user); 472 new ChromeOSUserData(public_slot.Pass());
480 return true; 473 return true;
481 } 474 }
482 475
476 bool ShouldInitializeTPMForChromeOSUser(const std::string& username_hash) {
477 DCHECK(thread_checker_.CalledOnValidThread());
478 DCHECK(chromeos_user_map_.find(username_hash) != chromeos_user_map_.end());
479
480 return !chromeos_user_map_[username_hash]
481 ->private_slot_initialization_started();
482 }
483
484 void WillInitializeTPMForChromeOSUser(const std::string& username_hash) {
485 DCHECK(thread_checker_.CalledOnValidThread());
486 DCHECK(chromeos_user_map_.find(username_hash) != chromeos_user_map_.end());
487
488 chromeos_user_map_[username_hash]
489 ->set_private_slot_initialization_started();
490 }
491
483 void InitializeTPMForChromeOSUser(const std::string& username_hash, 492 void InitializeTPMForChromeOSUser(const std::string& username_hash,
484 CK_SLOT_ID slot_id) { 493 CK_SLOT_ID slot_id) {
485 DCHECK(thread_checker_.CalledOnValidThread()); 494 DCHECK(thread_checker_.CalledOnValidThread());
486 DCHECK(chromeos_user_map_.find(username_hash) != chromeos_user_map_.end()); 495 DCHECK(chromeos_user_map_.find(username_hash) != chromeos_user_map_.end());
496 DCHECK(chromeos_user_map_[username_hash]->
497 private_slot_initialization_started());
487 498
488 if (!chaps_module_) 499 if (!chaps_module_)
489 return; 500 return;
490 501
491 // Note that a reference is not taken to chaps_module_. This is safe since 502 // Note that a reference is not taken to chaps_module_. This is safe since
492 // NSSInitSingleton is Leaky, so the reference it holds is never released. 503 // NSSInitSingleton is Leaky, so the reference it holds is never released.
493 scoped_ptr<TPMModuleAndSlot> tpm_args(new TPMModuleAndSlot(chaps_module_)); 504 scoped_ptr<TPMModuleAndSlot> tpm_args(new TPMModuleAndSlot(chaps_module_));
494 TPMModuleAndSlot* tpm_args_ptr = tpm_args.get(); 505 TPMModuleAndSlot* tpm_args_ptr = tpm_args.get();
495 base::WorkerPool::PostTaskAndReply( 506 base::WorkerPool::PostTaskAndReply(
496 FROM_HERE, 507 FROM_HERE,
(...skipping 15 matching lines...) Expand all
512 << !!tpm_args->tpm_slot; 523 << !!tpm_args->tpm_slot;
513 chromeos_user_map_[username_hash]->SetPrivateSlot( 524 chromeos_user_map_[username_hash]->SetPrivateSlot(
514 ScopedPK11Slot(tpm_args->tpm_slot)); 525 ScopedPK11Slot(tpm_args->tpm_slot));
515 } 526 }
516 527
517 void InitializePrivateSoftwareSlotForChromeOSUser( 528 void InitializePrivateSoftwareSlotForChromeOSUser(
518 const std::string& username_hash) { 529 const std::string& username_hash) {
519 DCHECK(thread_checker_.CalledOnValidThread()); 530 DCHECK(thread_checker_.CalledOnValidThread());
520 VLOG(1) << "using software private slot for " << username_hash; 531 VLOG(1) << "using software private slot for " << username_hash;
521 DCHECK(chromeos_user_map_.find(username_hash) != chromeos_user_map_.end()); 532 DCHECK(chromeos_user_map_.find(username_hash) != chromeos_user_map_.end());
533 DCHECK(chromeos_user_map_[username_hash]->
534 private_slot_initialization_started());
535
522 chromeos_user_map_[username_hash]->SetPrivateSlot( 536 chromeos_user_map_[username_hash]->SetPrivateSlot(
523 chromeos_user_map_[username_hash]->GetPublicSlot()); 537 chromeos_user_map_[username_hash]->GetPublicSlot());
524 } 538 }
525 539
526 ScopedPK11Slot GetPublicSlotForChromeOSUser( 540 ScopedPK11Slot GetPublicSlotForChromeOSUser(
527 const std::string& username_hash) { 541 const std::string& username_hash) {
528 DCHECK(thread_checker_.CalledOnValidThread()); 542 DCHECK(thread_checker_.CalledOnValidThread());
529 543
530 if (username_hash.empty()) { 544 if (username_hash.empty()) {
531 DVLOG(2) << "empty username_hash"; 545 DVLOG(2) << "empty username_hash";
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
612 626
613 PK11SlotInfo* GetPublicNSSKeySlot() { 627 PK11SlotInfo* GetPublicNSSKeySlot() {
614 // TODO(mattm): Change to DCHECK when callers have been fixed. 628 // TODO(mattm): Change to DCHECK when callers have been fixed.
615 if (!thread_checker_.CalledOnValidThread()) { 629 if (!thread_checker_.CalledOnValidThread()) {
616 DVLOG(1) << "Called on wrong thread.\n" 630 DVLOG(1) << "Called on wrong thread.\n"
617 << base::debug::StackTrace().ToString(); 631 << base::debug::StackTrace().ToString();
618 } 632 }
619 633
620 if (test_slot_) 634 if (test_slot_)
621 return PK11_ReferenceSlot(test_slot_); 635 return PK11_ReferenceSlot(test_slot_);
622 if (software_slot_)
623 return PK11_ReferenceSlot(software_slot_);
624 return PK11_GetInternalKeySlot(); 636 return PK11_GetInternalKeySlot();
625 } 637 }
626 638
627 PK11SlotInfo* GetPrivateNSSKeySlot() { 639 PK11SlotInfo* GetPrivateNSSKeySlot() {
628 // TODO(mattm): Change to DCHECK when callers have been fixed. 640 // TODO(mattm): Change to DCHECK when callers have been fixed.
629 if (!thread_checker_.CalledOnValidThread()) { 641 if (!thread_checker_.CalledOnValidThread()) {
630 DVLOG(1) << "Called on wrong thread.\n" 642 DVLOG(1) << "Called on wrong thread.\n"
631 << base::debug::StackTrace().ToString(); 643 << base::debug::StackTrace().ToString();
632 } 644 }
633 645
634 if (test_slot_) 646 if (test_slot_)
635 return PK11_ReferenceSlot(test_slot_); 647 return PK11_ReferenceSlot(test_slot_);
636 648
637 #if defined(OS_CHROMEOS) 649 #if defined(OS_CHROMEOS)
638 if (tpm_token_enabled_for_nss_) { 650 if (tpm_token_enabled_for_nss_) {
639 if (IsTPMTokenReady(base::Closure())) { 651 if (IsTPMTokenReady(base::Closure())) {
640 return PK11_ReferenceSlot(tpm_slot_); 652 return PK11_ReferenceSlot(tpm_slot_);
641 } else { 653 } else {
642 // If we were supposed to get the hardware token, but were 654 // If we were supposed to get the hardware token, but were
643 // unable to, return NULL rather than fall back to sofware. 655 // unable to, return NULL rather than fall back to sofware.
644 return NULL; 656 return NULL;
645 } 657 }
646 } 658 }
647 #endif 659 #endif
648 // If we weren't supposed to enable the TPM for NSS, then return
649 // the software slot.
650 if (software_slot_)
651 return PK11_ReferenceSlot(software_slot_);
652 return PK11_GetInternalKeySlot(); 660 return PK11_GetInternalKeySlot();
653 } 661 }
654 662
655 #if defined(USE_NSS) 663 #if defined(USE_NSS)
656 base::Lock* write_lock() { 664 base::Lock* write_lock() {
657 return &write_lock_; 665 return &write_lock_;
658 } 666 }
659 #endif // defined(USE_NSS) 667 #endif // defined(USE_NSS)
660 668
661 // This method is used to force NSS to be initialized without a DB. 669 // This method is used to force NSS to be initialized without a DB.
662 // Call this method before NSSInitSingleton() is constructed. 670 // Call this method before NSSInitSingleton() is constructed.
663 static void ForceNoDBInit() { 671 static void ForceNoDBInit() {
664 force_nodb_init_ = true; 672 force_nodb_init_ = true;
665 } 673 }
666 674
667 private: 675 private:
668 friend struct base::DefaultLazyInstanceTraits<NSSInitSingleton>; 676 friend struct base::DefaultLazyInstanceTraits<NSSInitSingleton>;
669 677
670 NSSInitSingleton() 678 NSSInitSingleton()
671 : tpm_token_enabled_for_nss_(false), 679 : tpm_token_enabled_for_nss_(false),
672 initializing_tpm_token_(false), 680 initializing_tpm_token_(false),
673 chaps_module_(NULL), 681 chaps_module_(NULL),
674 software_slot_(NULL),
675 test_slot_(NULL), 682 test_slot_(NULL),
676 tpm_slot_(NULL), 683 tpm_slot_(NULL),
677 root_(NULL), 684 root_(NULL) {
678 chromeos_user_logged_in_(false) {
679 base::TimeTicks start_time = base::TimeTicks::Now(); 685 base::TimeTicks start_time = base::TimeTicks::Now();
680 686
681 // It's safe to construct on any thread, since LazyInstance will prevent any 687 // It's safe to construct on any thread, since LazyInstance will prevent any
682 // other threads from accessing until the constructor is done. 688 // other threads from accessing until the constructor is done.
683 thread_checker_.DetachFromThread(); 689 thread_checker_.DetachFromThread();
684 690
685 DisableAESNIIfNeeded(); 691 DisableAESNIIfNeeded();
686 692
687 EnsureNSPRInit(); 693 EnsureNSPRInit();
688 694
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
788 // prevent non-joinable threads from using NSS after it's already been shut 794 // prevent non-joinable threads from using NSS after it's already been shut
789 // down. 795 // down.
790 ~NSSInitSingleton() { 796 ~NSSInitSingleton() {
791 #if defined(OS_CHROMEOS) 797 #if defined(OS_CHROMEOS)
792 STLDeleteValues(&chromeos_user_map_); 798 STLDeleteValues(&chromeos_user_map_);
793 #endif 799 #endif
794 if (tpm_slot_) { 800 if (tpm_slot_) {
795 PK11_FreeSlot(tpm_slot_); 801 PK11_FreeSlot(tpm_slot_);
796 tpm_slot_ = NULL; 802 tpm_slot_ = NULL;
797 } 803 }
798 if (software_slot_) {
799 SECMOD_CloseUserDB(software_slot_);
800 PK11_FreeSlot(software_slot_);
801 software_slot_ = NULL;
802 }
803 CloseTestNSSDB(); 804 CloseTestNSSDB();
804 if (root_) { 805 if (root_) {
805 SECMOD_UnloadUserModule(root_); 806 SECMOD_UnloadUserModule(root_);
806 SECMOD_DestroyModule(root_); 807 SECMOD_DestroyModule(root_);
807 root_ = NULL; 808 root_ = NULL;
808 } 809 }
809 if (chaps_module_) { 810 if (chaps_module_) {
810 SECMOD_UnloadUserModule(chaps_module_); 811 SECMOD_UnloadUserModule(chaps_module_);
811 SECMOD_DestroyModule(chaps_module_); 812 SECMOD_DestroyModule(chaps_module_);
812 chaps_module_ = NULL; 813 chaps_module_ = NULL;
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
895 } 896 }
896 897
897 // If this is set to true NSS is forced to be initialized without a DB. 898 // If this is set to true NSS is forced to be initialized without a DB.
898 static bool force_nodb_init_; 899 static bool force_nodb_init_;
899 900
900 bool tpm_token_enabled_for_nss_; 901 bool tpm_token_enabled_for_nss_;
901 bool initializing_tpm_token_; 902 bool initializing_tpm_token_;
902 typedef std::vector<base::Closure> TPMReadyCallbackList; 903 typedef std::vector<base::Closure> TPMReadyCallbackList;
903 TPMReadyCallbackList tpm_ready_callback_list_; 904 TPMReadyCallbackList tpm_ready_callback_list_;
904 SECMODModule* chaps_module_; 905 SECMODModule* chaps_module_;
905 PK11SlotInfo* software_slot_;
906 PK11SlotInfo* test_slot_; 906 PK11SlotInfo* test_slot_;
907 PK11SlotInfo* tpm_slot_; 907 PK11SlotInfo* tpm_slot_;
908 SECMODModule* root_; 908 SECMODModule* root_;
909 bool chromeos_user_logged_in_;
910 #if defined(OS_CHROMEOS) 909 #if defined(OS_CHROMEOS)
911 typedef std::map<std::string, ChromeOSUserData*> ChromeOSUserMap; 910 typedef std::map<std::string, ChromeOSUserData*> ChromeOSUserMap;
912 ChromeOSUserMap chromeos_user_map_; 911 ChromeOSUserMap chromeos_user_map_;
913 #endif 912 #endif
914 #if defined(USE_NSS) 913 #if defined(USE_NSS)
915 // TODO(davidben): When https://bugzilla.mozilla.org/show_bug.cgi?id=564011 914 // TODO(davidben): When https://bugzilla.mozilla.org/show_bug.cgi?id=564011
916 // is fixed, we will no longer need the lock. 915 // is fixed, we will no longer need the lock.
917 base::Lock write_lock_; 916 base::Lock write_lock_;
918 #endif // defined(USE_NSS) 917 #endif // defined(USE_NSS)
919 918
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
1063 SECMOD_GetReadLock(lock_); 1062 SECMOD_GetReadLock(lock_);
1064 } 1063 }
1065 1064
1066 AutoSECMODListReadLock::~AutoSECMODListReadLock() { 1065 AutoSECMODListReadLock::~AutoSECMODListReadLock() {
1067 SECMOD_ReleaseReadLock(lock_); 1066 SECMOD_ReleaseReadLock(lock_);
1068 } 1067 }
1069 1068
1070 #endif // defined(USE_NSS) 1069 #endif // defined(USE_NSS)
1071 1070
1072 #if defined(OS_CHROMEOS) 1071 #if defined(OS_CHROMEOS)
1073 void OpenPersistentNSSDB() {
1074 g_nss_singleton.Get().OpenPersistentNSSDB();
1075 }
1076
1077 void EnableTPMTokenForNSS() { 1072 void EnableTPMTokenForNSS() {
1078 g_nss_singleton.Get().EnableTPMTokenForNSS(); 1073 g_nss_singleton.Get().EnableTPMTokenForNSS();
1079 } 1074 }
1080 1075
1081 bool IsTPMTokenEnabledForNSS() { 1076 bool IsTPMTokenEnabledForNSS() {
1082 return g_nss_singleton.Get().IsTPMTokenEnabledForNSS(); 1077 return g_nss_singleton.Get().IsTPMTokenEnabledForNSS();
1083 } 1078 }
1084 1079
1085 bool IsTPMTokenReady(const base::Closure& callback) { 1080 bool IsTPMTokenReady(const base::Closure& callback) {
1086 return g_nss_singleton.Get().IsTPMTokenReady(callback); 1081 return g_nss_singleton.Get().IsTPMTokenReady(callback);
1087 } 1082 }
1088 1083
1089 void InitializeTPMToken(int token_slot_id, 1084 void InitializeTPMToken(int token_slot_id,
1090 const base::Callback<void(bool)>& callback) { 1085 const base::Callback<void(bool)>& callback) {
1091 g_nss_singleton.Get().InitializeTPMToken(token_slot_id, callback); 1086 g_nss_singleton.Get().InitializeTPMToken(token_slot_id, callback);
1092 } 1087 }
1093 1088
1094 ScopedTestNSSChromeOSUser::ScopedTestNSSChromeOSUser( 1089 ScopedTestNSSChromeOSUser::ScopedTestNSSChromeOSUser(
1095 const std::string& username_hash) 1090 const std::string& username_hash)
1096 : username_hash_(username_hash), constructed_successfully_(false) { 1091 : username_hash_(username_hash), constructed_successfully_(false) {
1097 if (!temp_dir_.CreateUniqueTempDir()) 1092 if (!temp_dir_.CreateUniqueTempDir())
1098 return; 1093 return;
1099 constructed_successfully_ = 1094 constructed_successfully_ =
1100 InitializeNSSForChromeOSUser(username_hash, 1095 InitializeNSSForChromeOSUser(username_hash,
1101 username_hash, 1096 username_hash,
1102 false /* is_primary_user */,
1103 temp_dir_.path()); 1097 temp_dir_.path());
1104 } 1098 }
1105 1099
1106 ScopedTestNSSChromeOSUser::~ScopedTestNSSChromeOSUser() { 1100 ScopedTestNSSChromeOSUser::~ScopedTestNSSChromeOSUser() {
1107 if (constructed_successfully_) 1101 if (constructed_successfully_)
1108 g_nss_singleton.Get().CloseTestChromeOSUser(username_hash_); 1102 g_nss_singleton.Get().CloseTestChromeOSUser(username_hash_);
1109 } 1103 }
1110 1104
1111 void ScopedTestNSSChromeOSUser::FinishInit() { 1105 void ScopedTestNSSChromeOSUser::FinishInit() {
1106 DCHECK(constructed_successfully_);
1107 if (!ShouldInitializeTPMForChromeOSUser(username_hash_))
1108 return;
1109 WillInitializeTPMForChromeOSUser(username_hash_);
1112 InitializePrivateSoftwareSlotForChromeOSUser(username_hash_); 1110 InitializePrivateSoftwareSlotForChromeOSUser(username_hash_);
1113 } 1111 }
1114 1112
1115 bool InitializeNSSForChromeOSUser( 1113 bool InitializeNSSForChromeOSUser(
1116 const std::string& email, 1114 const std::string& email,
1117 const std::string& username_hash, 1115 const std::string& username_hash,
1118 bool is_primary_user,
1119 const base::FilePath& path) { 1116 const base::FilePath& path) {
1120 return g_nss_singleton.Get().InitializeNSSForChromeOSUser( 1117 return g_nss_singleton.Get().InitializeNSSForChromeOSUser(
1121 email, username_hash, is_primary_user, path); 1118 email, username_hash, path);
1122 } 1119 }
1120
1121 bool ShouldInitializeTPMForChromeOSUser(const std::string& username_hash) {
1122 return g_nss_singleton.Get().ShouldInitializeTPMForChromeOSUser(
1123 username_hash);
1124 }
1125
1126 void WillInitializeTPMForChromeOSUser(const std::string& username_hash) {
1127 g_nss_singleton.Get().WillInitializeTPMForChromeOSUser(username_hash);
1128 }
1129
1123 void InitializeTPMForChromeOSUser( 1130 void InitializeTPMForChromeOSUser(
1124 const std::string& username_hash, 1131 const std::string& username_hash,
1125 CK_SLOT_ID slot_id) { 1132 CK_SLOT_ID slot_id) {
1126 g_nss_singleton.Get().InitializeTPMForChromeOSUser(username_hash, slot_id); 1133 g_nss_singleton.Get().InitializeTPMForChromeOSUser(username_hash, slot_id);
1127 } 1134 }
1128 void InitializePrivateSoftwareSlotForChromeOSUser( 1135 void InitializePrivateSoftwareSlotForChromeOSUser(
1129 const std::string& username_hash) { 1136 const std::string& username_hash) {
1130 g_nss_singleton.Get().InitializePrivateSoftwareSlotForChromeOSUser( 1137 g_nss_singleton.Get().InitializePrivateSoftwareSlotForChromeOSUser(
1131 username_hash); 1138 username_hash);
1132 } 1139 }
(...skipping 19 matching lines...) Expand all
1152 1159
1153 PK11SlotInfo* GetPublicNSSKeySlot() { 1160 PK11SlotInfo* GetPublicNSSKeySlot() {
1154 return g_nss_singleton.Get().GetPublicNSSKeySlot(); 1161 return g_nss_singleton.Get().GetPublicNSSKeySlot();
1155 } 1162 }
1156 1163
1157 PK11SlotInfo* GetPrivateNSSKeySlot() { 1164 PK11SlotInfo* GetPrivateNSSKeySlot() {
1158 return g_nss_singleton.Get().GetPrivateNSSKeySlot(); 1165 return g_nss_singleton.Get().GetPrivateNSSKeySlot();
1159 } 1166 }
1160 1167
1161 } // namespace crypto 1168 } // namespace crypto
OLDNEW
« no previous file with comments | « crypto/nss_util.h ('k') | crypto/nss_util_internal.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698