| 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 #if defined(OS_CHROMEOS) | 35 #if defined(OS_CHROMEOS) |
| 35 #include "crypto/symmetric_key.h" | 36 #include "crypto/symmetric_key.h" |
| 36 #endif | 37 #endif |
| 37 | 38 |
| 38 // USE_NSS means we use NSS for everything crypto-related. If USE_NSS is not | 39 // USE_NSS means we use NSS for everything crypto-related. If USE_NSS is not |
| 39 // defined, such as on Mac and Windows, we use NSS for SSL only -- we don't | 40 // defined, such as on Mac and Windows, we use NSS for SSL only -- we don't |
| 40 // use NSS for crypto or certificate verification, and we don't use the NSS | 41 // use NSS for crypto or certificate verification, and we don't use the NSS |
| 41 // certificate and key databases. | 42 // certificate and key databases. |
| (...skipping 601 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 643 | 644 |
| 644 void LoadNSSLibraries() { | 645 void LoadNSSLibraries() { |
| 645 // Some NSS libraries are linked dynamically so load them here. | 646 // Some NSS libraries are linked dynamically so load them here. |
| 646 #if defined(USE_NSS) | 647 #if defined(USE_NSS) |
| 647 // Try to search for multiple directories to load the libraries. | 648 // Try to search for multiple directories to load the libraries. |
| 648 std::vector<FilePath> paths; | 649 std::vector<FilePath> paths; |
| 649 | 650 |
| 650 // Use relative path to Search PATH for the library files. | 651 // Use relative path to Search PATH for the library files. |
| 651 paths.push_back(FilePath()); | 652 paths.push_back(FilePath()); |
| 652 | 653 |
| 653 // For Debian derivaties NSS libraries are located here. | 654 // For Debian derivatives NSS libraries are located here. |
| 654 paths.push_back(FilePath("/usr/lib/nss")); | 655 paths.push_back(FilePath("/usr/lib/nss")); |
| 655 | 656 |
| 657 // Ubuntu 11.10 (Oneiric) places the libraries here. |
| 658 #if defined(ARCH_CPU_X86_64) |
| 659 paths.push_back(FilePath("/usr/lib/x86_64-linux-gnu/nss")); |
| 660 #elif defined(ARCH_CPU_X86) |
| 661 paths.push_back(FilePath("/usr/lib/i386-linux-gnu/nss")); |
| 662 #elif defined(ARCH_CPU_ARMEL) |
| 663 paths.push_back(FilePath("/usr/lib/arm-linux-gnueabi/nss")); |
| 664 #endif |
| 665 |
| 656 // A list of library files to load. | 666 // A list of library files to load. |
| 657 std::vector<std::string> libs; | 667 std::vector<std::string> libs; |
| 658 libs.push_back("libsoftokn3.so"); | 668 libs.push_back("libsoftokn3.so"); |
| 659 libs.push_back("libfreebl3.so"); | 669 libs.push_back("libfreebl3.so"); |
| 660 | 670 |
| 661 // For each combination of library file and path, check for existence and | 671 // For each combination of library file and path, check for existence and |
| 662 // then load. | 672 // then load. |
| 663 size_t loaded = 0; | 673 size_t loaded = 0; |
| 664 for (size_t i = 0; i < libs.size(); ++i) { | 674 for (size_t i = 0; i < libs.size(); ++i) { |
| 665 for (size_t j = 0; j < paths.size(); ++j) { | 675 for (size_t j = 0; j < paths.size(); ++j) { |
| 666 FilePath path = paths[j].Append(libs[i]); | 676 FilePath path = paths[j].Append(libs[i]); |
| 667 base::NativeLibrary lib = base::LoadNativeLibrary(path, NULL); | 677 base::NativeLibrary lib = base::LoadNativeLibrary(path, NULL); |
| 668 if (lib) { | 678 if (lib) { |
| 669 ++loaded; | 679 ++loaded; |
| 670 break; | 680 break; |
| 671 } | 681 } |
| 672 } | 682 } |
| 673 } | 683 } |
| 674 | 684 |
| 675 if (loaded == libs.size()) { | 685 if (loaded == libs.size()) { |
| 676 VLOG(3) << "NSS libraries loaded."; | 686 VLOG(3) << "NSS libraries loaded."; |
| 677 } else { | 687 } else { |
| 678 LOG(WARNING) << "Failed to load NSS libraries."; | 688 LOG(ERROR) << "Failed to load NSS libraries."; |
| 679 } | 689 } |
| 680 #endif | 690 #endif |
| 681 } | 691 } |
| 682 | 692 |
| 683 bool CheckNSSVersion(const char* version) { | 693 bool CheckNSSVersion(const char* version) { |
| 684 return !!NSS_VersionCheck(version); | 694 return !!NSS_VersionCheck(version); |
| 685 } | 695 } |
| 686 | 696 |
| 687 #if defined(USE_NSS) | 697 #if defined(USE_NSS) |
| 688 bool OpenTestNSSDB(const FilePath& path, const char* description) { | 698 bool OpenTestNSSDB(const FilePath& path, const char* description) { |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 775 | 785 |
| 776 PK11SlotInfo* GetPublicNSSKeySlot() { | 786 PK11SlotInfo* GetPublicNSSKeySlot() { |
| 777 return g_nss_singleton.Get().GetPublicNSSKeySlot(); | 787 return g_nss_singleton.Get().GetPublicNSSKeySlot(); |
| 778 } | 788 } |
| 779 | 789 |
| 780 PK11SlotInfo* GetPrivateNSSKeySlot() { | 790 PK11SlotInfo* GetPrivateNSSKeySlot() { |
| 781 return g_nss_singleton.Get().GetPrivateNSSKeySlot(); | 791 return g_nss_singleton.Get().GetPrivateNSSKeySlot(); |
| 782 } | 792 } |
| 783 | 793 |
| 784 } // namespace crypto | 794 } // namespace crypto |
| OLD | NEW |