OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 "net/tools/transport_security_state_generator/spki_hash.h" | 5 #include "net/tools/transport_security_state_generator/spki_hash.h" |
6 #include "base/strings/string_number_conversions.h" | 6 #include "base/strings/string_number_conversions.h" |
7 #include "testing/gmock/include/gmock/gmock.h" | 7 #include "testing/gmock/include/gmock/gmock.h" |
8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
9 | 9 |
10 namespace net { | 10 namespace net { |
(...skipping 22 matching lines...) Expand all Loading... |
33 std::vector<uint8_t> hash_vector2(hash2.data(), hash2.data() + hash2.size()); | 33 std::vector<uint8_t> hash_vector2(hash2.data(), hash2.data() + hash2.size()); |
34 EXPECT_THAT( | 34 EXPECT_THAT( |
35 hash_vector2, | 35 hash_vector2, |
36 testing::ElementsAreArray( | 36 testing::ElementsAreArray( |
37 {0xE2, 0x8B, 0x14, 0xEF, 0xD8, 0x5F, 0x63, 0x73, 0xF6, 0xF9, 0x62, | 37 {0xE2, 0x8B, 0x14, 0xEF, 0xD8, 0x5F, 0x63, 0x73, 0xF6, 0xF9, 0x62, |
38 0x46, 0x95, 0x3D, 0XA6, 0xC6, 0x64, 0x8B, 0xFB, 0x91, 0x48, 0xC0, | 38 0x46, 0x95, 0x3D, 0XA6, 0xC6, 0x64, 0x8B, 0xFB, 0x91, 0x48, 0xC0, |
39 0xB1, 0x15, 0xC5, 0x34, 0x1C, 0x6A, 0xFC, 0x81, 0x36, 0x04})); | 39 0xB1, 0x15, 0xC5, 0x34, 0x1C, 0x6A, 0xFC, 0x81, 0x36, 0x04})); |
40 | 40 |
41 SPKIHash hash3; | 41 SPKIHash hash3; |
42 | 42 |
43 // Valid SHA1 should rejected. | 43 // Valid SHA1 should be rejected. |
44 EXPECT_FALSE(hash3.FromString("sha1/111111111111111111111111111=")); | 44 EXPECT_FALSE(hash3.FromString("sha1/111111111111111111111111111=")); |
45 EXPECT_FALSE(hash3.FromString("sha1/gzF+YoVCU9bXeDGQ7JGQVumRueM=")); | 45 EXPECT_FALSE(hash3.FromString("sha1/gzF+YoVCU9bXeDGQ7JGQVumRueM=")); |
46 | 46 |
47 // SHA1 disguised as SHA256. | 47 // SHA1 disguised as SHA256. |
48 EXPECT_FALSE(hash3.FromString("sha256/111111111111111111111111111=")); | 48 EXPECT_FALSE(hash3.FromString("sha256/111111111111111111111111111=")); |
49 | 49 |
50 // SHA512 disguised as SHA256. | 50 // SHA512 disguised as SHA256. |
51 EXPECT_FALSE( | 51 EXPECT_FALSE( |
52 hash3.FromString("sha256/ns3smS51SK/4P7uSVhSlCIMNAxkD+r6C/ZZA/" | 52 hash3.FromString("sha256/ns3smS51SK/4P7uSVhSlCIMNAxkD+r6C/ZZA/" |
53 "07vac0uyMdRS4jKfqlvk3XxLFP1v5aMIxM5cdTM7FHNwxagQg==")); | 53 "07vac0uyMdRS4jKfqlvk3XxLFP1v5aMIxM5cdTM7FHNwxagQg==")); |
54 | 54 |
55 // Invalid BASE64. | 55 // Invalid BASE64. |
56 EXPECT_FALSE(hash3.FromString("sha256/hsts-preload")); | 56 EXPECT_FALSE(hash3.FromString("sha256/hsts-preload")); |
57 EXPECT_FALSE(hash3.FromString("sha256/1. 2. 3. security!=")); | 57 EXPECT_FALSE(hash3.FromString("sha256/1. 2. 3. security!=")); |
58 } | 58 } |
59 | 59 |
60 } // namespace | 60 } // namespace |
61 | 61 |
62 } // namespace transport_security_state | 62 } // namespace transport_security_state |
63 | 63 |
64 } // namespace net | 64 } // namespace net |
OLD | NEW |