| 1 |
// Copyright (c) 2018, Google Inc. |
| 2 |
// SPDX-License-Identifier: ISC |
| 3 |
|
| 4 |
#ifndef HEADER_TEST_HANDSHAKE |
| 5 |
#define HEADER_TEST_HANDSHAKE |
| 6 |
|
| 7 |
#include <functional> |
| 8 |
|
| 9 |
#include <openssl/base.h> |
| 10 |
|
| 11 |
#include "settings_writer.h" |
| 12 |
|
| 13 |
|
| 14 |
#if defined(OPENSSL_LINUX) && !defined(OPENSSL_ANDROID) |
| 15 |
#define HANDSHAKER_SUPPORTED |
| 16 |
#endif |
| 17 |
|
| 18 |
// RetryAsync is called after a failed operation on |ssl| with return code |
| 19 |
// |ret|. If the operation should be retried, it simulates one asynchronous |
| 20 |
// event and returns true. Otherwise it returns false. |
| 21 |
bool RetryAsync(SSL *ssl, int ret); |
| 22 |
|
| 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 |
|
| 27 |
#if defined(HANDSHAKER_SUPPORTED) |
| 28 |
// DoSplitHandshake delegates the SSL handshake to a separate process, called |
| 29 |
// the handshaker. This process proxies I/O between the handshaker and the |
| 30 |
// client, using the |BIO| from |ssl|. After a successful handshake, |ssl| is |
| 31 |
// replaced with a new |SSL| object, in a way that is intended to be invisible |
| 32 |
// to the caller. |
| 33 |
bool DoSplitHandshake(bssl::UniquePtr<SSL> *ssl, SettingsWriter *writer, |
| 34 |
bool is_resume); |
| 35 |
|
| 36 |
// GetHandshakeHint requests a handshake hint from the handshaker process and |
| 37 |
// configures the result on |ssl|. It returns true on success and false on |
| 38 |
// error. |
| 39 |
bool GetHandshakeHint(SSL *ssl, SettingsWriter *writer, bool is_resume, |
| 40 |
const SSL_CLIENT_HELLO *client_hello); |
| 41 |
|
| 42 |
// The protocol between the proxy and the handshaker is defined by these |
| 43 |
// single-character prefixes. |kControlMsgDone| uses 'H' for compatibility with |
| 44 |
// older binaries. |
| 45 |
constexpr char kControlMsgWantRead = 'R'; // Handshaker wants data |
| 46 |
constexpr char kControlMsgWriteCompleted = 'W'; // Proxy has sent data |
| 47 |
constexpr char kControlMsgDone = 'H'; // Proxy should resume control |
| 48 |
constexpr char kControlMsgError = 'E'; // Handshaker hit an error |
| 49 |
|
| 50 |
// The protocol between the proxy and handshaker uses these file descriptors. |
| 51 |
constexpr int kFdControl = 3; // Bi-directional dgram socket. |
| 52 |
constexpr int kFdProxyToHandshaker = 4; // Uni-directional pipe. |
| 53 |
constexpr int kFdHandshakerToProxy = 5; // Uni-directional pipe. |
| 54 |
#endif // HANDSHAKER_SUPPORTED |
| 55 |
|
| 56 |
#endif // HEADER_TEST_HANDSHAKE |