• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.
4 
5 #ifndef NET_QUIC_QUIC_CRYPTO_CLIENT_STREAM_H_
6 #define NET_QUIC_QUIC_CRYPTO_CLIENT_STREAM_H_
7 
8 #include <string>
9 
10 #include "net/cert/cert_verify_result.h"
11 #include "net/cert/x509_certificate.h"
12 #include "net/quic/crypto/proof_verifier.h"
13 #include "net/quic/crypto/quic_crypto_client_config.h"
14 #include "net/quic/quic_config.h"
15 #include "net/quic/quic_crypto_stream.h"
16 
17 namespace net {
18 
19 class ProofVerifyDetails;
20 class QuicSession;
21 class SSLInfo;
22 
23 namespace test {
24 class CryptoTestUtils;
25 }  // namespace test
26 
27 class NET_EXPORT_PRIVATE QuicCryptoClientStream : public QuicCryptoStream {
28  public:
29   QuicCryptoClientStream(const string& server_hostname,
30                          QuicSession* session,
31                          QuicCryptoClientConfig* crypto_config);
32   virtual ~QuicCryptoClientStream();
33 
34   // CryptoFramerVisitorInterface implementation
35   virtual void OnHandshakeMessage(
36       const CryptoHandshakeMessage& message) OVERRIDE;
37 
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();
42 
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;
47 
48   // Gets the SSL connection information.
49   bool GetSSLInfo(SSLInfo* ssl_info);
50 
51  private:
52   // ProofVerifierCallbackImpl is passed as the callback method to VerifyProof.
53   // The ProofVerifier calls this class with the result of proof verification
54   // when verification is performed asynchronously.
55   class ProofVerifierCallbackImpl : public ProofVerifierCallback {
56    public:
57     explicit ProofVerifierCallbackImpl(QuicCryptoClientStream* stream);
58     virtual ~ProofVerifierCallbackImpl();
59 
60     // ProofVerifierCallback interface.
61     virtual void Run(bool ok,
62                      const string& error_details,
63                      scoped_ptr<ProofVerifyDetails>* details) OVERRIDE;
64 
65     // Cancel causes any future callbacks to be ignored. It must be called on
66     // the same thread as the callback will be made on.
67     void Cancel();
68 
69    private:
70     QuicCryptoClientStream* stream_;
71   };
72 
73   friend class test::CryptoTestUtils;
74   friend class ProofVerifierCallbackImpl;
75 
76   enum State {
77     STATE_IDLE,
78     STATE_SEND_CHLO,
79     STATE_RECV_REJ,
80     STATE_VERIFY_PROOF,
81     STATE_VERIFY_PROOF_COMPLETE,
82     STATE_RECV_SHLO,
83   };
84 
85   // DoHandshakeLoop performs a step of the handshake state machine. Note that
86   // |in| may be NULL if the call did not result from a received message
87   void DoHandshakeLoop(const CryptoHandshakeMessage* in);
88 
89   State next_state_;
90   // num_client_hellos_ contains the number of client hello messages that this
91   // connection has sent.
92   int num_client_hellos_;
93 
94   QuicCryptoClientConfig* const crypto_config_;
95 
96   // Client's connection nonce (4-byte timestamp + 28 random bytes)
97   std::string nonce_;
98   // Server's hostname
99   std::string server_hostname_;
100 
101   // Generation counter from QuicCryptoClientConfig's CachedState.
102   uint64 generation_counter_;
103 
104   // proof_verify_callback_ contains the callback object that we passed to an
105   // asynchronous proof verification. The ProofVerifier owns this object.
106   ProofVerifierCallbackImpl* proof_verify_callback_;
107 
108   // These members are used to store the result of an asynchronous proof
109   // verification. These members must not be used after
110   // STATE_VERIFY_PROOF_COMPLETE.
111   bool verify_ok_;
112   string verify_error_details_;
113   scoped_ptr<ProofVerifyDetails> verify_details_;
114 
115   // The result of certificate verification.
116   scoped_ptr<CertVerifyResult> cert_verify_result_;
117 
118   DISALLOW_COPY_AND_ASSIGN(QuicCryptoClientStream);
119 };
120 
121 }  // namespace net
122 
123 #endif  // NET_QUIC_QUIC_CRYPTO_CLIENT_STREAM_H_
124