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