File: mock_crypto_client_stream.h

package info (click to toggle)
chromium 139.0.7258.127-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 6,122,068 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (126 lines) | stat: -rw-r--r-- 4,892 bytes parent folder | download | duplicates (11)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
// Copyright 2013 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef NET_QUIC_MOCK_CRYPTO_CLIENT_STREAM_H_
#define NET_QUIC_MOCK_CRYPTO_CLIENT_STREAM_H_

#include "base/memory/raw_ptr.h"
#include "base/memory/weak_ptr.h"
#include "net/quic/crypto/proof_verifier_chromium.h"
#include "net/third_party/quiche/src/quiche/quic/core/crypto/crypto_handshake.h"
#include "net/third_party/quiche/src/quiche/quic/core/crypto/crypto_protocol.h"
#include "net/third_party/quiche/src/quiche/quic/core/http/quic_spdy_client_session_base.h"
#include "net/third_party/quiche/src/quiche/quic/core/quic_crypto_client_stream.h"
#include "net/third_party/quiche/src/quiche/quic/core/quic_server_id.h"
#include "net/third_party/quiche/src/quiche/quic/core/quic_session.h"

namespace net {

class MockCryptoClientStream : public quic::QuicCryptoClientStream,
                               public quic::QuicCryptoHandshaker {
 public:
  // HandshakeMode enumerates the handshake mode MockCryptoClientStream should
  // mock in CryptoConnect.
  enum HandshakeMode {
    // CONFIRM_HANDSHAKE indicates that CryptoConnect will immediately confirm
    // the handshake and establish encryption.  This behavior will never happen
    // in the field, but is convenient for higher level tests.
    CONFIRM_HANDSHAKE,

    // ZERO_RTT indicates that CryptoConnect will establish encryption but will
    // not confirm the handshake.
    ZERO_RTT,

    // ASYNC_ZERO_RTT indicates that 0-RTT setup will be completed
    // asynchronously. This is possible in TLS. Tests need to call
    // NotifySessionZeroRttComplete() to setup 0-RTT encryption.
    ASYNC_ZERO_RTT,

    // COLD_START indicates that CryptoConnect will neither establish encryption
    // nor confirm the handshake.
    COLD_START,

    // COLD_START_WITH_CHLO_SENT indicates that CryptoConnection will attempt to
    // establish encryption by sending the initial CHLO packet on wire, which
    // contains an empty CryptoHandshakeMessage. It will not confirm the
    // hanshake though.
    COLD_START_WITH_CHLO_SENT,
  };

  MockCryptoClientStream(
      const quic::QuicServerId& server_id,
      quic::QuicSpdyClientSessionBase* session,
      std::unique_ptr<quic::ProofVerifyContext> verify_context,
      const quic::QuicConfig& config,
      quic::QuicCryptoClientConfig* crypto_config,
      HandshakeMode handshake_mode,
      const net::ProofVerifyDetailsChromium* proof_verify_details_,
      bool use_mock_crypter);

  MockCryptoClientStream(const MockCryptoClientStream&) = delete;
  MockCryptoClientStream& operator=(const MockCryptoClientStream&) = delete;

  ~MockCryptoClientStream() override;

  // CryptoFramerVisitorInterface implementation.
  void OnHandshakeMessage(const quic::CryptoHandshakeMessage& message) override;

  // QuicCryptoClientStream implementation.
  bool CryptoConnect() override;
  bool encryption_established() const override;
  bool one_rtt_keys_available() const override;
  quic::HandshakeState GetHandshakeState() const override;
  const quic::QuicCryptoNegotiatedParameters& crypto_negotiated_params()
      const override;
  quic::CryptoMessageParser* crypto_message_parser() override;
  void OnOneRttPacketAcknowledged() override;
  std::unique_ptr<quic::QuicDecrypter>
  AdvanceKeysAndCreateCurrentOneRttDecrypter() override;
  bool EarlyDataAccepted() const override;
  // Override QuicCryptoClientStream::SetServerApplicationStateForResumption()
  // to avoid tripping over the DCHECK on handshaker state.
  void SetServerApplicationStateForResumption(
      std::unique_ptr<quic::ApplicationState> application_state) override {}

  // Notify session that 1-RTT key is available.
  void NotifySessionOneRttKeyAvailable();

  // Notify session that 0-RTT setup is complete.
  void NotifySessionZeroRttComplete();

  base::WeakPtr<MockCryptoClientStream> GetWeakPtr() {
    return weak_factory_.GetWeakPtr();
  }

  void setHandshakeConfirmedForce(bool state);

  static quic::CryptoHandshakeMessage GetDummyCHLOMessage();

 protected:
  using quic::QuicCryptoClientStream::session;

 private:
  void SetConfigNegotiated();

  // Called from CryptoConnect to set appropriate values in
  // |crypto_negotiated_params_|.
  void FillCryptoParams();

  HandshakeMode handshake_mode_;
  bool encryption_established_ = false;
  bool handshake_confirmed_ = false;
  quiche::QuicheReferenceCountedPointer<quic::QuicCryptoNegotiatedParameters>
      crypto_negotiated_params_;
  quic::CryptoFramer crypto_framer_;
  bool use_mock_crypter_;

  const quic::QuicServerId server_id_;
  raw_ptr<const net::ProofVerifyDetailsChromium> proof_verify_details_;
  const quic::QuicConfig config_;
  base::WeakPtrFactory<MockCryptoClientStream> weak_factory_{this};
};

}  // namespace net

#endif  // NET_QUIC_MOCK_CRYPTO_CLIENT_STREAM_H_