| 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 "base/basictypes.h" | |
| 8 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/macros.h" |
| 9 #include "base/memory/singleton.h" | 9 #include "base/memory/singleton.h" |
| 10 #include "net/quic/quic_utils.h" | 10 #include "net/quic/quic_utils.h" |
| 11 | 11 |
| 12 using base::StringPiece; | 12 using base::StringPiece; |
| 13 | 13 |
| 14 namespace net { | 14 namespace net { |
| 15 | 15 |
| 16 namespace common_cert_set_1 { | 16 namespace common_cert_set_1 { |
| 17 #include "net/quic/crypto/common_cert_set_1.c" | 17 #include "net/quic/crypto/common_cert_set_1.c" |
| 18 } | 18 } |
| 19 | 19 |
| 20 namespace common_cert_set_2 { | 20 namespace common_cert_set_2 { |
| 21 #include "net/quic/crypto/common_cert_set_2.c" | 21 #include "net/quic/crypto/common_cert_set_2.c" |
| 22 } | 22 } |
| 23 | 23 |
| 24 namespace { | 24 namespace { |
| 25 | 25 |
| 26 struct CertSet { | 26 struct CertSet { |
| 27 // num_certs contains the number of certificates in this set. | 27 // num_certs contains the number of certificates in this set. |
| 28 size_t num_certs; | 28 size_t num_certs; |
| 29 // certs is an array of |num_certs| pointers to the DER encoded certificates. | 29 // certs is an array of |num_certs| pointers to the DER encoded certificates. |
| 30 const unsigned char* const* certs; | 30 const unsigned char* const* certs; |
| 31 // lens is an array of |num_certs| integers describing the length, in bytes, | 31 // lens is an array of |num_certs| integers describing the length, in bytes, |
| 32 // of each certificate. | 32 // of each certificate. |
| 33 const size_t* lens; | 33 const size_t* lens; |
| 34 // hash contains the 64-bit, FNV-1a hash of this set. | 34 // hash contains the 64-bit, FNV-1a hash of this set. |
| 35 uint64 hash; | 35 uint64_t hash; |
| 36 }; | 36 }; |
| 37 | 37 |
| 38 const CertSet kSets[] = { | 38 const CertSet kSets[] = { |
| 39 { | 39 { |
| 40 common_cert_set_1::kNumCerts, common_cert_set_1::kCerts, | 40 common_cert_set_1::kNumCerts, common_cert_set_1::kCerts, |
| 41 common_cert_set_1::kLens, common_cert_set_1::kHash, | 41 common_cert_set_1::kLens, common_cert_set_1::kHash, |
| 42 }, | 42 }, |
| 43 { | 43 { |
| 44 common_cert_set_2::kNumCerts, common_cert_set_2::kCerts, | 44 common_cert_set_2::kNumCerts, common_cert_set_2::kCerts, |
| 45 common_cert_set_2::kLens, common_cert_set_2::kHash, | 45 common_cert_set_2::kLens, common_cert_set_2::kHash, |
| 46 }, | 46 }, |
| 47 }; | 47 }; |
| 48 | 48 |
| 49 const uint64 kSetHashes[] = { | 49 const uint64_t kSetHashes[] = { |
| 50 common_cert_set_1::kHash, common_cert_set_2::kHash, | 50 common_cert_set_1::kHash, common_cert_set_2::kHash, |
| 51 }; | 51 }; |
| 52 | 52 |
| 53 // Compare returns a value less than, equal to or greater than zero if |a| is | 53 // Compare returns a value less than, equal to or greater than zero if |a| is |
| 54 // lexicographically less than, equal to or greater than |b|, respectively. | 54 // lexicographically less than, equal to or greater than |b|, respectively. |
| 55 int Compare(StringPiece a, const unsigned char* b, size_t b_len) { | 55 int Compare(StringPiece a, const unsigned char* b, size_t b_len) { |
| 56 size_t len = a.size(); | 56 size_t len = a.size(); |
| 57 if (len > b_len) { | 57 if (len > b_len) { |
| 58 len = b_len; | 58 len = b_len; |
| 59 } | 59 } |
| (...skipping 10 matching lines...) Expand all Loading... |
| 70 return 0; | 70 return 0; |
| 71 } | 71 } |
| 72 | 72 |
| 73 // CommonCertSetsQUIC implements the CommonCertSets interface using the default | 73 // CommonCertSetsQUIC implements the CommonCertSets interface using the default |
| 74 // certificate sets. | 74 // certificate sets. |
| 75 class CommonCertSetsQUIC : public CommonCertSets { | 75 class CommonCertSetsQUIC : public CommonCertSets { |
| 76 public: | 76 public: |
| 77 // CommonCertSets interface. | 77 // CommonCertSets interface. |
| 78 StringPiece GetCommonHashes() const override { | 78 StringPiece GetCommonHashes() const override { |
| 79 return StringPiece(reinterpret_cast<const char*>(kSetHashes), | 79 return StringPiece(reinterpret_cast<const char*>(kSetHashes), |
| 80 sizeof(uint64) * arraysize(kSetHashes)); | 80 sizeof(uint64_t) * arraysize(kSetHashes)); |
| 81 } | 81 } |
| 82 | 82 |
| 83 StringPiece GetCert(uint64 hash, uint32 index) const override { | 83 StringPiece GetCert(uint64_t hash, uint32_t index) const override { |
| 84 for (size_t i = 0; i < arraysize(kSets); i++) { | 84 for (size_t i = 0; i < arraysize(kSets); i++) { |
| 85 if (kSets[i].hash == hash) { | 85 if (kSets[i].hash == hash) { |
| 86 if (index < kSets[i].num_certs) { | 86 if (index < kSets[i].num_certs) { |
| 87 return StringPiece( | 87 return StringPiece( |
| 88 reinterpret_cast<const char*>(kSets[i].certs[index]), | 88 reinterpret_cast<const char*>(kSets[i].certs[index]), |
| 89 kSets[i].lens[index]); | 89 kSets[i].lens[index]); |
| 90 } | 90 } |
| 91 break; | 91 break; |
| 92 } | 92 } |
| 93 } | 93 } |
| 94 | 94 |
| 95 return StringPiece(); | 95 return StringPiece(); |
| 96 } | 96 } |
| 97 | 97 |
| 98 bool MatchCert(StringPiece cert, | 98 bool MatchCert(StringPiece cert, |
| 99 StringPiece common_set_hashes, | 99 StringPiece common_set_hashes, |
| 100 uint64* out_hash, | 100 uint64_t* out_hash, |
| 101 uint32* out_index) const override { | 101 uint32_t* out_index) const override { |
| 102 if (common_set_hashes.size() % sizeof(uint64) != 0) { | 102 if (common_set_hashes.size() % sizeof(uint64_t) != 0) { |
| 103 return false; | 103 return false; |
| 104 } | 104 } |
| 105 | 105 |
| 106 for (size_t i = 0; i < common_set_hashes.size() / sizeof(uint64); i++) { | 106 for (size_t i = 0; i < common_set_hashes.size() / sizeof(uint64_t); i++) { |
| 107 uint64 hash; | 107 uint64_t hash; |
| 108 memcpy(&hash, common_set_hashes.data() + i * sizeof(uint64), | 108 memcpy(&hash, common_set_hashes.data() + i * sizeof(uint64_t), |
| 109 sizeof(uint64)); | 109 sizeof(uint64_t)); |
| 110 | 110 |
| 111 for (size_t j = 0; j < arraysize(kSets); j++) { | 111 for (size_t j = 0; j < arraysize(kSets); j++) { |
| 112 if (kSets[j].hash != hash) { | 112 if (kSets[j].hash != hash) { |
| 113 continue; | 113 continue; |
| 114 } | 114 } |
| 115 | 115 |
| 116 if (kSets[j].num_certs == 0) { | 116 if (kSets[j].num_certs == 0) { |
| 117 continue; | 117 continue; |
| 118 } | 118 } |
| 119 | 119 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 157 } // anonymous namespace | 157 } // anonymous namespace |
| 158 | 158 |
| 159 CommonCertSets::~CommonCertSets() {} | 159 CommonCertSets::~CommonCertSets() {} |
| 160 | 160 |
| 161 // static | 161 // static |
| 162 const CommonCertSets* CommonCertSets::GetInstanceQUIC() { | 162 const CommonCertSets* CommonCertSets::GetInstanceQUIC() { |
| 163 return CommonCertSetsQUIC::GetInstance(); | 163 return CommonCertSetsQUIC::GetInstance(); |
| 164 } | 164 } |
| 165 | 165 |
| 166 } // namespace net | 166 } // namespace net |
| OLD | NEW |