OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "net/tools/transport_security_state_generator/spki_hash.h" |
| 6 #include "base/strings/string_number_conversions.h" |
| 7 #include "testing/gmock/include/gmock/gmock.h" |
| 8 #include "testing/gtest/include/gtest/gtest.h" |
| 9 |
| 10 namespace net { |
| 11 |
| 12 namespace transport_security_state { |
| 13 |
| 14 namespace { |
| 15 |
| 16 TEST(SPKIHashTest, FromString) { |
| 17 SPKIHash hash; |
| 18 |
| 19 // Valid SHA256. |
| 20 EXPECT_TRUE( |
| 21 hash.FromString("sha256/1111111111111111111111111111111111111111111=")); |
| 22 std::vector<uint8_t> hash_vector(hash.data(), hash.data() + hash.size()); |
| 23 EXPECT_THAT( |
| 24 hash_vector, |
| 25 testing::ElementsAreArray( |
| 26 {0xD7, 0x5D, 0x75, 0xD7, 0x5D, 0x75, 0xD7, 0x5D, 0x75, 0xD7, 0x5D, |
| 27 0x75, 0xD7, 0x5D, 0x75, 0xD7, 0x5D, 0x75, 0xD7, 0x5D, 0x75, 0xD7, |
| 28 0x5D, 0x75, 0xD7, 0x5D, 0x75, 0xD7, 0x5D, 0x75, 0xD7, 0x5D})); |
| 29 |
| 30 SPKIHash hash2; |
| 31 EXPECT_TRUE( |
| 32 hash2.FromString("sha256/4osU79hfY3P2+WJGlT2mxmSL+5FIwLEVxTQcavyBNgQ=")); |
| 33 std::vector<uint8_t> hash_vector2(hash2.data(), hash2.data() + hash2.size()); |
| 34 EXPECT_THAT( |
| 35 hash_vector2, |
| 36 testing::ElementsAreArray( |
| 37 {0xE2, 0x8B, 0x14, 0xEF, 0xD8, 0x5F, 0x63, 0x73, 0xF6, 0xF9, 0x62, |
| 38 0x46, 0x95, 0x3D, 0XA6, 0xC6, 0x64, 0x8B, 0xFB, 0x91, 0x48, 0xC0, |
| 39 0xB1, 0x15, 0xC5, 0x34, 0x1C, 0x6A, 0xFC, 0x81, 0x36, 0x04})); |
| 40 |
| 41 SPKIHash hash3; |
| 42 |
| 43 // Valid SHA1 should rejected. |
| 44 EXPECT_FALSE(hash3.FromString("sha1/111111111111111111111111111=")); |
| 45 EXPECT_FALSE(hash3.FromString("sha1/gzF+YoVCU9bXeDGQ7JGQVumRueM=")); |
| 46 |
| 47 // SHA1 disguised as SHA256. |
| 48 EXPECT_FALSE(hash3.FromString("sha256/111111111111111111111111111=")); |
| 49 |
| 50 // SHA512 disguised as SHA256. |
| 51 EXPECT_FALSE( |
| 52 hash3.FromString("sha256/ns3smS51SK/4P7uSVhSlCIMNAxkD+r6C/ZZA/" |
| 53 "07vac0uyMdRS4jKfqlvk3XxLFP1v5aMIxM5cdTM7FHNwxagQg==")); |
| 54 |
| 55 // Invalid BASE64. |
| 56 EXPECT_FALSE(hash3.FromString("sha256/hsts-preload")); |
| 57 EXPECT_FALSE(hash3.FromString("sha256/1. 2. 3. security!=")); |
| 58 } |
| 59 |
| 60 } // namespace |
| 61 |
| 62 } // namespace transport_security_state |
| 63 |
| 64 } // namespace net |
OLD | NEW |