Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1046)

Unified Diff: chrome/browser/importer/nss_decryptor_mac.mm

Issue 174206: Bring up Firefox Password Import Unittest on OS X. (Closed)
Patch Set: Small fix Created 11 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/importer/nss_decryptor_mac.mm
diff --git a/chrome/browser/importer/nss_decryptor_mac.mm b/chrome/browser/importer/nss_decryptor_mac.mm
index 97e85b687869c01eee19d987a2f1f0286698f35a..c35064158f44c4b551fe60739e39d03bda11760c 100644
--- a/chrome/browser/importer/nss_decryptor_mac.mm
+++ b/chrome/browser/importer/nss_decryptor_mac.mm
@@ -4,20 +4,69 @@
#include <Cocoa/Cocoa.h>
+#include <dlfcn.h>
+#include </usr/include/mach-o/dyld.h>
kuchhal 2009/08/21 16:24:57 is that the right convention? not just mach-o/dyld
+
+#include "base/sys_string_conversions.h"
+
#include "chrome/browser/importer/nss_decryptor_mac.h"
+#include "chrome/browser/importer/firefox_importer_utils.h"
#include "base/logging.h"
// static
const wchar_t NSSDecryptor::kNSS3Library[] = L"libnss3.dylib";
-const wchar_t NSSDecryptor::kSoftokn3Library[] = L"libsoftokn3.dylib";
-const wchar_t NSSDecryptor::kPLDS4Library[] = L"libplds4.dylib";
-const wchar_t NSSDecryptor::kNSPR4Library[] = L"libnspr4.dylib";
+// Important!! : On OS X the nss3 libraries are compiled with depedencies
+// on one another, referenced using dyld's @executable_path directive.
+// To make a long story short in order to get the libraries to load, dyld's
+// fallback path needs to be set to the directory containing the libraries.
+// To do s, the process this function runs in must have the
kuchhal 2009/08/21 16:24:57 To do so
+// DYLD_FALLBACK_LIBRARY_PATH set on startup to said directory.
bool NSSDecryptor::Init(const std::wstring& dll_path,
const std::wstring& db_path) {
- // TODO(port): Load the NSS libraries and call InitNSS()
- // http://code.google.com/p/chromium/issues/detail?id=15455
- NOTIMPLEMENTED();
- return false;
+ FilePath dylib_file_path = FilePath::FromWStringHack(dll_path);
+ FilePath nss3_path = dylib_file_path.Append("libnss3.dylib");
+
+ void *nss_3_lib = dlopen(nss3_path.value().c_str(), RTLD_LAZY);
+ if (!nss_3_lib) {
+ LOG(ERROR) << "Failed to load nss3 lib" << dlerror();
+ return false;
+ }
+
+ NSS_Init = (NSSInitFunc)dlsym(nss_3_lib, "NSS_Init");
+ NSS_Shutdown = (NSSShutdownFunc)dlsym(nss_3_lib, "NSS_Shutdown");
+ PK11_GetInternalKeySlot =
+ (PK11GetInternalKeySlotFunc)dlsym(nss_3_lib, "PK11_GetInternalKeySlot");
+ PK11_CheckUserPassword =
+ (PK11CheckUserPasswordFunc)dlsym(nss_3_lib, "PK11_CheckUserPassword");
+ PK11_FreeSlot = (PK11FreeSlotFunc)dlsym(nss_3_lib, "PK11_FreeSlot");
+ PK11_Authenticate =
+ (PK11AuthenticateFunc)dlsym(nss_3_lib, "PK11_Authenticate");
+ PK11SDR_Decrypt = (PK11SDRDecryptFunc)dlsym(nss_3_lib, "PK11SDR_Decrypt");
+ SECITEM_FreeItem = (SECITEMFreeItemFunc)dlsym(nss_3_lib, "SECITEM_FreeItem");
+
+ if (!NSS_Init || !NSS_Shutdown || !PK11_GetInternalKeySlot ||
+ !PK11_CheckUserPassword || !PK11_FreeSlot || !PK11_Authenticate ||
+ !PK11SDR_Decrypt || !SECITEM_FreeItem) {
+ LOG(ERROR) << "NSS3 importer couldn't find entry points";
+ return false;
+ }
+
+ SECStatus result = NSS_Init(base::SysWideToNativeMB(db_path).c_str());
+
+ if (result != SECSuccess) {
+ LOG(ERROR) << "NSS_Init Failed returned: " << result;
+ return false;
+ }
+
+ is_nss_initialized_ = true;
+ return true;
+}
+
+NSSDecryptor::~NSSDecryptor() {
+ if (NSS_Shutdown && is_nss_initialized_) {
+ NSS_Shutdown();
+ is_nss_initialized_ = false;
+ }
}

Powered by Google App Engine
This is Rietveld 408576698