| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/password_manager/ie7_password.h" | 5 #include "chrome/browser/password_manager/ie7_password.h" |
| 6 | 6 |
| 7 #include <wincrypt.h> | 7 #include <wincrypt.h> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/sha1.h" | 12 #include "base/sha1.h" |
| 13 #include "base/string_util.h" | 13 #include "base/string_util.h" |
| 14 #include "base/stringprintf.h" |
| 14 | 15 |
| 15 namespace { | 16 namespace { |
| 16 | 17 |
| 17 // Structures that IE7/IE8 use to store a username/password. | 18 // Structures that IE7/IE8 use to store a username/password. |
| 18 // Some of the fields might have been incorrectly reverse engineered. | 19 // Some of the fields might have been incorrectly reverse engineered. |
| 19 struct PreHeader { | 20 struct PreHeader { |
| 20 DWORD pre_header_size; // Size of this header structure. Always 12. | 21 DWORD pre_header_size; // Size of this header structure. Always 12. |
| 21 DWORD header_size; // Size of the real Header: sizeof(Header) + | 22 DWORD header_size; // Size of the real Header: sizeof(Header) + |
| 22 // item_count * sizeof(Entry); | 23 // item_count * sizeof(Entry); |
| 23 DWORD data_size; // Size of the data referenced by the entries. | 24 DWORD data_size; // Size of the data referenced by the entries. |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 | 94 |
| 94 std::wstring url_hash; | 95 std::wstring url_hash; |
| 95 | 96 |
| 96 // Transform the buffer to an hexadecimal string. | 97 // Transform the buffer to an hexadecimal string. |
| 97 unsigned char checksum = 0; | 98 unsigned char checksum = 0; |
| 98 for (size_t i = 0; i < hash_bin.size(); ++i) { | 99 for (size_t i = 0; i < hash_bin.size(); ++i) { |
| 99 // std::string gives signed chars, which mess with StringPrintf and | 100 // std::string gives signed chars, which mess with StringPrintf and |
| 100 // check_sum. | 101 // check_sum. |
| 101 unsigned char hash_byte = static_cast<unsigned char>(hash_bin[i]); | 102 unsigned char hash_byte = static_cast<unsigned char>(hash_bin[i]); |
| 102 checksum += hash_byte; | 103 checksum += hash_byte; |
| 103 url_hash += StringPrintf(L"%2.2X", static_cast<unsigned>(hash_byte)); | 104 url_hash += base::StringPrintf(L"%2.2X", static_cast<unsigned>(hash_byte)); |
| 104 } | 105 } |
| 105 url_hash += StringPrintf(L"%2.2X", checksum); | 106 url_hash += base::StringPrintf(L"%2.2X", checksum); |
| 106 | 107 |
| 107 return url_hash; | 108 return url_hash; |
| 108 } | 109 } |
| 109 | 110 |
| 110 bool DecryptPassword(const std::wstring& url, | 111 bool DecryptPassword(const std::wstring& url, |
| 111 const std::vector<unsigned char>& data, | 112 const std::vector<unsigned char>& data, |
| 112 std::wstring* username, std::wstring* password) { | 113 std::wstring* username, std::wstring* password) { |
| 113 std::wstring lower_case_url = StringToLowerASCII(url); | 114 std::wstring lower_case_url = StringToLowerASCII(url); |
| 114 DATA_BLOB input = {0}; | 115 DATA_BLOB input = {0}; |
| 115 DATA_BLOB output = {0}; | 116 DATA_BLOB output = {0}; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 134 GetUserPassFromData(decrypted_data, username, password); | 135 GetUserPassFromData(decrypted_data, username, password); |
| 135 | 136 |
| 136 LocalFree(output.pbData); | 137 LocalFree(output.pbData); |
| 137 return true; | 138 return true; |
| 138 } | 139 } |
| 139 | 140 |
| 140 return false; | 141 return false; |
| 141 } | 142 } |
| 142 | 143 |
| 143 } // namespace ie7_password | 144 } // namespace ie7_password |
| OLD | NEW |