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/crypto_utils.h" | 5 #include "net/quic/crypto/crypto_utils.h" |
6 | 6 |
7 #include "crypto/hkdf.h" | 7 #include "crypto/hkdf.h" |
8 #include "net/base/net_util.h" | 8 #include "net/base/net_util.h" |
9 #include "net/quic/crypto/crypto_handshake.h" | 9 #include "net/quic/crypto/crypto_handshake.h" |
10 #include "net/quic/crypto/crypto_protocol.h" | 10 #include "net/quic/crypto/crypto_protocol.h" |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 0 /* no subkey secret */); | 158 0 /* no subkey secret */); |
159 hkdf.client_write_key().CopyToString(result); | 159 hkdf.client_write_key().CopyToString(result); |
160 return true; | 160 return true; |
161 } | 161 } |
162 | 162 |
163 // static | 163 // static |
164 uint64 CryptoUtils::ComputeLeafCertHash(const std::string& cert) { | 164 uint64 CryptoUtils::ComputeLeafCertHash(const std::string& cert) { |
165 return QuicUtils::FNV1a_64_Hash(cert.data(), cert.size()); | 165 return QuicUtils::FNV1a_64_Hash(cert.data(), cert.size()); |
166 } | 166 } |
167 | 167 |
| 168 QuicErrorCode CryptoUtils::ValidateServerHello( |
| 169 const CryptoHandshakeMessage& server_hello, |
| 170 const QuicVersionVector& negotiated_versions, |
| 171 string* error_details) { |
| 172 DCHECK(error_details != nullptr); |
| 173 |
| 174 if (server_hello.tag() != kSHLO) { |
| 175 *error_details = "Bad tag"; |
| 176 return QUIC_INVALID_CRYPTO_MESSAGE_TYPE; |
| 177 } |
| 178 |
| 179 const QuicTag* supported_version_tags; |
| 180 size_t num_supported_versions; |
| 181 |
| 182 if (server_hello.GetTaglist(kVER, &supported_version_tags, |
| 183 &num_supported_versions) != QUIC_NO_ERROR) { |
| 184 *error_details = "server hello missing version list"; |
| 185 return QUIC_INVALID_CRYPTO_MESSAGE_PARAMETER; |
| 186 } |
| 187 if (!negotiated_versions.empty()) { |
| 188 bool mismatch = num_supported_versions != negotiated_versions.size(); |
| 189 for (size_t i = 0; i < num_supported_versions && !mismatch; ++i) { |
| 190 mismatch = QuicTagToQuicVersion(supported_version_tags[i]) != |
| 191 negotiated_versions[i]; |
| 192 } |
| 193 // The server sent a list of supported versions, and the connection |
| 194 // reports that there was a version negotiation during the handshake. |
| 195 // Ensure that these two lists are identical. |
| 196 if (mismatch) { |
| 197 *error_details = "Downgrade attack detected"; |
| 198 return QUIC_VERSION_NEGOTIATION_MISMATCH; |
| 199 } |
| 200 } |
| 201 return QUIC_NO_ERROR; |
| 202 } |
| 203 |
168 } // namespace net | 204 } // namespace net |
OLD | NEW |