OLD | NEW |
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 "testing/gtest/include/gtest/gtest.h" | 5 #include "testing/gtest/include/gtest/gtest.h" |
6 | 6 |
7 #include <windows.h> | 7 #include <windows.h> |
8 | 8 |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/strings/string16.h" | 11 #include "components/webdata/encryptor/ie7_password_win.h" |
12 #include "components/webdata/encryptor/ie7_password.h" | |
13 | 12 |
14 TEST(IE7PasswordTest, GetUserPassword) { | 13 TEST(IE7PasswordTest, GetUserPassword) { |
15 // This is the unencrypted values of my keys under Storage2. | 14 // This is the unencrypted values of my keys under Storage2. |
16 // The passwords have been manually changed to abcdef... but the size remains | 15 // The passwords have been manually changed to abcdef... but the size remains |
17 // the same. | 16 // the same. |
18 unsigned char data1[] = "\x0c\x00\x00\x00\x38\x00\x00\x00\x2c\x00\x00\x00" | 17 const unsigned char kData1[] = |
19 "\x57\x49\x43\x4b\x18\x00\x00\x00\x02\x00\x00\x00" | 18 "\x0c\x00\x00\x00\x38\x00\x00\x00\x2c\x00\x00\x00" |
20 "\x67\x00\x72\x00\x01\x00\x00\x00\x00\x00\x00\x00" | 19 "\x57\x49\x43\x4b\x18\x00\x00\x00\x02\x00\x00\x00" |
21 "\x00\x00\x00\x00\x4e\xfa\x67\x76\x22\x94\xc8\x01" | 20 "\x67\x00\x72\x00\x01\x00\x00\x00\x00\x00\x00\x00" |
22 "\x08\x00\x00\x00\x12\x00\x00\x00\x4e\xfa\x67\x76" | 21 "\x00\x00\x00\x00\x4e\xfa\x67\x76\x22\x94\xc8\x01" |
23 "\x22\x94\xc8\x01\x0c\x00\x00\x00\x61\x00\x62\x00" | 22 "\x08\x00\x00\x00\x12\x00\x00\x00\x4e\xfa\x67\x76" |
24 "\x63\x00\x64\x00\x65\x00\x66\x00\x67\x00\x68\x00" | 23 "\x22\x94\xc8\x01\x0c\x00\x00\x00\x61\x00\x62\x00" |
25 "\x00\x00\x61\x00\x62\x00\x63\x00\x64\x00\x65\x00" | 24 "\x63\x00\x64\x00\x65\x00\x66\x00\x67\x00\x68\x00" |
26 "\x66\x00\x67\x00\x68\x00\x69\x00\x6a\x00\x6b\x00" | 25 "\x00\x00\x61\x00\x62\x00\x63\x00\x64\x00\x65\x00" |
27 "\x6c\x00\x00\x00"; | 26 "\x66\x00\x67\x00\x68\x00\x69\x00\x6a\x00\x6b\x00" |
| 27 "\x6c\x00\x00\x00"; |
28 | 28 |
29 unsigned char data2[] = "\x0c\x00\x00\x00\x38\x00\x00\x00\x24\x00\x00\x00" | 29 const unsigned char kData2[] = |
30 "\x57\x49\x43\x4b\x18\x00\x00\x00\x02\x00\x00\x00" | 30 "\x0c\x00\x00\x00\x38\x00\x00\x00\x24\x00\x00\x00" |
31 "\x67\x00\x72\x00\x01\x00\x00\x00\x00\x00\x00\x00" | 31 "\x57\x49\x43\x4b\x18\x00\x00\x00\x02\x00\x00\x00" |
32 "\x00\x00\x00\x00\xa8\xea\xf4\xe5\x9f\x9a\xc8\x01" | 32 "\x67\x00\x72\x00\x01\x00\x00\x00\x00\x00\x00\x00" |
33 "\x09\x00\x00\x00\x14\x00\x00\x00\xa8\xea\xf4\xe5" | 33 "\x00\x00\x00\x00\xa8\xea\xf4\xe5\x9f\x9a\xc8\x01" |
34 "\x9f\x9a\xc8\x01\x07\x00\x00\x00\x61\x00\x62\x00" | 34 "\x09\x00\x00\x00\x14\x00\x00\x00\xa8\xea\xf4\xe5" |
35 "\x63\x00\x64\x00\x65\x00\x66\x00\x67\x00\x68\x00" | 35 "\x9f\x9a\xc8\x01\x07\x00\x00\x00\x61\x00\x62\x00" |
36 "\x69\x00\x00\x00\x61\x00\x62\x00\x63\x00\x64\x00" | 36 "\x63\x00\x64\x00\x65\x00\x66\x00\x67\x00\x68\x00" |
37 "\x65\x00\x66\x00\x67\x00\x00\x00"; | 37 "\x69\x00\x00\x00\x61\x00\x62\x00\x63\x00\x64\x00" |
38 | 38 "\x65\x00\x66\x00\x67\x00\x00\x00"; |
39 | |
40 | 39 |
41 std::vector<unsigned char> decrypted_data1; | 40 std::vector<unsigned char> decrypted_data1; |
42 decrypted_data1.resize(arraysize(data1)); | 41 decrypted_data1.resize(arraysize(kData1)); |
43 memcpy(&decrypted_data1.front(), data1, sizeof(data1)); | 42 memcpy(&decrypted_data1.front(), kData1, sizeof(kData1)); |
44 | 43 |
45 std::vector<unsigned char> decrypted_data2; | 44 std::vector<unsigned char> decrypted_data2; |
46 decrypted_data2.resize(arraysize(data2)); | 45 decrypted_data2.resize(arraysize(kData2)); |
47 memcpy(&decrypted_data2.front(), data2, sizeof(data2)); | 46 memcpy(&decrypted_data2.front(), kData2, sizeof(kData2)); |
48 | 47 |
49 string16 password; | 48 std::vector<ie7_password::DecryptedCredentials> credentials; |
50 string16 username; | 49 ASSERT_TRUE(ie7_password::GetUserPassFromData(decrypted_data1, &credentials)); |
51 ASSERT_TRUE(ie7_password::GetUserPassFromData(decrypted_data1, &username, | 50 ASSERT_EQ(1u, credentials.size()); |
52 &password)); | 51 EXPECT_EQ(L"abcdefgh", credentials[0].username); |
53 EXPECT_EQ(L"abcdefgh", username); | 52 EXPECT_EQ(L"abcdefghijkl", credentials[0].password); |
54 EXPECT_EQ(L"abcdefghijkl", password); | |
55 | 53 |
56 ASSERT_TRUE(ie7_password::GetUserPassFromData(decrypted_data2, &username, | 54 credentials.clear(); |
57 &password)); | 55 ASSERT_TRUE(ie7_password::GetUserPassFromData(decrypted_data2, &credentials)); |
58 EXPECT_EQ(L"abcdefghi", username); | 56 ASSERT_EQ(1u, credentials.size()); |
59 EXPECT_EQ(L"abcdefg", password); | 57 EXPECT_EQ(L"abcdefghi", credentials[0].username); |
| 58 EXPECT_EQ(L"abcdefg", credentials[0].password); |
60 } | 59 } |
| 60 |
| 61 TEST(IE7PasswordTest, GetThreeUserPasswords) { |
| 62 // Unencrypted binary data holding 3 sets of credentials |
| 63 const unsigned char kData[] = |
| 64 "\x0c\x00\x00\x00\x78\x00\x00\x00\x48\x00\x00\x00\x57\x49\x43\x4b\x18" |
| 65 "\x00\x00\x00\x06\x00\x00\x00\x5c\x00\x55\x00\x01\x00\x00\x00\x00\x00" |
| 66 "\x00\x00\x00\x00\x00\x00\xc3\xf2\x4b\xda\x1d\xc4\xce\x01\x04\x00\x00" |
| 67 "\x00\x0a\x00\x00\x00\xc3\xf2\x4b\xda\x1d\xc4\xce\x01\x06\x00\x00\x00" |
| 68 "\x18\x00\x00\x00\xbe\x5e\xe9\xe1\x1d\xc4\xce\x01\x04\x00\x00\x00\x22" |
| 69 "\x00\x00\x00\xbe\x5e\xe9\xe1\x1d\xc4\xce\x01\x06\x00\x00\x00\x30\x00" |
| 70 "\x00\x00\x07\x50\x1f\xe6\x1d\xc4\xce\x01\x04\x00\x00\x00\x3a\x00\x00" |
| 71 "\x00\x07\x50\x1f\xe6\x1d\xc4\xce\x01\x06\x00\x00\x00\x71\x00\x77\x00" |
| 72 "\x65\x00\x72\x00\x00\x00\x71\x00\x77\x00\x65\x00\x72\x00\x74\x00\x79" |
| 73 "\x00\x00\x00\x61\x00\x73\x00\x64\x00\x66\x00\x00\x00\x61\x00\x73\x00" |
| 74 "\x64\x00\x66\x00\x67\x00\x68\x00\x00\x00\x7a\x00\x78\x00\x63\x00\x76" |
| 75 "\x00\x00\x00\x7a\x00\x78\x00\x63\x00\x76\x00\x62\x00\x6e\x00\x00\x00"; |
| 76 |
| 77 std::vector<unsigned char> decrypted_data; |
| 78 decrypted_data.resize(arraysize(kData)); |
| 79 memcpy(&decrypted_data.front(), kData, sizeof(kData)); |
| 80 |
| 81 std::vector<ie7_password::DecryptedCredentials> credentials; |
| 82 ASSERT_TRUE(ie7_password::GetUserPassFromData(decrypted_data, &credentials)); |
| 83 ASSERT_EQ(3u, credentials.size()); |
| 84 EXPECT_EQ(L"qwer", credentials[0].username); |
| 85 EXPECT_EQ(L"qwerty", credentials[0].password); |
| 86 EXPECT_EQ(L"asdf", credentials[1].username); |
| 87 EXPECT_EQ(L"asdfgh", credentials[1].password); |
| 88 EXPECT_EQ(L"zxcv", credentials[2].username); |
| 89 EXPECT_EQ(L"zxcvbn", credentials[2].password); |
| 90 } |
OLD | NEW |