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

Side by Side Diff: crypto/nss_util.cc

Issue 1082123003: Rename USE_NSS to USE_NSS_CERTS. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@use-nss-certs
Patch Set: rebase Created 5 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
« no previous file with comments | « crypto/nss_util.h ('k') | crypto/rsa_private_key.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 25 matching lines...) Expand all
36 #include "base/metrics/histogram.h" 36 #include "base/metrics/histogram.h"
37 #include "base/native_library.h" 37 #include "base/native_library.h"
38 #include "base/path_service.h" 38 #include "base/path_service.h"
39 #include "base/stl_util.h" 39 #include "base/stl_util.h"
40 #include "base/strings/stringprintf.h" 40 #include "base/strings/stringprintf.h"
41 #include "base/threading/thread_checker.h" 41 #include "base/threading/thread_checker.h"
42 #include "base/threading/thread_restrictions.h" 42 #include "base/threading/thread_restrictions.h"
43 #include "base/threading/worker_pool.h" 43 #include "base/threading/worker_pool.h"
44 #include "build/build_config.h" 44 #include "build/build_config.h"
45 45
46 // USE_NSS means we use NSS for everything crypto-related. If USE_NSS is not 46 // USE_NSS_CERTS means NSS is used for certificates and platform integration.
47 // defined, such as on Mac and Windows, we use NSS for SSL only -- we don't 47 // This requires additional support to manage the platform certificate and key
48 // use NSS for crypto or certificate verification, and we don't use the NSS 48 // stores.
49 // certificate and key databases. 49 #if defined(USE_NSS_CERTS)
50 #if defined(USE_NSS)
51 #include "base/synchronization/lock.h" 50 #include "base/synchronization/lock.h"
52 #include "crypto/nss_crypto_module_delegate.h" 51 #include "crypto/nss_crypto_module_delegate.h"
53 #endif // defined(USE_NSS) 52 #endif // defined(USE_NSS_CERTS)
54 53
55 namespace crypto { 54 namespace crypto {
56 55
57 namespace { 56 namespace {
58 57
59 #if defined(OS_CHROMEOS) 58 #if defined(OS_CHROMEOS)
60 const char kUserNSSDatabaseName[] = "UserNSSDB"; 59 const char kUserNSSDatabaseName[] = "UserNSSDB";
61 60
62 // Constants for loading the Chrome OS TPM-backed PKCS #11 library. 61 // Constants for loading the Chrome OS TPM-backed PKCS #11 library.
63 const char kChapsModuleName[] = "Chaps"; 62 const char kChapsModuleName[] = "Chaps";
64 const char kChapsPath[] = "libchaps.so"; 63 const char kChapsPath[] = "libchaps.so";
65 64
66 // Fake certificate authority database used for testing. 65 // Fake certificate authority database used for testing.
67 static const base::FilePath::CharType kReadOnlyCertDB[] = 66 static const base::FilePath::CharType kReadOnlyCertDB[] =
68 FILE_PATH_LITERAL("/etc/fake_root_ca/nssdb"); 67 FILE_PATH_LITERAL("/etc/fake_root_ca/nssdb");
69 #endif // defined(OS_CHROMEOS) 68 #endif // defined(OS_CHROMEOS)
70 69
71 std::string GetNSSErrorMessage() { 70 std::string GetNSSErrorMessage() {
72 std::string result; 71 std::string result;
73 if (PR_GetErrorTextLength()) { 72 if (PR_GetErrorTextLength()) {
74 scoped_ptr<char[]> error_text(new char[PR_GetErrorTextLength() + 1]); 73 scoped_ptr<char[]> error_text(new char[PR_GetErrorTextLength() + 1]);
75 PRInt32 copied = PR_GetErrorText(error_text.get()); 74 PRInt32 copied = PR_GetErrorText(error_text.get());
76 result = std::string(error_text.get(), copied); 75 result = std::string(error_text.get(), copied);
77 } else { 76 } else {
78 result = base::StringPrintf("NSS error code: %d", PR_GetError()); 77 result = base::StringPrintf("NSS error code: %d", PR_GetError());
79 } 78 }
80 return result; 79 return result;
81 } 80 }
82 81
83 #if defined(USE_NSS) 82 #if defined(USE_NSS_CERTS)
84 #if !defined(OS_CHROMEOS) 83 #if !defined(OS_CHROMEOS)
85 base::FilePath GetDefaultConfigDirectory() { 84 base::FilePath GetDefaultConfigDirectory() {
86 base::FilePath dir; 85 base::FilePath dir;
87 PathService::Get(base::DIR_HOME, &dir); 86 PathService::Get(base::DIR_HOME, &dir);
88 if (dir.empty()) { 87 if (dir.empty()) {
89 LOG(ERROR) << "Failed to get home directory."; 88 LOG(ERROR) << "Failed to get home directory.";
90 return dir; 89 return dir;
91 } 90 }
92 dir = dir.AppendASCII(".pki").AppendASCII("nssdb"); 91 dir = dir.AppendASCII(".pki").AppendASCII("nssdb");
93 if (!base::CreateDirectory(dir)) { 92 if (!base::CreateDirectory(dir)) {
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 return NULL; 134 return NULL;
136 } 135 }
137 136
138 // NSS creates a local cache of the sqlite database if it detects that the 137 // NSS creates a local cache of the sqlite database if it detects that the
139 // filesystem the database is on is much slower than the local disk. The 138 // filesystem the database is on is much slower than the local disk. The
140 // detection doesn't work with the latest versions of sqlite, such as 3.6.22 139 // detection doesn't work with the latest versions of sqlite, such as 3.6.22
141 // (NSS bug https://bugzilla.mozilla.org/show_bug.cgi?id=578561). So we set 140 // (NSS bug https://bugzilla.mozilla.org/show_bug.cgi?id=578561). So we set
142 // the NSS environment variable NSS_SDB_USE_CACHE to "yes" to override NSS's 141 // the NSS environment variable NSS_SDB_USE_CACHE to "yes" to override NSS's
143 // detection when database_dir is on NFS. See http://crbug.com/48585. 142 // detection when database_dir is on NFS. See http://crbug.com/48585.
144 // 143 //
145 // TODO(wtc): port this function to other USE_NSS platforms. It is defined 144 // TODO(wtc): port this function to other USE_NSS_CERTS platforms. It is
146 // only for OS_LINUX and OS_OPENBSD simply because the statfs structure 145 // defined only for OS_LINUX and OS_OPENBSD simply because the statfs structure
147 // is OS-specific. 146 // is OS-specific.
148 // 147 //
149 // Because this function sets an environment variable it must be run before we 148 // Because this function sets an environment variable it must be run before we
150 // go multi-threaded. 149 // go multi-threaded.
151 void UseLocalCacheOfNSSDatabaseIfNFS(const base::FilePath& database_dir) { 150 void UseLocalCacheOfNSSDatabaseIfNFS(const base::FilePath& database_dir) {
152 bool db_on_nfs = false; 151 bool db_on_nfs = false;
153 #if defined(OS_LINUX) 152 #if defined(OS_LINUX)
154 base::FileSystemType fs_type = base::FILE_SYSTEM_UNKNOWN; 153 base::FileSystemType fs_type = base::FILE_SYSTEM_UNKNOWN;
155 if (base::GetFileSystemType(database_dir, &fs_type)) 154 if (base::GetFileSystemType(database_dir, &fs_type))
156 db_on_nfs = (fs_type == base::FILE_SYSTEM_NFS); 155 db_on_nfs = (fs_type == base::FILE_SYSTEM_NFS);
157 #elif defined(OS_OPENBSD) 156 #elif defined(OS_OPENBSD)
158 struct statfs buf; 157 struct statfs buf;
159 if (statfs(database_dir.value().c_str(), &buf) == 0) 158 if (statfs(database_dir.value().c_str(), &buf) == 0)
160 db_on_nfs = (strcmp(buf.f_fstypename, MOUNT_NFS) == 0); 159 db_on_nfs = (strcmp(buf.f_fstypename, MOUNT_NFS) == 0);
161 #else 160 #else
162 NOTIMPLEMENTED(); 161 NOTIMPLEMENTED();
163 #endif 162 #endif
164 163
165 if (db_on_nfs) { 164 if (db_on_nfs) {
166 scoped_ptr<base::Environment> env(base::Environment::Create()); 165 scoped_ptr<base::Environment> env(base::Environment::Create());
167 static const char kUseCacheEnvVar[] = "NSS_SDB_USE_CACHE"; 166 static const char kUseCacheEnvVar[] = "NSS_SDB_USE_CACHE";
168 if (!env->HasVar(kUseCacheEnvVar)) 167 if (!env->HasVar(kUseCacheEnvVar))
169 env->SetVar(kUseCacheEnvVar, "yes"); 168 env->SetVar(kUseCacheEnvVar, "yes");
170 } 169 }
171 } 170 }
172 171
173 #endif // defined(USE_NSS) 172 #endif // defined(USE_NSS_CERTS)
174 173
175 // A singleton to initialize/deinitialize NSPR. 174 // A singleton to initialize/deinitialize NSPR.
176 // Separate from the NSS singleton because we initialize NSPR on the UI thread. 175 // Separate from the NSS singleton because we initialize NSPR on the UI thread.
177 // Now that we're leaking the singleton, we could merge back with the NSS 176 // Now that we're leaking the singleton, we could merge back with the NSS
178 // singleton. 177 // singleton.
179 class NSPRInitSingleton { 178 class NSPRInitSingleton {
180 private: 179 private:
181 friend struct base::DefaultLazyInstanceTraits<NSPRInitSingleton>; 180 friend struct base::DefaultLazyInstanceTraits<NSPRInitSingleton>;
182 181
183 NSPRInitSingleton() { 182 NSPRInitSingleton() {
(...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after
621 base::Bind(&NSSInitSingleton::GetSystemNSSKeySlotCallback, 620 base::Bind(&NSSInitSingleton::GetSystemNSSKeySlotCallback,
622 base::Unretained(this) /* singleton is leaky */, 621 base::Unretained(this) /* singleton is leaky */,
623 callback); 622 callback);
624 } 623 }
625 if (IsTPMTokenReady(wrapped_callback)) 624 if (IsTPMTokenReady(wrapped_callback))
626 return ScopedPK11Slot(PK11_ReferenceSlot(tpm_slot_.get())); 625 return ScopedPK11Slot(PK11_ReferenceSlot(tpm_slot_.get()));
627 return ScopedPK11Slot(); 626 return ScopedPK11Slot();
628 } 627 }
629 #endif 628 #endif
630 629
631 #if defined(USE_NSS) 630 #if defined(USE_NSS_CERTS)
632 base::Lock* write_lock() { 631 base::Lock* write_lock() {
633 return &write_lock_; 632 return &write_lock_;
634 } 633 }
635 #endif // defined(USE_NSS) 634 #endif // defined(USE_NSS_CERTS)
636 635
637 // This method is used to force NSS to be initialized without a DB. 636 // This method is used to force NSS to be initialized without a DB.
638 // Call this method before NSSInitSingleton() is constructed. 637 // Call this method before NSSInitSingleton() is constructed.
639 static void ForceNoDBInit() { 638 static void ForceNoDBInit() {
640 force_nodb_init_ = true; 639 force_nodb_init_ = true;
641 } 640 }
642 641
643 private: 642 private:
644 friend struct base::DefaultLazyInstanceTraits<NSSInitSingleton>; 643 friend struct base::DefaultLazyInstanceTraits<NSSInitSingleton>;
645 644
(...skipping 23 matching lines...) Expand all
669 if (!NSS_VersionCheck("3.14.3")) { 668 if (!NSS_VersionCheck("3.14.3")) {
670 LOG(FATAL) << "NSS_VersionCheck(\"3.14.3\") failed. NSS >= 3.14.3 is " 669 LOG(FATAL) << "NSS_VersionCheck(\"3.14.3\") failed. NSS >= 3.14.3 is "
671 "required. Please upgrade to the latest NSS, and if you " 670 "required. Please upgrade to the latest NSS, and if you "
672 "still get this error, contact your distribution " 671 "still get this error, contact your distribution "
673 "maintainer."; 672 "maintainer.";
674 } 673 }
675 674
676 SECStatus status = SECFailure; 675 SECStatus status = SECFailure;
677 bool nodb_init = force_nodb_init_; 676 bool nodb_init = force_nodb_init_;
678 677
679 #if !defined(USE_NSS) 678 #if !defined(USE_NSS_CERTS)
680 // Use the system certificate store, so initialize NSS without database. 679 // Use the system certificate store, so initialize NSS without database.
681 nodb_init = true; 680 nodb_init = true;
682 #endif 681 #endif
683 682
684 if (nodb_init) { 683 if (nodb_init) {
685 status = NSS_NoDB_Init(NULL); 684 status = NSS_NoDB_Init(NULL);
686 if (status != SECSuccess) { 685 if (status != SECSuccess) {
687 CrashOnNSSInitFailure(); 686 CrashOnNSSInitFailure();
688 return; 687 return;
689 } 688 }
690 #if defined(OS_IOS) 689 #if defined(OS_IOS)
691 root_ = InitDefaultRootCerts(); 690 root_ = InitDefaultRootCerts();
692 #endif // defined(OS_IOS) 691 #endif // defined(OS_IOS)
693 } else { 692 } else {
694 #if defined(USE_NSS) 693 #if defined(USE_NSS_CERTS)
695 base::FilePath database_dir = GetInitialConfigDirectory(); 694 base::FilePath database_dir = GetInitialConfigDirectory();
696 if (!database_dir.empty()) { 695 if (!database_dir.empty()) {
697 // This duplicates the work which should have been done in 696 // This duplicates the work which should have been done in
698 // EarlySetupForNSSInit. However, this function is idempotent so 697 // EarlySetupForNSSInit. However, this function is idempotent so
699 // there's no harm done. 698 // there's no harm done.
700 UseLocalCacheOfNSSDatabaseIfNFS(database_dir); 699 UseLocalCacheOfNSSDatabaseIfNFS(database_dir);
701 700
702 // Initialize with a persistent database (likely, ~/.pki/nssdb). 701 // Initialize with a persistent database (likely, ~/.pki/nssdb).
703 // Use "sql:" which can be shared by multiple processes safely. 702 // Use "sql:" which can be shared by multiple processes safely.
704 std::string nss_config_dir = 703 std::string nss_config_dir =
(...skipping 26 matching lines...) Expand all
731 PK11SlotInfo* slot = PK11_GetInternalKeySlot(); 730 PK11SlotInfo* slot = PK11_GetInternalKeySlot();
732 if (slot) { 731 if (slot) {
733 // PK11_InitPin may write to the keyDB, but no other thread can use NSS 732 // PK11_InitPin may write to the keyDB, but no other thread can use NSS
734 // yet, so we don't need to lock. 733 // yet, so we don't need to lock.
735 if (PK11_NeedUserInit(slot)) 734 if (PK11_NeedUserInit(slot))
736 PK11_InitPin(slot, NULL, NULL); 735 PK11_InitPin(slot, NULL, NULL);
737 PK11_FreeSlot(slot); 736 PK11_FreeSlot(slot);
738 } 737 }
739 738
740 root_ = InitDefaultRootCerts(); 739 root_ = InitDefaultRootCerts();
741 #endif // defined(USE_NSS) 740 #endif // defined(USE_NSS_CERTS)
742 } 741 }
743 742
744 // Disable MD5 certificate signatures. (They are disabled by default in 743 // Disable MD5 certificate signatures. (They are disabled by default in
745 // NSS 3.14.) 744 // NSS 3.14.)
746 NSS_SetAlgorithmPolicy(SEC_OID_MD5, 0, NSS_USE_ALG_IN_CERT_SIGNATURE); 745 NSS_SetAlgorithmPolicy(SEC_OID_MD5, 0, NSS_USE_ALG_IN_CERT_SIGNATURE);
747 NSS_SetAlgorithmPolicy(SEC_OID_PKCS1_MD5_WITH_RSA_ENCRYPTION, 746 NSS_SetAlgorithmPolicy(SEC_OID_PKCS1_MD5_WITH_RSA_ENCRYPTION,
748 0, NSS_USE_ALG_IN_CERT_SIGNATURE); 747 0, NSS_USE_ALG_IN_CERT_SIGNATURE);
749 748
750 // The UMA bit is conditionally set for this histogram in 749 // The UMA bit is conditionally set for this histogram in
751 // components/startup_metric_utils.cc . 750 // components/startup_metric_utils.cc .
(...skipping 24 matching lines...) Expand all
776 } 775 }
777 776
778 SECStatus status = NSS_Shutdown(); 777 SECStatus status = NSS_Shutdown();
779 if (status != SECSuccess) { 778 if (status != SECSuccess) {
780 // We VLOG(1) because this failure is relatively harmless (leaking, but 779 // We VLOG(1) because this failure is relatively harmless (leaking, but
781 // we're shutting down anyway). 780 // we're shutting down anyway).
782 VLOG(1) << "NSS_Shutdown failed; see http://crbug.com/4609"; 781 VLOG(1) << "NSS_Shutdown failed; see http://crbug.com/4609";
783 } 782 }
784 } 783 }
785 784
786 #if defined(USE_NSS) || defined(OS_IOS) 785 #if defined(USE_NSS_CERTS) || defined(OS_IOS)
787 // Load nss's built-in root certs. 786 // Load nss's built-in root certs.
788 SECMODModule* InitDefaultRootCerts() { 787 SECMODModule* InitDefaultRootCerts() {
789 SECMODModule* root = LoadModule("Root Certs", "libnssckbi.so", NULL); 788 SECMODModule* root = LoadModule("Root Certs", "libnssckbi.so", NULL);
790 if (root) 789 if (root)
791 return root; 790 return root;
792 791
793 // Aw, snap. Can't find/load root cert shared library. 792 // Aw, snap. Can't find/load root cert shared library.
794 // This will make it hard to talk to anybody via https. 793 // This will make it hard to talk to anybody via https.
795 // TODO(mattm): Re-add the NOTREACHED here when crbug.com/310972 is fixed. 794 // TODO(mattm): Re-add the NOTREACHED here when crbug.com/310972 is fixed.
796 return NULL; 795 return NULL;
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
849 typedef std::vector<base::Closure> TPMReadyCallbackList; 848 typedef std::vector<base::Closure> TPMReadyCallbackList;
850 TPMReadyCallbackList tpm_ready_callback_list_; 849 TPMReadyCallbackList tpm_ready_callback_list_;
851 SECMODModule* chaps_module_; 850 SECMODModule* chaps_module_;
852 crypto::ScopedPK11Slot tpm_slot_; 851 crypto::ScopedPK11Slot tpm_slot_;
853 SECMODModule* root_; 852 SECMODModule* root_;
854 #if defined(OS_CHROMEOS) 853 #if defined(OS_CHROMEOS)
855 typedef std::map<std::string, ChromeOSUserData*> ChromeOSUserMap; 854 typedef std::map<std::string, ChromeOSUserData*> ChromeOSUserMap;
856 ChromeOSUserMap chromeos_user_map_; 855 ChromeOSUserMap chromeos_user_map_;
857 ScopedPK11Slot test_system_slot_; 856 ScopedPK11Slot test_system_slot_;
858 #endif 857 #endif
859 #if defined(USE_NSS) 858 #if defined(USE_NSS_CERTS)
860 // TODO(davidben): When https://bugzilla.mozilla.org/show_bug.cgi?id=564011 859 // TODO(davidben): When https://bugzilla.mozilla.org/show_bug.cgi?id=564011
861 // is fixed, we will no longer need the lock. 860 // is fixed, we will no longer need the lock.
862 base::Lock write_lock_; 861 base::Lock write_lock_;
863 #endif // defined(USE_NSS) 862 #endif // defined(USE_NSS_CERTS)
864 863
865 base::ThreadChecker thread_checker_; 864 base::ThreadChecker thread_checker_;
866 }; 865 };
867 866
868 // static 867 // static
869 bool NSSInitSingleton::force_nodb_init_ = false; 868 bool NSSInitSingleton::force_nodb_init_ = false;
870 869
871 base::LazyInstance<NSSInitSingleton>::Leaky 870 base::LazyInstance<NSSInitSingleton>::Leaky
872 g_nss_singleton = LAZY_INSTANCE_INITIALIZER; 871 g_nss_singleton = LAZY_INSTANCE_INITIALIZER;
873 } // namespace 872 } // namespace
874 873
875 #if defined(USE_NSS) 874 #if defined(USE_NSS_CERTS)
876 ScopedPK11Slot OpenSoftwareNSSDB(const base::FilePath& path, 875 ScopedPK11Slot OpenSoftwareNSSDB(const base::FilePath& path,
877 const std::string& description) { 876 const std::string& description) {
878 const std::string modspec = 877 const std::string modspec =
879 base::StringPrintf("configDir='sql:%s' tokenDescription='%s'", 878 base::StringPrintf("configDir='sql:%s' tokenDescription='%s'",
880 path.value().c_str(), 879 path.value().c_str(),
881 description.c_str()); 880 description.c_str());
882 PK11SlotInfo* db_slot = SECMOD_OpenUserDB(modspec.c_str()); 881 PK11SlotInfo* db_slot = SECMOD_OpenUserDB(modspec.c_str());
883 if (db_slot) { 882 if (db_slot) {
884 if (PK11_NeedUserInit(db_slot)) 883 if (PK11_NeedUserInit(db_slot))
885 PK11_InitPin(db_slot, NULL, NULL); 884 PK11_InitPin(db_slot, NULL, NULL);
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
924 NSSInitSingleton::ForceNoDBInit(); 923 NSSInitSingleton::ForceNoDBInit();
925 } 924 }
926 925
927 void DisableNSSForkCheck() { 926 void DisableNSSForkCheck() {
928 scoped_ptr<base::Environment> env(base::Environment::Create()); 927 scoped_ptr<base::Environment> env(base::Environment::Create());
929 env->SetVar("NSS_STRICT_NOFORK", "DISABLED"); 928 env->SetVar("NSS_STRICT_NOFORK", "DISABLED");
930 } 929 }
931 930
932 void LoadNSSLibraries() { 931 void LoadNSSLibraries() {
933 // Some NSS libraries are linked dynamically so load them here. 932 // Some NSS libraries are linked dynamically so load them here.
934 #if defined(USE_NSS) 933 #if defined(USE_NSS_CERTS)
935 // Try to search for multiple directories to load the libraries. 934 // Try to search for multiple directories to load the libraries.
936 std::vector<base::FilePath> paths; 935 std::vector<base::FilePath> paths;
937 936
938 // Use relative path to Search PATH for the library files. 937 // Use relative path to Search PATH for the library files.
939 paths.push_back(base::FilePath()); 938 paths.push_back(base::FilePath());
940 939
941 // For Debian derivatives NSS libraries are located here. 940 // For Debian derivatives NSS libraries are located here.
942 paths.push_back(base::FilePath("/usr/lib/nss")); 941 paths.push_back(base::FilePath("/usr/lib/nss"));
943 942
944 // Ubuntu 11.10 (Oneiric) and Debian Wheezy place the libraries here. 943 // Ubuntu 11.10 (Oneiric) and Debian Wheezy place the libraries here.
(...skipping 28 matching lines...) Expand all
973 break; 972 break;
974 } 973 }
975 } 974 }
976 } 975 }
977 976
978 if (loaded == libs.size()) { 977 if (loaded == libs.size()) {
979 VLOG(3) << "NSS libraries loaded."; 978 VLOG(3) << "NSS libraries loaded.";
980 } else { 979 } else {
981 LOG(ERROR) << "Failed to load NSS libraries."; 980 LOG(ERROR) << "Failed to load NSS libraries.";
982 } 981 }
983 #endif // defined(USE_NSS) 982 #endif // defined(USE_NSS_CERTS)
984 } 983 }
985 984
986 bool CheckNSSVersion(const char* version) { 985 bool CheckNSSVersion(const char* version) {
987 return !!NSS_VersionCheck(version); 986 return !!NSS_VersionCheck(version);
988 } 987 }
989 988
990 #if defined(USE_NSS) 989 #if defined(USE_NSS_CERTS)
991 base::Lock* GetNSSWriteLock() { 990 base::Lock* GetNSSWriteLock() {
992 return g_nss_singleton.Get().write_lock(); 991 return g_nss_singleton.Get().write_lock();
993 } 992 }
994 993
995 AutoNSSWriteLock::AutoNSSWriteLock() : lock_(GetNSSWriteLock()) { 994 AutoNSSWriteLock::AutoNSSWriteLock() : lock_(GetNSSWriteLock()) {
996 // May be NULL if the lock is not needed in our version of NSS. 995 // May be NULL if the lock is not needed in our version of NSS.
997 if (lock_) 996 if (lock_)
998 lock_->Acquire(); 997 lock_->Acquire();
999 } 998 }
1000 999
1001 AutoNSSWriteLock::~AutoNSSWriteLock() { 1000 AutoNSSWriteLock::~AutoNSSWriteLock() {
1002 if (lock_) { 1001 if (lock_) {
1003 lock_->AssertAcquired(); 1002 lock_->AssertAcquired();
1004 lock_->Release(); 1003 lock_->Release();
1005 } 1004 }
1006 } 1005 }
1007 1006
1008 AutoSECMODListReadLock::AutoSECMODListReadLock() 1007 AutoSECMODListReadLock::AutoSECMODListReadLock()
1009 : lock_(SECMOD_GetDefaultModuleListLock()) { 1008 : lock_(SECMOD_GetDefaultModuleListLock()) {
1010 SECMOD_GetReadLock(lock_); 1009 SECMOD_GetReadLock(lock_);
1011 } 1010 }
1012 1011
1013 AutoSECMODListReadLock::~AutoSECMODListReadLock() { 1012 AutoSECMODListReadLock::~AutoSECMODListReadLock() {
1014 SECMOD_ReleaseReadLock(lock_); 1013 SECMOD_ReleaseReadLock(lock_);
1015 } 1014 }
1016 #endif // defined(USE_NSS) 1015 #endif // defined(USE_NSS_CERTS)
1017 1016
1018 #if defined(OS_CHROMEOS) 1017 #if defined(OS_CHROMEOS)
1019 ScopedPK11Slot GetSystemNSSKeySlot( 1018 ScopedPK11Slot GetSystemNSSKeySlot(
1020 const base::Callback<void(ScopedPK11Slot)>& callback) { 1019 const base::Callback<void(ScopedPK11Slot)>& callback) {
1021 return g_nss_singleton.Get().GetSystemNSSKeySlot(callback); 1020 return g_nss_singleton.Get().GetSystemNSSKeySlot(callback);
1022 } 1021 }
1023 1022
1024 void SetSystemKeySlotForTesting(ScopedPK11Slot slot) { 1023 void SetSystemKeySlotForTesting(ScopedPK11Slot slot) {
1025 g_nss_singleton.Get().SetSystemKeySlotForTesting(slot.Pass()); 1024 g_nss_singleton.Get().SetSystemKeySlotForTesting(slot.Pass());
1026 } 1025 }
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
1096 return time.ToInternalValue() - base::Time::UnixEpoch().ToInternalValue(); 1095 return time.ToInternalValue() - base::Time::UnixEpoch().ToInternalValue();
1097 } 1096 }
1098 1097
1099 #if !defined(OS_CHROMEOS) 1098 #if !defined(OS_CHROMEOS)
1100 PK11SlotInfo* GetPersistentNSSKeySlot() { 1099 PK11SlotInfo* GetPersistentNSSKeySlot() {
1101 return g_nss_singleton.Get().GetPersistentNSSKeySlot(); 1100 return g_nss_singleton.Get().GetPersistentNSSKeySlot();
1102 } 1101 }
1103 #endif 1102 #endif
1104 1103
1105 } // namespace crypto 1104 } // namespace crypto
OLDNEW
« no previous file with comments | « crypto/nss_util.h ('k') | crypto/rsa_private_key.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698