test_state.h 3.2 KB

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