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