| 6 | // |
| 7 | // https://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 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 |