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 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 ValidateClientHelloResultCallback::Result* result, | 113 ValidateClientHelloResultCallback::Result* result, |
114 ValidateClientHelloResultCallback* done_cb) | 114 ValidateClientHelloResultCallback* done_cb) |
115 : result_(result), done_cb_(done_cb) { | 115 : result_(result), done_cb_(done_cb) { |
116 } | 116 } |
117 | 117 |
118 protected: | 118 protected: |
119 void RunImpl(bool nonce_is_valid_and_unique, | 119 void RunImpl(bool nonce_is_valid_and_unique, |
120 InsertStatus nonce_error) override { | 120 InsertStatus nonce_error) override { |
121 DVLOG(1) << "Using client nonce, unique: " << nonce_is_valid_and_unique | 121 DVLOG(1) << "Using client nonce, unique: " << nonce_is_valid_and_unique |
122 << " nonce_error: " << nonce_error; | 122 << " nonce_error: " << nonce_error; |
123 result_->info.unique = nonce_is_valid_and_unique; | |
124 if (!nonce_is_valid_and_unique) { | 123 if (!nonce_is_valid_and_unique) { |
125 HandshakeFailureReason client_nonce_error; | 124 HandshakeFailureReason client_nonce_error; |
126 switch (nonce_error) { | 125 switch (nonce_error) { |
127 case NONCE_INVALID_FAILURE: | 126 case NONCE_INVALID_FAILURE: |
128 client_nonce_error = CLIENT_NONCE_INVALID_FAILURE; | 127 client_nonce_error = CLIENT_NONCE_INVALID_FAILURE; |
129 break; | 128 break; |
130 case NONCE_NOT_UNIQUE_FAILURE: | 129 case NONCE_NOT_UNIQUE_FAILURE: |
131 client_nonce_error = CLIENT_NONCE_NOT_UNIQUE_FAILURE; | 130 client_nonce_error = CLIENT_NONCE_NOT_UNIQUE_FAILURE; |
132 break; | 131 break; |
133 case NONCE_INVALID_ORBIT_FAILURE: | 132 case NONCE_INVALID_ORBIT_FAILURE: |
(...skipping 27 matching lines...) Expand all Loading... |
161 ValidateClientHelloResultCallback* done_cb_; | 160 ValidateClientHelloResultCallback* done_cb_; |
162 | 161 |
163 DISALLOW_COPY_AND_ASSIGN(VerifyNonceIsValidAndUniqueCallback); | 162 DISALLOW_COPY_AND_ASSIGN(VerifyNonceIsValidAndUniqueCallback); |
164 }; | 163 }; |
165 | 164 |
166 // static | 165 // static |
167 const char QuicCryptoServerConfig::TESTING[] = "secret string for testing"; | 166 const char QuicCryptoServerConfig::TESTING[] = "secret string for testing"; |
168 | 167 |
169 ClientHelloInfo::ClientHelloInfo(const IPAddressNumber& in_client_ip, | 168 ClientHelloInfo::ClientHelloInfo(const IPAddressNumber& in_client_ip, |
170 QuicWallTime in_now) | 169 QuicWallTime in_now) |
171 : client_ip(in_client_ip), | 170 : client_ip(in_client_ip), now(in_now), valid_source_address_token(false) {} |
172 now(in_now), | |
173 valid_source_address_token(false), | |
174 client_nonce_well_formed(false), | |
175 unique(false) { | |
176 } | |
177 | 171 |
178 ClientHelloInfo::~ClientHelloInfo() { | 172 ClientHelloInfo::~ClientHelloInfo() { |
179 } | 173 } |
180 | 174 |
181 PrimaryConfigChangedCallback::PrimaryConfigChangedCallback() { | 175 PrimaryConfigChangedCallback::PrimaryConfigChangedCallback() { |
182 } | 176 } |
183 | 177 |
184 PrimaryConfigChangedCallback::~PrimaryConfigChangedCallback() { | 178 PrimaryConfigChangedCallback::~PrimaryConfigChangedCallback() { |
185 } | 179 } |
186 | 180 |
(...skipping 423 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
610 bool x509_ecdsa_supported = false; | 604 bool x509_ecdsa_supported = false; |
611 ParseProofDemand(client_hello, &x509_supported, &x509_ecdsa_supported); | 605 ParseProofDemand(client_hello, &x509_supported, &x509_ecdsa_supported); |
612 if (proof_source_.get() && !crypto_proof->certs && | 606 if (proof_source_.get() && !crypto_proof->certs && |
613 !proof_source_->GetProof(server_ip, info.sni.as_string(), | 607 !proof_source_->GetProof(server_ip, info.sni.as_string(), |
614 primary_config->serialized, x509_ecdsa_supported, | 608 primary_config->serialized, x509_ecdsa_supported, |
615 &crypto_proof->certs, | 609 &crypto_proof->certs, |
616 &crypto_proof->signature)) { | 610 &crypto_proof->signature)) { |
617 return QUIC_HANDSHAKE_FAILED; | 611 return QUIC_HANDSHAKE_FAILED; |
618 } | 612 } |
619 | 613 |
620 if (!info.valid_source_address_token || | 614 if (!info.reject_reasons.empty() || !requested_config.get()) { |
621 !info.client_nonce_well_formed || | |
622 !info.unique || | |
623 !requested_config.get()) { | |
624 BuildRejection(*primary_config, client_hello, info, | 615 BuildRejection(*primary_config, client_hello, info, |
625 validate_chlo_result.cached_network_params, | 616 validate_chlo_result.cached_network_params, |
626 use_stateless_rejects, server_designated_connection_id, rand, | 617 use_stateless_rejects, server_designated_connection_id, rand, |
627 params, *crypto_proof, out); | 618 params, *crypto_proof, out); |
628 return QUIC_NO_ERROR; | 619 return QUIC_NO_ERROR; |
629 } | 620 } |
630 | 621 |
631 const QuicTag* their_aeads; | 622 const QuicTag* their_aeads; |
632 const QuicTag* their_key_exchanges; | 623 const QuicTag* their_key_exchanges; |
633 size_t num_their_aeads, num_their_key_exchanges; | 624 size_t num_their_aeads, num_their_key_exchanges; |
(...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1025 found_error = true; | 1016 found_error = true; |
1026 info->reject_reasons.push_back(SERVER_CONFIG_UNKNOWN_CONFIG_FAILURE); | 1017 info->reject_reasons.push_back(SERVER_CONFIG_UNKNOWN_CONFIG_FAILURE); |
1027 } | 1018 } |
1028 | 1019 |
1029 if (!ValidateExpectedLeafCertificate(client_hello, *crypto_proof)) { | 1020 if (!ValidateExpectedLeafCertificate(client_hello, *crypto_proof)) { |
1030 found_error = true; | 1021 found_error = true; |
1031 info->reject_reasons.push_back(INVALID_EXPECTED_LEAF_CERTIFICATE); | 1022 info->reject_reasons.push_back(INVALID_EXPECTED_LEAF_CERTIFICATE); |
1032 } | 1023 } |
1033 } | 1024 } |
1034 | 1025 |
1035 if (client_hello.GetStringPiece(kNONC, &info->client_nonce) && | 1026 if (!client_hello.GetStringPiece(kNONC, &info->client_nonce) || |
1036 info->client_nonce.size() == kNonceSize) { | 1027 info->client_nonce.size() != kNonceSize) { |
1037 info->client_nonce_well_formed = true; | |
1038 } else { | |
1039 info->reject_reasons.push_back(CLIENT_NONCE_INVALID_FAILURE); | 1028 info->reject_reasons.push_back(CLIENT_NONCE_INVALID_FAILURE); |
1040 // Invalid client nonce. | 1029 // Invalid client nonce. |
1041 DVLOG(1) << "Invalid client nonce."; | 1030 DVLOG(1) << "Invalid client nonce."; |
1042 if (FLAGS_use_early_return_when_verifying_chlo) { | 1031 if (FLAGS_use_early_return_when_verifying_chlo) { |
1043 helper.ValidationComplete(QUIC_NO_ERROR, ""); | 1032 helper.ValidationComplete(QUIC_NO_ERROR, ""); |
1044 return; | 1033 return; |
1045 } | 1034 } |
1046 found_error = true; | 1035 found_error = true; |
1047 } | 1036 } |
1048 | 1037 |
1049 if (!replay_protection_) { | 1038 if (!replay_protection_) { |
1050 if (!found_error) { | |
1051 info->unique = true; | |
1052 } | |
1053 DVLOG(1) << "No replay protection."; | 1039 DVLOG(1) << "No replay protection."; |
1054 helper.ValidationComplete(QUIC_NO_ERROR, ""); | 1040 helper.ValidationComplete(QUIC_NO_ERROR, ""); |
1055 return; | 1041 return; |
1056 } | 1042 } |
1057 | 1043 |
1058 client_hello.GetStringPiece(kServerNonceTag, &info->server_nonce); | 1044 client_hello.GetStringPiece(kServerNonceTag, &info->server_nonce); |
1059 if (!info->server_nonce.empty()) { | 1045 if (!info->server_nonce.empty()) { |
1060 // If the server nonce is present, use it to establish uniqueness. | 1046 // If the server nonce is present, use it to establish uniqueness. |
1061 HandshakeFailureReason server_nonce_error = | 1047 HandshakeFailureReason server_nonce_error = |
1062 ValidateServerNonce(info->server_nonce, info->now); | 1048 ValidateServerNonce(info->server_nonce, info->now); |
1063 if (server_nonce_error == HANDSHAKE_OK) { | 1049 bool is_unique = server_nonce_error == HANDSHAKE_OK; |
1064 info->unique = true; | 1050 if (!is_unique) { |
1065 } else { | |
1066 info->reject_reasons.push_back(server_nonce_error); | 1051 info->reject_reasons.push_back(server_nonce_error); |
1067 info->unique = false; | |
1068 } | 1052 } |
1069 DVLOG(1) << "Using server nonce, unique: " << info->unique; | 1053 DVLOG(1) << "Using server nonce, unique: " << is_unique; |
1070 helper.ValidationComplete(QUIC_NO_ERROR, ""); | 1054 helper.ValidationComplete(QUIC_NO_ERROR, ""); |
1071 return; | 1055 return; |
1072 } | 1056 } |
1073 // If we hit this block, the server nonce was empty. If we're requiring | 1057 // If we hit this block, the server nonce was empty. If we're requiring |
1074 // handshake confirmation for DoS reasons and there's no server nonce present, | 1058 // handshake confirmation for DoS reasons and there's no server nonce present, |
1075 // reject the CHLO. | 1059 // reject the CHLO. |
1076 if (FLAGS_quic_require_handshake_confirmation) { | 1060 if (FLAGS_quic_require_handshake_confirmation) { |
1077 info->reject_reasons.push_back(SERVER_NONCE_REQUIRED_FAILURE); | 1061 info->reject_reasons.push_back(SERVER_NONCE_REQUIRED_FAILURE); |
1078 helper.ValidationComplete(QUIC_NO_ERROR, ""); | 1062 helper.ValidationComplete(QUIC_NO_ERROR, ""); |
1079 return; | 1063 return; |
(...skipping 646 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1726 QuicCryptoServerConfig::Config::Config() | 1710 QuicCryptoServerConfig::Config::Config() |
1727 : channel_id_enabled(false), | 1711 : channel_id_enabled(false), |
1728 is_primary(false), | 1712 is_primary(false), |
1729 primary_time(QuicWallTime::Zero()), | 1713 primary_time(QuicWallTime::Zero()), |
1730 priority(0), | 1714 priority(0), |
1731 source_address_token_boxer(nullptr) {} | 1715 source_address_token_boxer(nullptr) {} |
1732 | 1716 |
1733 QuicCryptoServerConfig::Config::~Config() { STLDeleteElements(&key_exchanges); } | 1717 QuicCryptoServerConfig::Config::~Config() { STLDeleteElements(&key_exchanges); } |
1734 | 1718 |
1735 } // namespace net | 1719 } // namespace net |
OLD | NEW |