Index: chrome/browser/importer/nss_decryptor_win.cc |
=================================================================== |
--- chrome/browser/importer/nss_decryptor_win.cc (revision 21221) |
+++ chrome/browser/importer/nss_decryptor_win.cc (working copy) |
@@ -2,12 +2,9 @@ |
// Use of this source code is governed by a BSD-style license that can be |
// found in the LICENSE file. |
-#include "chrome/browser/importer/firefox_importer_utils.h" |
- |
-#include <shlobj.h> |
- |
+#include "chrome/browser/importer/nss_decryptor_win.h" |
#include "base/file_util.h" |
-#include "base/registry.h" |
+#include "base/sys_string_conversions.h" |
namespace { |
@@ -33,69 +30,6 @@ |
} // namespace |
-// NOTE: Keep these in order since we need test all those paths according |
-// to priority. For example. One machine has multiple users. One non-admin |
-// user installs Firefox 2, which causes there is a Firefox2 entry under HKCU. |
-// One admin user installs Firefox 3, which causes there is a Firefox 3 entry |
-// under HKLM. So when the non-admin user log in, we should deal with Firefox 2 |
-// related data instead of Firefox 3. |
-static const HKEY kFireFoxRegistryPaths[] = { |
- HKEY_CURRENT_USER, |
- HKEY_LOCAL_MACHINE |
-}; |
- |
-int GetCurrentFirefoxMajorVersionFromRegistry() { |
- TCHAR ver_buffer[128]; |
- DWORD ver_buffer_length = sizeof(ver_buffer); |
- int highest_version = 0; |
- // When installing Firefox with admin account, the product keys will be |
- // written under HKLM\Mozilla. Otherwise it the keys will be written under |
- // HKCU\Mozilla. |
- for (int i = 0; i < arraysize(kFireFoxRegistryPaths); ++i) { |
- bool result = ReadFromRegistry(kFireFoxRegistryPaths[i], |
- L"Software\\Mozilla\\Mozilla Firefox", |
- L"CurrentVersion", ver_buffer, &ver_buffer_length); |
- if (!result) |
- continue; |
- highest_version = std::max(highest_version, _wtoi(ver_buffer)); |
- } |
- return highest_version; |
-} |
- |
-std::wstring GetFirefoxInstallPathFromRegistry() { |
- // Detects the path that Firefox is installed in. |
- std::wstring registry_path = L"Software\\Mozilla\\Mozilla Firefox"; |
- TCHAR buffer[MAX_PATH]; |
- DWORD buffer_length = sizeof(buffer); |
- bool result; |
- result = ReadFromRegistry(HKEY_LOCAL_MACHINE, registry_path.c_str(), |
- L"CurrentVersion", buffer, &buffer_length); |
- if (!result) |
- return std::wstring(); |
- registry_path += L"\\" + std::wstring(buffer) + L"\\Main"; |
- buffer_length = sizeof(buffer); |
- result = ReadFromRegistry(HKEY_LOCAL_MACHINE, registry_path.c_str(), |
- L"Install Directory", buffer, &buffer_length); |
- if (!result) |
- return std::wstring(); |
- return buffer; |
-} |
- |
-FilePath GetProfilesINI() { |
- FilePath ini_file; |
- // The default location of the profile folder containing user data is |
- // under the "Application Data" folder in Windows XP. |
- wchar_t buffer[MAX_PATH] = {0}; |
- if (SUCCEEDED(SHGetFolderPath(NULL, CSIDL_APPDATA, NULL, |
- SHGFP_TYPE_CURRENT, buffer))) { |
- ini_file = FilePath(buffer).Append(L"Mozilla\\Firefox\\profiles.ini"); |
- } |
- if (file_util::PathExists(ini_file)) |
- return ini_file; |
- |
- return FilePath(); |
-} |
- |
// static |
const wchar_t NSSDecryptor::kNSS3Library[] = L"nss3.dll"; |
const wchar_t NSSDecryptor::kSoftokn3Library[] = L"softokn3.dll"; |
@@ -156,3 +90,89 @@ |
return InitNSS(db_path, plds4_dll, nspr4_dll); |
} |
+ |
+NSSDecryptor::NSSDecryptor() |
+ : NSS_Init(NULL), NSS_Shutdown(NULL), PK11_GetInternalKeySlot(NULL), |
+ PK11_CheckUserPassword(NULL), PK11_FreeSlot(NULL), |
+ PK11_Authenticate(NULL), PK11SDR_Decrypt(NULL), SECITEM_FreeItem(NULL), |
+ PL_ArenaFinish(NULL), PR_Cleanup(NULL), |
+ nss3_dll_(NULL), softokn3_dll_(NULL), |
+ is_nss_initialized_(false) { |
+} |
+ |
+NSSDecryptor::~NSSDecryptor() { |
+ Free(); |
+} |
+ |
+bool NSSDecryptor::InitNSS(const std::wstring& db_path, |
+ base::NativeLibrary plds4_dll, |
+ base::NativeLibrary nspr4_dll) { |
+ // NSPR DLLs are already loaded now. |
+ if (plds4_dll == NULL || nspr4_dll == NULL) { |
+ Free(); |
+ return false; |
+ } |
+ |
+ // Gets the function address. |
+ NSS_Init = (NSSInitFunc) |
+ base::GetFunctionPointerFromNativeLibrary(nss3_dll_, "NSS_Init"); |
+ NSS_Shutdown = (NSSShutdownFunc) |
+ base::GetFunctionPointerFromNativeLibrary(nss3_dll_, "NSS_Shutdown"); |
+ PK11_GetInternalKeySlot = (PK11GetInternalKeySlotFunc) |
+ base::GetFunctionPointerFromNativeLibrary(nss3_dll_, |
+ "PK11_GetInternalKeySlot"); |
+ PK11_FreeSlot = (PK11FreeSlotFunc) |
+ base::GetFunctionPointerFromNativeLibrary(nss3_dll_, "PK11_FreeSlot"); |
+ PK11_Authenticate = (PK11AuthenticateFunc) |
+ base::GetFunctionPointerFromNativeLibrary(nss3_dll_, "PK11_Authenticate"); |
+ PK11SDR_Decrypt = (PK11SDRDecryptFunc) |
+ base::GetFunctionPointerFromNativeLibrary(nss3_dll_, "PK11SDR_Decrypt"); |
+ SECITEM_FreeItem = (SECITEMFreeItemFunc) |
+ base::GetFunctionPointerFromNativeLibrary(nss3_dll_, "SECITEM_FreeItem"); |
+ PL_ArenaFinish = (PLArenaFinishFunc) |
+ base::GetFunctionPointerFromNativeLibrary(plds4_dll, "PL_ArenaFinish"); |
+ PR_Cleanup = (PRCleanupFunc) |
+ base::GetFunctionPointerFromNativeLibrary(nspr4_dll, "PR_Cleanup"); |
+ |
+ if (NSS_Init == NULL || NSS_Shutdown == NULL || |
+ PK11_GetInternalKeySlot == NULL || PK11_FreeSlot == NULL || |
+ PK11_Authenticate == NULL || PK11SDR_Decrypt == NULL || |
+ SECITEM_FreeItem == NULL || PL_ArenaFinish == NULL || |
+ PR_Cleanup == NULL) { |
+ Free(); |
+ return false; |
+ } |
+ |
+ SECStatus result = NSS_Init(base::SysWideToNativeMB(db_path).c_str()); |
+ if (result != SECSuccess) { |
+ Free(); |
+ return false; |
+ } |
+ |
+ is_nss_initialized_ = true; |
+ return true; |
+} |
+ |
+void NSSDecryptor::Free() { |
+ if (is_nss_initialized_) { |
+ NSS_Shutdown(); |
+ PL_ArenaFinish(); |
+ PR_Cleanup(); |
+ is_nss_initialized_ = false; |
+ } |
+ if (softokn3_dll_ != NULL) |
+ base::UnloadNativeLibrary(softokn3_dll_); |
+ if (nss3_dll_ != NULL) |
+ base::UnloadNativeLibrary(nss3_dll_); |
+ NSS_Init = NULL; |
+ NSS_Shutdown = NULL; |
+ PK11_GetInternalKeySlot = NULL; |
+ PK11_FreeSlot = NULL; |
+ PK11_Authenticate = NULL; |
+ PK11SDR_Decrypt = NULL; |
+ SECITEM_FreeItem = NULL; |
+ PL_ArenaFinish = NULL; |
+ PR_Cleanup = NULL; |
+ nss3_dll_ = NULL; |
+ softokn3_dll_ = NULL; |
+} |
Property changes on: chrome/browser/importer/nss_decryptor_win.cc |
___________________________________________________________________ |
Name: svn:eol-style |
+ LF |