| 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 #ifndef CHROME_BROWSER_IMPORTER_FIREFOX_IMPORTER_UTILS_H_ | 5 #ifndef CHROME_BROWSER_IMPORTER_NSS_DECRYPTOR_MAC_H_ |
| 6 #define CHROME_BROWSER_IMPORTER_FIREFOX_IMPORTER_UTILS_H_ | 6 #define CHROME_BROWSER_IMPORTER_NSS_DECRYPTOR_MAC_H_ |
| 7 | 7 |
| 8 #include <string> |
| 8 #include <vector> | 9 #include <vector> |
| 9 | 10 |
| 10 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 11 #include "base/file_path.h" | 12 #include "base/logging.h" |
| 12 #include "base/native_library.h" | |
| 13 #include "build/build_config.h" | |
| 14 | |
| 15 class DictionaryValue; | |
| 16 class GURL; | |
| 17 class TemplateURL; | |
| 18 | |
| 19 namespace webkit_glue { | |
| 20 struct PasswordForm; | |
| 21 } | |
| 22 | |
| 23 #if defined(OS_WIN) | |
| 24 // Detects which version of Firefox is installed from registry. Returns its | |
| 25 // major version, and drops the minor version. Returns 0 if | |
| 26 // failed. If there are indicators of both FF2 and FF3 it is | |
| 27 // biased to return the biggest version. | |
| 28 int GetCurrentFirefoxMajorVersionFromRegistry(); | |
| 29 | |
| 30 // Detects where Firefox lives. Returns a empty string if Firefox | |
| 31 // is not installed. | |
| 32 std::wstring GetFirefoxInstallPathFromRegistry(); | |
| 33 #endif | |
| 34 | |
| 35 // Detects version of Firefox and installation path from given Firefox profile | |
| 36 bool GetFirefoxVersionAndPathFromProfile(const std::wstring& profile_path, | |
| 37 int* version, | |
| 38 std::wstring* app_path); | |
| 39 | |
| 40 // Gets the full path of the profiles.ini file. This file records | |
| 41 // the profiles that can be used by Firefox. Returns an empty | |
| 42 // string if failed. | |
| 43 FilePath GetProfilesINI(); | |
| 44 | |
| 45 // Parses the profile.ini file, and stores its information in |root|. | |
| 46 // This file is a plain-text file. Key/value pairs are stored one per | |
| 47 // line, and they are separeated in different sections. For example: | |
| 48 // [General] | |
| 49 // StartWithLastProfile=1 | |
| 50 // | |
| 51 // [Profile0] | |
| 52 // Name=default | |
| 53 // IsRelative=1 | |
| 54 // Path=Profiles/abcdefeg.default | |
| 55 // We set "[value]" in path "<Section>.<Key>". For example, the path | |
| 56 // "Genenral.StartWithLastProfile" has the value "1". | |
| 57 void ParseProfileINI(std::wstring file, DictionaryValue* root); | |
| 58 | |
| 59 // Returns true if we want to add the URL to the history. We filter | |
| 60 // out the URL with a unsupported scheme. | |
| 61 bool CanImportURL(const GURL& url); | |
| 62 | |
| 63 // Parses the OpenSearch XML files in |xml_files| and populates |search_engines| | |
| 64 // with the resulting TemplateURLs. | |
| 65 void ParseSearchEnginesFromXMLFiles(const std::vector<std::wstring>& xml_files, | |
| 66 std::vector<TemplateURL*>* search_engines); | |
| 67 | |
| 68 // Returns the index of the default search engine in the |search_engines| list. | |
| 69 // If none is found, -1 is returned. | |
| 70 int GetFirefoxDefaultSearchEngineIndex( | |
| 71 const std::vector<TemplateURL*>& search_engines, | |
| 72 const std::wstring& profile_path); | |
| 73 | |
| 74 // Returns the home page set in Firefox in a particular profile. | |
| 75 GURL GetHomepage(const std::wstring& profile_path); | |
| 76 | |
| 77 // Checks to see if this home page is a default home page, as specified by | |
| 78 // the resource file browserconfig.properties in the Firefox application | |
| 79 // directory. | |
| 80 bool IsDefaultHomepage(const GURL& homepage, const std::wstring& app_path); | |
| 81 | 13 |
| 82 // The following declarations of functions and types are from Firefox | 14 // The following declarations of functions and types are from Firefox |
| 83 // NSS library. | 15 // NSS library. |
| 84 // source code: | 16 // source code: |
| 85 // security/nss/lib/util/seccomon.h | 17 // security/nss/lib/util/seccomon.h |
| 86 // security/nss/lib/nss/nss.h | 18 // security/nss/lib/nss/nss.h |
| 87 // The license block is: | 19 // The license block is: |
| 88 | 20 |
| 89 /* ***** BEGIN LICENSE BLOCK ***** | 21 /* ***** BEGIN LICENSE BLOCK ***** |
| 90 * Version: MPL 1.1/GPL 2.0/LGPL 2.1 | 22 * Version: MPL 1.1/GPL 2.0/LGPL 2.1 |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 163 typedef PK11SlotInfo* (*PK11GetInternalKeySlotFunc)(void); | 95 typedef PK11SlotInfo* (*PK11GetInternalKeySlotFunc)(void); |
| 164 typedef void (*PK11FreeSlotFunc)(PK11SlotInfo *slot); | 96 typedef void (*PK11FreeSlotFunc)(PK11SlotInfo *slot); |
| 165 typedef SECStatus (*PK11CheckUserPasswordFunc)(PK11SlotInfo *slot, char *pw); | 97 typedef SECStatus (*PK11CheckUserPasswordFunc)(PK11SlotInfo *slot, char *pw); |
| 166 typedef SECStatus | 98 typedef SECStatus |
| 167 (*PK11AuthenticateFunc)(PK11SlotInfo *slot, PRBool loadCerts, void *wincx); | 99 (*PK11AuthenticateFunc)(PK11SlotInfo *slot, PRBool loadCerts, void *wincx); |
| 168 typedef SECStatus | 100 typedef SECStatus |
| 169 (*PK11SDRDecryptFunc)(SECItem *data, SECItem *result, void *cx); | 101 (*PK11SDRDecryptFunc)(SECItem *data, SECItem *result, void *cx); |
| 170 typedef void (*SECITEMFreeItemFunc)(SECItem *item, PRBool free_it); | 102 typedef void (*SECITEMFreeItemFunc)(SECItem *item, PRBool free_it); |
| 171 typedef void (*PLArenaFinishFunc)(void); | 103 typedef void (*PLArenaFinishFunc)(void); |
| 172 typedef PRStatus (*PRCleanupFunc)(void); | 104 typedef PRStatus (*PRCleanupFunc)(void); |
| 105 namespace webkit_glue { |
| 106 struct PasswordForm; |
| 107 } |
| 173 | 108 |
| 174 // A wrapper for Firefox NSS decrypt component. | 109 // A wrapper for Firefox NSS decrypt component. |
| 175 class NSSDecryptor { | 110 class NSSDecryptor { |
| 176 public: | 111 public: |
| 177 NSSDecryptor(); | 112 NSSDecryptor() |
| 178 ~NSSDecryptor(); | 113 : NSS_Init(NULL), NSS_Shutdown(NULL), PK11_GetInternalKeySlot(NULL), |
| 114 PK11_CheckUserPassword(NULL), PK11_FreeSlot(NULL), |
| 115 PK11_Authenticate(NULL), PK11SDR_Decrypt(NULL), SECITEM_FreeItem(NULL), |
| 116 PL_ArenaFinish(NULL), PR_Cleanup(NULL), |
| 117 is_nss_initialized_(false) {} |
| 118 ~NSSDecryptor() {} |
| 179 | 119 |
| 180 // Loads NSS3 library and returns true if successful. | 120 // Initializes NSS if it hasn't already been initialized. |
| 181 // |dll_path| indicates the location of NSS3 DLL files, and |db_path| | 121 bool Init(const std::wstring& /* dll_path */, |
| 182 // is the location of the database file that stores the keys. | 122 const std::wstring& /* db_path */) { |
| 183 bool Init(const std::wstring& dll_path, const std::wstring& db_path); | 123 // TODO(port): Load the NSS libraries and call InitNSS() |
| 184 | 124 // http://code.google.com/p/chromium/issues/detail?id=15455 |
| 185 // Frees the libraries. | 125 NOTIMPLEMENTED(); |
| 186 void Free(); | 126 return false; |
| 127 } |
| 187 | 128 |
| 188 // Decrypts Firefox stored passwords. Before using this method, | 129 // Decrypts Firefox stored passwords. Before using this method, |
| 189 // make sure Init() returns true. | 130 // make sure Init() returns true. |
| 190 std::wstring Decrypt(const std::string& crypt) const; | 131 std::wstring Decrypt(const std::string& crypt) const; |
| 191 | 132 |
| 192 // Parses the Firefox password file content, decrypts the | 133 // Parses the Firefox password file content, decrypts the |
| 193 // username/password and reads other related information. | 134 // username/password and reads other related information. |
| 194 // The result will be stored in |forms|. | 135 // The result will be stored in |forms|. |
| 195 void ParseSignons(const std::string& content, | 136 void ParseSignons(const std::string& content, |
| 196 std::vector<webkit_glue::PasswordForm>* forms); | 137 std::vector<webkit_glue::PasswordForm>* forms); |
| 197 | 138 |
| 198 private: | 139 private: |
| 199 // Performs tasks common across all platforms to initialize NSS. | |
| 200 bool InitNSS(const std::wstring& db_path, | |
| 201 base::NativeLibrary plds4_dll, | |
| 202 base::NativeLibrary nspr4_dll); | |
| 203 | |
| 204 // Methods in Firefox security components. | 140 // Methods in Firefox security components. |
| 205 NSSInitFunc NSS_Init; | 141 NSSInitFunc NSS_Init; |
| 206 NSSShutdownFunc NSS_Shutdown; | 142 NSSShutdownFunc NSS_Shutdown; |
| 207 PK11GetInternalKeySlotFunc PK11_GetInternalKeySlot; | 143 PK11GetInternalKeySlotFunc PK11_GetInternalKeySlot; |
| 208 PK11CheckUserPasswordFunc PK11_CheckUserPassword; | 144 PK11CheckUserPasswordFunc PK11_CheckUserPassword; |
| 209 PK11FreeSlotFunc PK11_FreeSlot; | 145 PK11FreeSlotFunc PK11_FreeSlot; |
| 210 PK11AuthenticateFunc PK11_Authenticate; | 146 PK11AuthenticateFunc PK11_Authenticate; |
| 211 PK11SDRDecryptFunc PK11SDR_Decrypt; | 147 PK11SDRDecryptFunc PK11SDR_Decrypt; |
| 212 SECITEMFreeItemFunc SECITEM_FreeItem; | 148 SECITEMFreeItemFunc SECITEM_FreeItem; |
| 213 PLArenaFinishFunc PL_ArenaFinish; | 149 PLArenaFinishFunc PL_ArenaFinish; |
| 214 PRCleanupFunc PR_Cleanup; | 150 PRCleanupFunc PR_Cleanup; |
| 215 | 151 |
| 216 // Libraries necessary for decrypting the passwords. | |
| 217 static const wchar_t kNSS3Library[]; | |
| 218 static const wchar_t kSoftokn3Library[]; | |
| 219 static const wchar_t kPLDS4Library[]; | |
| 220 static const wchar_t kNSPR4Library[]; | |
| 221 | |
| 222 // NSS3 module handles. | |
| 223 base::NativeLibrary nss3_dll_; | |
| 224 base::NativeLibrary softokn3_dll_; | |
| 225 | |
| 226 // True if NSS_Init() has been called | 152 // True if NSS_Init() has been called |
| 227 bool is_nss_initialized_; | 153 bool is_nss_initialized_; |
| 228 | 154 |
| 229 DISALLOW_COPY_AND_ASSIGN(NSSDecryptor); | 155 DISALLOW_COPY_AND_ASSIGN(NSSDecryptor); |
| 230 }; | 156 }; |
| 231 | 157 |
| 232 #endif // CHROME_BROWSER_IMPORTER_FIREFOX_IMPORTER_UTILS_H_ | 158 #endif // CHROME_BROWSER_IMPORTER_NSS_DECRYPTOR_MAC_H_ |
| OLD | NEW |