test_state.h
Go to the documentation of this file.
1 /* Copyright (c) 2018, 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_TEST_STATE
16 #define HEADER_TEST_STATE
17 
18 #include <openssl/base.h>
19 
20 #include <functional>
21 #include <memory>
22 #include <string>
23 #include <vector>
24 
25 #include "mock_quic_transport.h"
26 
27 struct TestState {
28  // Serialize writes |pending_session| and |msg_callback_text| to |out|, for
29  // use in split-handshake tests. We don't try to serialize every bit of test
30  // state, but serializing |pending_session| is necessary to exercise session
31  // resumption, and |msg_callback_text| is especially useful. In the general
32  // case, checks of state updated during the handshake can be skipped when
33  // |config->handoff|.
34  bool Serialize(CBB *out) const;
35 
36  // Deserialize returns a new |TestState| from data written by |Serialize|.
37  static std::unique_ptr<TestState> Deserialize(CBS *cbs, SSL_CTX *ctx);
38 
39  // async_bio is async BIO which pauses reads and writes.
40  BIO *async_bio = nullptr;
41  // packeted_bio is the packeted BIO which simulates read timeouts.
42  BIO *packeted_bio = nullptr;
43  std::unique_ptr<MockQuicTransport> quic_transport;
44  bool cert_ready = false;
45  bssl::UniquePtr<SSL_SESSION> session;
46  bssl::UniquePtr<SSL_SESSION> pending_session;
47  bool early_callback_called = false;
48  bool handshake_done = false;
49  // private_key is the underlying private key used when testing custom keys.
50  bssl::UniquePtr<EVP_PKEY> private_key;
51  // When private key methods are used, whether the private key was used.
52  bool used_private_key = false;
53  std::vector<uint8_t> private_key_result;
54  // private_key_retries is the number of times an asynchronous private key
55  // operation has been retried.
56  unsigned private_key_retries = 0;
57  bool got_new_session = false;
58  bssl::UniquePtr<SSL_SESSION> new_session;
59  bool ticket_decrypt_done = false;
60  bool alpn_select_done = false;
61  bool early_callback_ready = false;
62  bool custom_verify_ready = false;
64  bool msg_callback_ok = true;
65  // cert_verified is true if certificate verification has been driven to
66  // completion. This tests that the callback is not called again after this.
67  bool cert_verified = false;
71 };
72 
73 bool SetTestState(SSL *ssl, std::unique_ptr<TestState> state);
74 
75 TestState *GetTestState(const SSL *ssl);
76 
77 struct timeval *GetClock();
78 
79 void AdvanceClock(unsigned seconds);
80 
81 void CopySessions(SSL_CTX *dest, const SSL_CTX *src);
82 
83 // SerializeContextState writes session material (sessions and ticket keys) from
84 // |ctx| into |cbb|.
86 
87 // DeserializeContextState updates |out| with material previously serialized by
88 // SerializeContextState.
90 
91 #endif // HEADER_TEST_STATE
absl::time_internal::cctz::seconds
std::chrono::duration< std::int_fast64_t > seconds
Definition: abseil-cpp/absl/time/internal/cctz/include/cctz/time_zone.h:40
gen_build_yaml.out
dictionary out
Definition: src/benchmark/gen_build_yaml.py:24
cbs_st
Definition: bytestring.h:39
ctx
Definition: benchmark-async.c:30
bool
bool
Definition: setup_once.h:312
CopySessions
void CopySessions(SSL_CTX *dest, const SSL_CTX *src)
Definition: test_state.cc:76
bio_st
Definition: bio.h:822
TestState::Serialize
bool Serialize(CBB *out) const
Definition: test_state.cc:130
TestState::used_private_key
bool used_private_key
Definition: test_state.h:52
AdvanceClock
void AdvanceClock(unsigned seconds)
Definition: test_state.cc:47
TestState::handshake_done
bool handshake_done
Definition: test_state.h:48
testing::internal::string
::std::string string
Definition: bloaty/third_party/protobuf/third_party/googletest/googletest/include/gtest/internal/gtest-port.h:881
mock_quic_transport.h
TestState::early_callback_ready
bool early_callback_ready
Definition: test_state.h:61
TestState::alpn_select_done
bool alpn_select_done
Definition: test_state.h:60
cbs
const CBS * cbs
Definition: third_party/boringssl-with-bazel/src/crypto/trust_token/internal.h:107
ssl_ctx_st
Definition: third_party/boringssl-with-bazel/src/ssl/internal.h:3404
TestState::msg_callback_text
std::string msg_callback_text
Definition: test_state.h:63
base.h
TestState::last_message_received
int last_message_received
Definition: test_state.h:70
TestState::Deserialize
static std::unique_ptr< TestState > Deserialize(CBS *cbs, SSL_CTX *ctx)
Definition: test_state.cc:149
TestState::packeted_bio
BIO * packeted_bio
Definition: test_state.h:42
TestState::explicit_renegotiates
int explicit_renegotiates
Definition: test_state.h:68
TestState::cert_verified
bool cert_verified
Definition: test_state.h:67
in
const char * in
Definition: third_party/abseil-cpp/absl/strings/internal/str_format/parser_test.cc:391
TestState::private_key
bssl::UniquePtr< EVP_PKEY > private_key
Definition: test_state.h:50
ssl_st
Definition: third_party/boringssl-with-bazel/src/ssl/internal.h:3698
GetTestState
TestState * GetTestState(const SSL *ssl)
Definition: test_state.cc:62
ssl_early_callback_ctx
Definition: ssl.h:4186
SetTestState
bool SetTestState(SSL *ssl, std::unique_ptr< TestState > state)
Definition: test_state.cc:52
TestState::msg_callback_ok
bool msg_callback_ok
Definition: test_state.h:64
TestState::ticket_decrypt_done
bool ticket_decrypt_done
Definition: test_state.h:59
SerializeContextState
bool SerializeContextState(SSL_CTX *ctx, CBB *cbb)
Definition: test_state.cc:85
TestState::early_callback_called
bool early_callback_called
Definition: test_state.h:47
TestState::private_key_result
std::vector< uint8_t > private_key_result
Definition: test_state.h:53
TestState
Definition: test_state.h:27
TestState::get_handshake_hints_cb
std::function< bool(const SSL_CLIENT_HELLO *)> get_handshake_hints_cb
Definition: test_state.h:69
DeserializeContextState
bool DeserializeContextState(CBS *in, SSL_CTX *out)
Definition: test_state.cc:106
tests.qps.qps_worker.dest
dest
Definition: qps_worker.py:45
TestState::cert_ready
bool cert_ready
Definition: test_state.h:44
TestState::session
bssl::UniquePtr< SSL_SESSION > session
Definition: test_state.h:45
timeval
Definition: setup_once.h:113
TestState::pending_session
bssl::UniquePtr< SSL_SESSION > pending_session
Definition: test_state.h:46
state
Definition: bloaty/third_party/zlib/contrib/blast/blast.c:41
GetClock
struct timeval * GetClock()
Definition: test_state.cc:42
TestState::custom_verify_ready
bool custom_verify_ready
Definition: test_state.h:62
TestState::new_session
bssl::UniquePtr< SSL_SESSION > new_session
Definition: test_state.h:58
function
std::function< bool(GrpcTool *, int, const char **, const CliCredentials &, GrpcToolOutputCallback)> function
Definition: grpc_tool.cc:250
TestState::private_key_retries
unsigned private_key_retries
Definition: test_state.h:56
TestState::async_bio
BIO * async_bio
Definition: test_state.h:40
TestState::quic_transport
std::unique_ptr< MockQuicTransport > quic_transport
Definition: test_state.h:43
TestState::got_new_session
bool got_new_session
Definition: test_state.h:57
cbb_st
Definition: bytestring.h:375


grpc
Author(s):
autogenerated on Thu Mar 13 2025 03:01:32