mock_quic_transport.h
Go to the documentation of this file.
1 /* Copyright (c) 2019, Google Inc.
2  *
3  * Permission to use, copy, modify, and/or distribute this software for any
4  * purpose with or without fee is hereby granted, provided that the above
5  * copyright notice and this permission notice appear in all copies.
6  *
7  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
8  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
9  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
10  * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
11  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
12  * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
13  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */
14 
15 #ifndef HEADER_MOCK_QUIC_TRANSPORT
16 #define HEADER_MOCK_QUIC_TRANSPORT
17 
18 #include <openssl/base.h>
19 #include <openssl/bio.h>
20 #include <openssl/ssl.h>
21 
22 #include <vector>
23 
25  public:
26  explicit MockQuicTransport(bssl::UniquePtr<BIO> bio, SSL *ssl);
27 
28  bool SetReadSecret(enum ssl_encryption_level_t level,
29  const SSL_CIPHER *cipher, const uint8_t *secret,
30  size_t secret_len);
31  bool SetWriteSecret(enum ssl_encryption_level_t level,
32  const SSL_CIPHER *cipher, const uint8_t *secret,
33  size_t secret_len);
34 
35  bool ReadHandshake();
36  bool WriteHandshakeData(enum ssl_encryption_level_t level,
37  const uint8_t *data, size_t len);
38  // Returns the number of bytes read.
39  int ReadApplicationData(uint8_t *out, size_t max_out);
40  bool WriteApplicationData(const uint8_t *in, size_t len);
41  bool Flush();
42  bool SendAlert(enum ssl_encryption_level_t level, uint8_t alert);
43 
44  private:
45  // Reads a record header from |bio_| and returns whether the record was read
46  // successfully. As part of reading the header, this function checks that the
47  // cipher suite and secret in the header are correct. On success, the TLS
48  // record type is put in |*out_type|, the encryption level is put in
49  // |*out_level|, the length of the TLS record is put in |*out_len|, and the
50  // next thing to be read from |bio_| is |*out_len| bytes of the TLS record.
51  bool ReadHeader(uint8_t *out_type, enum ssl_encryption_level_t *out_level,
52  size_t *out_len);
53 
54  // Writes a MockQuicTransport record to |bio_| at encryption level |level|
55  // with record type |type| and a TLS record payload of length |len| from
56  // |data|.
57  bool WriteRecord(enum ssl_encryption_level_t level, uint8_t type,
58  const uint8_t *data, size_t len);
59 
60  bssl::UniquePtr<BIO> bio_;
61 
62  std::vector<uint8_t> pending_app_data_;
64 
65  struct EncryptionLevel {
67  std::vector<uint8_t> secret;
68  };
69 
70  std::vector<EncryptionLevel> read_levels_;
71  std::vector<EncryptionLevel> write_levels_;
72 
73  SSL *ssl_; // Unowned.
74 };
75 
76 
77 #endif // HEADER_MOCK_QUIC_TRANSPORT
MockQuicTransport::Flush
bool Flush()
Definition: mock_quic_transport.cc:274
ssl_cipher_st
Definition: third_party/boringssl-with-bazel/src/ssl/internal.h:520
gen_build_yaml.out
dictionary out
Definition: src/benchmark/gen_build_yaml.py:24
MockQuicTransport::EncryptionLevel
Definition: mock_quic_transport.h:65
uint16_t
unsigned short uint16_t
Definition: stdint-msvc2008.h:79
MockQuicTransport::EncryptionLevel::secret
std::vector< uint8_t > secret
Definition: mock_quic_transport.h:67
bio.h
MockQuicTransport::WriteRecord
bool WriteRecord(enum ssl_encryption_level_t level, uint8_t type, const uint8_t *data, size_t len)
Definition: mock_quic_transport.cc:241
MockQuicTransport::WriteApplicationData
bool WriteApplicationData(const uint8_t *in, size_t len)
Definition: mock_quic_transport.cc:266
uint8_t
unsigned char uint8_t
Definition: stdint-msvc2008.h:78
base.h
MockQuicTransport::ReadHeader
bool ReadHeader(uint8_t *out_type, enum ssl_encryption_level_t *out_level, size_t *out_len)
Definition: mock_quic_transport.cc:84
MockQuicTransport::MockQuicTransport
MockQuicTransport(bssl::UniquePtr< BIO > bio, SSL *ssl)
Definition: mock_quic_transport.cc:22
in
const char * in
Definition: third_party/abseil-cpp/absl/strings/internal/str_format/parser_test.cc:391
MockQuicTransport::read_levels_
std::vector< EncryptionLevel > read_levels_
Definition: mock_quic_transport.h:70
MockQuicTransport::app_data_offset_
size_t app_data_offset_
Definition: mock_quic_transport.h:63
ssl_st
Definition: third_party/boringssl-with-bazel/src/ssl/internal.h:3698
MockQuicTransport::pending_app_data_
std::vector< uint8_t > pending_app_data_
Definition: mock_quic_transport.h:62
MockQuicTransport::bio_
bssl::UniquePtr< BIO > bio_
Definition: mock_quic_transport.h:60
data
char data[kBufferLength]
Definition: abseil-cpp/absl/strings/internal/str_format/float_conversion.cc:1006
MockQuicTransport::SetReadSecret
bool SetReadSecret(enum ssl_encryption_level_t level, const SSL_CIPHER *cipher, const uint8_t *secret, size_t secret_len)
Definition: mock_quic_transport.cc:28
MockQuicTransport::SendAlert
bool SendAlert(enum ssl_encryption_level_t level, uint8_t alert)
Definition: mock_quic_transport.cc:276
ssl.h
MockQuicTransport::ReadApplicationData
int ReadApplicationData(uint8_t *out, size_t max_out)
Definition: mock_quic_transport.cc:172
MockQuicTransport::SetWriteSecret
bool SetWriteSecret(enum ssl_encryption_level_t level, const SSL_CIPHER *cipher, const uint8_t *secret, size_t secret_len)
Definition: mock_quic_transport.cc:38
MockQuicTransport::ReadHandshake
bool ReadHandshake()
Definition: mock_quic_transport.cc:154
MockQuicTransport::ssl_
SSL * ssl_
Definition: mock_quic_transport.h:73
MockQuicTransport::EncryptionLevel::cipher
uint16_t cipher
Definition: mock_quic_transport.h:66
MockQuicTransport
Definition: mock_quic_transport.h:24
client.level
level
Definition: examples/python/async_streaming/client.py:118
asyncio_get_stats.type
type
Definition: asyncio_get_stats.py:37
len
int len
Definition: abseil-cpp/absl/base/internal/low_level_alloc_test.cc:46
MockQuicTransport::WriteHandshakeData
bool WriteHandshakeData(enum ssl_encryption_level_t level, const uint8_t *data, size_t len)
Definition: mock_quic_transport.cc:261
MockQuicTransport::write_levels_
std::vector< EncryptionLevel > write_levels_
Definition: mock_quic_transport.h:71


grpc
Author(s):
autogenerated on Fri May 16 2025 02:59:30