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

Side by Side Diff: chrome/browser/importer/nss_decryptor_mac.mm

Issue 174259: Recommit "Bring up Firefox Password Import Unittest on OS X." (Closed)
Patch Set: 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 unified diff | Download patch
« no previous file with comments | « chrome/browser/importer/nss_decryptor_mac.h ('k') | chrome/chrome.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
9 #include "base/sys_string_conversions.h"
10
7 #include "chrome/browser/importer/nss_decryptor_mac.h" 11 #include "chrome/browser/importer/nss_decryptor_mac.h"
12 #include "chrome/browser/importer/firefox_importer_utils.h"
8 13
9 #include "base/logging.h" 14 #include "base/logging.h"
10 15
11 // static 16 // static
12 const wchar_t NSSDecryptor::kNSS3Library[] = L"libnss3.dylib"; 17 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 18
19 // Important!! : On OS X the nss3 libraries are compiled with depedencies
20 // on one another, referenced using dyld's @executable_path directive.
21 // To make a long story short in order to get the libraries to load, dyld's
22 // fallback path needs to be set to the directory containing the libraries.
23 // To do so, the process this function runs in must have the
24 // DYLD_FALLBACK_LIBRARY_PATH set on startup to said directory.
17 bool NSSDecryptor::Init(const std::wstring& dll_path, 25 bool NSSDecryptor::Init(const std::wstring& dll_path,
18 const std::wstring& db_path) { 26 const std::wstring& db_path) {
19 // TODO(port): Load the NSS libraries and call InitNSS() 27 FilePath dylib_file_path = FilePath::FromWStringHack(dll_path);
20 // http://code.google.com/p/chromium/issues/detail?id=15455 28 FilePath nss3_path = dylib_file_path.Append("libnss3.dylib");
21 NOTIMPLEMENTED(); 29
22 return false; 30 void *nss_3_lib = dlopen(nss3_path.value().c_str(), RTLD_LAZY);
31 if (!nss_3_lib) {
32 LOG(ERROR) << "Failed to load nss3 lib" << dlerror();
33 return false;
34 }
35
36 NSS_Init = (NSSInitFunc)dlsym(nss_3_lib, "NSS_Init");
37 NSS_Shutdown = (NSSShutdownFunc)dlsym(nss_3_lib, "NSS_Shutdown");
38 PK11_GetInternalKeySlot =
39 (PK11GetInternalKeySlotFunc)dlsym(nss_3_lib, "PK11_GetInternalKeySlot");
40 PK11_CheckUserPassword =
41 (PK11CheckUserPasswordFunc)dlsym(nss_3_lib, "PK11_CheckUserPassword");
42 PK11_FreeSlot = (PK11FreeSlotFunc)dlsym(nss_3_lib, "PK11_FreeSlot");
43 PK11_Authenticate =
44 (PK11AuthenticateFunc)dlsym(nss_3_lib, "PK11_Authenticate");
45 PK11SDR_Decrypt = (PK11SDRDecryptFunc)dlsym(nss_3_lib, "PK11SDR_Decrypt");
46 SECITEM_FreeItem = (SECITEMFreeItemFunc)dlsym(nss_3_lib, "SECITEM_FreeItem");
47
48 if (!NSS_Init || !NSS_Shutdown || !PK11_GetInternalKeySlot ||
49 !PK11_CheckUserPassword || !PK11_FreeSlot || !PK11_Authenticate ||
50 !PK11SDR_Decrypt || !SECITEM_FreeItem) {
51 LOG(ERROR) << "NSS3 importer couldn't find entry points";
52 return false;
53 }
54
55 SECStatus result = NSS_Init(base::SysWideToNativeMB(db_path).c_str());
56
57 if (result != SECSuccess) {
58 LOG(ERROR) << "NSS_Init Failed returned: " << result;
59 return false;
60 }
61
62 is_nss_initialized_ = true;
63 return true;
23 } 64 }
65
66 NSSDecryptor::~NSSDecryptor() {
67 if (NSS_Shutdown && is_nss_initialized_) {
68 NSS_Shutdown();
69 is_nss_initialized_ = false;
70 }
71 }
OLDNEW
« no previous file with comments | « chrome/browser/importer/nss_decryptor_mac.h ('k') | chrome/chrome.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698