OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/quic/crypto/common_cert_set.h" | 5 #include "net/quic/crypto/common_cert_set.h" |
6 | 6 |
7 #include "testing/gtest/include/gtest/gtest.h" | 7 #include "testing/gtest/include/gtest/gtest.h" |
8 | 8 |
9 using base::StringPiece; | 9 using base::StringPiece; |
10 | 10 |
11 namespace net { | 11 namespace net { |
12 namespace test { | 12 namespace test { |
13 | 13 |
14 static unsigned char kGIACertificate[] = { | 14 static const unsigned char kGIACertificate[] = { |
15 0x30, 0x82, 0x02, 0xb0, 0x30, 0x82, 0x02, 0x19, 0xa0, 0x03, 0x02, 0x01, | 15 0x30, 0x82, 0x02, 0xb0, 0x30, 0x82, 0x02, 0x19, 0xa0, 0x03, 0x02, 0x01, |
16 0x02, 0x02, 0x03, 0x0b, 0x67, 0x71, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, | 16 0x02, 0x02, 0x03, 0x0b, 0x67, 0x71, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, |
17 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x05, 0x05, 0x00, 0x30, 0x4e, 0x31, | 17 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x05, 0x05, 0x00, 0x30, 0x4e, 0x31, |
18 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x55, 0x53, | 18 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x55, 0x53, |
19 0x31, 0x10, 0x30, 0x0e, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x13, 0x07, 0x45, | 19 0x31, 0x10, 0x30, 0x0e, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x13, 0x07, 0x45, |
20 0x71, 0x75, 0x69, 0x66, 0x61, 0x78, 0x31, 0x2d, 0x30, 0x2b, 0x06, 0x03, | 20 0x71, 0x75, 0x69, 0x66, 0x61, 0x78, 0x31, 0x2d, 0x30, 0x2b, 0x06, 0x03, |
21 0x55, 0x04, 0x0b, 0x13, 0x24, 0x45, 0x71, 0x75, 0x69, 0x66, 0x61, 0x78, | 21 0x55, 0x04, 0x0b, 0x13, 0x24, 0x45, 0x71, 0x75, 0x69, 0x66, 0x61, 0x78, |
22 0x20, 0x53, 0x65, 0x63, 0x75, 0x72, 0x65, 0x20, 0x43, 0x65, 0x72, 0x74, | 22 0x20, 0x53, 0x65, 0x63, 0x75, 0x72, 0x65, 0x20, 0x43, 0x65, 0x72, 0x74, |
23 0x69, 0x66, 0x69, 0x63, 0x61, 0x74, 0x65, 0x20, 0x41, 0x75, 0x74, 0x68, | 23 0x69, 0x66, 0x69, 0x63, 0x61, 0x74, 0x65, 0x20, 0x41, 0x75, 0x74, 0x68, |
24 0x6f, 0x72, 0x69, 0x74, 0x79, 0x30, 0x1e, 0x17, 0x0d, 0x30, 0x39, 0x30, | 24 0x6f, 0x72, 0x69, 0x74, 0x79, 0x30, 0x1e, 0x17, 0x0d, 0x30, 0x39, 0x30, |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 0x9a, 0x5a, 0x09, 0xd2, 0x90, 0xb7, 0xfa, 0x0c, 0xf8, 0x7e, 0x78, 0xa2, | 69 0x9a, 0x5a, 0x09, 0xd2, 0x90, 0xb7, 0xfa, 0x0c, 0xf8, 0x7e, 0x78, 0xa2, |
70 0xb0, 0x85, 0xaf, 0x5c, 0x4c, 0x99, 0xd9, 0x5c, 0x55, 0x29, 0xf9, 0xa5, | 70 0xb0, 0x85, 0xaf, 0x5c, 0x4c, 0x99, 0xd9, 0x5c, 0x55, 0x29, 0xf9, 0xa5, |
71 0x51, 0x42, 0x2e, 0x3a, 0xcb, 0x38, 0x8c, 0x78, 0x3b, 0xcb, 0xf8, 0xfb, | 71 0x51, 0x42, 0x2e, 0x3a, 0xcb, 0x38, 0x8c, 0x78, 0x3b, 0xcb, 0xf8, 0xfb, |
72 0x95, 0x87, 0xbc, 0xbc, 0x90, 0xf9, 0x50, 0x32, | 72 0x95, 0x87, 0xbc, 0xbc, 0x90, 0xf9, 0x50, 0x32, |
73 }; | 73 }; |
74 | 74 |
75 TEST(CommonCertSets, FindGIA) { | 75 TEST(CommonCertSets, FindGIA) { |
76 StringPiece gia(reinterpret_cast<const char*>(kGIACertificate), | 76 StringPiece gia(reinterpret_cast<const char*>(kGIACertificate), |
77 sizeof(kGIACertificate)); | 77 sizeof(kGIACertificate)); |
78 | 78 |
79 CommonCertSetsQUIC set; | 79 CommonCertSetsQUIC sets; |
80 | 80 |
81 const uint64 in_hash = GG_UINT64_C(0xde8086f914a3af54); | 81 const uint64 in_hash = GG_UINT64_C(0xde8086f914a3af54); |
82 uint64 hash; | 82 uint64 hash; |
83 uint32 index; | 83 uint32 index; |
84 ASSERT_TRUE(set.MatchCert( | 84 ASSERT_TRUE(sets.MatchCert( |
85 gia, | 85 gia, |
86 StringPiece(reinterpret_cast<const char*>(&in_hash), sizeof(in_hash)), | 86 StringPiece(reinterpret_cast<const char*>(&in_hash), sizeof(in_hash)), |
87 &hash, &index)); | 87 &hash, &index)); |
88 EXPECT_EQ(in_hash, hash); | 88 EXPECT_EQ(in_hash, hash); |
89 | 89 |
90 StringPiece gia_copy = set.GetCert(hash, index); | 90 StringPiece gia_copy = sets.GetCert(hash, index); |
91 EXPECT_FALSE(gia_copy.empty()); | 91 EXPECT_FALSE(gia_copy.empty()); |
92 ASSERT_EQ(gia.size(), gia_copy.size()); | 92 ASSERT_EQ(gia.size(), gia_copy.size()); |
93 EXPECT_TRUE(0 == memcmp(gia.data(), gia_copy.data(), gia.size())); | 93 EXPECT_TRUE(0 == memcmp(gia.data(), gia_copy.data(), gia.size())); |
94 } | 94 } |
95 | 95 |
96 TEST(CommonCertSets, NonMatch) { | 96 TEST(CommonCertSets, NonMatch) { |
97 CommonCertSetsQUIC set; | 97 CommonCertSetsQUIC sets; |
98 StringPiece not_a_cert("hello"); | 98 StringPiece not_a_cert("hello"); |
99 const uint64 in_hash = GG_UINT64_C(0xde8086f914a3af54); | 99 const uint64 in_hash = GG_UINT64_C(0xde8086f914a3af54); |
100 uint64 hash; | 100 uint64 hash; |
101 uint32 index; | 101 uint32 index; |
102 EXPECT_FALSE(set.MatchCert( | 102 EXPECT_FALSE(sets.MatchCert( |
103 not_a_cert, | 103 not_a_cert, |
104 StringPiece(reinterpret_cast<const char*>(&in_hash), sizeof(in_hash)), | 104 StringPiece(reinterpret_cast<const char*>(&in_hash), sizeof(in_hash)), |
105 &hash, &index)); | 105 &hash, &index)); |
106 } | 106 } |
107 | 107 |
108 } // namespace test | 108 } // namespace test |
109 } // namespace net | 109 } // namespace net |
OLD | NEW |