OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 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/quic_crypto_server_config.h" | 5 #include "net/quic/crypto/quic_crypto_server_config.h" |
6 | 6 |
7 #include <stdlib.h> | 7 #include <stdlib.h> |
8 #include <algorithm> | 8 #include <algorithm> |
9 | 9 |
10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
(...skipping 1084 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1095 out->set_tag(kREJ); | 1095 out->set_tag(kREJ); |
1096 out->SetStringPiece(kSCFG, config.serialized); | 1096 out->SetStringPiece(kSCFG, config.serialized); |
1097 out->SetStringPiece( | 1097 out->SetStringPiece( |
1098 kSourceAddressTokenTag, | 1098 kSourceAddressTokenTag, |
1099 NewSourceAddressToken(config, info.source_address_tokens, info.client_ip, | 1099 NewSourceAddressToken(config, info.source_address_tokens, info.client_ip, |
1100 rand, info.now, &cached_network_params)); | 1100 rand, info.now, &cached_network_params)); |
1101 if (replay_protection_) { | 1101 if (replay_protection_) { |
1102 out->SetStringPiece(kServerNonceTag, NewServerNonce(rand, info.now)); | 1102 out->SetStringPiece(kServerNonceTag, NewServerNonce(rand, info.now)); |
1103 } | 1103 } |
1104 | 1104 |
1105 if (FLAGS_send_quic_crypto_reject_reason) { | 1105 // Send client the reject reason for debugging purposes. |
1106 // Send client the reject reason for debugging purposes. | 1106 DCHECK_LT(0u, info.reject_reasons.size()); |
1107 DCHECK_LT(0u, info.reject_reasons.size()); | 1107 out->SetVector(kRREJ, info.reject_reasons); |
1108 out->SetVector(kRREJ, info.reject_reasons); | |
1109 } | |
1110 | 1108 |
1111 // The client may have requested a certificate chain. | 1109 // The client may have requested a certificate chain. |
1112 const QuicTag* their_proof_demands; | 1110 const QuicTag* their_proof_demands; |
1113 size_t num_their_proof_demands; | 1111 size_t num_their_proof_demands; |
1114 | 1112 |
1115 if (proof_source_.get() == nullptr || | 1113 if (proof_source_.get() == nullptr || |
1116 client_hello.GetTaglist(kPDMD, &their_proof_demands, | 1114 client_hello.GetTaglist(kPDMD, &their_proof_demands, |
1117 &num_their_proof_demands) != | 1115 &num_their_proof_demands) != |
1118 QUIC_NO_ERROR) { | 1116 QUIC_NO_ERROR) { |
1119 return; | 1117 return; |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1168 const size_t kREJOverheadBytes = 166; | 1166 const size_t kREJOverheadBytes = 166; |
1169 // kMultiplier is the multiple of the CHLO message size that a REJ message | 1167 // kMultiplier is the multiple of the CHLO message size that a REJ message |
1170 // must stay under when the client doesn't present a valid source-address | 1168 // must stay under when the client doesn't present a valid source-address |
1171 // token. | 1169 // token. |
1172 const size_t kMultiplier = 2; | 1170 const size_t kMultiplier = 2; |
1173 // max_unverified_size is the number of bytes that the certificate chain | 1171 // max_unverified_size is the number of bytes that the certificate chain |
1174 // and signature can consume before we will demand a valid source-address | 1172 // and signature can consume before we will demand a valid source-address |
1175 // token. | 1173 // token. |
1176 const size_t max_unverified_size = | 1174 const size_t max_unverified_size = |
1177 client_hello.size() * kMultiplier - kREJOverheadBytes; | 1175 client_hello.size() * kMultiplier - kREJOverheadBytes; |
1178 COMPILE_ASSERT(kClientHelloMinimumSize * kMultiplier >= kREJOverheadBytes, | 1176 static_assert(kClientHelloMinimumSize * kMultiplier >= kREJOverheadBytes, |
1179 overhead_calculation_may_underflow); | 1177 "overhead calculation may overflow"); |
1180 if (info.valid_source_address_token || | 1178 if (info.valid_source_address_token || |
1181 signature.size() + compressed.size() < max_unverified_size) { | 1179 signature.size() + compressed.size() < max_unverified_size) { |
1182 out->SetStringPiece(kCertificateTag, compressed); | 1180 out->SetStringPiece(kCertificateTag, compressed); |
1183 out->SetStringPiece(kPROF, signature); | 1181 out->SetStringPiece(kPROF, signature); |
1184 } | 1182 } |
1185 } | 1183 } |
1186 | 1184 |
1187 scoped_refptr<QuicCryptoServerConfig::Config> | 1185 scoped_refptr<QuicCryptoServerConfig::Config> |
1188 QuicCryptoServerConfig::ParseConfigProtobuf( | 1186 QuicCryptoServerConfig::ParseConfigProtobuf( |
1189 QuicServerConfigProtobuf* protobuf) { | 1187 QuicServerConfigProtobuf* protobuf) { |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1244 if (!msg->GetStringPiece(kORBT, &orbit)) { | 1242 if (!msg->GetStringPiece(kORBT, &orbit)) { |
1245 LOG(WARNING) << "Server config message is missing ORBT"; | 1243 LOG(WARNING) << "Server config message is missing ORBT"; |
1246 return nullptr; | 1244 return nullptr; |
1247 } | 1245 } |
1248 | 1246 |
1249 if (orbit.size() != kOrbitSize) { | 1247 if (orbit.size() != kOrbitSize) { |
1250 LOG(WARNING) << "Orbit value in server config is the wrong length." | 1248 LOG(WARNING) << "Orbit value in server config is the wrong length." |
1251 " Got " << orbit.size() << " want " << kOrbitSize; | 1249 " Got " << orbit.size() << " want " << kOrbitSize; |
1252 return nullptr; | 1250 return nullptr; |
1253 } | 1251 } |
1254 COMPILE_ASSERT(sizeof(config->orbit) == kOrbitSize, orbit_incorrect_size); | 1252 static_assert(sizeof(config->orbit) == kOrbitSize, |
| 1253 "orbit has incorrect size"); |
1255 memcpy(config->orbit, orbit.data(), sizeof(config->orbit)); | 1254 memcpy(config->orbit, orbit.data(), sizeof(config->orbit)); |
1256 | 1255 |
1257 { | 1256 { |
1258 StrikeRegisterClient* strike_register_client; | 1257 StrikeRegisterClient* strike_register_client; |
1259 { | 1258 { |
1260 base::AutoLock locked(strike_register_client_lock_); | 1259 base::AutoLock locked(strike_register_client_lock_); |
1261 strike_register_client = strike_register_client_.get(); | 1260 strike_register_client = strike_register_client_.get(); |
1262 } | 1261 } |
1263 | 1262 |
1264 if (strike_register_client != nullptr && | 1263 if (strike_register_client != nullptr && |
(...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1608 // kServerNoncePlaintextSize is the number of bytes in an unencrypted server | 1607 // kServerNoncePlaintextSize is the number of bytes in an unencrypted server |
1609 // nonce. | 1608 // nonce. |
1610 static const size_t kServerNoncePlaintextSize = | 1609 static const size_t kServerNoncePlaintextSize = |
1611 4 /* timestamp */ + 20 /* random bytes */; | 1610 4 /* timestamp */ + 20 /* random bytes */; |
1612 | 1611 |
1613 string QuicCryptoServerConfig::NewServerNonce(QuicRandom* rand, | 1612 string QuicCryptoServerConfig::NewServerNonce(QuicRandom* rand, |
1614 QuicWallTime now) const { | 1613 QuicWallTime now) const { |
1615 const uint32 timestamp = static_cast<uint32>(now.ToUNIXSeconds()); | 1614 const uint32 timestamp = static_cast<uint32>(now.ToUNIXSeconds()); |
1616 | 1615 |
1617 uint8 server_nonce[kServerNoncePlaintextSize]; | 1616 uint8 server_nonce[kServerNoncePlaintextSize]; |
1618 COMPILE_ASSERT(sizeof(server_nonce) > sizeof(timestamp), nonce_too_small); | 1617 static_assert(sizeof(server_nonce) > sizeof(timestamp), "nonce too small"); |
1619 server_nonce[0] = static_cast<uint8>(timestamp >> 24); | 1618 server_nonce[0] = static_cast<uint8>(timestamp >> 24); |
1620 server_nonce[1] = static_cast<uint8>(timestamp >> 16); | 1619 server_nonce[1] = static_cast<uint8>(timestamp >> 16); |
1621 server_nonce[2] = static_cast<uint8>(timestamp >> 8); | 1620 server_nonce[2] = static_cast<uint8>(timestamp >> 8); |
1622 server_nonce[3] = static_cast<uint8>(timestamp); | 1621 server_nonce[3] = static_cast<uint8>(timestamp); |
1623 rand->RandBytes(&server_nonce[sizeof(timestamp)], | 1622 rand->RandBytes(&server_nonce[sizeof(timestamp)], |
1624 sizeof(server_nonce) - sizeof(timestamp)); | 1623 sizeof(server_nonce) - sizeof(timestamp)); |
1625 | 1624 |
1626 return server_nonce_boxer_.Box( | 1625 return server_nonce_boxer_.Box( |
1627 rand, | 1626 rand, |
1628 StringPiece(reinterpret_cast<char*>(server_nonce), sizeof(server_nonce))); | 1627 StringPiece(reinterpret_cast<char*>(server_nonce), sizeof(server_nonce))); |
(...skipping 16 matching lines...) Expand all Loading... |
1645 // This should never happen because the value decrypted correctly. | 1644 // This should never happen because the value decrypted correctly. |
1646 LOG(DFATAL) << "Seemingly valid server nonce had incorrect length."; | 1645 LOG(DFATAL) << "Seemingly valid server nonce had incorrect length."; |
1647 return SERVER_NONCE_INVALID_FAILURE; | 1646 return SERVER_NONCE_INVALID_FAILURE; |
1648 } | 1647 } |
1649 | 1648 |
1650 uint8 server_nonce[32]; | 1649 uint8 server_nonce[32]; |
1651 memcpy(server_nonce, plaintext.data(), 4); | 1650 memcpy(server_nonce, plaintext.data(), 4); |
1652 memcpy(server_nonce + 4, server_nonce_orbit_, sizeof(server_nonce_orbit_)); | 1651 memcpy(server_nonce + 4, server_nonce_orbit_, sizeof(server_nonce_orbit_)); |
1653 memcpy(server_nonce + 4 + sizeof(server_nonce_orbit_), plaintext.data() + 4, | 1652 memcpy(server_nonce + 4 + sizeof(server_nonce_orbit_), plaintext.data() + 4, |
1654 20); | 1653 20); |
1655 COMPILE_ASSERT(4 + sizeof(server_nonce_orbit_) + 20 == sizeof(server_nonce), | 1654 static_assert(4 + sizeof(server_nonce_orbit_) + 20 == sizeof(server_nonce), |
1656 bad_nonce_buffer_length); | 1655 "bad nonce buffer length"); |
1657 | 1656 |
1658 InsertStatus nonce_error; | 1657 InsertStatus nonce_error; |
1659 { | 1658 { |
1660 base::AutoLock auto_lock(server_nonce_strike_register_lock_); | 1659 base::AutoLock auto_lock(server_nonce_strike_register_lock_); |
1661 if (server_nonce_strike_register_.get() == nullptr) { | 1660 if (server_nonce_strike_register_.get() == nullptr) { |
1662 server_nonce_strike_register_.reset(new StrikeRegister( | 1661 server_nonce_strike_register_.reset(new StrikeRegister( |
1663 server_nonce_strike_register_max_entries_, | 1662 server_nonce_strike_register_max_entries_, |
1664 static_cast<uint32>(now.ToUNIXSeconds()), | 1663 static_cast<uint32>(now.ToUNIXSeconds()), |
1665 server_nonce_strike_register_window_secs_, server_nonce_orbit_, | 1664 server_nonce_strike_register_window_secs_, server_nonce_orbit_, |
1666 StrikeRegister::NO_STARTUP_PERIOD_NEEDED)); | 1665 StrikeRegister::NO_STARTUP_PERIOD_NEEDED)); |
(...skipping 24 matching lines...) Expand all Loading... |
1691 QuicCryptoServerConfig::Config::Config() | 1690 QuicCryptoServerConfig::Config::Config() |
1692 : channel_id_enabled(false), | 1691 : channel_id_enabled(false), |
1693 is_primary(false), | 1692 is_primary(false), |
1694 primary_time(QuicWallTime::Zero()), | 1693 primary_time(QuicWallTime::Zero()), |
1695 priority(0), | 1694 priority(0), |
1696 source_address_token_boxer(nullptr) {} | 1695 source_address_token_boxer(nullptr) {} |
1697 | 1696 |
1698 QuicCryptoServerConfig::Config::~Config() { STLDeleteElements(&key_exchanges); } | 1697 QuicCryptoServerConfig::Config::~Config() { STLDeleteElements(&key_exchanges); } |
1699 | 1698 |
1700 } // namespace net | 1699 } // namespace net |
OLD | NEW |