OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/quic_server_info.h" | 5 #include "net/quic/crypto/quic_server_info.h" |
6 | 6 |
7 #include <limits> | 7 #include <limits> |
8 | 8 |
9 #include "base/pickle.h" | 9 #include "base/pickle.h" |
10 | 10 |
11 using std::string; | 11 using std::string; |
12 | 12 |
13 namespace { | 13 namespace { |
14 | 14 |
15 const int kQuicCryptoConfigVersion = 1; | 15 // TODO(rtenneti): Delete kQuicCryptoConfigVersionNoChloHash after |
| 16 // QUIC_VERSION_31 becomes the default. |
| 17 const int kQuicCryptoConfigVersionNoChloHash = 1; |
| 18 const int kQuicCryptoConfigVersion = 2; |
16 | 19 |
17 } // namespace | 20 } // namespace |
18 | 21 |
19 namespace net { | 22 namespace net { |
20 | 23 |
21 QuicServerInfo::State::State() {} | 24 QuicServerInfo::State::State() {} |
22 | 25 |
23 QuicServerInfo::State::~State() {} | 26 QuicServerInfo::State::~State() {} |
24 | 27 |
25 void QuicServerInfo::State::Clear() { | 28 void QuicServerInfo::State::Clear() { |
26 server_config.clear(); | 29 server_config.clear(); |
27 source_address_token.clear(); | 30 source_address_token.clear(); |
| 31 cert_sct.clear(); |
| 32 chlo_hash.clear(); |
28 server_config_sig.clear(); | 33 server_config_sig.clear(); |
29 certs.clear(); | 34 certs.clear(); |
30 } | 35 } |
31 | 36 |
32 QuicServerInfo::QuicServerInfo(const QuicServerId& server_id) | 37 QuicServerInfo::QuicServerInfo(const QuicServerId& server_id) |
33 : server_id_(server_id) {} | 38 : server_id_(server_id) {} |
34 | 39 |
35 QuicServerInfo::~QuicServerInfo() {} | 40 QuicServerInfo::~QuicServerInfo() {} |
36 | 41 |
37 const QuicServerInfo::State& QuicServerInfo::state() const { | 42 const QuicServerInfo::State& QuicServerInfo::state() const { |
(...skipping 25 matching lines...) Expand all Loading... |
63 | 68 |
64 base::Pickle p(data.data(), data.size()); | 69 base::Pickle p(data.data(), data.size()); |
65 base::PickleIterator iter(p); | 70 base::PickleIterator iter(p); |
66 | 71 |
67 int version = -1; | 72 int version = -1; |
68 if (!iter.ReadInt(&version)) { | 73 if (!iter.ReadInt(&version)) { |
69 DVLOG(1) << "Missing version"; | 74 DVLOG(1) << "Missing version"; |
70 return false; | 75 return false; |
71 } | 76 } |
72 | 77 |
73 if (version != kQuicCryptoConfigVersion) { | 78 // TODO(rtenneti): Delete kQuicCryptoConfigVersionNoChloHash after |
| 79 // QUIC_VERSION_31 becomes the default. |
| 80 if (!(version == kQuicCryptoConfigVersionNoChloHash || |
| 81 version == kQuicCryptoConfigVersion)) { |
74 DVLOG(1) << "Unsupported version"; | 82 DVLOG(1) << "Unsupported version"; |
75 return false; | 83 return false; |
76 } | 84 } |
77 | 85 |
78 if (!iter.ReadString(&state->server_config)) { | 86 if (!iter.ReadString(&state->server_config)) { |
79 DVLOG(1) << "Malformed server_config"; | 87 DVLOG(1) << "Malformed server_config"; |
80 return false; | 88 return false; |
81 } | 89 } |
82 if (!iter.ReadString(&state->source_address_token)) { | 90 if (!iter.ReadString(&state->source_address_token)) { |
83 DVLOG(1) << "Malformed source_address_token"; | 91 DVLOG(1) << "Malformed source_address_token"; |
84 return false; | 92 return false; |
85 } | 93 } |
| 94 // TODO(rtenneti): Delete kQuicCryptoConfigVersionNoChloHash after |
| 95 // QUIC_VERSION_31 becomes the default. |
| 96 if (version == kQuicCryptoConfigVersionNoChloHash) { |
| 97 state->cert_sct.clear(); |
| 98 state->chlo_hash.clear(); |
| 99 } else { |
| 100 if (!iter.ReadString(&state->cert_sct)) { |
| 101 DVLOG(1) << "Malformed cert_sct"; |
| 102 return false; |
| 103 } |
| 104 if (!iter.ReadString(&state->chlo_hash)) { |
| 105 DVLOG(1) << "Malformed chlo_hash"; |
| 106 return false; |
| 107 } |
| 108 } |
86 if (!iter.ReadString(&state->server_config_sig)) { | 109 if (!iter.ReadString(&state->server_config_sig)) { |
87 DVLOG(1) << "Malformed server_config_sig"; | 110 DVLOG(1) << "Malformed server_config_sig"; |
88 return false; | 111 return false; |
89 } | 112 } |
90 | 113 |
91 // Read certs. | 114 // Read certs. |
92 uint32_t num_certs; | 115 uint32_t num_certs; |
93 if (!iter.ReadUInt32(&num_certs)) { | 116 if (!iter.ReadUInt32(&num_certs)) { |
94 DVLOG(1) << "Malformed num_certs"; | 117 DVLOG(1) << "Malformed num_certs"; |
95 return false; | 118 return false; |
(...skipping 16 matching lines...) Expand all Loading... |
112 state_.Clear(); | 135 state_.Clear(); |
113 return pickled_data; | 136 return pickled_data; |
114 } | 137 } |
115 | 138 |
116 string QuicServerInfo::SerializeInner() const { | 139 string QuicServerInfo::SerializeInner() const { |
117 base::Pickle p(sizeof(base::Pickle::Header)); | 140 base::Pickle p(sizeof(base::Pickle::Header)); |
118 | 141 |
119 if (!p.WriteInt(kQuicCryptoConfigVersion) || | 142 if (!p.WriteInt(kQuicCryptoConfigVersion) || |
120 !p.WriteString(state_.server_config) || | 143 !p.WriteString(state_.server_config) || |
121 !p.WriteString(state_.source_address_token) || | 144 !p.WriteString(state_.source_address_token) || |
| 145 !p.WriteString(state_.cert_sct) || !p.WriteString(state_.chlo_hash) || |
122 !p.WriteString(state_.server_config_sig) || | 146 !p.WriteString(state_.server_config_sig) || |
123 state_.certs.size() > std::numeric_limits<uint32_t>::max() || | 147 state_.certs.size() > std::numeric_limits<uint32_t>::max() || |
124 !p.WriteUInt32(state_.certs.size())) { | 148 !p.WriteUInt32(state_.certs.size())) { |
125 return string(); | 149 return string(); |
126 } | 150 } |
127 | 151 |
128 for (size_t i = 0; i < state_.certs.size(); i++) { | 152 for (size_t i = 0; i < state_.certs.size(); i++) { |
129 if (!p.WriteString(state_.certs[i])) { | 153 if (!p.WriteString(state_.certs[i])) { |
130 return string(); | 154 return string(); |
131 } | 155 } |
132 } | 156 } |
133 | 157 |
134 return string(reinterpret_cast<const char*>(p.data()), p.size()); | 158 return string(reinterpret_cast<const char*>(p.data()), p.size()); |
135 } | 159 } |
136 | 160 |
137 QuicServerInfoFactory::~QuicServerInfoFactory() {} | 161 QuicServerInfoFactory::~QuicServerInfoFactory() {} |
138 | 162 |
139 } // namespace net | 163 } // namespace net |
OLD | NEW |