OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/core/quic_crypto_server_stream.h" | 5 #include "net/quic/core/quic_crypto_server_stream.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 | 8 |
9 #include "base/base64.h" | 9 #include "base/base64.h" |
10 #include "crypto/secure_hash.h" | 10 #include "crypto/secure_hash.h" |
(...skipping 10 matching lines...) Expand all Loading... |
21 using base::StringPiece; | 21 using base::StringPiece; |
22 using std::string; | 22 using std::string; |
23 | 23 |
24 namespace net { | 24 namespace net { |
25 | 25 |
26 class QuicCryptoServerStream::ProcessClientHelloCallback | 26 class QuicCryptoServerStream::ProcessClientHelloCallback |
27 : public ProcessClientHelloResultCallback { | 27 : public ProcessClientHelloResultCallback { |
28 public: | 28 public: |
29 ProcessClientHelloCallback( | 29 ProcessClientHelloCallback( |
30 QuicCryptoServerStream* stream, | 30 QuicCryptoServerStream* stream, |
31 const scoped_refptr<ValidateClientHelloResultCallback::Result>& result) | 31 const QuicReferenceCountedPointer< |
| 32 ValidateClientHelloResultCallback::Result>& result) |
32 : stream_(stream), result_(result) {} | 33 : stream_(stream), result_(result) {} |
33 | 34 |
34 void Run(QuicErrorCode error, | 35 void Run(QuicErrorCode error, |
35 const string& error_details, | 36 const string& error_details, |
36 std::unique_ptr<CryptoHandshakeMessage> message, | 37 std::unique_ptr<CryptoHandshakeMessage> message, |
37 std::unique_ptr<DiversificationNonce> diversification_nonce, | 38 std::unique_ptr<DiversificationNonce> diversification_nonce, |
38 std::unique_ptr<net::ProofSource::Details> proof_source_details) | 39 std::unique_ptr<net::ProofSource::Details> proof_source_details) |
39 override { | 40 override { |
40 if (stream_ == nullptr) { | 41 if (stream_ == nullptr) { |
41 return; | 42 return; |
42 } | 43 } |
43 | 44 |
44 // Note: set the parent's callback to nullptr here because | 45 // Note: set the parent's callback to nullptr here because |
45 // FinishProcessingHandshakeMessageAfterProcessClientHello can be invoked | 46 // FinishProcessingHandshakeMessageAfterProcessClientHello can be invoked |
46 // from either synchronous or asynchronous codepaths. When the synchronous | 47 // from either synchronous or asynchronous codepaths. When the synchronous |
47 // codepaths are removed, this assignment should move to | 48 // codepaths are removed, this assignment should move to |
48 // FinishProcessingHandshakeMessageAfterProcessClientHello. | 49 // FinishProcessingHandshakeMessageAfterProcessClientHello. |
49 stream_->process_client_hello_cb_ = nullptr; | 50 stream_->process_client_hello_cb_ = nullptr; |
50 | 51 |
51 stream_->FinishProcessingHandshakeMessageAfterProcessClientHello( | 52 stream_->FinishProcessingHandshakeMessageAfterProcessClientHello( |
52 *result_, error, error_details, std::move(message), | 53 *result_, error, error_details, std::move(message), |
53 std::move(diversification_nonce), std::move(proof_source_details)); | 54 std::move(diversification_nonce), std::move(proof_source_details)); |
54 } | 55 } |
55 | 56 |
56 void Cancel() { stream_ = nullptr; } | 57 void Cancel() { stream_ = nullptr; } |
57 | 58 |
58 private: | 59 private: |
59 QuicCryptoServerStream* stream_; | 60 QuicCryptoServerStream* stream_; |
60 scoped_refptr<ValidateClientHelloResultCallback::Result> result_; | 61 QuicReferenceCountedPointer<ValidateClientHelloResultCallback::Result> |
| 62 result_; |
61 }; | 63 }; |
62 | 64 |
63 QuicCryptoServerStreamBase::QuicCryptoServerStreamBase(QuicSession* session) | 65 QuicCryptoServerStreamBase::QuicCryptoServerStreamBase(QuicSession* session) |
64 : QuicCryptoStream(session) {} | 66 : QuicCryptoStream(session) {} |
65 | 67 |
66 // TODO(jokulik): Once stateless rejects support is inherent in the version | 68 // TODO(jokulik): Once stateless rejects support is inherent in the version |
67 // number, this function will likely go away entirely. | 69 // number, this function will likely go away entirely. |
68 // static | 70 // static |
69 bool QuicCryptoServerStreamBase::DoesPeerSupportStatelessRejects( | 71 bool QuicCryptoServerStreamBase::DoesPeerSupportStatelessRejects( |
70 const CryptoHandshakeMessage& message) { | 72 const CryptoHandshakeMessage& message) { |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 | 162 |
161 std::unique_ptr<ValidateCallback> cb(new ValidateCallback(this)); | 163 std::unique_ptr<ValidateCallback> cb(new ValidateCallback(this)); |
162 validate_client_hello_cb_ = cb.get(); | 164 validate_client_hello_cb_ = cb.get(); |
163 crypto_config_->ValidateClientHello( | 165 crypto_config_->ValidateClientHello( |
164 message, session()->connection()->peer_address().host(), | 166 message, session()->connection()->peer_address().host(), |
165 session()->connection()->self_address(), version(), | 167 session()->connection()->self_address(), version(), |
166 session()->connection()->clock(), signed_config_, std::move(cb)); | 168 session()->connection()->clock(), signed_config_, std::move(cb)); |
167 } | 169 } |
168 | 170 |
169 void QuicCryptoServerStream::FinishProcessingHandshakeMessage( | 171 void QuicCryptoServerStream::FinishProcessingHandshakeMessage( |
170 scoped_refptr<ValidateClientHelloResultCallback::Result> result, | 172 QuicReferenceCountedPointer<ValidateClientHelloResultCallback::Result> |
| 173 result, |
171 std::unique_ptr<ProofSource::Details> details) { | 174 std::unique_ptr<ProofSource::Details> details) { |
172 const CryptoHandshakeMessage& message = result->client_hello; | 175 const CryptoHandshakeMessage& message = result->client_hello; |
173 | 176 |
174 // Clear the callback that got us here. | 177 // Clear the callback that got us here. |
175 DCHECK(validate_client_hello_cb_ != nullptr); | 178 DCHECK(validate_client_hello_cb_ != nullptr); |
176 validate_client_hello_cb_ = nullptr; | 179 validate_client_hello_cb_ = nullptr; |
177 | 180 |
178 if (use_stateless_rejects_if_peer_supported_) { | 181 if (use_stateless_rejects_if_peer_supported_) { |
179 peer_supports_stateless_rejects_ = DoesPeerSupportStatelessRejects(message); | 182 peer_supports_stateless_rejects_ = DoesPeerSupportStatelessRejects(message); |
180 } | 183 } |
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
428 if ((*output)[len - 1] == '=') { | 431 if ((*output)[len - 1] == '=') { |
429 len--; | 432 len--; |
430 } | 433 } |
431 output->resize(len); | 434 output->resize(len); |
432 } | 435 } |
433 } | 436 } |
434 return true; | 437 return true; |
435 } | 438 } |
436 | 439 |
437 void QuicCryptoServerStream::ProcessClientHello( | 440 void QuicCryptoServerStream::ProcessClientHello( |
438 scoped_refptr<ValidateClientHelloResultCallback::Result> result, | 441 QuicReferenceCountedPointer<ValidateClientHelloResultCallback::Result> |
| 442 result, |
439 std::unique_ptr<ProofSource::Details> proof_source_details, | 443 std::unique_ptr<ProofSource::Details> proof_source_details, |
440 std::unique_ptr<ProcessClientHelloResultCallback> done_cb) { | 444 std::unique_ptr<ProcessClientHelloResultCallback> done_cb) { |
441 const CryptoHandshakeMessage& message = result->client_hello; | 445 const CryptoHandshakeMessage& message = result->client_hello; |
442 string error_details; | 446 string error_details; |
443 if (!helper_->CanAcceptClientHello( | 447 if (!helper_->CanAcceptClientHello( |
444 message, session()->connection()->self_address(), &error_details)) { | 448 message, session()->connection()->self_address(), &error_details)) { |
445 done_cb->Run(QUIC_HANDSHAKE_FAILED, error_details, nullptr, nullptr, | 449 done_cb->Run(QUIC_HANDSHAKE_FAILED, error_details, nullptr, nullptr, |
446 nullptr); | 450 nullptr); |
447 return; | 451 return; |
448 } | 452 } |
(...skipping 29 matching lines...) Expand all Loading... |
478 | 482 |
479 QuicCryptoServerStream::ValidateCallback::ValidateCallback( | 483 QuicCryptoServerStream::ValidateCallback::ValidateCallback( |
480 QuicCryptoServerStream* parent) | 484 QuicCryptoServerStream* parent) |
481 : parent_(parent) {} | 485 : parent_(parent) {} |
482 | 486 |
483 void QuicCryptoServerStream::ValidateCallback::Cancel() { | 487 void QuicCryptoServerStream::ValidateCallback::Cancel() { |
484 parent_ = nullptr; | 488 parent_ = nullptr; |
485 } | 489 } |
486 | 490 |
487 void QuicCryptoServerStream::ValidateCallback::Run( | 491 void QuicCryptoServerStream::ValidateCallback::Run( |
488 scoped_refptr<Result> result, | 492 QuicReferenceCountedPointer<Result> result, |
489 std::unique_ptr<ProofSource::Details> details) { | 493 std::unique_ptr<ProofSource::Details> details) { |
490 if (parent_ != nullptr) { | 494 if (parent_ != nullptr) { |
491 parent_->FinishProcessingHandshakeMessage(std::move(result), | 495 parent_->FinishProcessingHandshakeMessage(std::move(result), |
492 std::move(details)); | 496 std::move(details)); |
493 } | 497 } |
494 } | 498 } |
495 | 499 |
496 QuicConnectionId QuicCryptoServerStream::GenerateConnectionIdForReject( | 500 QuicConnectionId QuicCryptoServerStream::GenerateConnectionIdForReject( |
497 bool use_stateless_rejects) { | 501 bool use_stateless_rejects) { |
498 if (!use_stateless_rejects) { | 502 if (!use_stateless_rejects) { |
499 return 0; | 503 return 0; |
500 } | 504 } |
501 return helper_->GenerateConnectionIdForReject( | 505 return helper_->GenerateConnectionIdForReject( |
502 session()->connection()->connection_id()); | 506 session()->connection()->connection_id()); |
503 } | 507 } |
504 | 508 |
505 } // namespace net | 509 } // namespace net |
OLD | NEW |