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

Side by Side Diff: chrome/browser/importer/nss_decryptor.cc

Issue 11000016: Move forms/ out of webkit/. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Response to review Created 8 years, 2 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "chrome/browser/importer/nss_decryptor.h" 5 #include "chrome/browser/importer/nss_decryptor.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/base64.h" 10 #include "base/base64.h"
11 #include "base/memory/scoped_ptr.h" 11 #include "base/memory/scoped_ptr.h"
12 #include "base/string_split.h" 12 #include "base/string_split.h"
13 #include "base/string_util.h" 13 #include "base/string_util.h"
14 #include "base/utf_string_conversions.h" 14 #include "base/utf_string_conversions.h"
15 #include "content/public/common/password_form.h"
15 #include "sql/connection.h" 16 #include "sql/connection.h"
16 #include "sql/statement.h" 17 #include "sql/statement.h"
17 #include "webkit/forms/password_form.h"
18 18
19 #if defined(USE_NSS) 19 #if defined(USE_NSS)
20 #include <pk11pub.h> 20 #include <pk11pub.h>
21 #include <pk11sdr.h> 21 #include <pk11sdr.h>
22 #endif // defined(USE_NSS) 22 #endif // defined(USE_NSS)
23 23
24 // This method is based on some Firefox code in 24 // This method is based on some Firefox code in
25 // security/manager/ssl/src/nsSDR.cpp 25 // security/manager/ssl/src/nsSDR.cpp
26 // The license block is: 26 // The license block is:
27 27
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 } 105 }
106 106
107 // There are three versions of password files. They store saved user 107 // There are three versions of password files. They store saved user
108 // names and passwords. 108 // names and passwords.
109 // References: 109 // References:
110 // http://kb.mozillazine.org/Signons.txt 110 // http://kb.mozillazine.org/Signons.txt
111 // http://kb.mozillazine.org/Signons2.txt 111 // http://kb.mozillazine.org/Signons2.txt
112 // http://kb.mozillazine.org/Signons3.txt 112 // http://kb.mozillazine.org/Signons3.txt
113 void NSSDecryptor::ParseSignons( 113 void NSSDecryptor::ParseSignons(
114 const std::string& content, 114 const std::string& content,
115 std::vector<webkit::forms::PasswordForm>* forms) { 115 std::vector<content::PasswordForm>* forms) {
116 forms->clear(); 116 forms->clear();
117 117
118 // Splits the file content into lines. 118 // Splits the file content into lines.
119 std::vector<std::string> lines; 119 std::vector<std::string> lines;
120 base::SplitString(content, '\n', &lines); 120 base::SplitString(content, '\n', &lines);
121 121
122 // The first line is the file version. We skip the unknown versions. 122 // The first line is the file version. We skip the unknown versions.
123 if (lines.empty()) 123 if (lines.empty())
124 return; 124 return;
125 int version; 125 int version;
126 if (lines[0] == "#2c") 126 if (lines[0] == "#2c")
127 version = 1; 127 version = 1;
128 else if (lines[0] == "#2d") 128 else if (lines[0] == "#2d")
129 version = 2; 129 version = 2;
130 else if (lines[0] == "#2e") 130 else if (lines[0] == "#2e")
131 version = 3; 131 version = 3;
132 else 132 else
133 return; 133 return;
134 134
135 GURL::Replacements rep; 135 GURL::Replacements rep;
136 rep.ClearQuery(); 136 rep.ClearQuery();
137 rep.ClearRef(); 137 rep.ClearRef();
138 rep.ClearUsername(); 138 rep.ClearUsername();
139 rep.ClearPassword(); 139 rep.ClearPassword();
140 140
141 // Reads never-saved list. Domains are stored one per line. 141 // Reads never-saved list. Domains are stored one per line.
142 size_t i; 142 size_t i;
143 for (i = 1; i < lines.size() && lines[i].compare(".") != 0; ++i) { 143 for (i = 1; i < lines.size() && lines[i].compare(".") != 0; ++i) {
144 webkit::forms::PasswordForm form; 144 content::PasswordForm form;
145 form.origin = GURL(lines[i]).ReplaceComponents(rep); 145 form.origin = GURL(lines[i]).ReplaceComponents(rep);
146 form.signon_realm = form.origin.GetOrigin().spec(); 146 form.signon_realm = form.origin.GetOrigin().spec();
147 form.blacklisted_by_user = true; 147 form.blacklisted_by_user = true;
148 forms->push_back(form); 148 forms->push_back(form);
149 } 149 }
150 ++i; 150 ++i;
151 151
152 // Reads saved passwords. The information is stored in blocks 152 // Reads saved passwords. The information is stored in blocks
153 // seperated by lines that only contain a dot. We find a block 153 // seperated by lines that only contain a dot. We find a block
154 // by the seperator and parse them one by one. 154 // by the seperator and parse them one by one.
155 while (i < lines.size()) { 155 while (i < lines.size()) {
156 size_t begin = i; 156 size_t begin = i;
157 size_t end = i + 1; 157 size_t end = i + 1;
158 while (end < lines.size() && lines[end].compare(".") != 0) 158 while (end < lines.size() && lines[end].compare(".") != 0)
159 ++end; 159 ++end;
160 i = end + 1; 160 i = end + 1;
161 161
162 // A block has at least five lines. 162 // A block has at least five lines.
163 if (end - begin < 5) 163 if (end - begin < 5)
164 continue; 164 continue;
165 165
166 webkit::forms::PasswordForm form; 166 content::PasswordForm form;
167 167
168 // The first line is the site URL. 168 // The first line is the site URL.
169 // For HTTP authentication logins, the URL may contain http realm, 169 // For HTTP authentication logins, the URL may contain http realm,
170 // which will be in bracket: 170 // which will be in bracket:
171 // sitename:8080 (realm) 171 // sitename:8080 (realm)
172 GURL url; 172 GURL url;
173 std::string realm; 173 std::string realm;
174 const char kRealmBracketBegin[] = " ("; 174 const char kRealmBracketBegin[] = " (";
175 const char kRealmBracketEnd[] = ")"; 175 const char kRealmBracketEnd[] = ")";
176 if (lines[begin].find(kRealmBracketBegin) != std::string::npos) { 176 if (lines[begin].find(kRealmBracketBegin) != std::string::npos) {
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
226 if (version == 3) { 226 if (version == 3) {
227 ++begin; 227 ++begin;
228 } 228 }
229 229
230 forms->push_back(form); 230 forms->push_back(form);
231 } 231 }
232 } 232 }
233 } 233 }
234 234
235 bool NSSDecryptor::ReadAndParseSignons(const FilePath& sqlite_file, 235 bool NSSDecryptor::ReadAndParseSignons(const FilePath& sqlite_file,
236 std::vector<webkit::forms::PasswordForm>* forms) { 236 std::vector<content::PasswordForm>* forms) {
237 sql::Connection db; 237 sql::Connection db;
238 if (!db.Open(sqlite_file)) 238 if (!db.Open(sqlite_file))
239 return false; 239 return false;
240 240
241 const char* query = "SELECT hostname FROM moz_disabledHosts"; 241 const char* query = "SELECT hostname FROM moz_disabledHosts";
242 sql::Statement s(db.GetUniqueStatement(query)); 242 sql::Statement s(db.GetUniqueStatement(query));
243 if (!s.is_valid()) 243 if (!s.is_valid())
244 return false; 244 return false;
245 245
246 GURL::Replacements rep; 246 GURL::Replacements rep;
247 rep.ClearQuery(); 247 rep.ClearQuery();
248 rep.ClearRef(); 248 rep.ClearRef();
249 rep.ClearUsername(); 249 rep.ClearUsername();
250 rep.ClearPassword(); 250 rep.ClearPassword();
251 // Read domains for which passwords are never saved. 251 // Read domains for which passwords are never saved.
252 while (s.Step()) { 252 while (s.Step()) {
253 webkit::forms::PasswordForm form; 253 content::PasswordForm form;
254 form.origin = GURL(s.ColumnString(0)).ReplaceComponents(rep); 254 form.origin = GURL(s.ColumnString(0)).ReplaceComponents(rep);
255 form.signon_realm = form.origin.GetOrigin().spec(); 255 form.signon_realm = form.origin.GetOrigin().spec();
256 form.blacklisted_by_user = true; 256 form.blacklisted_by_user = true;
257 forms->push_back(form); 257 forms->push_back(form);
258 } 258 }
259 259
260 const char* query2 = "SELECT hostname, httpRealm, formSubmitURL, " 260 const char* query2 = "SELECT hostname, httpRealm, formSubmitURL, "
261 "usernameField, passwordField, encryptedUsername, " 261 "usernameField, passwordField, encryptedUsername, "
262 "encryptedPassword FROM moz_logins"; 262 "encryptedPassword FROM moz_logins";
263 263
(...skipping 10 matching lines...) Expand all
274 if (host.find("://") == std::string::npos) 274 if (host.find("://") == std::string::npos)
275 host = "http://" + host; 275 host = "http://" + host;
276 url = GURL(host); 276 url = GURL(host);
277 } else { 277 } else {
278 url = GURL(s2.ColumnString(0)); 278 url = GURL(s2.ColumnString(0));
279 } 279 }
280 // Skip this row if the URL is not valid. 280 // Skip this row if the URL is not valid.
281 if (!url.is_valid()) 281 if (!url.is_valid())
282 continue; 282 continue;
283 283
284 webkit::forms::PasswordForm form; 284 content::PasswordForm form;
285 form.origin = url.ReplaceComponents(rep); 285 form.origin = url.ReplaceComponents(rep);
286 form.signon_realm = form.origin.GetOrigin().spec(); 286 form.signon_realm = form.origin.GetOrigin().spec();
287 if (!realm.empty()) 287 if (!realm.empty())
288 form.signon_realm += realm; 288 form.signon_realm += realm;
289 form.ssl_valid = form.origin.SchemeIsSecure(); 289 form.ssl_valid = form.origin.SchemeIsSecure();
290 // The user name, password and action. 290 // The user name, password and action.
291 form.username_element = s2.ColumnString16(3); 291 form.username_element = s2.ColumnString16(3);
292 form.username_value = Decrypt(s2.ColumnString(5)); 292 form.username_value = Decrypt(s2.ColumnString(5));
293 form.password_element = s2.ColumnString16(4); 293 form.password_element = s2.ColumnString16(4);
294 form.password_value = Decrypt(s2.ColumnString(6)); 294 form.password_value = Decrypt(s2.ColumnString(6));
295 form.action = GURL(s2.ColumnString(2)).ReplaceComponents(rep); 295 form.action = GURL(s2.ColumnString(2)).ReplaceComponents(rep);
296 forms->push_back(form); 296 forms->push_back(form);
297 } 297 }
298 return true; 298 return true;
299 } 299 }
OLDNEW
« no previous file with comments | « chrome/browser/importer/in_process_importer_bridge.cc ('k') | chrome/browser/importer/nss_decryptor_mac.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698