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 #include "chrome/browser/importer/nss_decryptor.h" | 5 #include "chrome/browser/importer/nss_decryptor.h" |
6 | 6 |
7 #include "base/scoped_ptr.h" | 7 #include "base/scoped_ptr.h" |
8 #include "build/build_config.h" | 8 #include "build/build_config.h" |
9 #include "chrome/common/sqlite_utils.h" | 9 #include "chrome/common/sqlite_utils.h" |
10 | 10 |
11 #if defined(OS_LINUX) | 11 #if defined(OS_LINUX) |
12 #include <pk11pub.h> | 12 #include <pk11pub.h> |
13 #include <pk11sdr.h> | 13 #include <pk11sdr.h> |
14 #endif // defined(OS_LINUX) | 14 #endif // defined(OS_LINUX) |
15 | 15 |
| 16 #include "base/base64.h" |
16 #include "base/string_util.h" | 17 #include "base/string_util.h" |
17 #include "net/base/base64.h" | |
18 #include "webkit/glue/password_form.h" | 18 #include "webkit/glue/password_form.h" |
19 | 19 |
20 using webkit_glue::PasswordForm; | 20 using webkit_glue::PasswordForm; |
21 | 21 |
22 // This method is based on some Firefox code in | 22 // This method is based on some Firefox code in |
23 // security/manager/ssl/src/nsSDR.cpp | 23 // security/manager/ssl/src/nsSDR.cpp |
24 // The license block is: | 24 // The license block is: |
25 | 25 |
26 /* ***** BEGIN LICENSE BLOCK ***** | 26 /* ***** BEGIN LICENSE BLOCK ***** |
27 * Version: MPL 1.1/GPL 2.0/LGPL 2.1 | 27 * Version: MPL 1.1/GPL 2.0/LGPL 2.1 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 string16 NSSDecryptor::Decrypt(const std::string& crypt) const { | 62 string16 NSSDecryptor::Decrypt(const std::string& crypt) const { |
63 // Do nothing if NSS is not loaded. | 63 // Do nothing if NSS is not loaded. |
64 if (!is_nss_initialized_) | 64 if (!is_nss_initialized_) |
65 return string16(); | 65 return string16(); |
66 | 66 |
67 // The old style password is encoded in base64. They are identified | 67 // The old style password is encoded in base64. They are identified |
68 // by a leading '~'. Otherwise, we should decrypt the text. | 68 // by a leading '~'. Otherwise, we should decrypt the text. |
69 std::string plain; | 69 std::string plain; |
70 if (crypt[0] != '~') { | 70 if (crypt[0] != '~') { |
71 std::string decoded_data; | 71 std::string decoded_data; |
72 net::Base64Decode(crypt, &decoded_data); | 72 base::Base64Decode(crypt, &decoded_data); |
73 PK11SlotInfo* slot = GetKeySlotForDB(); | 73 PK11SlotInfo* slot = GetKeySlotForDB(); |
74 SECStatus result = PK11_Authenticate(slot, PR_TRUE, NULL); | 74 SECStatus result = PK11_Authenticate(slot, PR_TRUE, NULL); |
75 if (result != SECSuccess) { | 75 if (result != SECSuccess) { |
76 FreeSlot(slot); | 76 FreeSlot(slot); |
77 return string16(); | 77 return string16(); |
78 } | 78 } |
79 | 79 |
80 SECItem request; | 80 SECItem request; |
81 request.data = reinterpret_cast<unsigned char*>( | 81 request.data = reinterpret_cast<unsigned char*>( |
82 const_cast<char*>(decoded_data.data())); | 82 const_cast<char*>(decoded_data.data())); |
83 request.len = static_cast<unsigned int>(decoded_data.size()); | 83 request.len = static_cast<unsigned int>(decoded_data.size()); |
84 SECItem reply; | 84 SECItem reply; |
85 reply.data = NULL; | 85 reply.data = NULL; |
86 reply.len = 0; | 86 reply.len = 0; |
87 #if defined(OS_LINUX) | 87 #if defined(OS_LINUX) |
88 result = PK11SDR_DecryptWithSlot(slot, &request, &reply, NULL); | 88 result = PK11SDR_DecryptWithSlot(slot, &request, &reply, NULL); |
89 #else | 89 #else |
90 result = PK11SDR_Decrypt(&request, &reply, NULL); | 90 result = PK11SDR_Decrypt(&request, &reply, NULL); |
91 #endif // defined(OS_LINUX) | 91 #endif // defined(OS_LINUX) |
92 if (result == SECSuccess) | 92 if (result == SECSuccess) |
93 plain.assign(reinterpret_cast<char*>(reply.data), reply.len); | 93 plain.assign(reinterpret_cast<char*>(reply.data), reply.len); |
94 | 94 |
95 SECITEM_FreeItem(&reply, PR_FALSE); | 95 SECITEM_FreeItem(&reply, PR_FALSE); |
96 FreeSlot(slot); | 96 FreeSlot(slot); |
97 } else { | 97 } else { |
98 // Deletes the leading '~' before decoding. | 98 // Deletes the leading '~' before decoding. |
99 net::Base64Decode(crypt.substr(1), &plain); | 99 base::Base64Decode(crypt.substr(1), &plain); |
100 } | 100 } |
101 | 101 |
102 return UTF8ToUTF16(plain); | 102 return UTF8ToUTF16(plain); |
103 } | 103 } |
104 | 104 |
105 // There are three versions of password filess. They store saved user | 105 // There are three versions of password filess. They store saved user |
106 // names and passwords. | 106 // names and passwords. |
107 // References: | 107 // References: |
108 // http://kb.mozillazine.org/Signons.txt | 108 // http://kb.mozillazine.org/Signons.txt |
109 // http://kb.mozillazine.org/Signons2.txt | 109 // http://kb.mozillazine.org/Signons2.txt |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
288 // The user name, password and action. | 288 // The user name, password and action. |
289 form.username_element = UTF8ToUTF16(s2.column_string(3)); | 289 form.username_element = UTF8ToUTF16(s2.column_string(3)); |
290 form.username_value = Decrypt(s2.column_string(5)); | 290 form.username_value = Decrypt(s2.column_string(5)); |
291 form.password_element = UTF8ToUTF16(s2.column_string(4)); | 291 form.password_element = UTF8ToUTF16(s2.column_string(4)); |
292 form.password_value = Decrypt(s2.column_string(6)); | 292 form.password_value = Decrypt(s2.column_string(6)); |
293 form.action = GURL(s2.column_string(2)).ReplaceComponents(rep); | 293 form.action = GURL(s2.column_string(2)).ReplaceComponents(rep); |
294 forms->push_back(form); | 294 forms->push_back(form); |
295 } | 295 } |
296 return true; | 296 return true; |
297 } | 297 } |
OLD | NEW |