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
3 // found in the LICENSE file.
5 #ifndef NET_QUIC_QUIC_CRYPTO_CLIENT_STREAM_H_
6 #define NET_QUIC_QUIC_CRYPTO_CLIENT_STREAM_H_
10 #include "net/quic/crypto/channel_id.h"
11 #include "net/quic/crypto/proof_verifier.h"
12 #include "net/quic/crypto/quic_crypto_client_config.h"
13 #include "net/quic/quic_config.h"
14 #include "net/quic/quic_crypto_stream.h"
15 #include "net/quic/quic_server_id.h"
19 class QuicClientSessionBase
;
22 class CryptoTestUtils
;
23 class QuicClientSessionPeer
;
26 class NET_EXPORT_PRIVATE QuicCryptoClientStream
: public QuicCryptoStream
{
28 QuicCryptoClientStream(const QuicServerId
& server_id
,
29 QuicClientSessionBase
* session
,
30 ProofVerifyContext
* verify_context
,
31 QuicCryptoClientConfig
* crypto_config
);
32 virtual ~QuicCryptoClientStream();
34 // CryptoFramerVisitorInterface implementation
35 virtual void OnHandshakeMessage(
36 const CryptoHandshakeMessage
& message
) OVERRIDE
;
38 // Performs a crypto handshake with the server. Returns true if the crypto
39 // handshake is started successfully.
40 // TODO(agl): this should probably return void.
41 virtual bool CryptoConnect();
43 // num_sent_client_hellos returns the number of client hello messages that
44 // have been sent. If the handshake has completed then this is one greater
45 // than the number of round-trips needed for the handshake.
46 int num_sent_client_hellos() const;
48 // Returns true if a channel ID was sent on this connection.
49 bool WasChannelIDSent() const;
51 // Returns true if our ChannelIDSourceCallback was run, which implies the
52 // ChannelIDSource operated asynchronously. Intended for testing.
53 bool WasChannelIDSourceCallbackRun() const;
56 // ChannelIDSourceCallbackImpl is passed as the callback method to
57 // GetChannelIDKey. The ChannelIDSource calls this class with the result of
58 // channel ID lookup when lookup is performed asynchronously.
59 class ChannelIDSourceCallbackImpl
: public ChannelIDSourceCallback
{
61 explicit ChannelIDSourceCallbackImpl(QuicCryptoClientStream
* stream
);
62 virtual ~ChannelIDSourceCallbackImpl();
64 // ChannelIDSourceCallback interface.
65 virtual void Run(scoped_ptr
<ChannelIDKey
>* channel_id_key
) OVERRIDE
;
67 // Cancel causes any future callbacks to be ignored. It must be called on
68 // the same thread as the callback will be made on.
72 QuicCryptoClientStream
* stream_
;
75 // ProofVerifierCallbackImpl is passed as the callback method to VerifyProof.
76 // The ProofVerifier calls this class with the result of proof verification
77 // when verification is performed asynchronously.
78 class ProofVerifierCallbackImpl
: public ProofVerifierCallback
{
80 explicit ProofVerifierCallbackImpl(QuicCryptoClientStream
* stream
);
81 virtual ~ProofVerifierCallbackImpl();
83 // ProofVerifierCallback interface.
84 virtual void Run(bool ok
,
85 const string
& error_details
,
86 scoped_ptr
<ProofVerifyDetails
>* details
) OVERRIDE
;
88 // Cancel causes any future callbacks to be ignored. It must be called on
89 // the same thread as the callback will be made on.
93 QuicCryptoClientStream
* stream_
;
96 friend class test::CryptoTestUtils
;
97 friend class test::QuicClientSessionPeer
;
105 STATE_VERIFY_PROOF_COMPLETE
,
106 STATE_GET_CHANNEL_ID
,
107 STATE_GET_CHANNEL_ID_COMPLETE
,
111 // Handles new server config and optional source-address token provided by the
112 // server during a connection.
113 void HandleServerConfigUpdateMessage(
114 const CryptoHandshakeMessage
& server_config_update
);
116 // DoHandshakeLoop performs a step of the handshake state machine. Note that
117 // |in| may be NULL if the call did not result from a received message.
118 void DoHandshakeLoop(const CryptoHandshakeMessage
* in
);
120 // Called to set the proof of |cached| valid. Also invokes the session's
121 // OnProofValid() method.
122 void SetCachedProofValid(QuicCryptoClientConfig::CachedState
* cached
);
124 // Returns true if the server crypto config in |cached| requires a ChannelID
125 // and the client config settings also allow sending a ChannelID.
126 bool RequiresChannelID(QuicCryptoClientConfig::CachedState
* cached
);
128 QuicClientSessionBase
* client_session();
131 // num_client_hellos_ contains the number of client hello messages that this
132 // connection has sent.
133 int num_client_hellos_
;
135 QuicCryptoClientConfig
* const crypto_config_
;
137 // Client's connection nonce (4-byte timestamp + 28 random bytes)
139 // Server's (hostname, port, is_https, privacy_mode) tuple.
140 const QuicServerId server_id_
;
142 // Generation counter from QuicCryptoClientConfig's CachedState.
143 uint64 generation_counter_
;
145 // True if a channel ID was sent.
146 bool channel_id_sent_
;
148 // True if channel_id_source_callback_ was run.
149 bool channel_id_source_callback_run_
;
151 // channel_id_source_callback_ contains the callback object that we passed
152 // to an asynchronous channel ID lookup. The ChannelIDSource owns this
154 ChannelIDSourceCallbackImpl
* channel_id_source_callback_
;
156 // These members are used to store the result of an asynchronous channel ID
157 // lookup. These members must not be used after
158 // STATE_GET_CHANNEL_ID_COMPLETE.
159 scoped_ptr
<ChannelIDKey
> channel_id_key_
;
161 // verify_context_ contains the context object that we pass to asynchronous
162 // proof verifications.
163 scoped_ptr
<ProofVerifyContext
> verify_context_
;
165 // proof_verify_callback_ contains the callback object that we passed to an
166 // asynchronous proof verification. The ProofVerifier owns this object.
167 ProofVerifierCallbackImpl
* proof_verify_callback_
;
169 // These members are used to store the result of an asynchronous proof
170 // verification. These members must not be used after
171 // STATE_VERIFY_PROOF_COMPLETE.
173 string verify_error_details_
;
174 scoped_ptr
<ProofVerifyDetails
> verify_details_
;
176 DISALLOW_COPY_AND_ASSIGN(QuicCryptoClientStream
);
181 #endif // NET_QUIC_QUIC_CRYPTO_CLIENT_STREAM_H_