handshake_util.h 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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_HANDSHAKE
  15. #define HEADER_TEST_HANDSHAKE
  16. #include <functional>
  17. #include <openssl/base.h>
  18. #include "settings_writer.h"
  19. // RetryAsync is called after a failed operation on |ssl| with return code
  20. // |ret|. If the operation should be retried, it simulates one asynchronous
  21. // event and returns true. Otherwise it returns false.
  22. bool RetryAsync(SSL *ssl, int ret);
  23. // CheckIdempotentError runs |func|, an operation on |ssl|, ensuring that
  24. // errors are idempotent.
  25. int CheckIdempotentError(const char *name, SSL *ssl, std::function<int()> func);
  26. // DoSplitHandshake delegates the SSL handshake to a separate process, called
  27. // the handshaker. This process proxies I/O between the handshaker and the
  28. // client, using the |BIO| from |ssl|. After a successful handshake, |ssl| is
  29. // replaced with a new |SSL| object, in a way that is intended to be invisible
  30. // to the caller.
  31. bool DoSplitHandshake(bssl::UniquePtr<SSL> *ssl, SettingsWriter *writer,
  32. bool is_resume);
  33. // The protocol between the proxy and the handshaker is defined by these
  34. // single-character prefixes.
  35. constexpr char kControlMsgWantRead = 'R'; // Handshaker wants data
  36. constexpr char kControlMsgWriteCompleted = 'W'; // Proxy has sent data
  37. constexpr char kControlMsgHandback = 'H'; // Proxy should resume control
  38. constexpr char kControlMsgError = 'E'; // Handshaker hit an error
  39. // The protocol between the proxy and handshaker uses these file descriptors.
  40. constexpr int kFdControl = 3; // Bi-directional dgram socket.
  41. constexpr int kFdProxyToHandshaker = 4; // Uni-directional pipe.
  42. constexpr int kFdHandshakerToProxy = 5; // Uni-directional pipe.
  43. #endif // HEADER_TEST_HANDSHAKE