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 <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 Loading... | |
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 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
532 void InitializeTPMTokenInternal(InitializeTPMTokenCallback callback, | 558 void InitializeTPMTokenInternal(InitializeTPMTokenCallback callback, |
533 bool is_token_ready) { | 559 bool is_token_ready) { |
534 if (is_token_ready) { | 560 if (is_token_ready) { |
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. |
wtc
2012/04/03 23:00:58
This comment is incorrect. 'trustOrder' is define
| |
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). |
546 "trustOrder=100 slotParams=(1={slotFlags=[RSA] askpw=only})"); | 572 "trustOrder=100 slotParams=(1={slotFlags=[RSA] askpw=only})"); |
wtc
2012/04/03 19:56:55
I can now prove that adding the SECMOD_LoadUserMod
wtc
2012/04/03 20:47:27
rsleevi showed that my proof is wrong because I mi
Ryan Sleevi
2012/04/03 21:57:14
This should be
NSS=\"trustOrder=100 slotParams=(1=
wtc
2012/04/03 22:17:24
rsleevi: good job! Thank you for tracking this do
| |
547 } | 573 } |
548 if (chaps_module_) { | 574 if (chaps_module_ && chaps_module_->loaded) { |
575 int size = 0; | |
576 PK11DefaultArrayEntry* entries = PK11_GetDefaultArray(&size); | |
wtc
2012/04/03 19:27:26
It would be a good idea to document where this cry
| |
577 PK11DefaultArrayEntry* friendly_entry = NULL; | |
578 for (int i = 0; i < size; ++i) { | |
579 if (entries[i].flag == SECMOD_FRIENDLY_FLAG) { | |
580 friendly_entry = &entries[i]; | |
581 break; | |
582 } | |
583 } | |
584 | |
549 // If this gets set, then we'll use the TPM for certs with | 585 // If this gets set, then we'll use the TPM for certs with |
550 // private keys, otherwise we'll fall back to the software | 586 // private keys, otherwise we'll fall back to the software |
551 // implementation. | 587 // implementation. |
552 tpm_slot_ = GetTPMSlot(); | 588 tpm_slot_ = GetTPMSlot(); |
589 | |
590 // Force the TPM slot to be "Friendly", since it seems to ignore setting | |
591 // "PublicCerts" above, and otherwise NSS does some unnecessary locking, | |
wtc
2012/04/03 19:27:26
Nit: this comment still references "PublicCerts".
| |
592 // and slows things down. | |
593 if (tpm_slot_ && friendly_entry) | |
594 PK11_UpdateSlotAttribute(tpm_slot_, friendly_entry, PR_TRUE); | |
595 | |
596 if (VLOG_IS_ON(1)) | |
597 LogSlotInfo(); | |
598 | |
553 callback.Run(tpm_slot_ != NULL); | 599 callback.Run(tpm_slot_ != NULL); |
554 return; | 600 return; |
555 } | 601 } |
556 } | 602 } |
557 callback.Run(false); | 603 callback.Run(false); |
558 } | 604 } |
559 #endif | 605 #endif // defined(OS_CHROMEOS) |
560 | 606 |
561 #if defined(USE_NSS) | 607 #if defined(USE_NSS) |
562 // Load nss's built-in root certs. | 608 // Load nss's built-in root certs. |
563 SECMODModule* InitDefaultRootCerts() { | 609 SECMODModule* InitDefaultRootCerts() { |
564 SECMODModule* root = LoadModule("Root Certs", "libnssckbi.so", NULL); | 610 SECMODModule* root = LoadModule("Root Certs", "libnssckbi.so", NULL); |
565 if (root) | 611 if (root) |
566 return root; | 612 return root; |
567 | 613 |
568 // Aw, snap. Can't find/load root cert shared library. | 614 // Aw, snap. Can't find/load root cert shared library. |
569 // This will make it hard to talk to anybody via https. | 615 // This will make it hard to talk to anybody via https. |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
630 // is fixed, we will no longer need the lock. | 676 // is fixed, we will no longer need the lock. |
631 base::Lock write_lock_; | 677 base::Lock write_lock_; |
632 #endif // defined(USE_NSS) | 678 #endif // defined(USE_NSS) |
633 }; | 679 }; |
634 | 680 |
635 // static | 681 // static |
636 bool NSSInitSingleton::force_nodb_init_ = false; | 682 bool NSSInitSingleton::force_nodb_init_ = false; |
637 | 683 |
638 base::LazyInstance<NSSInitSingleton>::Leaky | 684 base::LazyInstance<NSSInitSingleton>::Leaky |
639 g_nss_singleton = LAZY_INSTANCE_INITIALIZER; | 685 g_nss_singleton = LAZY_INSTANCE_INITIALIZER; |
640 | |
641 } // namespace | 686 } // namespace |
642 | 687 |
643 #if defined(USE_NSS) | 688 #if defined(USE_NSS) |
644 void EarlySetupForNSSInit() { | 689 void EarlySetupForNSSInit() { |
645 FilePath database_dir = GetInitialConfigDirectory(); | 690 FilePath database_dir = GetInitialConfigDirectory(); |
646 if (!database_dir.empty()) | 691 if (!database_dir.empty()) |
647 UseLocalCacheOfNSSDatabaseIfNFS(database_dir); | 692 UseLocalCacheOfNSSDatabaseIfNFS(database_dir); |
648 } | 693 } |
649 #endif | 694 #endif |
650 | 695 |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
798 | 843 |
799 PK11SlotInfo* GetPublicNSSKeySlot() { | 844 PK11SlotInfo* GetPublicNSSKeySlot() { |
800 return g_nss_singleton.Get().GetPublicNSSKeySlot(); | 845 return g_nss_singleton.Get().GetPublicNSSKeySlot(); |
801 } | 846 } |
802 | 847 |
803 PK11SlotInfo* GetPrivateNSSKeySlot() { | 848 PK11SlotInfo* GetPrivateNSSKeySlot() { |
804 return g_nss_singleton.Get().GetPrivateNSSKeySlot(); | 849 return g_nss_singleton.Get().GetPrivateNSSKeySlot(); |
805 } | 850 } |
806 | 851 |
807 } // namespace crypto | 852 } // namespace crypto |
OLD | NEW |