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 <pk11pub.h> | 9 #include <pk11pub.h> |
10 #include <plarena.h> | 10 #include <plarena.h> |
11 #include <prerror.h> | 11 #include <prerror.h> |
12 #include <prinit.h> | 12 #include <prinit.h> |
13 #include <prtime.h> | 13 #include <prtime.h> |
14 #include <secmod.h> | 14 #include <secmod.h> |
15 | 15 |
16 #if defined(OS_LINUX) | 16 #if defined(OS_OPENBSD) |
17 #include <linux/nfs_fs.h> | |
18 #include <sys/vfs.h> | |
19 #elif defined(OS_OPENBSD) | |
20 #include <sys/mount.h> | 17 #include <sys/mount.h> |
21 #include <sys/param.h> | 18 #include <sys/param.h> |
22 #endif | 19 #endif |
23 | 20 |
24 #include <map> | 21 #include <map> |
25 #include <vector> | 22 #include <vector> |
26 | 23 |
27 #include "base/bind.h" | 24 #include "base/bind.h" |
28 #include "base/callback.h" | 25 #include "base/callback.h" |
29 #include "base/cpu.h" | 26 #include "base/cpu.h" |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
140 // the NSS environment variable NSS_SDB_USE_CACHE to "yes" to override NSS's | 137 // the NSS environment variable NSS_SDB_USE_CACHE to "yes" to override NSS's |
141 // detection when database_dir is on NFS. See http://crbug.com/48585. | 138 // detection when database_dir is on NFS. See http://crbug.com/48585. |
142 // | 139 // |
143 // TODO(wtc): port this function to other USE_NSS platforms. It is defined | 140 // TODO(wtc): port this function to other USE_NSS platforms. It is defined |
144 // only for OS_LINUX and OS_OPENBSD simply because the statfs structure | 141 // only for OS_LINUX and OS_OPENBSD simply because the statfs structure |
145 // is OS-specific. | 142 // is OS-specific. |
146 // | 143 // |
147 // Because this function sets an environment variable it must be run before we | 144 // Because this function sets an environment variable it must be run before we |
148 // go multi-threaded. | 145 // go multi-threaded. |
149 void UseLocalCacheOfNSSDatabaseIfNFS(const base::FilePath& database_dir) { | 146 void UseLocalCacheOfNSSDatabaseIfNFS(const base::FilePath& database_dir) { |
150 #if defined(OS_LINUX) || defined(OS_OPENBSD) | 147 bool db_on_nfs = false; |
| 148 #if defined(OS_LINUX) |
| 149 file_util::FileSystemType fs_type = file_util::FILE_SYSTEM_UNKNOWN; |
| 150 if (file_util::GetFileSystemType(database_dir, &fs_type)) |
| 151 db_on_nfs = (fs_type == file_util::FILE_SYSTEM_NFS); |
| 152 #elif defined(OS_OPENBSD) |
151 struct statfs buf; | 153 struct statfs buf; |
152 if (statfs(database_dir.value().c_str(), &buf) == 0) { | 154 if (statfs(database_dir.value().c_str(), &buf) == 0) |
153 #if defined(OS_LINUX) | 155 db_on_nfs = (strcmp(buf.f_fstypename, MOUNT_NFS) == 0); |
154 if (buf.f_type == NFS_SUPER_MAGIC) { | 156 #else |
155 #elif defined(OS_OPENBSD) | 157 NOTIMPLEMENTED(); |
156 if (strcmp(buf.f_fstypename, MOUNT_NFS) == 0) { | |
157 #endif | 158 #endif |
158 scoped_ptr<base::Environment> env(base::Environment::Create()); | 159 |
159 const char* use_cache_env_var = "NSS_SDB_USE_CACHE"; | 160 if (db_on_nfs) { |
160 if (!env->HasVar(use_cache_env_var)) | 161 scoped_ptr<base::Environment> env(base::Environment::Create()); |
161 env->SetVar(use_cache_env_var, "yes"); | 162 static const char kUseCacheEnvVar[] = "NSS_SDB_USE_CACHE"; |
162 } | 163 if (!env->HasVar(kUseCacheEnvVar)) |
| 164 env->SetVar(kUseCacheEnvVar, "yes"); |
163 } | 165 } |
164 #endif // defined(OS_LINUX) || defined(OS_OPENBSD) | |
165 } | 166 } |
166 | 167 |
167 #endif // defined(USE_NSS) | 168 #endif // defined(USE_NSS) |
168 | 169 |
169 // A singleton to initialize/deinitialize NSPR. | 170 // A singleton to initialize/deinitialize NSPR. |
170 // Separate from the NSS singleton because we initialize NSPR on the UI thread. | 171 // Separate from the NSS singleton because we initialize NSPR on the UI thread. |
171 // Now that we're leaking the singleton, we could merge back with the NSS | 172 // Now that we're leaking the singleton, we could merge back with the NSS |
172 // singleton. | 173 // singleton. |
173 class NSPRInitSingleton { | 174 class NSPRInitSingleton { |
174 private: | 175 private: |
(...skipping 727 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
902 // Ubuntu 11.10 (Oneiric) and Debian Wheezy place the libraries here. | 903 // Ubuntu 11.10 (Oneiric) and Debian Wheezy place the libraries here. |
903 #if defined(ARCH_CPU_X86_64) | 904 #if defined(ARCH_CPU_X86_64) |
904 paths.push_back(base::FilePath("/usr/lib/x86_64-linux-gnu/nss")); | 905 paths.push_back(base::FilePath("/usr/lib/x86_64-linux-gnu/nss")); |
905 #elif defined(ARCH_CPU_X86) | 906 #elif defined(ARCH_CPU_X86) |
906 paths.push_back(base::FilePath("/usr/lib/i386-linux-gnu/nss")); | 907 paths.push_back(base::FilePath("/usr/lib/i386-linux-gnu/nss")); |
907 #elif defined(ARCH_CPU_ARMEL) | 908 #elif defined(ARCH_CPU_ARMEL) |
908 #if defined(__ARM_PCS_VFP) | 909 #if defined(__ARM_PCS_VFP) |
909 paths.push_back(base::FilePath("/usr/lib/arm-linux-gnueabihf/nss")); | 910 paths.push_back(base::FilePath("/usr/lib/arm-linux-gnueabihf/nss")); |
910 #else | 911 #else |
911 paths.push_back(base::FilePath("/usr/lib/arm-linux-gnueabi/nss")); | 912 paths.push_back(base::FilePath("/usr/lib/arm-linux-gnueabi/nss")); |
912 #endif | 913 #endif // defined(__ARM_PCS_VFP) |
913 #elif defined(ARCH_CPU_MIPSEL) | 914 #elif defined(ARCH_CPU_MIPSEL) |
914 paths.push_back(base::FilePath("/usr/lib/mipsel-linux-gnu/nss")); | 915 paths.push_back(base::FilePath("/usr/lib/mipsel-linux-gnu/nss")); |
915 #endif | 916 #endif // defined(ARCH_CPU_X86_64) |
916 | 917 |
917 // A list of library files to load. | 918 // A list of library files to load. |
918 std::vector<std::string> libs; | 919 std::vector<std::string> libs; |
919 libs.push_back("libsoftokn3.so"); | 920 libs.push_back("libsoftokn3.so"); |
920 libs.push_back("libfreebl3.so"); | 921 libs.push_back("libfreebl3.so"); |
921 | 922 |
922 // For each combination of library file and path, check for existence and | 923 // For each combination of library file and path, check for existence and |
923 // then load. | 924 // then load. |
924 size_t loaded = 0; | 925 size_t loaded = 0; |
925 for (size_t i = 0; i < libs.size(); ++i) { | 926 for (size_t i = 0; i < libs.size(); ++i) { |
926 for (size_t j = 0; j < paths.size(); ++j) { | 927 for (size_t j = 0; j < paths.size(); ++j) { |
927 base::FilePath path = paths[j].Append(libs[i]); | 928 base::FilePath path = paths[j].Append(libs[i]); |
928 base::NativeLibrary lib = base::LoadNativeLibrary(path, NULL); | 929 base::NativeLibrary lib = base::LoadNativeLibrary(path, NULL); |
929 if (lib) { | 930 if (lib) { |
930 ++loaded; | 931 ++loaded; |
931 break; | 932 break; |
932 } | 933 } |
933 } | 934 } |
934 } | 935 } |
935 | 936 |
936 if (loaded == libs.size()) { | 937 if (loaded == libs.size()) { |
937 VLOG(3) << "NSS libraries loaded."; | 938 VLOG(3) << "NSS libraries loaded."; |
938 } else { | 939 } else { |
939 LOG(ERROR) << "Failed to load NSS libraries."; | 940 LOG(ERROR) << "Failed to load NSS libraries."; |
940 } | 941 } |
941 #endif | 942 #endif // defined(USE_NSS) |
942 } | 943 } |
943 | 944 |
944 bool CheckNSSVersion(const char* version) { | 945 bool CheckNSSVersion(const char* version) { |
945 return !!NSS_VersionCheck(version); | 946 return !!NSS_VersionCheck(version); |
946 } | 947 } |
947 | 948 |
948 #if defined(USE_NSS) | 949 #if defined(USE_NSS) |
949 ScopedTestNSSDB::ScopedTestNSSDB() | 950 ScopedTestNSSDB::ScopedTestNSSDB() |
950 : is_open_(g_nss_singleton.Get().OpenTestNSSDB()) { | 951 : is_open_(g_nss_singleton.Get().OpenTestNSSDB()) { |
951 } | 952 } |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1069 | 1070 |
1070 PK11SlotInfo* GetPublicNSSKeySlot() { | 1071 PK11SlotInfo* GetPublicNSSKeySlot() { |
1071 return g_nss_singleton.Get().GetPublicNSSKeySlot(); | 1072 return g_nss_singleton.Get().GetPublicNSSKeySlot(); |
1072 } | 1073 } |
1073 | 1074 |
1074 PK11SlotInfo* GetPrivateNSSKeySlot() { | 1075 PK11SlotInfo* GetPrivateNSSKeySlot() { |
1075 return g_nss_singleton.Get().GetPrivateNSSKeySlot(); | 1076 return g_nss_singleton.Get().GetPrivateNSSKeySlot(); |
1076 } | 1077 } |
1077 | 1078 |
1078 } // namespace crypto | 1079 } // namespace crypto |
OLD | NEW |