| 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_FIREFOX_IMPORTER_UTILS_H_ |
| 6 #define CHROME_BROWSER_IMPORTER_FIREFOX_IMPORTER_UTILS_H_ | 6 #define CHROME_BROWSER_IMPORTER_FIREFOX_IMPORTER_UTILS_H_ |
| 7 | 7 |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| 11 #include "base/file_path.h" | 11 #include "base/file_path.h" |
| 12 #include "base/native_library.h" | |
| 13 #include "build/build_config.h" | 12 #include "build/build_config.h" |
| 14 | 13 |
| 15 class DictionaryValue; | 14 class DictionaryValue; |
| 16 class GURL; | 15 class GURL; |
| 17 class TemplateURL; | 16 class TemplateURL; |
| 18 | 17 |
| 19 namespace webkit_glue { | |
| 20 struct PasswordForm; | |
| 21 } | |
| 22 | |
| 23 #if defined(OS_WIN) | 18 #if defined(OS_WIN) |
| 24 // Detects which version of Firefox is installed from registry. Returns its | 19 // Detects which version of Firefox is installed from registry. Returns its |
| 25 // major version, and drops the minor version. Returns 0 if | 20 // major version, and drops the minor version. Returns 0 if |
| 26 // failed. If there are indicators of both FF2 and FF3 it is | 21 // failed. If there are indicators of both FF2 and FF3 it is |
| 27 // biased to return the biggest version. | 22 // biased to return the biggest version. |
| 28 int GetCurrentFirefoxMajorVersionFromRegistry(); | 23 int GetCurrentFirefoxMajorVersionFromRegistry(); |
| 29 | 24 |
| 30 // Detects where Firefox lives. Returns a empty string if Firefox | 25 // Detects where Firefox lives. Returns a empty string if Firefox |
| 31 // is not installed. | 26 // is not installed. |
| 32 std::wstring GetFirefoxInstallPathFromRegistry(); | 27 std::wstring GetFirefoxInstallPathFromRegistry(); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 const std::wstring& profile_path); | 67 const std::wstring& profile_path); |
| 73 | 68 |
| 74 // Returns the home page set in Firefox in a particular profile. | 69 // Returns the home page set in Firefox in a particular profile. |
| 75 GURL GetHomepage(const std::wstring& profile_path); | 70 GURL GetHomepage(const std::wstring& profile_path); |
| 76 | 71 |
| 77 // Checks to see if this home page is a default home page, as specified by | 72 // 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 | 73 // the resource file browserconfig.properties in the Firefox application |
| 79 // directory. | 74 // directory. |
| 80 bool IsDefaultHomepage(const GURL& homepage, const std::wstring& app_path); | 75 bool IsDefaultHomepage(const GURL& homepage, const std::wstring& app_path); |
| 81 | 76 |
| 82 // The following declarations of functions and types are from Firefox | |
| 83 // NSS library. | |
| 84 // source code: | |
| 85 // security/nss/lib/util/seccomon.h | |
| 86 // security/nss/lib/nss/nss.h | |
| 87 // The license block is: | |
| 88 | |
| 89 /* ***** BEGIN LICENSE BLOCK ***** | |
| 90 * Version: MPL 1.1/GPL 2.0/LGPL 2.1 | |
| 91 * | |
| 92 * The contents of this file are subject to the Mozilla Public License Version | |
| 93 * 1.1 (the "License"); you may not use this file except in compliance with | |
| 94 * the License. You may obtain a copy of the License at | |
| 95 * http://www.mozilla.org/MPL/ | |
| 96 * | |
| 97 * Software distributed under the License is distributed on an "AS IS" basis, | |
| 98 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License | |
| 99 * for the specific language governing rights and limitations under the | |
| 100 * License. | |
| 101 * | |
| 102 * The Original Code is the Netscape security libraries. | |
| 103 * | |
| 104 * The Initial Developer of the Original Code is | |
| 105 * Netscape Communications Corporation. | |
| 106 * Portions created by the Initial Developer are Copyright (C) 1994-2000 | |
| 107 * the Initial Developer. All Rights Reserved. | |
| 108 * | |
| 109 * Contributor(s): | |
| 110 * | |
| 111 * Alternatively, the contents of this file may be used under the terms of | |
| 112 * either the GNU General Public License Version 2 or later (the "GPL"), or | |
| 113 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), | |
| 114 * in which case the provisions of the GPL or the LGPL are applicable instead | |
| 115 * of those above. If you wish to allow use of your version of this file only | |
| 116 * under the terms of either the GPL or the LGPL, and not to allow others to | |
| 117 * use your version of this file under the terms of the MPL, indicate your | |
| 118 * decision by deleting the provisions above and replace them with the notice | |
| 119 * and other provisions required by the GPL or the LGPL. If you do not delete | |
| 120 * the provisions above, a recipient may use your version of this file under | |
| 121 * the terms of any one of the MPL, the GPL or the LGPL. | |
| 122 * | |
| 123 * ***** END LICENSE BLOCK ***** */ | |
| 124 | |
| 125 enum SECItemType { | |
| 126 siBuffer = 0, | |
| 127 siClearDataBuffer = 1, | |
| 128 siCipherDataBuffer = 2, | |
| 129 siDERCertBuffer = 3, | |
| 130 siEncodedCertBuffer = 4, | |
| 131 siDERNameBuffer = 5, | |
| 132 siEncodedNameBuffer = 6, | |
| 133 siAsciiNameString = 7, | |
| 134 siAsciiString = 8, | |
| 135 siDEROID = 9, | |
| 136 siUnsignedInteger = 10, | |
| 137 siUTCTime = 11, | |
| 138 siGeneralizedTime = 12 | |
| 139 }; | |
| 140 | |
| 141 struct SECItem { | |
| 142 SECItemType type; | |
| 143 unsigned char *data; | |
| 144 unsigned int len; | |
| 145 }; | |
| 146 | |
| 147 enum SECStatus { | |
| 148 SECWouldBlock = -2, | |
| 149 SECFailure = -1, | |
| 150 SECSuccess = 0 | |
| 151 }; | |
| 152 | |
| 153 typedef int PRBool; | |
| 154 #define PR_TRUE 1 | |
| 155 #define PR_FALSE 0 | |
| 156 | |
| 157 typedef enum { PR_FAILURE = -1, PR_SUCCESS = 0 } PRStatus; | |
| 158 | |
| 159 typedef struct PK11SlotInfoStr PK11SlotInfo; | |
| 160 | |
| 161 typedef SECStatus (*NSSInitFunc)(const char *configdir); | |
| 162 typedef SECStatus (*NSSShutdownFunc)(void); | |
| 163 typedef PK11SlotInfo* (*PK11GetInternalKeySlotFunc)(void); | |
| 164 typedef void (*PK11FreeSlotFunc)(PK11SlotInfo *slot); | |
| 165 typedef SECStatus (*PK11CheckUserPasswordFunc)(PK11SlotInfo *slot, char *pw); | |
| 166 typedef SECStatus | |
| 167 (*PK11AuthenticateFunc)(PK11SlotInfo *slot, PRBool loadCerts, void *wincx); | |
| 168 typedef SECStatus | |
| 169 (*PK11SDRDecryptFunc)(SECItem *data, SECItem *result, void *cx); | |
| 170 typedef void (*SECITEMFreeItemFunc)(SECItem *item, PRBool free_it); | |
| 171 typedef void (*PLArenaFinishFunc)(void); | |
| 172 typedef PRStatus (*PRCleanupFunc)(void); | |
| 173 | |
| 174 // A wrapper for Firefox NSS decrypt component. | |
| 175 class NSSDecryptor { | |
| 176 public: | |
| 177 NSSDecryptor(); | |
| 178 ~NSSDecryptor(); | |
| 179 | |
| 180 // Loads NSS3 library and returns true if successful. | |
| 181 // |dll_path| indicates the location of NSS3 DLL files, and |db_path| | |
| 182 // is the location of the database file that stores the keys. | |
| 183 bool Init(const std::wstring& dll_path, const std::wstring& db_path); | |
| 184 | |
| 185 // Frees the libraries. | |
| 186 void Free(); | |
| 187 | |
| 188 // Decrypts Firefox stored passwords. Before using this method, | |
| 189 // make sure Init() returns true. | |
| 190 std::wstring Decrypt(const std::string& crypt) const; | |
| 191 | |
| 192 // Parses the Firefox password file content, decrypts the | |
| 193 // username/password and reads other related information. | |
| 194 // The result will be stored in |forms|. | |
| 195 void ParseSignons(const std::string& content, | |
| 196 std::vector<webkit_glue::PasswordForm>* forms); | |
| 197 | |
| 198 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. | |
| 205 NSSInitFunc NSS_Init; | |
| 206 NSSShutdownFunc NSS_Shutdown; | |
| 207 PK11GetInternalKeySlotFunc PK11_GetInternalKeySlot; | |
| 208 PK11CheckUserPasswordFunc PK11_CheckUserPassword; | |
| 209 PK11FreeSlotFunc PK11_FreeSlot; | |
| 210 PK11AuthenticateFunc PK11_Authenticate; | |
| 211 PK11SDRDecryptFunc PK11SDR_Decrypt; | |
| 212 SECITEMFreeItemFunc SECITEM_FreeItem; | |
| 213 PLArenaFinishFunc PL_ArenaFinish; | |
| 214 PRCleanupFunc PR_Cleanup; | |
| 215 | |
| 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 | |
| 227 bool is_nss_initialized_; | |
| 228 | |
| 229 DISALLOW_COPY_AND_ASSIGN(NSSDecryptor); | |
| 230 }; | |
| 231 | 77 |
| 232 #endif // CHROME_BROWSER_IMPORTER_FIREFOX_IMPORTER_UTILS_H_ | 78 #endif // CHROME_BROWSER_IMPORTER_FIREFOX_IMPORTER_UTILS_H_ |
| OLD | NEW |