| 6 | // |
| 7 | // https://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 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 async_ticket_decrypt_ready = false; |
| 60 | bool ticket_decrypt_done = false; |
| 61 | bool alpn_select_done = false; |
| 62 | bool early_callback_ready = false; |
| 63 | bool custom_verify_ready = false; |
| 64 | std::string msg_callback_text; |
| 65 | bool msg_callback_ok = true; |
| 66 | // cert_verified is true if certificate verification has been driven to |
| 67 | // completion. This tests that the callback is not called again after this. |
| 68 | bool cert_verified = false; |
| 69 | int explicit_renegotiates = 0; |
| 70 | std::function<bool(const SSL_CLIENT_HELLO*)> get_handshake_hints_cb; |
| 71 | int last_message_received = -1; |
| 72 | int selected_credential = -1; |
| 73 | }; |
| 74 |
| 75 | bool SetTestState(SSL *ssl, std::unique_ptr<TestState> state); |
| 76 |
| 77 | TestState *GetTestState(const SSL *ssl); |
| 78 |
| 79 | struct timeval *GetClock(); |
| 80 |
| 81 | void AdvanceClock(unsigned seconds); |
| 82 |
| 83 | void CopySessions(SSL_CTX *dest, const SSL_CTX *src); |
| 84 |
| 85 | // SerializeContextState writes session material (sessions and ticket keys) from |
| 86 | // |ctx| into |cbb|. |
| 87 | bool SerializeContextState(SSL_CTX *ctx, CBB *cbb); |
| 88 |
| 89 | // DeserializeContextState updates |out| with material previously serialized by |
| 90 | // SerializeContextState. |
| 91 | bool DeserializeContextState(CBS *in, SSL_CTX *out); |
| 92 |
| 93 | #endif // HEADER_TEST_STATE |
| 94 |