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 15 matching lines...) Expand all Loading... | |
26 #include "net/quic/crypto/local_strike_register_client.h" | 26 #include "net/quic/crypto/local_strike_register_client.h" |
27 #include "net/quic/crypto/p256_key_exchange.h" | 27 #include "net/quic/crypto/p256_key_exchange.h" |
28 #include "net/quic/crypto/proof_source.h" | 28 #include "net/quic/crypto/proof_source.h" |
29 #include "net/quic/crypto/quic_decrypter.h" | 29 #include "net/quic/crypto/quic_decrypter.h" |
30 #include "net/quic/crypto/quic_encrypter.h" | 30 #include "net/quic/crypto/quic_encrypter.h" |
31 #include "net/quic/crypto/quic_random.h" | 31 #include "net/quic/crypto/quic_random.h" |
32 #include "net/quic/crypto/source_address_token.h" | 32 #include "net/quic/crypto/source_address_token.h" |
33 #include "net/quic/crypto/strike_register.h" | 33 #include "net/quic/crypto/strike_register.h" |
34 #include "net/quic/crypto/strike_register_client.h" | 34 #include "net/quic/crypto/strike_register_client.h" |
35 #include "net/quic/quic_clock.h" | 35 #include "net/quic/quic_clock.h" |
36 #include "net/quic/quic_flags.h" | |
36 #include "net/quic/quic_protocol.h" | 37 #include "net/quic/quic_protocol.h" |
37 #include "net/quic/quic_socket_address_coder.h" | 38 #include "net/quic/quic_socket_address_coder.h" |
38 #include "net/quic/quic_utils.h" | 39 #include "net/quic/quic_utils.h" |
39 | 40 |
40 using base::StringPiece; | 41 using base::StringPiece; |
41 using crypto::SecureHash; | 42 using crypto::SecureHash; |
42 using std::map; | 43 using std::map; |
43 using std::sort; | 44 using std::sort; |
44 using std::string; | 45 using std::string; |
45 using std::vector; | 46 using std::vector; |
(...skipping 28 matching lines...) Expand all Loading... | |
74 const QuicWallTime now; | 75 const QuicWallTime now; |
75 | 76 |
76 // Outputs from EvaluateClientHello. | 77 // Outputs from EvaluateClientHello. |
77 bool valid_source_address_token; | 78 bool valid_source_address_token; |
78 bool client_nonce_well_formed; | 79 bool client_nonce_well_formed; |
79 bool unique; | 80 bool unique; |
80 StringPiece sni; | 81 StringPiece sni; |
81 StringPiece client_nonce; | 82 StringPiece client_nonce; |
82 StringPiece server_nonce; | 83 StringPiece server_nonce; |
83 StringPiece user_agent_id; | 84 StringPiece user_agent_id; |
85 | |
86 // Errors from EvaluateClientHello. | |
87 vector<HandshakeFailureReason> reject_reasons; | |
wtc
2014/06/19 00:13:24
Since reject_reasons is passed to SetVector(), we
ramant (doing other things)
2014/06/19 01:57:35
Done.
avd
2014/06/19 02:27:54
QuicTag has a very specific meaning, and this is n
ramant (doing other things)
2014/06/19 17:25:48
Changed it vector<uint32> and added static_cast<ui
| |
84 }; | 88 }; |
85 | 89 |
86 struct ValidateClientHelloResultCallback::Result { | 90 struct ValidateClientHelloResultCallback::Result { |
87 Result(const CryptoHandshakeMessage& in_client_hello, | 91 Result(const CryptoHandshakeMessage& in_client_hello, |
88 IPEndPoint in_client_ip, | 92 IPEndPoint in_client_ip, |
89 QuicWallTime in_now) | 93 QuicWallTime in_now) |
90 : client_hello(in_client_hello), | 94 : client_hello(in_client_hello), |
91 info(in_client_ip, in_now), | 95 info(in_client_ip, in_now), |
92 error_code(QUIC_NO_ERROR) { | 96 error_code(QUIC_NO_ERROR) { |
93 } | 97 } |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
139 VerifyNonceIsValidAndUniqueCallback( | 143 VerifyNonceIsValidAndUniqueCallback( |
140 ValidateClientHelloResultCallback::Result* result, | 144 ValidateClientHelloResultCallback::Result* result, |
141 ValidateClientHelloResultCallback* done_cb) | 145 ValidateClientHelloResultCallback* done_cb) |
142 : result_(result), done_cb_(done_cb) { | 146 : result_(result), done_cb_(done_cb) { |
143 } | 147 } |
144 | 148 |
145 protected: | 149 protected: |
146 virtual void RunImpl(bool nonce_is_valid_and_unique) OVERRIDE { | 150 virtual void RunImpl(bool nonce_is_valid_and_unique) OVERRIDE { |
147 DVLOG(1) << "Using client nonce, unique: " << nonce_is_valid_and_unique; | 151 DVLOG(1) << "Using client nonce, unique: " << nonce_is_valid_and_unique; |
148 result_->info.unique = nonce_is_valid_and_unique; | 152 result_->info.unique = nonce_is_valid_and_unique; |
153 // TODO(rtenneti): Implement capturing of error from strike register. | |
154 // Temporarily treat them as CLIENT_NONCE_UNKNOWN_FAILURE. | |
155 if (!nonce_is_valid_and_unique) { | |
156 result_->info.reject_reasons.push_back(CLIENT_NONCE_UNKNOWN_FAILURE); | |
157 } | |
149 done_cb_->Run(result_); | 158 done_cb_->Run(result_); |
150 } | 159 } |
151 | 160 |
152 private: | 161 private: |
153 ValidateClientHelloResultCallback::Result* result_; | 162 ValidateClientHelloResultCallback::Result* result_; |
154 ValidateClientHelloResultCallback* done_cb_; | 163 ValidateClientHelloResultCallback* done_cb_; |
155 | 164 |
156 DISALLOW_COPY_AND_ASSIGN(VerifyNonceIsValidAndUniqueCallback); | 165 DISALLOW_COPY_AND_ASSIGN(VerifyNonceIsValidAndUniqueCallback); |
157 }; | 166 }; |
158 | 167 |
(...skipping 722 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
881 | 890 |
882 if (client_hello.GetStringPiece(kSNI, &info->sni) && | 891 if (client_hello.GetStringPiece(kSNI, &info->sni) && |
883 !CryptoUtils::IsValidSNI(info->sni)) { | 892 !CryptoUtils::IsValidSNI(info->sni)) { |
884 helper.ValidationComplete(QUIC_INVALID_CRYPTO_MESSAGE_PARAMETER, | 893 helper.ValidationComplete(QUIC_INVALID_CRYPTO_MESSAGE_PARAMETER, |
885 "Invalid SNI name"); | 894 "Invalid SNI name"); |
886 return; | 895 return; |
887 } | 896 } |
888 | 897 |
889 client_hello.GetStringPiece(kUAID, &info->user_agent_id); | 898 client_hello.GetStringPiece(kUAID, &info->user_agent_id); |
890 | 899 |
891 StringPiece srct; | 900 if (!requested_config.get()) { |
892 if (requested_config.get() != NULL && | 901 StringPiece requested_scid; |
893 client_hello.GetStringPiece(kSourceAddressTokenTag, &srct) && | 902 client_hello.GetStringPiece(kSCID, &requested_scid); |
894 ValidateSourceAddressToken(*requested_config, | 903 if (requested_scid.empty()) { |
895 srct, | 904 info->reject_reasons.push_back(SERVER_CONFIG_INCHOATE_HELLO_FAILURE); |
896 info->client_ip, | 905 } else { |
897 info->now)) { | 906 info->reject_reasons.push_back(SERVER_CONFIG_UNKNOWN_CONFIG_FAILURE); |
898 info->valid_source_address_token = true; | 907 } |
wtc
2014/06/19 00:13:24
Nit: require lines 902-907 as follows:
if (clie
ramant (doing other things)
2014/06/19 01:57:34
Done.
| |
899 } else { | 908 // No server config with the requested ID. |
wtc
2014/06/19 00:13:24
It is possible to keep going in this case, althoug
ramant (doing other things)
2014/06/19 01:57:34
avd suggested we do an early return. Will submit a
| |
900 // No server config with the requested ID, or no valid source address token. | |
901 helper.ValidationComplete(QUIC_NO_ERROR, ""); | 909 helper.ValidationComplete(QUIC_NO_ERROR, ""); |
902 return; | 910 return; |
903 } | 911 } |
904 | 912 |
913 HandshakeFailureReason source_address_token_error; | |
914 StringPiece srct; | |
915 DCHECK(requested_config.get()); | |
wtc
2014/06/19 00:13:24
This DCHECK's condition is ensured by the test on
ramant (doing other things)
2014/06/19 01:57:35
Done.
| |
916 if (client_hello.GetStringPiece(kSourceAddressTokenTag, &srct)) { | |
917 source_address_token_error = | |
918 ValidateSourceAddressToken(*requested_config, | |
919 srct, | |
920 info->client_ip, | |
921 info->now); | |
922 info->valid_source_address_token = | |
923 (source_address_token_error == HANDSHAKE_OK); | |
924 } else { | |
925 source_address_token_error = SOURCE_ADDRESS_TOKEN_INVALID_FAILURE; | |
926 } | |
927 | |
928 bool found_error = false; | |
929 if (source_address_token_error != HANDSHAKE_OK) { | |
930 info->reject_reasons.push_back(source_address_token_error); | |
931 // No valid source address token. | |
932 if (FLAGS_use_early_return_when_verifying_chlo) { | |
933 helper.ValidationComplete(QUIC_NO_ERROR, ""); | |
934 return; | |
935 } | |
936 found_error = true; | |
937 } | |
938 | |
905 if (client_hello.GetStringPiece(kNONC, &info->client_nonce) && | 939 if (client_hello.GetStringPiece(kNONC, &info->client_nonce) && |
906 info->client_nonce.size() == kNonceSize) { | 940 info->client_nonce.size() == kNonceSize) { |
907 info->client_nonce_well_formed = true; | 941 info->client_nonce_well_formed = true; |
908 } else { | 942 } else { |
943 info->reject_reasons.push_back(CLIENT_NONCE_INVALID_FAILURE); | |
909 // Invalid client nonce. | 944 // Invalid client nonce. |
910 DVLOG(1) << "Invalid client nonce."; | 945 DVLOG(1) << "Invalid client nonce."; |
911 helper.ValidationComplete(QUIC_NO_ERROR, ""); | 946 if (FLAGS_use_early_return_when_verifying_chlo) { |
912 return; | 947 helper.ValidationComplete(QUIC_NO_ERROR, ""); |
948 return; | |
949 } | |
950 found_error = true; | |
913 } | 951 } |
914 | 952 |
915 if (!replay_protection_) { | 953 if (!replay_protection_) { |
916 info->unique = true; | 954 info->unique = true; |
wtc
2014/06/19 00:13:24
IMPORTANT: change this line to:
if (!found_erro
ramant (doing other things)
2014/06/19 01:57:34
Thanks for catching this.
Done.
avd
2014/06/19 02:27:53
In practice it doesn't matter since other failure
ramant (doing other things)
2014/06/19 17:25:48
Acknowledged.
| |
917 DVLOG(1) << "No replay protection."; | 955 DVLOG(1) << "No replay protection."; |
918 helper.ValidationComplete(QUIC_NO_ERROR, ""); | 956 helper.ValidationComplete(QUIC_NO_ERROR, ""); |
919 return; | 957 return; |
920 } | 958 } |
921 | 959 |
922 client_hello.GetStringPiece(kServerNonceTag, &info->server_nonce); | 960 client_hello.GetStringPiece(kServerNonceTag, &info->server_nonce); |
923 if (!info->server_nonce.empty()) { | 961 if (!info->server_nonce.empty()) { |
924 // If the server nonce is present, use it to establish uniqueness. | 962 // If the server nonce is present, use it to establish uniqueness. |
925 info->unique = ValidateServerNonce(info->server_nonce, info->now); | 963 HandshakeFailureReason server_nonce_error = |
964 ValidateServerNonce(info->server_nonce, info->now); | |
965 if (server_nonce_error == HANDSHAKE_OK) { | |
966 info->unique = true; | |
967 } else { | |
968 info->reject_reasons.push_back(server_nonce_error); | |
969 info->unique = false; | |
970 } | |
926 DVLOG(1) << "Using server nonce, unique: " << info->unique; | 971 DVLOG(1) << "Using server nonce, unique: " << info->unique; |
972 if (FLAGS_use_early_return_when_verifying_chlo) { | |
973 helper.ValidationComplete(QUIC_NO_ERROR, ""); | |
974 return; | |
975 } | |
976 found_error = true; | |
wtc
2014/06/19 00:13:24
IMPORTANT: replace lines 972-976 with:
helper
ramant (doing other things)
2014/06/19 01:57:34
Done.
| |
977 } | |
978 | |
979 if (found_error) { | |
wtc
2014/06/19 00:13:24
Please add a comment to explain why you do not kee
ramant (doing other things)
2014/06/19 01:57:34
Done.
| |
927 helper.ValidationComplete(QUIC_NO_ERROR, ""); | 980 helper.ValidationComplete(QUIC_NO_ERROR, ""); |
928 return; | 981 return; |
929 } | 982 } |
930 | 983 |
931 // Use the client nonce to establish uniqueness. | 984 // Use the client nonce to establish uniqueness. |
932 StrikeRegisterClient* strike_register_client; | 985 StrikeRegisterClient* strike_register_client; |
933 { | 986 { |
934 base::AutoLock locked(strike_register_client_lock_); | 987 base::AutoLock locked(strike_register_client_lock_); |
935 | 988 |
936 if (strike_register_client_.get() == NULL) { | 989 if (strike_register_client_.get() == NULL) { |
(...skipping 27 matching lines...) Expand all Loading... | |
964 out->SetStringPiece(kSourceAddressTokenTag, | 1017 out->SetStringPiece(kSourceAddressTokenTag, |
965 NewSourceAddressToken( | 1018 NewSourceAddressToken( |
966 config, | 1019 config, |
967 info.client_ip, | 1020 info.client_ip, |
968 rand, | 1021 rand, |
969 info.now)); | 1022 info.now)); |
970 if (replay_protection_) { | 1023 if (replay_protection_) { |
971 out->SetStringPiece(kServerNonceTag, NewServerNonce(rand, info.now)); | 1024 out->SetStringPiece(kServerNonceTag, NewServerNonce(rand, info.now)); |
972 } | 1025 } |
973 | 1026 |
1027 if (FLAGS_send_quic_crypto_reject_reason) { | |
1028 // Send client the reject reason for debugging purposes. | |
1029 DCHECK_LT(0u, info.reject_reasons.size()); | |
1030 out->SetVector(kRejectReason, info.reject_reasons); | |
1031 } | |
1032 | |
974 // The client may have requested a certificate chain. | 1033 // The client may have requested a certificate chain. |
975 const QuicTag* their_proof_demands; | 1034 const QuicTag* their_proof_demands; |
976 size_t num_their_proof_demands; | 1035 size_t num_their_proof_demands; |
977 | 1036 |
978 if (proof_source_.get() == NULL || | 1037 if (proof_source_.get() == NULL || |
979 client_hello.GetTaglist(kPDMD, &their_proof_demands, | 1038 client_hello.GetTaglist(kPDMD, &their_proof_demands, |
980 &num_their_proof_demands) != | 1039 &num_their_proof_demands) != |
981 QUIC_NO_ERROR) { | 1040 QUIC_NO_ERROR) { |
982 return; | 1041 return; |
983 } | 1042 } |
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1281 if (ip.GetSockAddrFamily() == AF_INET) { | 1340 if (ip.GetSockAddrFamily() == AF_INET) { |
1282 ip_address = ConvertIPv4NumberToIPv6Number(ip_address); | 1341 ip_address = ConvertIPv4NumberToIPv6Number(ip_address); |
1283 } | 1342 } |
1284 source_address_token.set_ip(IPAddressToPackedString(ip_address)); | 1343 source_address_token.set_ip(IPAddressToPackedString(ip_address)); |
1285 source_address_token.set_timestamp(now.ToUNIXSeconds()); | 1344 source_address_token.set_timestamp(now.ToUNIXSeconds()); |
1286 | 1345 |
1287 return config.source_address_token_boxer->Box( | 1346 return config.source_address_token_boxer->Box( |
1288 rand, source_address_token.SerializeAsString()); | 1347 rand, source_address_token.SerializeAsString()); |
1289 } | 1348 } |
1290 | 1349 |
1291 bool QuicCryptoServerConfig::ValidateSourceAddressToken( | 1350 HandshakeFailureReason QuicCryptoServerConfig::ValidateSourceAddressToken( |
1292 const Config& config, | 1351 const Config& config, |
1293 StringPiece token, | 1352 StringPiece token, |
1294 const IPEndPoint& ip, | 1353 const IPEndPoint& ip, |
1295 QuicWallTime now) const { | 1354 QuicWallTime now) const { |
1296 string storage; | 1355 string storage; |
1297 StringPiece plaintext; | 1356 StringPiece plaintext; |
1298 if (!config.source_address_token_boxer->Unbox(token, &storage, &plaintext)) { | 1357 if (!config.source_address_token_boxer->Unbox(token, &storage, &plaintext)) { |
1299 return false; | 1358 return SOURCE_ADDRESS_TOKEN_DECRYPTION_FAILURE; |
1300 } | 1359 } |
1301 | 1360 |
1302 SourceAddressToken source_address_token; | 1361 SourceAddressToken source_address_token; |
1303 if (!source_address_token.ParseFromArray(plaintext.data(), | 1362 if (!source_address_token.ParseFromArray(plaintext.data(), |
1304 plaintext.size())) { | 1363 plaintext.size())) { |
1305 return false; | 1364 return SOURCE_ADDRESS_TOKEN_PARSE_FAILURE; |
1306 } | 1365 } |
1307 | 1366 |
1308 IPAddressNumber ip_address = ip.address(); | 1367 IPAddressNumber ip_address = ip.address(); |
1309 if (ip.GetSockAddrFamily() == AF_INET) { | 1368 if (ip.GetSockAddrFamily() == AF_INET) { |
1310 ip_address = ConvertIPv4NumberToIPv6Number(ip_address); | 1369 ip_address = ConvertIPv4NumberToIPv6Number(ip_address); |
1311 } | 1370 } |
1312 if (source_address_token.ip() != IPAddressToPackedString(ip_address)) { | 1371 if (source_address_token.ip() != IPAddressToPackedString(ip_address)) { |
1313 // It's for a different IP address. | 1372 // It's for a different IP address. |
1314 return false; | 1373 return SOURCE_ADDRESS_TOKEN_DIFFERENT_IP_ADDRESS_FAILURE; |
1315 } | 1374 } |
1316 | 1375 |
1317 const QuicWallTime timestamp( | 1376 const QuicWallTime timestamp( |
1318 QuicWallTime::FromUNIXSeconds(source_address_token.timestamp())); | 1377 QuicWallTime::FromUNIXSeconds(source_address_token.timestamp())); |
1319 const QuicTime::Delta delta(now.AbsoluteDifference(timestamp)); | 1378 const QuicTime::Delta delta(now.AbsoluteDifference(timestamp)); |
1320 | 1379 |
1321 if (now.IsBefore(timestamp) && | 1380 if (now.IsBefore(timestamp) && |
1322 delta.ToSeconds() > source_address_token_future_secs_) { | 1381 delta.ToSeconds() > source_address_token_future_secs_) { |
1323 return false; | 1382 return SOURCE_ADDRESS_TOKEN_CLOCK_SKEW_FAILURE; |
1324 } | 1383 } |
1325 | 1384 |
1326 if (now.IsAfter(timestamp) && | 1385 if (now.IsAfter(timestamp) && |
1327 delta.ToSeconds() > source_address_token_lifetime_secs_) { | 1386 delta.ToSeconds() > source_address_token_lifetime_secs_) { |
1328 return false; | 1387 return SOURCE_ADDRESS_TOKEN_EXPIRED_FAILURE; |
1329 } | 1388 } |
1330 | 1389 |
1331 return true; | 1390 return HANDSHAKE_OK; |
1332 } | 1391 } |
1333 | 1392 |
1334 // kServerNoncePlaintextSize is the number of bytes in an unencrypted server | 1393 // kServerNoncePlaintextSize is the number of bytes in an unencrypted server |
1335 // nonce. | 1394 // nonce. |
1336 static const size_t kServerNoncePlaintextSize = | 1395 static const size_t kServerNoncePlaintextSize = |
1337 4 /* timestamp */ + 20 /* random bytes */; | 1396 4 /* timestamp */ + 20 /* random bytes */; |
1338 | 1397 |
1339 string QuicCryptoServerConfig::NewServerNonce(QuicRandom* rand, | 1398 string QuicCryptoServerConfig::NewServerNonce(QuicRandom* rand, |
1340 QuicWallTime now) const { | 1399 QuicWallTime now) const { |
1341 const uint32 timestamp = static_cast<uint32>(now.ToUNIXSeconds()); | 1400 const uint32 timestamp = static_cast<uint32>(now.ToUNIXSeconds()); |
1342 | 1401 |
1343 uint8 server_nonce[kServerNoncePlaintextSize]; | 1402 uint8 server_nonce[kServerNoncePlaintextSize]; |
1344 COMPILE_ASSERT(sizeof(server_nonce) > sizeof(timestamp), nonce_too_small); | 1403 COMPILE_ASSERT(sizeof(server_nonce) > sizeof(timestamp), nonce_too_small); |
1345 server_nonce[0] = static_cast<uint8>(timestamp >> 24); | 1404 server_nonce[0] = static_cast<uint8>(timestamp >> 24); |
1346 server_nonce[1] = static_cast<uint8>(timestamp >> 16); | 1405 server_nonce[1] = static_cast<uint8>(timestamp >> 16); |
1347 server_nonce[2] = static_cast<uint8>(timestamp >> 8); | 1406 server_nonce[2] = static_cast<uint8>(timestamp >> 8); |
1348 server_nonce[3] = static_cast<uint8>(timestamp); | 1407 server_nonce[3] = static_cast<uint8>(timestamp); |
1349 rand->RandBytes(&server_nonce[sizeof(timestamp)], | 1408 rand->RandBytes(&server_nonce[sizeof(timestamp)], |
1350 sizeof(server_nonce) - sizeof(timestamp)); | 1409 sizeof(server_nonce) - sizeof(timestamp)); |
1351 | 1410 |
1352 return server_nonce_boxer_.Box( | 1411 return server_nonce_boxer_.Box( |
1353 rand, | 1412 rand, |
1354 StringPiece(reinterpret_cast<char*>(server_nonce), sizeof(server_nonce))); | 1413 StringPiece(reinterpret_cast<char*>(server_nonce), sizeof(server_nonce))); |
1355 } | 1414 } |
1356 | 1415 |
1357 bool QuicCryptoServerConfig::ValidateServerNonce(StringPiece token, | 1416 HandshakeFailureReason QuicCryptoServerConfig::ValidateServerNonce( |
1358 QuicWallTime now) const { | 1417 StringPiece token, |
1418 QuicWallTime now) const { | |
1359 string storage; | 1419 string storage; |
1360 StringPiece plaintext; | 1420 StringPiece plaintext; |
1361 if (!server_nonce_boxer_.Unbox(token, &storage, &plaintext)) { | 1421 if (!server_nonce_boxer_.Unbox(token, &storage, &plaintext)) { |
1362 return false; | 1422 return SERVER_NONCE_DECRYPTION_FAILURE; |
1363 } | 1423 } |
1364 | 1424 |
1365 // plaintext contains: | 1425 // plaintext contains: |
1366 // uint32 timestamp | 1426 // uint32 timestamp |
1367 // uint8[20] random bytes | 1427 // uint8[20] random bytes |
1368 | 1428 |
1369 if (plaintext.size() != kServerNoncePlaintextSize) { | 1429 if (plaintext.size() != kServerNoncePlaintextSize) { |
1370 // This should never happen because the value decrypted correctly. | 1430 // This should never happen because the value decrypted correctly. |
1371 LOG(DFATAL) << "Seemingly valid server nonce had incorrect length."; | 1431 LOG(DFATAL) << "Seemingly valid server nonce had incorrect length."; |
1372 return false; | 1432 return SERVER_NONCE_INVALID_FAILURE; |
1373 } | 1433 } |
1374 | 1434 |
1375 uint8 server_nonce[32]; | 1435 uint8 server_nonce[32]; |
1376 memcpy(server_nonce, plaintext.data(), 4); | 1436 memcpy(server_nonce, plaintext.data(), 4); |
1377 memcpy(server_nonce + 4, server_nonce_orbit_, sizeof(server_nonce_orbit_)); | 1437 memcpy(server_nonce + 4, server_nonce_orbit_, sizeof(server_nonce_orbit_)); |
1378 memcpy(server_nonce + 4 + sizeof(server_nonce_orbit_), plaintext.data() + 4, | 1438 memcpy(server_nonce + 4 + sizeof(server_nonce_orbit_), plaintext.data() + 4, |
1379 20); | 1439 20); |
1380 COMPILE_ASSERT(4 + sizeof(server_nonce_orbit_) + 20 == sizeof(server_nonce), | 1440 COMPILE_ASSERT(4 + sizeof(server_nonce_orbit_) + 20 == sizeof(server_nonce), |
1381 bad_nonce_buffer_length); | 1441 bad_nonce_buffer_length); |
1382 | 1442 |
1383 bool is_unique; | 1443 bool is_unique; |
1384 { | 1444 { |
1385 base::AutoLock auto_lock(server_nonce_strike_register_lock_); | 1445 base::AutoLock auto_lock(server_nonce_strike_register_lock_); |
1386 if (server_nonce_strike_register_.get() == NULL) { | 1446 if (server_nonce_strike_register_.get() == NULL) { |
1387 server_nonce_strike_register_.reset(new StrikeRegister( | 1447 server_nonce_strike_register_.reset(new StrikeRegister( |
1388 server_nonce_strike_register_max_entries_, | 1448 server_nonce_strike_register_max_entries_, |
1389 static_cast<uint32>(now.ToUNIXSeconds()), | 1449 static_cast<uint32>(now.ToUNIXSeconds()), |
1390 server_nonce_strike_register_window_secs_, server_nonce_orbit_, | 1450 server_nonce_strike_register_window_secs_, server_nonce_orbit_, |
1391 StrikeRegister::NO_STARTUP_PERIOD_NEEDED)); | 1451 StrikeRegister::NO_STARTUP_PERIOD_NEEDED)); |
1392 } | 1452 } |
1393 is_unique = server_nonce_strike_register_->Insert( | 1453 is_unique = server_nonce_strike_register_->Insert( |
1394 server_nonce, static_cast<uint32>(now.ToUNIXSeconds())); | 1454 server_nonce, static_cast<uint32>(now.ToUNIXSeconds())); |
1395 } | 1455 } |
1396 | 1456 |
1397 return is_unique; | 1457 return is_unique ? HANDSHAKE_OK : SERVER_NONCE_NOT_UNIQUE_FAILURE; |
1398 } | 1458 } |
1399 | 1459 |
1400 QuicCryptoServerConfig::Config::Config() | 1460 QuicCryptoServerConfig::Config::Config() |
1401 : channel_id_enabled(false), | 1461 : channel_id_enabled(false), |
1402 is_primary(false), | 1462 is_primary(false), |
1403 primary_time(QuicWallTime::Zero()), | 1463 primary_time(QuicWallTime::Zero()), |
1404 priority(0), | 1464 priority(0), |
1405 source_address_token_boxer(NULL) {} | 1465 source_address_token_boxer(NULL) {} |
1406 | 1466 |
1407 QuicCryptoServerConfig::Config::~Config() { STLDeleteElements(&key_exchanges); } | 1467 QuicCryptoServerConfig::Config::~Config() { STLDeleteElements(&key_exchanges); } |
1408 | 1468 |
1409 } // namespace net | 1469 } // namespace net |
OLD | NEW |