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

Side by Side Diff: crypto/nss_util.cc

Issue 424523002: Enable system NSS key slot. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix compilation of profile_io_data on !OS_CHROMEOS. Created 6 years, 4 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 | « chrome/browser/profiles/profile_io_data.cc ('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 376 matching lines...) Expand 10 before | Expand all | Expand 10 after
387 387
388 chaps_module_ = tpm_args->chaps_module; 388 chaps_module_ = tpm_args->chaps_module;
389 tpm_slot_ = tpm_args->tpm_slot.Pass(); 389 tpm_slot_ = tpm_args->tpm_slot.Pass();
390 if (!chaps_module_ && test_system_slot_) { 390 if (!chaps_module_ && test_system_slot_) {
391 // chromeos_unittests try to test the TPM initialization process. If we 391 // chromeos_unittests try to test the TPM initialization process. If we
392 // have a test DB open, pretend that it is the TPM slot. 392 // have a test DB open, pretend that it is the TPM slot.
393 tpm_slot_.reset(PK11_ReferenceSlot(test_system_slot_.get())); 393 tpm_slot_.reset(PK11_ReferenceSlot(test_system_slot_.get()));
394 } 394 }
395 initializing_tpm_token_ = false; 395 initializing_tpm_token_ = false;
396 396
397 if (tpm_slot_) { 397 if (tpm_slot_)
398 TPMReadyCallbackList callback_list; 398 RunAndClearTPMReadyCallbackList();
399 callback_list.swap(tpm_ready_callback_list_);
400 for (TPMReadyCallbackList::iterator i = callback_list.begin();
401 i != callback_list.end();
402 ++i) {
403 (*i).Run();
404 }
405 }
406 399
407 callback.Run(!!tpm_slot_); 400 callback.Run(!!tpm_slot_);
408 } 401 }
409 402
403 void RunAndClearTPMReadyCallbackList() {
404 TPMReadyCallbackList callback_list;
405 callback_list.swap(tpm_ready_callback_list_);
406 for (TPMReadyCallbackList::iterator i = callback_list.begin();
407 i != callback_list.end();
408 ++i) {
409 i->Run();
410 }
411 }
412
410 bool IsTPMTokenReady(const base::Closure& callback) { 413 bool IsTPMTokenReady(const base::Closure& callback) {
411 if (!callback.is_null()) { 414 if (!callback.is_null()) {
412 // Cannot DCHECK in the general case yet, but since the callback is 415 // Cannot DCHECK in the general case yet, but since the callback is
413 // a new addition to the API, DCHECK to make sure at least the new uses 416 // a new addition to the API, DCHECK to make sure at least the new uses
414 // don't regress. 417 // don't regress.
415 DCHECK(thread_checker_.CalledOnValidThread()); 418 DCHECK(thread_checker_.CalledOnValidThread());
416 } else if (!thread_checker_.CalledOnValidThread()) { 419 } else if (!thread_checker_.CalledOnValidThread()) {
417 // TODO(mattm): Change to DCHECK when callers have been fixed. 420 // TODO(mattm): Change to DCHECK when callers have been fixed.
418 DVLOG(1) << "Called on wrong thread.\n" 421 DVLOG(1) << "Called on wrong thread.\n"
419 << base::debug::StackTrace().ToString(); 422 << base::debug::StackTrace().ToString();
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
572 DCHECK(i != chromeos_user_map_.end()); 575 DCHECK(i != chromeos_user_map_.end());
573 delete i->second; 576 delete i->second;
574 chromeos_user_map_.erase(i); 577 chromeos_user_map_.erase(i);
575 } 578 }
576 579
577 void SetSystemKeySlotForTesting(ScopedPK11Slot slot) { 580 void SetSystemKeySlotForTesting(ScopedPK11Slot slot) {
578 // Ensure that a previous value of test_system_slot_ is not overwritten. 581 // Ensure that a previous value of test_system_slot_ is not overwritten.
579 // Unsetting, i.e. setting a NULL, however is allowed. 582 // Unsetting, i.e. setting a NULL, however is allowed.
580 DCHECK(!slot || !test_system_slot_); 583 DCHECK(!slot || !test_system_slot_);
581 test_system_slot_ = slot.Pass(); 584 test_system_slot_ = slot.Pass();
585 if (test_system_slot_) {
586 tpm_slot_.reset(PK11_ReferenceSlot(test_system_slot_.get()));
587 RunAndClearTPMReadyCallbackList();
588 } else {
589 tpm_slot_.reset();
590 }
582 } 591 }
583 #endif // defined(OS_CHROMEOS) 592 #endif // defined(OS_CHROMEOS)
584 593
585 #if !defined(OS_CHROMEOS) 594 #if !defined(OS_CHROMEOS)
586 PK11SlotInfo* GetPersistentNSSKeySlot() { 595 PK11SlotInfo* GetPersistentNSSKeySlot() {
587 // TODO(mattm): Change to DCHECK when callers have been fixed. 596 // TODO(mattm): Change to DCHECK when callers have been fixed.
588 if (!thread_checker_.CalledOnValidThread()) { 597 if (!thread_checker_.CalledOnValidThread()) {
589 DVLOG(1) << "Called on wrong thread.\n" 598 DVLOG(1) << "Called on wrong thread.\n"
590 << base::debug::StackTrace().ToString(); 599 << base::debug::StackTrace().ToString();
591 } 600 }
(...skipping 415 matching lines...) Expand 10 before | Expand all | Expand 10 after
1007 } 1016 }
1008 #endif // defined(USE_NSS) 1017 #endif // defined(USE_NSS)
1009 1018
1010 #if defined(OS_CHROMEOS) 1019 #if defined(OS_CHROMEOS)
1011 ScopedPK11Slot GetSystemNSSKeySlot( 1020 ScopedPK11Slot GetSystemNSSKeySlot(
1012 const base::Callback<void(ScopedPK11Slot)>& callback) { 1021 const base::Callback<void(ScopedPK11Slot)>& callback) {
1013 return g_nss_singleton.Get().GetSystemNSSKeySlot(callback); 1022 return g_nss_singleton.Get().GetSystemNSSKeySlot(callback);
1014 } 1023 }
1015 1024
1016 void SetSystemKeySlotForTesting(ScopedPK11Slot slot) { 1025 void SetSystemKeySlotForTesting(ScopedPK11Slot slot) {
1017 g_nss_singleton.Get().SetSystemKeySlotForTesting(ScopedPK11Slot()); 1026 g_nss_singleton.Get().SetSystemKeySlotForTesting(slot.Pass());
1018 } 1027 }
1019 1028
1020 void EnableTPMTokenForNSS() { 1029 void EnableTPMTokenForNSS() {
1021 g_nss_singleton.Get().EnableTPMTokenForNSS(); 1030 g_nss_singleton.Get().EnableTPMTokenForNSS();
1022 } 1031 }
1023 1032
1024 bool IsTPMTokenEnabledForNSS() { 1033 bool IsTPMTokenEnabledForNSS() {
1025 return g_nss_singleton.Get().IsTPMTokenEnabledForNSS(); 1034 return g_nss_singleton.Get().IsTPMTokenEnabledForNSS();
1026 } 1035 }
1027 1036
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
1090 return time.ToInternalValue() - base::Time::UnixEpoch().ToInternalValue(); 1099 return time.ToInternalValue() - base::Time::UnixEpoch().ToInternalValue();
1091 } 1100 }
1092 1101
1093 #if !defined(OS_CHROMEOS) 1102 #if !defined(OS_CHROMEOS)
1094 PK11SlotInfo* GetPersistentNSSKeySlot() { 1103 PK11SlotInfo* GetPersistentNSSKeySlot() {
1095 return g_nss_singleton.Get().GetPersistentNSSKeySlot(); 1104 return g_nss_singleton.Get().GetPersistentNSSKeySlot();
1096 } 1105 }
1097 #endif 1106 #endif
1098 1107
1099 } // namespace crypto 1108 } // namespace crypto
OLDNEW
« no previous file with comments | « chrome/browser/profiles/profile_io_data.cc ('k') | crypto/nss_util_internal.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698