OLD | NEW |
---|---|
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "base/nss_util.h" | 5 #include "base/nss_util.h" |
6 #include "base/nss_util_internal.h" | 6 #include "base/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> |
11 #include <prinit.h> | 11 #include <prinit.h> |
12 #include <prtime.h> | 12 #include <prtime.h> |
13 #include <pk11pub.h> | 13 #include <pk11pub.h> |
14 #include <secmod.h> | 14 #include <secmod.h> |
15 | 15 |
16 #if defined(OS_LINUX) | 16 #if defined(OS_LINUX) |
17 #include <linux/nfs_fs.h> | 17 #include <linux/nfs_fs.h> |
18 #include <sys/vfs.h> | 18 #include <sys/vfs.h> |
19 #endif | 19 #endif |
20 | 20 |
21 #include <vector> | |
22 | |
21 #include "base/environment.h" | 23 #include "base/environment.h" |
24 #include "base/file_path.h" | |
22 #include "base/file_util.h" | 25 #include "base/file_util.h" |
23 #include "base/lazy_instance.h" | 26 #include "base/lazy_instance.h" |
24 #include "base/logging.h" | 27 #include "base/logging.h" |
28 #include "base/native_library.h" | |
25 #include "base/scoped_ptr.h" | 29 #include "base/scoped_ptr.h" |
26 #include "base/stringprintf.h" | 30 #include "base/stringprintf.h" |
27 #include "base/threading/thread_restrictions.h" | 31 #include "base/threading/thread_restrictions.h" |
28 | 32 |
29 // USE_NSS means we use NSS for everything crypto-related. If USE_NSS is not | 33 // USE_NSS means we use NSS for everything crypto-related. If USE_NSS is not |
30 // defined, such as on Mac and Windows, we use NSS for SSL only -- we don't | 34 // defined, such as on Mac and Windows, we use NSS for SSL only -- we don't |
31 // use NSS for crypto or certificate verification, and we don't use the NSS | 35 // use NSS for crypto or certificate verification, and we don't use the NSS |
32 // certificate and key databases. | 36 // certificate and key databases. |
33 #if defined(USE_NSS) | 37 #if defined(USE_NSS) |
34 #include "base/crypto/crypto_module_blocking_password_delegate.h" | 38 #include "base/crypto/crypto_module_blocking_password_delegate.h" |
(...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
395 | 399 |
396 void ForceNSSNoDBInit() { | 400 void ForceNSSNoDBInit() { |
397 NSSInitSingleton::ForceNoDBInit(); | 401 NSSInitSingleton::ForceNoDBInit(); |
398 } | 402 } |
399 | 403 |
400 void DisableNSSForkCheck() { | 404 void DisableNSSForkCheck() { |
401 scoped_ptr<Environment> env(Environment::Create()); | 405 scoped_ptr<Environment> env(Environment::Create()); |
402 env->SetVar("NSS_STRICT_NOFORK", "DISABLED"); | 406 env->SetVar("NSS_STRICT_NOFORK", "DISABLED"); |
403 } | 407 } |
404 | 408 |
409 void LoadNSSLibraries() { | |
410 // Some NSS libraries are linked dynamically so load them here. | |
411 #if defined(USE_NSS) | |
412 // Try to search for multiple directories to load the libraries. | |
413 std::vector<FilePath> paths; | |
414 | |
415 // Use relative path to Search PATH for the library files. | |
wtc
2011/03/18 18:46:31
Nit: the PATH environment variable is only used fo
| |
416 paths.push_back(FilePath()); | |
417 | |
418 // For Debian derivaties NSS libraries are located here. | |
wtc
2011/03/18 18:46:31
Nit: NSS libraries => dynamically loaded NSS libra
| |
419 paths.push_back(FilePath("/usr/lib/nss")); | |
420 | |
421 // A list of library files to load. | |
422 std::vector<std::string> libs; | |
423 libs.push_back("libsoftokn3.so"); | |
424 libs.push_back("libfreebl3.so"); | |
425 | |
426 // For each combination of library file and path, check for existence and | |
427 // then load. | |
428 size_t loaded = 0; | |
429 for (size_t i = 0; i < libs.size(); ++i) { | |
430 for (size_t j = 0; j < paths.size(); ++j) { | |
431 FilePath path = paths[j].Append(libs[i]); | |
432 if (file_util::PathExists(path)) { | |
433 NativeLibrary lib = base::LoadNativeLibrary(path); | |
434 if (lib) { | |
435 ++loaded; | |
436 break; | |
437 } | |
438 } | |
439 } | |
440 } | |
441 | |
442 if (loaded == libs.size()) { | |
443 VLOG(3) << "NSS libraries loaded."; | |
444 } else { | |
445 LOG(WARNING) << "Failed to load NSS libraries."; | |
446 } | |
447 #endif | |
448 } | |
449 | |
405 bool CheckNSSVersion(const char* version) { | 450 bool CheckNSSVersion(const char* version) { |
406 return !!NSS_VersionCheck(version); | 451 return !!NSS_VersionCheck(version); |
407 } | 452 } |
408 | 453 |
409 #if defined(USE_NSS) | 454 #if defined(USE_NSS) |
410 bool OpenTestNSSDB(const FilePath& path, const char* description) { | 455 bool OpenTestNSSDB(const FilePath& path, const char* description) { |
411 return g_nss_singleton.Get().OpenTestNSSDB(path, description); | 456 return g_nss_singleton.Get().OpenTestNSSDB(path, description); |
412 } | 457 } |
413 | 458 |
414 void CloseTestNSSDB() { | 459 void CloseTestNSSDB() { |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
456 exploded.millisecond = prxtime.tm_usec / 1000; | 501 exploded.millisecond = prxtime.tm_usec / 1000; |
457 | 502 |
458 return Time::FromUTCExploded(exploded); | 503 return Time::FromUTCExploded(exploded); |
459 } | 504 } |
460 | 505 |
461 PK11SlotInfo* GetDefaultNSSKeySlot() { | 506 PK11SlotInfo* GetDefaultNSSKeySlot() { |
462 return g_nss_singleton.Get().GetDefaultKeySlot(); | 507 return g_nss_singleton.Get().GetDefaultKeySlot(); |
463 } | 508 } |
464 | 509 |
465 } // namespace base | 510 } // namespace base |
OLD | NEW |