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

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: moving to vlog 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 : "
217 << (PK11_NeedLogin(slot) ? "Yes" : "No");
218 VLOG(1) << " Is Hardware :" << (PK11_IsHW(slot) ? "Yes" : "No");
219 }
220 }
221 }
222 }
223 #endif
224
199 // A singleton to initialize/deinitialize NSPR. 225 // A singleton to initialize/deinitialize NSPR.
200 // Separate from the NSS singleton because we initialize NSPR on the UI thread. 226 // 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 227 // Now that we're leaking the singleton, we could merge back with the NSS
202 // singleton. 228 // singleton.
203 class NSPRInitSingleton { 229 class NSPRInitSingleton {
204 private: 230 private:
205 friend struct base::DefaultLazyInstanceTraits<NSPRInitSingleton>; 231 friend struct base::DefaultLazyInstanceTraits<NSPRInitSingleton>;
206 232
207 NSPRInitSingleton() { 233 NSPRInitSingleton() {
208 PR_Init(PR_USER_THREAD, PR_PRIORITY_NORMAL, 0); 234 PR_Init(PR_USER_THREAD, PR_PRIORITY_NORMAL, 0);
(...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after
535 // This tries to load the Chaps module so NSS can talk to the hardware 561 // This tries to load the Chaps module so NSS can talk to the hardware
536 // TPM. 562 // TPM.
537 if (!chaps_module_) { 563 if (!chaps_module_) {
538 chaps_module_ = LoadModule( 564 chaps_module_ = LoadModule(
539 kChapsModuleName, 565 kChapsModuleName,
540 kChapsPath, 566 kChapsPath,
541 // trustOrder=100 -- means it'll select this as the most 567 // trustOrder=100 -- means it'll select this as the most
542 // trusted slot for the mechanisms it provides. 568 // trusted slot for the mechanisms it provides.
543 // slotParams=... -- selects RSA as the only mechanism, and only 569 // slotParams=... -- selects RSA as the only mechanism, and only
544 // asks for the password when necessary (instead of every 570 // asks for the password when necessary (instead of every
545 // time, or after a timeout). 571 // time, or after a timeout). Turn on the "Friendly" flag
546 "trustOrder=100 slotParams=(1={slotFlags=[RSA] askpw=only})"); 572 // with "PublicCerts" so NSS doesn't try to lock things
573 // unnecessarily.
574 "trustOrder=100 slotParams=(0={slotFlags=[RSA,PublicCerts],"
wtc 2012/04/03 00:25:49 Please try replacing the last comma (right before
575 "askpw=only})");
547 } 576 }
548 if (chaps_module_) { 577 if (chaps_module_ && chaps_module_->loaded) {
578 int size = 0;
579 PK11DefaultArrayEntry* entries = PK11_GetDefaultArray(&size);
580 PK11DefaultArrayEntry* friendly_entry = NULL;
581 for (int i = 0; i < size; ++i) {
582 if (entries[i].flag == SECMOD_FRIENDLY_FLAG) {
583 friendly_entry = &entries[i];
584 break;
585 }
586 }
587
549 // If this gets set, then we'll use the TPM for certs with 588 // If this gets set, then we'll use the TPM for certs with
550 // private keys, otherwise we'll fall back to the software 589 // private keys, otherwise we'll fall back to the software
551 // implementation. 590 // implementation.
552 tpm_slot_ = GetTPMSlot(); 591 tpm_slot_ = GetTPMSlot();
592
593 // Force the TPM slot to be "Friendly", since it seems to ignore setting
594 // "PublicCerts" above, and otherwise NSS does some unnecessary locking,
595 // and slows things down.
596 if (tpm_slot_ && friendly_entry)
597 PK11_UpdateSlotAttribute(tpm_slot_, friendly_entry, PR_TRUE);
598
599 if (VLOG_IS_ON(1))
600 LogSlotInfo();
601
553 callback.Run(tpm_slot_ != NULL); 602 callback.Run(tpm_slot_ != NULL);
554 return; 603 return;
555 } 604 }
556 } 605 }
557 callback.Run(false); 606 callback.Run(false);
558 } 607 }
559 #endif 608 #endif // defined(OS_CHROMEOS)
560 609
561 #if defined(USE_NSS) 610 #if defined(USE_NSS)
562 // Load nss's built-in root certs. 611 // Load nss's built-in root certs.
563 SECMODModule* InitDefaultRootCerts() { 612 SECMODModule* InitDefaultRootCerts() {
564 SECMODModule* root = LoadModule("Root Certs", "libnssckbi.so", NULL); 613 SECMODModule* root = LoadModule("Root Certs", "libnssckbi.so", NULL);
565 if (root) 614 if (root)
566 return root; 615 return root;
567 616
568 // Aw, snap. Can't find/load root cert shared library. 617 // Aw, snap. Can't find/load root cert shared library.
569 // This will make it hard to talk to anybody via https. 618 // This will make it hard to talk to anybody via https.
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
630 // is fixed, we will no longer need the lock. 679 // is fixed, we will no longer need the lock.
631 base::Lock write_lock_; 680 base::Lock write_lock_;
632 #endif // defined(USE_NSS) 681 #endif // defined(USE_NSS)
633 }; 682 };
634 683
635 // static 684 // static
636 bool NSSInitSingleton::force_nodb_init_ = false; 685 bool NSSInitSingleton::force_nodb_init_ = false;
637 686
638 base::LazyInstance<NSSInitSingleton>::Leaky 687 base::LazyInstance<NSSInitSingleton>::Leaky
639 g_nss_singleton = LAZY_INSTANCE_INITIALIZER; 688 g_nss_singleton = LAZY_INSTANCE_INITIALIZER;
640
641 } // namespace 689 } // namespace
642 690
643 #if defined(USE_NSS) 691 #if defined(USE_NSS)
644 void EarlySetupForNSSInit() { 692 void EarlySetupForNSSInit() {
645 FilePath database_dir = GetInitialConfigDirectory(); 693 FilePath database_dir = GetInitialConfigDirectory();
646 if (!database_dir.empty()) 694 if (!database_dir.empty())
647 UseLocalCacheOfNSSDatabaseIfNFS(database_dir); 695 UseLocalCacheOfNSSDatabaseIfNFS(database_dir);
648 } 696 }
649 #endif 697 #endif
650 698
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
798 846
799 PK11SlotInfo* GetPublicNSSKeySlot() { 847 PK11SlotInfo* GetPublicNSSKeySlot() {
800 return g_nss_singleton.Get().GetPublicNSSKeySlot(); 848 return g_nss_singleton.Get().GetPublicNSSKeySlot();
801 } 849 }
802 850
803 PK11SlotInfo* GetPrivateNSSKeySlot() { 851 PK11SlotInfo* GetPrivateNSSKeySlot() {
804 return g_nss_singleton.Get().GetPrivateNSSKeySlot(); 852 return g_nss_singleton.Get().GetPrivateNSSKeySlot();
805 } 853 }
806 854
807 } // namespace crypto 855 } // 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