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 "testing/gtest/include/gtest/gtest.h" |
10 | 10 |
11 using base::StringPiece; | |
12 | |
13 namespace net { | 11 namespace net { |
14 namespace test { | 12 namespace test { |
15 | 13 |
16 // Google Internet Authority cert from v2 of the cert set. | 14 // Google Internet Authority cert from v2 of the cert set. |
17 static const unsigned char kGIACertificate2[] = { | 15 static const unsigned char kGIACertificate2[] = { |
18 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, |
19 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, |
20 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, |
21 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, |
22 0x31, 0x16, 0x30, 0x14, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x13, 0x0d, 0x47, | 20 0x31, 0x16, 0x30, 0x14, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x13, 0x0d, 0x47, |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
185 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, |
186 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, |
187 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, |
188 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, |
189 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, |
190 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, |
191 0xc1, 0x21, 0xc6, 0x16, | 189 0xc1, 0x21, 0xc6, 0x16, |
192 }; | 190 }; |
193 | 191 |
194 TEST(CommonCertSets, FindGIA_2) { | 192 TEST(CommonCertSets, FindGIA_2) { |
195 StringPiece gia(reinterpret_cast<const char*>(kGIACertificate2), | 193 QuicStringPiece gia(reinterpret_cast<const char*>(kGIACertificate2), |
196 sizeof(kGIACertificate2)); | 194 sizeof(kGIACertificate2)); |
197 | 195 |
198 const CommonCertSets* sets(CommonCertSets::GetInstanceQUIC()); | 196 const CommonCertSets* sets(CommonCertSets::GetInstanceQUIC()); |
199 // Common Cert Set 2's hash. | 197 // Common Cert Set 2's hash. |
200 const uint64_t in_hash = UINT64_C(0xe81a92926081e801); | 198 const uint64_t in_hash = UINT64_C(0xe81a92926081e801); |
201 uint64_t hash; | 199 uint64_t hash; |
202 uint32_t index; | 200 uint32_t index; |
203 ASSERT_TRUE(sets->MatchCert( | 201 ASSERT_TRUE(sets->MatchCert( |
204 gia, | 202 gia, |
205 StringPiece(reinterpret_cast<const char*>(&in_hash), sizeof(in_hash)), | 203 QuicStringPiece(reinterpret_cast<const char*>(&in_hash), sizeof(in_hash)), |
206 &hash, &index)); | 204 &hash, &index)); |
207 EXPECT_EQ(in_hash, hash); | 205 EXPECT_EQ(in_hash, hash); |
208 | 206 |
209 StringPiece gia_copy = sets->GetCert(hash, index); | 207 QuicStringPiece gia_copy = sets->GetCert(hash, index); |
210 EXPECT_FALSE(gia_copy.empty()); | 208 EXPECT_FALSE(gia_copy.empty()); |
211 ASSERT_EQ(gia.size(), gia_copy.size()); | 209 ASSERT_EQ(gia.size(), gia_copy.size()); |
212 EXPECT_EQ(0, memcmp(gia.data(), gia_copy.data(), gia.size())); | 210 EXPECT_EQ(0, memcmp(gia.data(), gia_copy.data(), gia.size())); |
213 } | 211 } |
214 | 212 |
215 TEST(CommonCertSets, FindGIA_3) { | 213 TEST(CommonCertSets, FindGIA_3) { |
216 StringPiece gia(reinterpret_cast<const char*>(kGIACertificate3), | 214 QuicStringPiece gia(reinterpret_cast<const char*>(kGIACertificate3), |
217 sizeof(kGIACertificate3)); | 215 sizeof(kGIACertificate3)); |
218 | 216 |
219 const CommonCertSets* sets(CommonCertSets::GetInstanceQUIC()); | 217 const CommonCertSets* sets(CommonCertSets::GetInstanceQUIC()); |
220 // Common Cert Set 3's hash. | 218 // Common Cert Set 3's hash. |
221 const uint64_t in_hash = UINT64_C(0x918215a28680ed7e); | 219 const uint64_t in_hash = UINT64_C(0x918215a28680ed7e); |
222 uint64_t hash; | 220 uint64_t hash; |
223 uint32_t index; | 221 uint32_t index; |
224 ASSERT_TRUE(sets->MatchCert( | 222 ASSERT_TRUE(sets->MatchCert( |
225 gia, | 223 gia, |
226 StringPiece(reinterpret_cast<const char*>(&in_hash), sizeof(in_hash)), | 224 QuicStringPiece(reinterpret_cast<const char*>(&in_hash), sizeof(in_hash)), |
227 &hash, &index)); | 225 &hash, &index)); |
228 EXPECT_EQ(in_hash, hash); | 226 EXPECT_EQ(in_hash, hash); |
229 | 227 |
230 StringPiece gia_copy = sets->GetCert(hash, index); | 228 QuicStringPiece gia_copy = sets->GetCert(hash, index); |
231 EXPECT_FALSE(gia_copy.empty()); | 229 EXPECT_FALSE(gia_copy.empty()); |
232 ASSERT_EQ(gia.size(), gia_copy.size()); | 230 ASSERT_EQ(gia.size(), gia_copy.size()); |
233 EXPECT_EQ(0, memcmp(gia.data(), gia_copy.data(), gia.size())); | 231 EXPECT_EQ(0, memcmp(gia.data(), gia_copy.data(), gia.size())); |
234 } | 232 } |
235 | 233 |
236 TEST(CommonCertSets, NonMatch) { | 234 TEST(CommonCertSets, NonMatch) { |
237 const CommonCertSets* sets(CommonCertSets::GetInstanceQUIC()); | 235 const CommonCertSets* sets(CommonCertSets::GetInstanceQUIC()); |
238 StringPiece not_a_cert("hello"); | 236 QuicStringPiece not_a_cert("hello"); |
239 const uint64_t in_hash = UINT64_C(0xc9fef74053f99f39); | 237 const uint64_t in_hash = UINT64_C(0xc9fef74053f99f39); |
240 uint64_t hash; | 238 uint64_t hash; |
241 uint32_t index; | 239 uint32_t index; |
242 EXPECT_FALSE(sets->MatchCert( | 240 EXPECT_FALSE(sets->MatchCert( |
243 not_a_cert, | 241 not_a_cert, |
244 StringPiece(reinterpret_cast<const char*>(&in_hash), sizeof(in_hash)), | 242 QuicStringPiece(reinterpret_cast<const char*>(&in_hash), sizeof(in_hash)), |
245 &hash, &index)); | 243 &hash, &index)); |
246 } | 244 } |
247 | 245 |
248 } // namespace test | 246 } // namespace test |
249 } // namespace net | 247 } // namespace net |
OLD | NEW |