OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 11 matching lines...) Expand all Loading... |
22 | 22 |
23 #include "base/environment.h" | 23 #include "base/environment.h" |
24 #include "base/file_path.h" | 24 #include "base/file_path.h" |
25 #include "base/file_util.h" | 25 #include "base/file_util.h" |
26 #include "base/lazy_instance.h" | 26 #include "base/lazy_instance.h" |
27 #include "base/logging.h" | 27 #include "base/logging.h" |
28 #include "base/memory/scoped_ptr.h" | 28 #include "base/memory/scoped_ptr.h" |
29 #include "base/native_library.h" | 29 #include "base/native_library.h" |
30 #include "base/stringprintf.h" | 30 #include "base/stringprintf.h" |
31 #include "base/threading/thread_restrictions.h" | 31 #include "base/threading/thread_restrictions.h" |
| 32 #include "build/build_config.h" |
32 #include "crypto/scoped_nss_types.h" | 33 #include "crypto/scoped_nss_types.h" |
33 | 34 |
34 // USE_NSS means we use NSS for everything crypto-related. If USE_NSS is not | 35 // USE_NSS means we use NSS for everything crypto-related. If USE_NSS is not |
35 // defined, such as on Mac and Windows, we use NSS for SSL only -- we don't | 36 // defined, such as on Mac and Windows, we use NSS for SSL only -- we don't |
36 // use NSS for crypto or certificate verification, and we don't use the NSS | 37 // use NSS for crypto or certificate verification, and we don't use the NSS |
37 // certificate and key databases. | 38 // certificate and key databases. |
38 #if defined(USE_NSS) | 39 #if defined(USE_NSS) |
39 #include "base/synchronization/lock.h" | 40 #include "base/synchronization/lock.h" |
40 #include "crypto/crypto_module_blocking_password_delegate.h" | 41 #include "crypto/crypto_module_blocking_password_delegate.h" |
41 #endif // defined(USE_NSS) | 42 #endif // defined(USE_NSS) |
(...skipping 554 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
596 | 597 |
597 void LoadNSSLibraries() { | 598 void LoadNSSLibraries() { |
598 // Some NSS libraries are linked dynamically so load them here. | 599 // Some NSS libraries are linked dynamically so load them here. |
599 #if defined(USE_NSS) | 600 #if defined(USE_NSS) |
600 // Try to search for multiple directories to load the libraries. | 601 // Try to search for multiple directories to load the libraries. |
601 std::vector<FilePath> paths; | 602 std::vector<FilePath> paths; |
602 | 603 |
603 // Use relative path to Search PATH for the library files. | 604 // Use relative path to Search PATH for the library files. |
604 paths.push_back(FilePath()); | 605 paths.push_back(FilePath()); |
605 | 606 |
606 // For Debian derivaties NSS libraries are located here. | 607 // For Debian derivatives NSS libraries are located here. |
607 paths.push_back(FilePath("/usr/lib/nss")); | 608 paths.push_back(FilePath("/usr/lib/nss")); |
608 | 609 |
| 610 // Ubuntu 11.10 (Oneiric) places the libraries here. |
| 611 #if defined(ARCH_CPU_X86_64) |
| 612 paths.push_back(FilePath("/usr/lib/x86_64-linux-gnu/nss")); |
| 613 #elif defined(ARCH_CPU_X86) |
| 614 paths.push_back(FilePath("/usr/lib/i386-linux-gnu/nss")); |
| 615 #elif defined(ARCH_CPU_ARMEL) |
| 616 paths.push_back(FilePath("/usr/lib/arm-linux-gnueabi/nss")); |
| 617 #endif |
| 618 |
609 // A list of library files to load. | 619 // A list of library files to load. |
610 std::vector<std::string> libs; | 620 std::vector<std::string> libs; |
611 libs.push_back("libsoftokn3.so"); | 621 libs.push_back("libsoftokn3.so"); |
612 libs.push_back("libfreebl3.so"); | 622 libs.push_back("libfreebl3.so"); |
613 | 623 |
614 // For each combination of library file and path, check for existence and | 624 // For each combination of library file and path, check for existence and |
615 // then load. | 625 // then load. |
616 size_t loaded = 0; | 626 size_t loaded = 0; |
617 for (size_t i = 0; i < libs.size(); ++i) { | 627 for (size_t i = 0; i < libs.size(); ++i) { |
618 for (size_t j = 0; j < paths.size(); ++j) { | 628 for (size_t j = 0; j < paths.size(); ++j) { |
619 FilePath path = paths[j].Append(libs[i]); | 629 FilePath path = paths[j].Append(libs[i]); |
620 base::NativeLibrary lib = base::LoadNativeLibrary(path, NULL); | 630 base::NativeLibrary lib = base::LoadNativeLibrary(path, NULL); |
621 if (lib) { | 631 if (lib) { |
622 ++loaded; | 632 ++loaded; |
623 break; | 633 break; |
624 } | 634 } |
625 } | 635 } |
626 } | 636 } |
627 | 637 |
628 if (loaded == libs.size()) { | 638 if (loaded == libs.size()) { |
629 VLOG(3) << "NSS libraries loaded."; | 639 VLOG(3) << "NSS libraries loaded."; |
630 } else { | 640 } else { |
631 LOG(WARNING) << "Failed to load NSS libraries."; | 641 LOG(ERROR) << "Failed to load NSS libraries."; |
632 } | 642 } |
633 #endif | 643 #endif |
634 } | 644 } |
635 | 645 |
636 bool CheckNSSVersion(const char* version) { | 646 bool CheckNSSVersion(const char* version) { |
637 return !!NSS_VersionCheck(version); | 647 return !!NSS_VersionCheck(version); |
638 } | 648 } |
639 | 649 |
640 #if defined(USE_NSS) | 650 #if defined(USE_NSS) |
641 bool OpenTestNSSDB(const FilePath& path, const char* description) { | 651 bool OpenTestNSSDB(const FilePath& path, const char* description) { |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
725 | 735 |
726 PK11SlotInfo* GetPublicNSSKeySlot() { | 736 PK11SlotInfo* GetPublicNSSKeySlot() { |
727 return g_nss_singleton.Get().GetPublicNSSKeySlot(); | 737 return g_nss_singleton.Get().GetPublicNSSKeySlot(); |
728 } | 738 } |
729 | 739 |
730 PK11SlotInfo* GetPrivateNSSKeySlot() { | 740 PK11SlotInfo* GetPrivateNSSKeySlot() { |
731 return g_nss_singleton.Get().GetPrivateNSSKeySlot(); | 741 return g_nss_singleton.Get().GetPrivateNSSKeySlot(); |
732 } | 742 } |
733 | 743 |
734 } // namespace crypto | 744 } // namespace crypto |
OLD | NEW |