OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 #ifndef NET_QUIC_STATELESS_REJECTOR_H_ | 5 #ifndef NET_QUIC_STATELESS_REJECTOR_H_ |
6 #define NET_QUIC_STATELESS_REJECTOR_H_ | 6 #define NET_QUIC_STATELESS_REJECTOR_H_ |
7 | 7 |
8 #include "base/strings/string_piece.h" | 8 #include "base/strings/string_piece.h" |
9 #include "net/quic/core/crypto/crypto_framer.h" | 9 #include "net/quic/core/crypto/crypto_framer.h" |
10 #include "net/quic/core/crypto/quic_crypto_server_config.h" | 10 #include "net/quic/core/crypto/quic_crypto_server_config.h" |
11 #include "net/quic/core/quic_protocol.h" | 11 #include "net/quic/core/quic_protocol.h" |
12 | 12 |
13 namespace net { | 13 namespace net { |
14 | 14 |
15 // The StatelessRejector receives CHLO messages and generates an SREJ | 15 // The StatelessRejector receives CHLO messages and generates an SREJ |
16 // message in response, if the CHLO can be statelessly rejected. | 16 // message in response, if the CHLO can be statelessly rejected. |
17 class StatelessRejector { | 17 class StatelessRejector { |
18 public: | 18 public: |
19 enum State { | 19 enum State { |
| 20 UNKNOWN, // State has not yet been determined |
20 UNSUPPORTED, // Stateless rejects are not supported | 21 UNSUPPORTED, // Stateless rejects are not supported |
21 FAILED, // There was an error processing the CHLO. | 22 FAILED, // There was an error processing the CHLO. |
22 ACCEPTED, // The CHLO was accepted | 23 ACCEPTED, // The CHLO was accepted |
23 REJECTED, // The CHLO was rejected. | 24 REJECTED, // The CHLO was rejected. |
24 }; | 25 }; |
25 | 26 |
26 StatelessRejector(QuicVersion version, | 27 StatelessRejector(QuicVersion version, |
27 const QuicVersionVector& versions, | 28 const QuicVersionVector& versions, |
28 const QuicCryptoServerConfig* crypto_config, | 29 const QuicCryptoServerConfig* crypto_config, |
29 QuicCompressedCertsCache* compressed_certs_cache, | 30 QuicCompressedCertsCache* compressed_certs_cache, |
30 const QuicClock* clock, | 31 const QuicClock* clock, |
31 QuicRandom* random, | 32 QuicRandom* random, |
32 QuicByteCount chlo_packet_size, | 33 QuicByteCount chlo_packet_size, |
33 const IPEndPoint& client_address, | 34 const IPEndPoint& client_address, |
34 const IPEndPoint& server_address); | 35 const IPEndPoint& server_address); |
35 | 36 |
36 ~StatelessRejector(); | 37 ~StatelessRejector(); |
37 | 38 |
38 // Called when |chlo| is received for |connection_id| to determine | 39 // Called when |chlo| is received for |connection_id|. |
39 // if it should be statelessly rejected. | |
40 void OnChlo(QuicVersion version, | 40 void OnChlo(QuicVersion version, |
41 QuicConnectionId connection_id, | 41 QuicConnectionId connection_id, |
42 QuicConnectionId server_designated_connection_id, | 42 QuicConnectionId server_designated_connection_id, |
43 const CryptoHandshakeMessage& chlo); | 43 const CryptoHandshakeMessage& chlo); |
44 | 44 |
| 45 class ProcessDoneCallback { |
| 46 public: |
| 47 virtual ~ProcessDoneCallback() = default; |
| 48 virtual void Run(std::unique_ptr<StatelessRejector> rejector) = 0; |
| 49 }; |
| 50 |
| 51 // Perform processing to determine whether the CHLO received in OnChlo should |
| 52 // be statelessly rejected, and invoke the callback once a decision has been |
| 53 // made. |
| 54 static void Process(std::unique_ptr<StatelessRejector> rejector, |
| 55 std::unique_ptr<ProcessDoneCallback> cb); |
| 56 |
45 // Returns the state of the rejector after OnChlo() has been called. | 57 // Returns the state of the rejector after OnChlo() has been called. |
46 State state() const { return state_; } | 58 State state() const { return state_; } |
47 | 59 |
48 // Returns the error code when state() returns FAILED. | 60 // Returns the error code when state() returns FAILED. |
49 QuicErrorCode error() const { return error_; } | 61 QuicErrorCode error() const { return error_; } |
50 | 62 |
51 // Returns the error details when state() returns FAILED. | 63 // Returns the error details when state() returns FAILED. |
52 std::string error_details() const { return error_details_; } | 64 std::string error_details() const { return error_details_; } |
53 | 65 |
| 66 // Returns the connection ID. |
| 67 QuicConnectionId connection_id() const { return connection_id_; } |
| 68 |
54 // Returns the SREJ message when state() returns REJECTED. | 69 // Returns the SREJ message when state() returns REJECTED. |
55 const CryptoHandshakeMessage& reply() const { return reply_; } | 70 const CryptoHandshakeMessage& reply() const { return reply_; } |
56 | 71 |
57 private: | 72 private: |
58 // Helper class which is passed in to | 73 // Helper class which is passed in to |
59 // QuicCryptoServerConfig::ValidateClientHello. | 74 // QuicCryptoServerConfig::ValidateClientHello. |
60 class ValidateCallback; | 75 class ValidateCallback; |
61 friend class ValidateCallback; | 76 friend class ValidateCallback; |
62 | 77 |
63 void ProcessClientHello( | 78 void ProcessClientHello( |
64 const CryptoHandshakeMessage& client_hello, | 79 const CryptoHandshakeMessage& client_hello, |
65 const ValidateClientHelloResultCallback::Result& result); | 80 const ValidateClientHelloResultCallback::Result& result, |
| 81 std::unique_ptr<StatelessRejector> rejector, |
| 82 std::unique_ptr<StatelessRejector::ProcessDoneCallback> cb); |
66 | 83 |
67 State state_; | 84 State state_; |
68 QuicErrorCode error_; | 85 QuicErrorCode error_; |
69 std::string error_details_; | 86 std::string error_details_; |
70 QuicVersion version_; | 87 QuicVersion version_; |
71 QuicVersionVector versions_; | 88 QuicVersionVector versions_; |
72 QuicConnectionId connection_id_; | 89 QuicConnectionId connection_id_; |
73 QuicConnectionId server_designated_connection_id_; | 90 QuicConnectionId server_designated_connection_id_; |
74 QuicByteCount chlo_packet_size_; | 91 QuicByteCount chlo_packet_size_; |
75 IPEndPoint client_address_; | 92 IPEndPoint client_address_; |
76 IPEndPoint server_address_; | 93 IPEndPoint server_address_; |
77 const QuicClock* clock_; | 94 const QuicClock* clock_; |
78 QuicRandom* random_; | 95 QuicRandom* random_; |
79 const QuicCryptoServerConfig* crypto_config_; | 96 const QuicCryptoServerConfig* crypto_config_; |
80 QuicCompressedCertsCache* compressed_certs_cache_; | 97 QuicCompressedCertsCache* compressed_certs_cache_; |
81 const CryptoHandshakeMessage* chlo_; | 98 CryptoHandshakeMessage chlo_; |
82 CryptoHandshakeMessage reply_; | 99 CryptoHandshakeMessage reply_; |
83 CryptoFramer crypto_framer_; | 100 CryptoFramer crypto_framer_; |
84 QuicCryptoProof proof_; | 101 QuicCryptoProof proof_; |
85 | 102 |
86 DISALLOW_COPY_AND_ASSIGN(StatelessRejector); | 103 DISALLOW_COPY_AND_ASSIGN(StatelessRejector); |
87 }; | 104 }; |
88 | 105 |
89 } // namespace net | 106 } // namespace net |
90 | 107 |
91 #endif // NET_QUIC_STATELESS_REJECTOR_H_ | 108 #endif // NET_QUIC_STATELESS_REJECTOR_H_ |
OLD | NEW |