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;
52 // ChannelIDSourceCallbackImpl is passed as the callback method to
53 // GetChannelIDKey. The ChannelIDSource calls this class with the result of
54 // channel ID lookup when lookup is performed asynchronously.
55 class ChannelIDSourceCallbackImpl
: public ChannelIDSourceCallback
{
57 explicit ChannelIDSourceCallbackImpl(QuicCryptoClientStream
* stream
);
58 virtual ~ChannelIDSourceCallbackImpl();
60 // ChannelIDSourceCallback interface.
61 virtual void Run(scoped_ptr
<ChannelIDKey
>* channel_id_key
) OVERRIDE
;
63 // Cancel causes any future callbacks to be ignored. It must be called on
64 // the same thread as the callback will be made on.
68 QuicCryptoClientStream
* stream_
;
71 // ProofVerifierCallbackImpl is passed as the callback method to VerifyProof.
72 // The ProofVerifier calls this class with the result of proof verification
73 // when verification is performed asynchronously.
74 class ProofVerifierCallbackImpl
: public ProofVerifierCallback
{
76 explicit ProofVerifierCallbackImpl(QuicCryptoClientStream
* stream
);
77 virtual ~ProofVerifierCallbackImpl();
79 // ProofVerifierCallback interface.
80 virtual void Run(bool ok
,
81 const string
& error_details
,
82 scoped_ptr
<ProofVerifyDetails
>* details
) OVERRIDE
;
84 // Cancel causes any future callbacks to be ignored. It must be called on
85 // the same thread as the callback will be made on.
89 QuicCryptoClientStream
* stream_
;
92 friend class test::CryptoTestUtils
;
93 friend class test::QuicClientSessionPeer
;
101 STATE_VERIFY_PROOF_COMPLETE
,
102 STATE_GET_CHANNEL_ID
,
103 STATE_GET_CHANNEL_ID_COMPLETE
,
107 // DoHandshakeLoop performs a step of the handshake state machine. Note that
108 // |in| may be NULL if the call did not result from a received message.
109 void DoHandshakeLoop(const CryptoHandshakeMessage
* in
);
111 // Called to set the proof of |cached| valid. Also invokes the session's
112 // OnProofValid() method.
113 void SetCachedProofValid(QuicCryptoClientConfig::CachedState
* cached
);
115 // Returns true if the server crypto config in |cached| requires a ChannelID
116 // and the client config settings also allow sending a ChannelID.
117 bool RequiresChannelID(QuicCryptoClientConfig::CachedState
* cached
);
119 QuicClientSessionBase
* client_session();
122 // num_client_hellos_ contains the number of client hello messages that this
123 // connection has sent.
124 int num_client_hellos_
;
126 QuicCryptoClientConfig
* const crypto_config_
;
128 // Client's connection nonce (4-byte timestamp + 28 random bytes)
130 // Server's (hostname, port, is_https, privacy_mode) tuple.
131 const QuicServerId server_id_
;
133 // Generation counter from QuicCryptoClientConfig's CachedState.
134 uint64 generation_counter_
;
136 // channel_id_source_callback_ contains the callback object that we passed
137 // to an asynchronous channel ID lookup. The ChannelIDSource owns this
139 ChannelIDSourceCallbackImpl
* channel_id_source_callback_
;
141 // These members are used to store the result of an asynchronous channel ID
142 // lookup. These members must not be used after
143 // STATE_GET_CHANNEL_ID_COMPLETE.
144 scoped_ptr
<ChannelIDKey
> channel_id_key_
;
146 // verify_context_ contains the context object that we pass to asynchronous
147 // proof verifications.
148 scoped_ptr
<ProofVerifyContext
> verify_context_
;
150 // proof_verify_callback_ contains the callback object that we passed to an
151 // asynchronous proof verification. The ProofVerifier owns this object.
152 ProofVerifierCallbackImpl
* proof_verify_callback_
;
154 // These members are used to store the result of an asynchronous proof
155 // verification. These members must not be used after
156 // STATE_VERIFY_PROOF_COMPLETE.
158 string verify_error_details_
;
159 scoped_ptr
<ProofVerifyDetails
> verify_details_
;
161 DISALLOW_COPY_AND_ASSIGN(QuicCryptoClientStream
);
166 #endif // NET_QUIC_QUIC_CRYPTO_CLIENT_STREAM_H_