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

Side by Side Diff: crypto/nss_util.cc

Issue 9969019: Forces TPM slot to be "Friendly", allowing NSS to avoid locking (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 8 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 | « no previous file | no next file » | 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 <plarena.h> 9 #include <plarena.h>
10 #include <prerror.h> 10 #include <prerror.h>
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 PK11SlotInfo* slot = item->module->slots[i]; 189 PK11SlotInfo* slot = item->module->slots[i];
190 if (PK11_GetTokenName(slot) == token_name) 190 if (PK11_GetTokenName(slot) == token_name)
191 return PK11_ReferenceSlot(slot); 191 return PK11_ReferenceSlot(slot);
192 } 192 }
193 } 193 }
194 return NULL; 194 return NULL;
195 } 195 }
196 196
197 #endif // defined(USE_NSS) 197 #endif // defined(USE_NSS)
198 198
199 #if defined(OS_CHROMEOS)
200 void LogSlotInfo() {
201 AutoSECMODListReadLock auto_lock;
202 SECMODModuleList* head = SECMOD_GetDefaultModuleList();
203 VLOG(1) << "Current PK11 Slot Status:";
204 for (SECMODModuleList* item = head; item != NULL; item = item->next) {
205 int slot_count = item->module->loaded ? item->module->slotCount : 0;
206 for (int i = 0; i < slot_count; i++) {
207 PK11SlotInfo* slot = item->module->slots[i];
208 if (slot) {
209 VLOG(1) << " ###############################";
210 VLOG(1) << " Token Name : " << PK11_GetTokenName(slot);
211 VLOG(1) << " Slot Name : " << PK11_GetSlotName(slot);
212 VLOG(1) << " Slot ID : " << PK11_GetSlotID(slot);
213 VLOG(1) << " Is Friendly : "
214 << (PK11_IsFriendly(slot) ? "True" : "False");
215 VLOG(1) << " Default Flags: " << PK11_GetDefaultFlags(slot);
216 VLOG(1) << " Need Login : " << (PK11_NeedLogin(slot) ? "Yes" : "No");
217 }
218 }
219 }
220 }
221 #endif
222
199 // A singleton to initialize/deinitialize NSPR. 223 // A singleton to initialize/deinitialize NSPR.
200 // Separate from the NSS singleton because we initialize NSPR on the UI thread. 224 // Separate from the NSS singleton because we initialize NSPR on the UI thread.
201 // Now that we're leaking the singleton, we could merge back with the NSS 225 // Now that we're leaking the singleton, we could merge back with the NSS
202 // singleton. 226 // singleton.
203 class NSPRInitSingleton { 227 class NSPRInitSingleton {
204 private: 228 private:
205 friend struct base::DefaultLazyInstanceTraits<NSPRInitSingleton>; 229 friend struct base::DefaultLazyInstanceTraits<NSPRInitSingleton>;
206 230
207 NSPRInitSingleton() { 231 NSPRInitSingleton() {
208 PR_Init(PR_USER_THREAD, PR_PRIORITY_NORMAL, 0); 232 PR_Init(PR_USER_THREAD, PR_PRIORITY_NORMAL, 0);
(...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after
536 // TPM. 560 // TPM.
537 if (!chaps_module_) { 561 if (!chaps_module_) {
538 chaps_module_ = LoadModule( 562 chaps_module_ = LoadModule(
539 kChapsModuleName, 563 kChapsModuleName,
540 kChapsPath, 564 kChapsPath,
541 // trustOrder=100 -- means it'll select this as the most 565 // trustOrder=100 -- means it'll select this as the most
542 // trusted slot for the mechanisms it provides. 566 // trusted slot for the mechanisms it provides.
543 // slotParams=... -- selects RSA as the only mechanism, and only 567 // slotParams=... -- selects RSA as the only mechanism, and only
544 // asks for the password when necessary (instead of every 568 // asks for the password when necessary (instead of every
545 // time, or after a timeout). 569 // time, or after a timeout).
546 "trustOrder=100 slotParams=(1={slotFlags=[RSA] askpw=only})"); 570 "trustOrder=100 slotParams=(1={slotFlags=[RSA,PublicCerts] "
Ryan Sleevi 2012/03/30 18:29:26 I believe you should update the 1= to 0=, based on
571 "askpw=only})");
Ryan Sleevi 2012/03/30 21:05:48 One more thing to try here: This will help determ
Ryan Sleevi 2012/03/30 21:07:14 Sorry, that should be: for (int i = 0; friendly_en
547 } 572 }
548 if (chaps_module_) { 573 if (chaps_module_) {
549 // If this gets set, then we'll use the TPM for certs with 574 // If this gets set, then we'll use the TPM for certs with
550 // private keys, otherwise we'll fall back to the software 575 // private keys, otherwise we'll fall back to the software
551 // implementation. 576 // implementation.
552 tpm_slot_ = GetTPMSlot(); 577 tpm_slot_ = GetTPMSlot();
578
579 if (VLOG_IS_ON(1))
580 LogSlotInfo();
581
553 callback.Run(tpm_slot_ != NULL); 582 callback.Run(tpm_slot_ != NULL);
554 return; 583 return;
555 } 584 }
556 } 585 }
557 callback.Run(false); 586 callback.Run(false);
558 } 587 }
559 #endif 588 #endif
560 589
561 #if defined(USE_NSS) 590 #if defined(USE_NSS)
562 // Load nss's built-in root certs. 591 // Load nss's built-in root certs.
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
630 // is fixed, we will no longer need the lock. 659 // is fixed, we will no longer need the lock.
631 base::Lock write_lock_; 660 base::Lock write_lock_;
632 #endif // defined(USE_NSS) 661 #endif // defined(USE_NSS)
633 }; 662 };
634 663
635 // static 664 // static
636 bool NSSInitSingleton::force_nodb_init_ = false; 665 bool NSSInitSingleton::force_nodb_init_ = false;
637 666
638 base::LazyInstance<NSSInitSingleton>::Leaky 667 base::LazyInstance<NSSInitSingleton>::Leaky
639 g_nss_singleton = LAZY_INSTANCE_INITIALIZER; 668 g_nss_singleton = LAZY_INSTANCE_INITIALIZER;
640
641 } // namespace 669 } // namespace
642 670
643 #if defined(USE_NSS) 671 #if defined(USE_NSS)
644 void EarlySetupForNSSInit() { 672 void EarlySetupForNSSInit() {
645 FilePath database_dir = GetInitialConfigDirectory(); 673 FilePath database_dir = GetInitialConfigDirectory();
646 if (!database_dir.empty()) 674 if (!database_dir.empty())
647 UseLocalCacheOfNSSDatabaseIfNFS(database_dir); 675 UseLocalCacheOfNSSDatabaseIfNFS(database_dir);
648 } 676 }
649 #endif 677 #endif
650 678
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
798 826
799 PK11SlotInfo* GetPublicNSSKeySlot() { 827 PK11SlotInfo* GetPublicNSSKeySlot() {
800 return g_nss_singleton.Get().GetPublicNSSKeySlot(); 828 return g_nss_singleton.Get().GetPublicNSSKeySlot();
801 } 829 }
802 830
803 PK11SlotInfo* GetPrivateNSSKeySlot() { 831 PK11SlotInfo* GetPrivateNSSKeySlot() {
804 return g_nss_singleton.Get().GetPrivateNSSKeySlot(); 832 return g_nss_singleton.Get().GetPrivateNSSKeySlot();
805 } 833 }
806 834
807 } // namespace crypto 835 } // namespace crypto
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698