OLD | NEW |
| (Empty) |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef CHROME_BROWSER_FIREFOX_IMPORTER_UTILS_H_ | |
6 #define CHROME_BROWSER_FIREFOX_IMPORTER_UTILS_H_ | |
7 | |
8 #include "base/values.h" | |
9 #include "webkit/glue/password_form.h" | |
10 | |
11 class GURL; | |
12 class TemplateURL; | |
13 | |
14 // Detects which version of Firefox is installed. Returns its | |
15 // major version, and drops the minor version. Returns 0 if | |
16 // failed. | |
17 int GetCurrentFirefoxMajorVersion(); | |
18 | |
19 // Gets the full path of the profiles.ini file. This file records | |
20 // the profiles that can be used by Firefox. Returns an empty | |
21 // string if failed. | |
22 std::wstring GetProfilesINI(); | |
23 | |
24 // Detects where Firefox lives. Returns a empty string if Firefox | |
25 // is not installed. | |
26 std::wstring GetFirefoxInstallPath(); | |
27 | |
28 // Parses the profile.ini file, and stores its information in |root|. | |
29 // This file is a plain-text file. Key/value pairs are stored one per | |
30 // line, and they are separeated in different sections. For example: | |
31 // [General] | |
32 // StartWithLastProfile=1 | |
33 // | |
34 // [Profile0] | |
35 // Name=default | |
36 // IsRelative=1 | |
37 // Path=Profiles/abcdefeg.default | |
38 // We set "[value]" in path "<Section>.<Key>". For example, the path | |
39 // "Genenral.StartWithLastProfile" has the value "1". | |
40 void ParseProfileINI(std::wstring file, DictionaryValue* root); | |
41 | |
42 // Returns true if we want to add the URL to the history. We filter | |
43 // out the URL with a unsupported scheme. | |
44 bool CanImportURL(const GURL& url); | |
45 | |
46 // Parses the OpenSearch XML files in |xml_files| and populates |search_engines| | |
47 // with the resulting TemplateURLs. | |
48 void ParseSearchEnginesFromXMLFiles(const std::vector<std::wstring>& xml_files, | |
49 std::vector<TemplateURL*>* search_engines); | |
50 | |
51 // Returns the index of the default search engine in the |search_engines| list. | |
52 // If none is found, -1 is returned. | |
53 int GetFirefoxDefaultSearchEngineIndex( | |
54 const std::vector<TemplateURL*>& search_engines, | |
55 const std::wstring& profile_path); | |
56 | |
57 // Returns the home page set in Firefox in a particular profile. | |
58 GURL GetHomepage(const std::wstring& profile_path); | |
59 | |
60 // Checks to see if this home page is a default home page, as specified by | |
61 // the resource file browserconfig.properties in the Firefox application | |
62 // directory. | |
63 bool IsDefaultHomepage(const GURL& homepage, const std::wstring& app_path); | |
64 | |
65 // The following declarations of functions and types are from Firefox | |
66 // NSS library. | |
67 // source code: | |
68 // security/nss/lib/util/seccomon.h | |
69 // security/nss/lib/nss/nss.h | |
70 // The license block is: | |
71 | |
72 /* ***** BEGIN LICENSE BLOCK ***** | |
73 * Version: MPL 1.1/GPL 2.0/LGPL 2.1 | |
74 * | |
75 * The contents of this file are subject to the Mozilla Public License Version | |
76 * 1.1 (the "License"); you may not use this file except in compliance with | |
77 * the License. You may obtain a copy of the License at | |
78 * http://www.mozilla.org/MPL/ | |
79 * | |
80 * Software distributed under the License is distributed on an "AS IS" basis, | |
81 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License | |
82 * for the specific language governing rights and limitations under the | |
83 * License. | |
84 * | |
85 * The Original Code is the Netscape security libraries. | |
86 * | |
87 * The Initial Developer of the Original Code is | |
88 * Netscape Communications Corporation. | |
89 * Portions created by the Initial Developer are Copyright (C) 1994-2000 | |
90 * the Initial Developer. All Rights Reserved. | |
91 * | |
92 * Contributor(s): | |
93 * | |
94 * Alternatively, the contents of this file may be used under the terms of | |
95 * either the GNU General Public License Version 2 or later (the "GPL"), or | |
96 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), | |
97 * in which case the provisions of the GPL or the LGPL are applicable instead | |
98 * of those above. If you wish to allow use of your version of this file only | |
99 * under the terms of either the GPL or the LGPL, and not to allow others to | |
100 * use your version of this file under the terms of the MPL, indicate your | |
101 * decision by deleting the provisions above and replace them with the notice | |
102 * and other provisions required by the GPL or the LGPL. If you do not delete | |
103 * the provisions above, a recipient may use your version of this file under | |
104 * the terms of any one of the MPL, the GPL or the LGPL. | |
105 * | |
106 * ***** END LICENSE BLOCK ***** */ | |
107 | |
108 enum SECItemType { | |
109 siBuffer = 0, | |
110 siClearDataBuffer = 1, | |
111 siCipherDataBuffer = 2, | |
112 siDERCertBuffer = 3, | |
113 siEncodedCertBuffer = 4, | |
114 siDERNameBuffer = 5, | |
115 siEncodedNameBuffer = 6, | |
116 siAsciiNameString = 7, | |
117 siAsciiString = 8, | |
118 siDEROID = 9, | |
119 siUnsignedInteger = 10, | |
120 siUTCTime = 11, | |
121 siGeneralizedTime = 12 | |
122 }; | |
123 | |
124 struct SECItem { | |
125 SECItemType type; | |
126 unsigned char *data; | |
127 unsigned int len; | |
128 }; | |
129 | |
130 enum SECStatus { | |
131 SECWouldBlock = -2, | |
132 SECFailure = -1, | |
133 SECSuccess = 0 | |
134 }; | |
135 | |
136 typedef int PRBool; | |
137 #define PR_TRUE 1 | |
138 #define PR_FALSE 0 | |
139 | |
140 typedef enum { PR_FAILURE = -1, PR_SUCCESS = 0 } PRStatus; | |
141 | |
142 typedef struct PK11SlotInfoStr PK11SlotInfo; | |
143 | |
144 typedef SECStatus (*NSSInitFunc)(const char *configdir); | |
145 typedef SECStatus (*NSSShutdownFunc)(void); | |
146 typedef PK11SlotInfo* (*PK11GetInternalKeySlotFunc)(void); | |
147 typedef void (*PK11FreeSlotFunc)(PK11SlotInfo *slot); | |
148 typedef SECStatus (*PK11CheckUserPasswordFunc)(PK11SlotInfo *slot, char *pw); | |
149 typedef SECStatus | |
150 (*PK11AuthenticateFunc)(PK11SlotInfo *slot, PRBool loadCerts, void *wincx); | |
151 typedef SECStatus | |
152 (*PK11SDRDecryptFunc)(SECItem *data, SECItem *result, void *cx); | |
153 typedef void (*SECITEMFreeItemFunc)(SECItem *item, PRBool free_it); | |
154 typedef void (*PLArenaFinishFunc)(void); | |
155 typedef PRStatus (*PRCleanupFunc)(void); | |
156 | |
157 // A wrapper for Firefox NSS decrypt component. | |
158 class NSSDecryptor { | |
159 public: | |
160 NSSDecryptor(); | |
161 ~NSSDecryptor(); | |
162 | |
163 // Loads NSS3 library and returns true if successful. | |
164 // |dll_path| indicates the location of NSS3 DLL files, and |db_path| | |
165 // is the location of the database file that stores the keys. | |
166 bool Init(const std::wstring& dll_path, const std::wstring& db_path); | |
167 | |
168 // Frees the libraries. | |
169 void Free(); | |
170 | |
171 // Decrypts Firefox stored passwords. Before using this method, | |
172 // make sure Init() returns true. | |
173 std::wstring Decrypt(const std::string& crypt) const; | |
174 | |
175 // Parses the Firefox password file content, decrypts the | |
176 // username/password and reads other related information. | |
177 // The result will be stored in |forms|. | |
178 void ParseSignons(const std::string& content, | |
179 std::vector<PasswordForm>* forms); | |
180 | |
181 private: | |
182 // Methods in Firefox security components. | |
183 NSSInitFunc NSS_Init; | |
184 NSSShutdownFunc NSS_Shutdown; | |
185 PK11GetInternalKeySlotFunc PK11_GetInternalKeySlot; | |
186 PK11CheckUserPasswordFunc PK11_CheckUserPassword; | |
187 PK11FreeSlotFunc PK11_FreeSlot; | |
188 PK11AuthenticateFunc PK11_Authenticate; | |
189 PK11SDRDecryptFunc PK11SDR_Decrypt; | |
190 SECITEMFreeItemFunc SECITEM_FreeItem; | |
191 PLArenaFinishFunc PL_ArenaFinish; | |
192 PRCleanupFunc PR_Cleanup; | |
193 | |
194 // Libraries necessary for decrypting the passwords. | |
195 static const wchar_t kNSS3Library[]; | |
196 static const wchar_t kSoftokn3Library[]; | |
197 static const wchar_t kPLDS4Library[]; | |
198 static const wchar_t kNSPR4Library[]; | |
199 | |
200 // NSS3 module handles. | |
201 HMODULE nss3_dll_; | |
202 HMODULE softokn3_dll_; | |
203 | |
204 // True if NSS_Init() has been called | |
205 bool is_nss_initialized_; | |
206 | |
207 DISALLOW_EVIL_CONSTRUCTORS(NSSDecryptor); | |
208 }; | |
209 | |
210 #endif // CHROME_BROWSER_FIREFOX_IMPORTER_UTILS_H__ | |
211 | |
OLD | NEW |