• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <memory>
19 #include <string>
20 #include <vector>
21 
22 #include <openssl/base.h>
23 
24 struct TestState {
25   // Serialize writes |pending_session| and |msg_callback_text| to |out|, for
26   // use in split-handshake tests.  We don't try to serialize every bit of test
27   // state, but serializing |pending_session| is necessary to exercise session
28   // resumption, and |msg_callback_text| is especially useful.  In the general
29   // case, checks of state updated during the handshake can be skipped when
30   // |config->handoff|.
31   bool Serialize(CBB *out) const;
32 
33   // Deserialize returns a new |TestState| from data written by |Serialize|.
34   static std::unique_ptr<TestState> Deserialize(CBS *cbs, SSL_CTX *ctx);
35 
36   // async_bio is async BIO which pauses reads and writes.
37   BIO *async_bio = nullptr;
38   // packeted_bio is the packeted BIO which simulates read timeouts.
39   BIO *packeted_bio = nullptr;
40   bssl::UniquePtr<EVP_PKEY> channel_id;
41   bool cert_ready = false;
42   bssl::UniquePtr<SSL_SESSION> session;
43   bssl::UniquePtr<SSL_SESSION> pending_session;
44   bool early_callback_called = false;
45   bool handshake_done = false;
46   // private_key is the underlying private key used when testing custom keys.
47   bssl::UniquePtr<EVP_PKEY> private_key;
48   std::vector<uint8_t> private_key_result;
49   // private_key_retries is the number of times an asynchronous private key
50   // operation has been retried.
51   unsigned private_key_retries = 0;
52   bool got_new_session = false;
53   bssl::UniquePtr<SSL_SESSION> new_session;
54   bool ticket_decrypt_done = false;
55   bool alpn_select_done = false;
56   bool is_resume = false;
57   bool early_callback_ready = false;
58   bool custom_verify_ready = false;
59   std::string msg_callback_text;
60   bool msg_callback_ok = true;
61   // cert_verified is true if certificate verification has been driven to
62   // completion. This tests that the callback is not called again after this.
63   bool cert_verified = false;
64 };
65 
66 bool SetTestState(SSL *ssl, std::unique_ptr<TestState> state);
67 
68 TestState *GetTestState(const SSL *ssl);
69 
70 struct timeval *GetClock();
71 
72 void AdvanceClock(unsigned seconds);
73 
74 void CopySessions(SSL_CTX *dest, const SSL_CTX *src);
75 
76 // SerializeContextState writes session material (sessions and ticket keys) from
77 // |ctx| into |cbb|.
78 bool SerializeContextState(SSL_CTX *ctx, CBB *cbb);
79 
80 // DeserializeContextState updates |out| with material previously serialized by
81 // SerializeContextState.
82 bool DeserializeContextState(CBS *in, SSL_CTX *out);
83 
84 #endif  // HEADER_TEST_STATE
85