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/proof_verifier.h"
11 #include "net/quic/crypto/quic_crypto_client_config.h"
12 #include "net/quic/quic_config.h"
13 #include "net/quic/quic_crypto_stream.h"
14 #include "net/quic/quic_session_key.h"
18 class QuicClientSessionBase
;
21 class CryptoTestUtils
;
24 class NET_EXPORT_PRIVATE QuicCryptoClientStream
: public QuicCryptoStream
{
26 QuicCryptoClientStream(const QuicSessionKey
& server_key
,
27 QuicClientSessionBase
* session
,
28 ProofVerifyContext
* verify_context
,
29 QuicCryptoClientConfig
* crypto_config
);
30 virtual ~QuicCryptoClientStream();
32 // CryptoFramerVisitorInterface implementation
33 virtual void OnHandshakeMessage(
34 const CryptoHandshakeMessage
& message
) OVERRIDE
;
36 // Performs a crypto handshake with the server. Returns true if the crypto
37 // handshake is started successfully.
38 // TODO(agl): this should probably return void.
39 virtual bool CryptoConnect();
41 // num_sent_client_hellos returns the number of client hello messages that
42 // have been sent. If the handshake has completed then this is one greater
43 // than the number of round-trips needed for the handshake.
44 int num_sent_client_hellos() const;
47 // ProofVerifierCallbackImpl is passed as the callback method to VerifyProof.
48 // The ProofVerifier calls this class with the result of proof verification
49 // when verification is performed asynchronously.
50 class ProofVerifierCallbackImpl
: public ProofVerifierCallback
{
52 explicit ProofVerifierCallbackImpl(QuicCryptoClientStream
* stream
);
53 virtual ~ProofVerifierCallbackImpl();
55 // ProofVerifierCallback interface.
56 virtual void Run(bool ok
,
57 const string
& error_details
,
58 scoped_ptr
<ProofVerifyDetails
>* details
) OVERRIDE
;
60 // Cancel causes any future callbacks to be ignored. It must be called on
61 // the same thread as the callback will be made on.
65 QuicCryptoClientStream
* stream_
;
68 friend class test::CryptoTestUtils
;
69 friend class ProofVerifierCallbackImpl
;
77 STATE_VERIFY_PROOF_COMPLETE
,
81 // DoHandshakeLoop performs a step of the handshake state machine. Note that
82 // |in| may be NULL if the call did not result from a received message.
83 void DoHandshakeLoop(const CryptoHandshakeMessage
* in
);
85 // Called to set the proof of |cached| valid. Also invokes the session's
86 // OnProofValid() method.
87 void SetCachedProofValid(QuicCryptoClientConfig::CachedState
* cached
);
89 QuicClientSessionBase
* client_session();
92 // num_client_hellos_ contains the number of client hello messages that this
93 // connection has sent.
94 int num_client_hellos_
;
96 QuicCryptoClientConfig
* const crypto_config_
;
98 // Client's connection nonce (4-byte timestamp + 28 random bytes)
100 // Server's (hostname, port, is_https) tuple.
101 const QuicSessionKey server_key_
;
103 // Generation counter from QuicCryptoClientConfig's CachedState.
104 uint64 generation_counter_
;
106 // proof_verify_callback_ contains the callback object that we passed to an
107 // asynchronous proof verification. The ProofVerifier owns this object.
108 ProofVerifierCallbackImpl
* proof_verify_callback_
;
110 // These members are used to store the result of an asynchronous proof
111 // verification. These members must not be used after
112 // STATE_VERIFY_PROOF_COMPLETE.
114 string verify_error_details_
;
115 scoped_ptr
<ProofVerifyDetails
> verify_details_
;
116 scoped_ptr
<ProofVerifyContext
> verify_context_
;
118 DISALLOW_COPY_AND_ASSIGN(QuicCryptoClientStream
);
123 #endif // NET_QUIC_QUIC_CRYPTO_CLIENT_STREAM_H_