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 <vector> | |
wtc
2011/03/17 20:03:55
Nit: list C++ system headers after C system header
Alpha Left Google
2011/03/17 22:31:34
Done.
| |
9 | |
8 #include <nss.h> | 10 #include <nss.h> |
9 #include <plarena.h> | 11 #include <plarena.h> |
10 #include <prerror.h> | 12 #include <prerror.h> |
11 #include <prinit.h> | 13 #include <prinit.h> |
12 #include <prtime.h> | 14 #include <prtime.h> |
13 #include <pk11pub.h> | 15 #include <pk11pub.h> |
14 #include <secmod.h> | 16 #include <secmod.h> |
15 | 17 |
16 #if defined(OS_LINUX) | 18 #if defined(OS_LINUX) |
17 #include <linux/nfs_fs.h> | 19 #include <linux/nfs_fs.h> |
18 #include <sys/vfs.h> | 20 #include <sys/vfs.h> |
19 #endif | 21 #endif |
20 | 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 // NSS libraries are linked dynamically on Linux so do this only on Linux. | |
wtc
2011/03/17 20:03:55
Nit: add "Some". Not all NSS libraries are loaded
Alpha Left Google
2011/03/17 22:31:34
Done.
| |
411 #if defined(OS_LINUX) | |
wtc
2011/03/17 20:03:55
It may be better to use defined(USE_NSS) or define
Alpha Left Google
2011/03/17 22:31:34
Done.
Alpha Left Google
2011/03/17 22:31:34
Done.
| |
412 // Try to search for multiple directories to load the libraries. | |
413 std::vector<FilePath> paths; | |
414 paths.push_back(FilePath()); | |
wtc
2011/03/17 20:03:55
Will this result in "/libsoftokn3.so" or "libsofto
Alpha Left Google
2011/03/17 22:31:34
This will load libsoftokn3.so.
| |
415 paths.push_back(FilePath("/usr/lib/nss")); | |
wtc
2011/03/17 20:03:55
Please document this is for Debian and its derivat
Alpha Left Google
2011/03/17 22:31:34
Done.
| |
416 | |
417 // A list of library files to load. | |
418 std::vector<std::string> libs; | |
419 libs.push_back("libsoftokn3.so"); | |
420 libs.push_back("libfreebl3.so"); | |
421 | |
422 // For each combination of library file and path, check for existence and | |
423 // then load. | |
424 size_t loaded = 0; | |
425 for (size_t i = 0; i < libs.size(); ++i) { | |
426 for (size_t j = 0; j < paths.size(); ++j) { | |
427 FilePath path = paths[j].Append(libs[i]); | |
428 if (file_util::PathExists(path)) { | |
429 NativeLibrary lib = base::LoadNativeLibrary(path); | |
430 if (lib) { | |
431 ++loaded; | |
432 break; | |
433 } | |
434 } | |
435 } | |
436 } | |
437 | |
438 if (loaded == libs.size()) { | |
439 LOG(INFO) << "NSS libraries loaded."; | |
440 } else { | |
441 LOG(WARNING) << "Failed to load NSS libraries."; | |
wtc
2011/03/17 20:03:55
This should be LOG(ERROR).
The LOG(INFO) should b
Alpha Left Google
2011/03/17 22:31:34
Done.
| |
442 } | |
443 #endif | |
444 } | |
445 | |
405 bool CheckNSSVersion(const char* version) { | 446 bool CheckNSSVersion(const char* version) { |
406 return !!NSS_VersionCheck(version); | 447 return !!NSS_VersionCheck(version); |
407 } | 448 } |
408 | 449 |
409 #if defined(USE_NSS) | 450 #if defined(USE_NSS) |
410 bool OpenTestNSSDB(const FilePath& path, const char* description) { | 451 bool OpenTestNSSDB(const FilePath& path, const char* description) { |
411 return g_nss_singleton.Get().OpenTestNSSDB(path, description); | 452 return g_nss_singleton.Get().OpenTestNSSDB(path, description); |
412 } | 453 } |
413 | 454 |
414 void CloseTestNSSDB() { | 455 void CloseTestNSSDB() { |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
456 exploded.millisecond = prxtime.tm_usec / 1000; | 497 exploded.millisecond = prxtime.tm_usec / 1000; |
457 | 498 |
458 return Time::FromUTCExploded(exploded); | 499 return Time::FromUTCExploded(exploded); |
459 } | 500 } |
460 | 501 |
461 PK11SlotInfo* GetDefaultNSSKeySlot() { | 502 PK11SlotInfo* GetDefaultNSSKeySlot() { |
462 return g_nss_singleton.Get().GetDefaultKeySlot(); | 503 return g_nss_singleton.Get().GetDefaultKeySlot(); |
463 } | 504 } |
464 | 505 |
465 } // namespace base | 506 } // namespace base |
OLD | NEW |