Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 <Cocoa/Cocoa.h> | 5 #include <Cocoa/Cocoa.h> |
| 6 | 6 |
| 7 #include <dlfcn.h> | |
| 8 #include </usr/include/mach-o/dyld.h> | |
|
kuchhal
2009/08/21 16:24:57
is that the right convention? not just mach-o/dyld
| |
| 9 | |
| 10 #include "base/sys_string_conversions.h" | |
| 11 | |
| 7 #include "chrome/browser/importer/nss_decryptor_mac.h" | 12 #include "chrome/browser/importer/nss_decryptor_mac.h" |
| 13 #include "chrome/browser/importer/firefox_importer_utils.h" | |
| 8 | 14 |
| 9 #include "base/logging.h" | 15 #include "base/logging.h" |
| 10 | 16 |
| 11 // static | 17 // static |
| 12 const wchar_t NSSDecryptor::kNSS3Library[] = L"libnss3.dylib"; | 18 const wchar_t NSSDecryptor::kNSS3Library[] = L"libnss3.dylib"; |
| 13 const wchar_t NSSDecryptor::kSoftokn3Library[] = L"libsoftokn3.dylib"; | |
| 14 const wchar_t NSSDecryptor::kPLDS4Library[] = L"libplds4.dylib"; | |
| 15 const wchar_t NSSDecryptor::kNSPR4Library[] = L"libnspr4.dylib"; | |
| 16 | 19 |
| 20 // Important!! : On OS X the nss3 libraries are compiled with depedencies | |
| 21 // on one another, referenced using dyld's @executable_path directive. | |
| 22 // To make a long story short in order to get the libraries to load, dyld's | |
| 23 // fallback path needs to be set to the directory containing the libraries. | |
| 24 // To do s, the process this function runs in must have the | |
|
kuchhal
2009/08/21 16:24:57
To do so
| |
| 25 // DYLD_FALLBACK_LIBRARY_PATH set on startup to said directory. | |
| 17 bool NSSDecryptor::Init(const std::wstring& dll_path, | 26 bool NSSDecryptor::Init(const std::wstring& dll_path, |
| 18 const std::wstring& db_path) { | 27 const std::wstring& db_path) { |
| 19 // TODO(port): Load the NSS libraries and call InitNSS() | 28 FilePath dylib_file_path = FilePath::FromWStringHack(dll_path); |
| 20 // http://code.google.com/p/chromium/issues/detail?id=15455 | 29 FilePath nss3_path = dylib_file_path.Append("libnss3.dylib"); |
| 21 NOTIMPLEMENTED(); | 30 |
| 22 return false; | 31 void *nss_3_lib = dlopen(nss3_path.value().c_str(), RTLD_LAZY); |
| 32 if (!nss_3_lib) { | |
| 33 LOG(ERROR) << "Failed to load nss3 lib" << dlerror(); | |
| 34 return false; | |
| 35 } | |
| 36 | |
| 37 NSS_Init = (NSSInitFunc)dlsym(nss_3_lib, "NSS_Init"); | |
| 38 NSS_Shutdown = (NSSShutdownFunc)dlsym(nss_3_lib, "NSS_Shutdown"); | |
| 39 PK11_GetInternalKeySlot = | |
| 40 (PK11GetInternalKeySlotFunc)dlsym(nss_3_lib, "PK11_GetInternalKeySlot"); | |
| 41 PK11_CheckUserPassword = | |
| 42 (PK11CheckUserPasswordFunc)dlsym(nss_3_lib, "PK11_CheckUserPassword"); | |
| 43 PK11_FreeSlot = (PK11FreeSlotFunc)dlsym(nss_3_lib, "PK11_FreeSlot"); | |
| 44 PK11_Authenticate = | |
| 45 (PK11AuthenticateFunc)dlsym(nss_3_lib, "PK11_Authenticate"); | |
| 46 PK11SDR_Decrypt = (PK11SDRDecryptFunc)dlsym(nss_3_lib, "PK11SDR_Decrypt"); | |
| 47 SECITEM_FreeItem = (SECITEMFreeItemFunc)dlsym(nss_3_lib, "SECITEM_FreeItem"); | |
| 48 | |
| 49 if (!NSS_Init || !NSS_Shutdown || !PK11_GetInternalKeySlot || | |
| 50 !PK11_CheckUserPassword || !PK11_FreeSlot || !PK11_Authenticate || | |
| 51 !PK11SDR_Decrypt || !SECITEM_FreeItem) { | |
| 52 LOG(ERROR) << "NSS3 importer couldn't find entry points"; | |
| 53 return false; | |
| 54 } | |
| 55 | |
| 56 SECStatus result = NSS_Init(base::SysWideToNativeMB(db_path).c_str()); | |
| 57 | |
| 58 if (result != SECSuccess) { | |
| 59 LOG(ERROR) << "NSS_Init Failed returned: " << result; | |
| 60 return false; | |
| 61 } | |
| 62 | |
| 63 is_nss_initialized_ = true; | |
| 64 return true; | |
| 23 } | 65 } |
| 66 | |
| 67 NSSDecryptor::~NSSDecryptor() { | |
| 68 if (NSS_Shutdown && is_nss_initialized_) { | |
| 69 NSS_Shutdown(); | |
| 70 is_nss_initialized_ = false; | |
| 71 } | |
| 72 } | |
| OLD | NEW |