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/core/crypto/common_cert_set.h" | 5 #include "net/quic/core/crypto/common_cert_set.h" |
6 | 6 |
7 #include <cstdint> | 7 #include <cstdint> |
8 | 8 |
9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "net/quic/platform/api/quic_test.h" |
10 | 10 |
11 namespace net { | 11 namespace net { |
12 namespace test { | 12 namespace test { |
13 | 13 |
14 // Google Internet Authority cert from v2 of the cert set. | 14 // Google Internet Authority cert from v2 of the cert set. |
15 static const unsigned char kGIACertificate2[] = { | 15 static const unsigned char kGIACertificate2[] = { |
16 0x30, 0x82, 0x03, 0xf0, 0x30, 0x82, 0x02, 0xd8, 0xa0, 0x03, 0x02, 0x01, | 16 0x30, 0x82, 0x03, 0xf0, 0x30, 0x82, 0x02, 0xd8, 0xa0, 0x03, 0x02, 0x01, |
17 0x02, 0x02, 0x03, 0x02, 0x3a, 0x83, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, | 17 0x02, 0x02, 0x03, 0x02, 0x3a, 0x83, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, |
18 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05, 0x00, 0x30, 0x42, 0x31, | 18 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05, 0x00, 0x30, 0x42, 0x31, |
19 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x55, 0x53, | 19 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x55, 0x53, |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 0x06, 0xf7, 0x66, 0x58, 0x5f, 0x5f, 0x64, 0xe1, 0xab, 0x5d, 0x6d, 0xa5, | 182 0x06, 0xf7, 0x66, 0x58, 0x5f, 0x5f, 0x64, 0xe1, 0xab, 0x5d, 0x6d, 0xa5, |
183 0x39, 0x48, 0x75, 0x98, 0x4c, 0x29, 0x5a, 0x3a, 0x8d, 0xd3, 0x2b, 0xca, | 183 0x39, 0x48, 0x75, 0x98, 0x4c, 0x29, 0x5a, 0x3a, 0x8d, 0xd3, 0x2b, 0xca, |
184 0x9c, 0x55, 0x04, 0xbf, 0xf4, 0xe6, 0x14, 0xd5, 0x80, 0xac, 0x26, 0xed, | 184 0x9c, 0x55, 0x04, 0xbf, 0xf4, 0xe6, 0x14, 0xd5, 0x80, 0xac, 0x26, 0xed, |
185 0x17, 0x89, 0xa6, 0x93, 0x6c, 0x5c, 0xa4, 0xcc, 0xb8, 0xf0, 0x66, 0x8e, | 185 0x17, 0x89, 0xa6, 0x93, 0x6c, 0x5c, 0xa4, 0xcc, 0xb8, 0xf0, 0x66, 0x8e, |
186 0x64, 0xe3, 0x7d, 0x9a, 0xe2, 0x00, 0xb3, 0x49, 0xc7, 0xe4, 0x0a, 0xaa, | 186 0x64, 0xe3, 0x7d, 0x9a, 0xe2, 0x00, 0xb3, 0x49, 0xc7, 0xe4, 0x0a, 0xaa, |
187 0xdd, 0x5b, 0x83, 0xc7, 0x70, 0x90, 0x46, 0x4e, 0xbe, 0xd0, 0xdb, 0x59, | 187 0xdd, 0x5b, 0x83, 0xc7, 0x70, 0x90, 0x46, 0x4e, 0xbe, 0xd0, 0xdb, 0x59, |
188 0x96, 0x6c, 0x2e, 0xf5, 0x16, 0x36, 0xde, 0x71, 0xcc, 0x01, 0xc2, 0x12, | 188 0x96, 0x6c, 0x2e, 0xf5, 0x16, 0x36, 0xde, 0x71, 0xcc, 0x01, 0xc2, 0x12, |
189 0xc1, 0x21, 0xc6, 0x16, | 189 0xc1, 0x21, 0xc6, 0x16, |
190 }; | 190 }; |
191 | 191 |
192 TEST(CommonCertSets, FindGIA_2) { | 192 class CommonCertSetsTest : public QuicTest {}; |
| 193 |
| 194 TEST_F(CommonCertSetsTest, FindGIA_2) { |
193 QuicStringPiece gia(reinterpret_cast<const char*>(kGIACertificate2), | 195 QuicStringPiece gia(reinterpret_cast<const char*>(kGIACertificate2), |
194 sizeof(kGIACertificate2)); | 196 sizeof(kGIACertificate2)); |
195 | 197 |
196 const CommonCertSets* sets(CommonCertSets::GetInstanceQUIC()); | 198 const CommonCertSets* sets(CommonCertSets::GetInstanceQUIC()); |
197 // Common Cert Set 2's hash. | 199 // Common Cert Set 2's hash. |
198 const uint64_t in_hash = UINT64_C(0xe81a92926081e801); | 200 const uint64_t in_hash = UINT64_C(0xe81a92926081e801); |
199 uint64_t hash; | 201 uint64_t hash; |
200 uint32_t index; | 202 uint32_t index; |
201 ASSERT_TRUE(sets->MatchCert( | 203 ASSERT_TRUE(sets->MatchCert( |
202 gia, | 204 gia, |
203 QuicStringPiece(reinterpret_cast<const char*>(&in_hash), sizeof(in_hash)), | 205 QuicStringPiece(reinterpret_cast<const char*>(&in_hash), sizeof(in_hash)), |
204 &hash, &index)); | 206 &hash, &index)); |
205 EXPECT_EQ(in_hash, hash); | 207 EXPECT_EQ(in_hash, hash); |
206 | 208 |
207 QuicStringPiece gia_copy = sets->GetCert(hash, index); | 209 QuicStringPiece gia_copy = sets->GetCert(hash, index); |
208 EXPECT_FALSE(gia_copy.empty()); | 210 EXPECT_FALSE(gia_copy.empty()); |
209 ASSERT_EQ(gia.size(), gia_copy.size()); | 211 ASSERT_EQ(gia.size(), gia_copy.size()); |
210 EXPECT_EQ(0, memcmp(gia.data(), gia_copy.data(), gia.size())); | 212 EXPECT_EQ(0, memcmp(gia.data(), gia_copy.data(), gia.size())); |
211 } | 213 } |
212 | 214 |
213 TEST(CommonCertSets, FindGIA_3) { | 215 TEST_F(CommonCertSetsTest, FindGIA_3) { |
214 QuicStringPiece gia(reinterpret_cast<const char*>(kGIACertificate3), | 216 QuicStringPiece gia(reinterpret_cast<const char*>(kGIACertificate3), |
215 sizeof(kGIACertificate3)); | 217 sizeof(kGIACertificate3)); |
216 | 218 |
217 const CommonCertSets* sets(CommonCertSets::GetInstanceQUIC()); | 219 const CommonCertSets* sets(CommonCertSets::GetInstanceQUIC()); |
218 // Common Cert Set 3's hash. | 220 // Common Cert Set 3's hash. |
219 const uint64_t in_hash = UINT64_C(0x918215a28680ed7e); | 221 const uint64_t in_hash = UINT64_C(0x918215a28680ed7e); |
220 uint64_t hash; | 222 uint64_t hash; |
221 uint32_t index; | 223 uint32_t index; |
222 ASSERT_TRUE(sets->MatchCert( | 224 ASSERT_TRUE(sets->MatchCert( |
223 gia, | 225 gia, |
224 QuicStringPiece(reinterpret_cast<const char*>(&in_hash), sizeof(in_hash)), | 226 QuicStringPiece(reinterpret_cast<const char*>(&in_hash), sizeof(in_hash)), |
225 &hash, &index)); | 227 &hash, &index)); |
226 EXPECT_EQ(in_hash, hash); | 228 EXPECT_EQ(in_hash, hash); |
227 | 229 |
228 QuicStringPiece gia_copy = sets->GetCert(hash, index); | 230 QuicStringPiece gia_copy = sets->GetCert(hash, index); |
229 EXPECT_FALSE(gia_copy.empty()); | 231 EXPECT_FALSE(gia_copy.empty()); |
230 ASSERT_EQ(gia.size(), gia_copy.size()); | 232 ASSERT_EQ(gia.size(), gia_copy.size()); |
231 EXPECT_EQ(0, memcmp(gia.data(), gia_copy.data(), gia.size())); | 233 EXPECT_EQ(0, memcmp(gia.data(), gia_copy.data(), gia.size())); |
232 } | 234 } |
233 | 235 |
234 TEST(CommonCertSets, NonMatch) { | 236 TEST_F(CommonCertSetsTest, NonMatch) { |
235 const CommonCertSets* sets(CommonCertSets::GetInstanceQUIC()); | 237 const CommonCertSets* sets(CommonCertSets::GetInstanceQUIC()); |
236 QuicStringPiece not_a_cert("hello"); | 238 QuicStringPiece not_a_cert("hello"); |
237 const uint64_t in_hash = UINT64_C(0xc9fef74053f99f39); | 239 const uint64_t in_hash = UINT64_C(0xc9fef74053f99f39); |
238 uint64_t hash; | 240 uint64_t hash; |
239 uint32_t index; | 241 uint32_t index; |
240 EXPECT_FALSE(sets->MatchCert( | 242 EXPECT_FALSE(sets->MatchCert( |
241 not_a_cert, | 243 not_a_cert, |
242 QuicStringPiece(reinterpret_cast<const char*>(&in_hash), sizeof(in_hash)), | 244 QuicStringPiece(reinterpret_cast<const char*>(&in_hash), sizeof(in_hash)), |
243 &hash, &index)); | 245 &hash, &index)); |
244 } | 246 } |
245 | 247 |
246 } // namespace test | 248 } // namespace test |
247 } // namespace net | 249 } // namespace net |
OLD | NEW |