| 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" | 7 #include "base/basictypes.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.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" |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 // certs is an array of |num_certs| pointers to the DER encoded certificates. | 25 // certs is an array of |num_certs| pointers to the DER encoded certificates. |
| 26 const unsigned char* const* certs; | 26 const unsigned char* const* certs; |
| 27 // lens is an array of |num_certs| integers describing the length, in bytes, | 27 // lens is an array of |num_certs| integers describing the length, in bytes, |
| 28 // of each certificate. | 28 // of each certificate. |
| 29 const size_t* lens; | 29 const size_t* lens; |
| 30 // hash contains the 64-bit, FNV-1a hash of this set. | 30 // hash contains the 64-bit, FNV-1a hash of this set. |
| 31 uint64 hash; | 31 uint64 hash; |
| 32 }; | 32 }; |
| 33 | 33 |
| 34 const CertSet kSets[] = { | 34 const CertSet kSets[] = { |
| 35 { | 35 { |
| 36 common_cert_set_0::kNumCerts, | 36 common_cert_set_0::kNumCerts, common_cert_set_0::kCerts, |
| 37 common_cert_set_0::kCerts, | 37 common_cert_set_0::kLens, common_cert_set_0::kHash, |
| 38 common_cert_set_0::kLens, | 38 }, |
| 39 common_cert_set_0::kHash, | |
| 40 }, | |
| 41 }; | 39 }; |
| 42 | 40 |
| 43 const uint64 kSetHashes[] = { | 41 const uint64 kSetHashes[] = { |
| 44 common_cert_set_0::kHash, | 42 common_cert_set_0::kHash, |
| 45 }; | 43 }; |
| 46 | 44 |
| 47 // Compare returns a value less than, equal to or greater than zero if |a| is | 45 // Compare returns a value less than, equal to or greater than zero if |a| is |
| 48 // lexicographically less than, equal to or greater than |b|, respectively. | 46 // lexicographically less than, equal to or greater than |b|, respectively. |
| 49 int Compare(StringPiece a, const unsigned char* b, size_t b_len) { | 47 int Compare(StringPiece a, const unsigned char* b, size_t b_len) { |
| 50 size_t len = a.size(); | 48 size_t len = a.size(); |
| 51 if (len > b_len) { | 49 if (len > b_len) { |
| 52 len = b_len; | 50 len = b_len; |
| 53 } | 51 } |
| 54 int n = memcmp(a.data(), b, len); | 52 int n = memcmp(a.data(), b, len); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 82 reinterpret_cast<const char*>(kSets[i].certs[index]), | 80 reinterpret_cast<const char*>(kSets[i].certs[index]), |
| 83 kSets[i].lens[index]); | 81 kSets[i].lens[index]); |
| 84 } | 82 } |
| 85 break; | 83 break; |
| 86 } | 84 } |
| 87 } | 85 } |
| 88 | 86 |
| 89 return StringPiece(); | 87 return StringPiece(); |
| 90 } | 88 } |
| 91 | 89 |
| 92 virtual bool MatchCert(StringPiece cert, StringPiece common_set_hashes, | 90 virtual bool MatchCert(StringPiece cert, |
| 93 uint64* out_hash, uint32* out_index) const OVERRIDE { | 91 StringPiece common_set_hashes, |
| 92 uint64* out_hash, |
| 93 uint32* out_index) const OVERRIDE { |
| 94 if (common_set_hashes.size() % sizeof(uint64) != 0) { | 94 if (common_set_hashes.size() % sizeof(uint64) != 0) { |
| 95 return false; | 95 return false; |
| 96 } | 96 } |
| 97 | 97 |
| 98 for (size_t i = 0; i < common_set_hashes.size() / sizeof(uint64); i++) { | 98 for (size_t i = 0; i < common_set_hashes.size() / sizeof(uint64); i++) { |
| 99 uint64 hash; | 99 uint64 hash; |
| 100 memcpy(&hash, common_set_hashes.data() + i * sizeof(uint64), | 100 memcpy( |
| 101 sizeof(uint64)); | 101 &hash, common_set_hashes.data() + i * sizeof(uint64), sizeof(uint64)); |
| 102 | 102 |
| 103 for (size_t j = 0; j < arraysize(kSets); j++) { | 103 for (size_t j = 0; j < arraysize(kSets); j++) { |
| 104 if (kSets[j].hash != hash) { | 104 if (kSets[j].hash != hash) { |
| 105 continue; | 105 continue; |
| 106 } | 106 } |
| 107 | 107 |
| 108 if (kSets[j].num_certs == 0) { | 108 if (kSets[j].num_certs == 0) { |
| 109 continue; | 109 continue; |
| 110 } | 110 } |
| 111 | 111 |
| (...skipping 29 matching lines...) Expand all Loading... |
| 141 private: | 141 private: |
| 142 CommonCertSetsQUIC() {} | 142 CommonCertSetsQUIC() {} |
| 143 virtual ~CommonCertSetsQUIC() {} | 143 virtual ~CommonCertSetsQUIC() {} |
| 144 | 144 |
| 145 friend struct DefaultSingletonTraits<CommonCertSetsQUIC>; | 145 friend struct DefaultSingletonTraits<CommonCertSetsQUIC>; |
| 146 DISALLOW_COPY_AND_ASSIGN(CommonCertSetsQUIC); | 146 DISALLOW_COPY_AND_ASSIGN(CommonCertSetsQUIC); |
| 147 }; | 147 }; |
| 148 | 148 |
| 149 } // anonymous namespace | 149 } // anonymous namespace |
| 150 | 150 |
| 151 CommonCertSets::~CommonCertSets() {} | 151 CommonCertSets::~CommonCertSets() { |
| 152 } |
| 152 | 153 |
| 153 // static | 154 // static |
| 154 const CommonCertSets* CommonCertSets::GetInstanceQUIC() { | 155 const CommonCertSets* CommonCertSets::GetInstanceQUIC() { |
| 155 return CommonCertSetsQUIC::GetInstance(); | 156 return CommonCertSetsQUIC::GetInstance(); |
| 156 } | 157 } |
| 157 | 158 |
| 158 } // namespace net | 159 } // namespace net |
| OLD | NEW |