| 1 |
// Copyright (c) 2018, Google Inc. |
| 2 |
// SPDX-License-Identifier: ISC |
| 3 |
|
| 4 |
#ifndef HEADER_TEST_STATE |
| 5 |
#define HEADER_TEST_STATE |
| 6 |
|
| 7 |
#include <openssl/base.h> |
| 8 |
|
| 9 |
#include <functional> |
| 10 |
#include <memory> |
| 11 |
#include <string> |
| 12 |
#include <vector> |
| 13 |
|
| 14 |
#include "mock_quic_transport.h" |
| 15 |
|
| 16 |
struct TestState { |
| 17 |
// Serialize writes |pending_session| and |msg_callback_text| to |out|, for |
| 18 |
// use in split-handshake tests. We don't try to serialize every bit of test |
| 19 |
// state, but serializing |pending_session| is necessary to exercise session |
| 20 |
// resumption, and |msg_callback_text| is especially useful. In the general |
| 21 |
// case, checks of state updated during the handshake can be skipped when |
| 22 |
// |config->handoff|. |
| 23 |
bool Serialize(CBB *out) const; |
| 24 |
|
| 25 |
// Deserialize returns a new |TestState| from data written by |Serialize|. |
| 26 |
static std::unique_ptr<TestState> Deserialize(CBS *cbs, SSL_CTX *ctx); |
| 27 |
|
| 28 |
// async_bio is async BIO which pauses reads and writes. |
| 29 |
BIO *async_bio = nullptr; |
| 30 |
// packeted_bio is the packeted BIO which simulates read timeouts. |
| 31 |
BIO *packeted_bio = nullptr; |
| 32 |
std::unique_ptr<MockQuicTransport> quic_transport; |
| 33 |
bool cert_ready = false; |
| 34 |
bssl::UniquePtr<SSL_SESSION> session; |
| 35 |
bssl::UniquePtr<SSL_SESSION> pending_session; |
| 36 |
bool early_callback_called = false; |
| 37 |
bool handshake_done = false; |
| 38 |
// private_key is the underlying private key used when testing custom keys. |
| 39 |
bssl::UniquePtr<EVP_PKEY> private_key; |
| 40 |
// When private key methods are used, whether the private key was used. |
| 41 |
bool used_private_key = false; |
| 42 |
std::vector<uint8_t> private_key_result; |
| 43 |
// private_key_retries is the number of times an asynchronous private key |
| 44 |
// operation has been retried. |
| 45 |
unsigned private_key_retries = 0; |
| 46 |
bool got_new_session = false; |
| 47 |
bssl::UniquePtr<SSL_SESSION> new_session; |
| 48 |
bool ticket_decrypt_done = false; |
| 49 |
bool alpn_select_done = false; |
| 50 |
bool early_callback_ready = false; |
| 51 |
bool custom_verify_ready = false; |
| 52 |
std::string msg_callback_text; |
| 53 |
bool msg_callback_ok = true; |
| 54 |
// cert_verified is true if certificate verification has been driven to |
| 55 |
// completion. This tests that the callback is not called again after this. |
| 56 |
bool cert_verified = false; |
| 57 |
int explicit_renegotiates = 0; |
| 58 |
std::function<bool(const SSL_CLIENT_HELLO*)> get_handshake_hints_cb; |
| 59 |
int last_message_received = -1; |
| 60 |
}; |
| 61 |
|
| 62 |
bool SetTestState(SSL *ssl, std::unique_ptr<TestState> state); |
| 63 |
|
| 64 |
TestState *GetTestState(const SSL *ssl); |
| 65 |
|
| 66 |
struct timeval *GetClock(); |
| 67 |
|
| 68 |
void AdvanceClock(unsigned seconds); |
| 69 |
|
| 70 |
void CopySessions(SSL_CTX *dest, const SSL_CTX *src); |
| 71 |
|
| 72 |
// SerializeContextState writes session material (sessions and ticket keys) from |
| 73 |
// |ctx| into |cbb|. |
| 74 |
bool SerializeContextState(SSL_CTX *ctx, CBB *cbb); |
| 75 |
|
| 76 |
// DeserializeContextState updates |out| with material previously serialized by |
| 77 |
// SerializeContextState. |
| 78 |
bool DeserializeContextState(CBS *in, SSL_CTX *out); |
| 79 |
|
| 80 |
#endif // HEADER_TEST_STATE |