BadVPN – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | /** |
2 | * @file BSSLConnection.h |
||
3 | * @author Ambroz Bizjak <ambrop7@gmail.com> |
||
4 | * |
||
5 | * @section LICENSE |
||
6 | * |
||
7 | * Redistribution and use in source and binary forms, with or without |
||
8 | * modification, are permitted provided that the following conditions are met: |
||
9 | * 1. Redistributions of source code must retain the above copyright |
||
10 | * notice, this list of conditions and the following disclaimer. |
||
11 | * 2. Redistributions in binary form must reproduce the above copyright |
||
12 | * notice, this list of conditions and the following disclaimer in the |
||
13 | * documentation and/or other materials provided with the distribution. |
||
14 | * 3. Neither the name of the author nor the |
||
15 | * names of its contributors may be used to endorse or promote products |
||
16 | * derived from this software without specific prior written permission. |
||
17 | * |
||
18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
||
19 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
||
20 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
||
21 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY |
||
22 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
||
23 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
||
24 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
||
25 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
||
26 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
||
27 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||
28 | */ |
||
29 | |||
30 | #ifndef BADVPN_BSSLCONNECTION_H |
||
31 | #define BADVPN_BSSLCONNECTION_H |
||
32 | |||
33 | #include <prio.h> |
||
34 | #include <nss/ssl.h> |
||
35 | |||
36 | #include <misc/debug.h> |
||
37 | #include <misc/debugerror.h> |
||
38 | #include <base/DebugObject.h> |
||
39 | #include <base/BPending.h> |
||
40 | #include <base/BMutex.h> |
||
41 | #include <flow/StreamPassInterface.h> |
||
42 | #include <flow/StreamRecvInterface.h> |
||
43 | #include <threadwork/BThreadWork.h> |
||
44 | |||
45 | #define BSSLCONNECTION_EVENT_UP 1 |
||
46 | #define BSSLCONNECTION_EVENT_ERROR 2 |
||
47 | |||
48 | #define BSSLCONNECTION_BUF_SIZE 4096 |
||
49 | |||
50 | #define BSSLCONNECTION_FLAG_THREADWORK_HANDSHAKE (1 << 0) |
||
51 | #define BSSLCONNECTION_FLAG_THREADWORK_IO (1 << 1) |
||
52 | |||
53 | typedef void (*BSSLConnection_handler) (void *user, int event); |
||
54 | |||
55 | struct BSSLConnection_backend; |
||
56 | |||
57 | typedef struct { |
||
58 | PRFileDesc *prfd; |
||
59 | BPendingGroup *pg; |
||
60 | void *user; |
||
61 | BSSLConnection_handler handler; |
||
62 | struct BSSLConnection_backend *backend; |
||
63 | int have_error; |
||
64 | int up; |
||
65 | BPending init_job; |
||
66 | StreamPassInterface send_if; |
||
67 | StreamRecvInterface recv_if; |
||
68 | BPending recv_job; |
||
69 | const uint8_t *send_data; |
||
70 | int send_len; |
||
71 | uint8_t *recv_data; |
||
72 | int recv_avail; |
||
73 | #ifndef NDEBUG |
||
74 | int user_io_started; |
||
75 | int releasebuffers_called; |
||
76 | #endif |
||
77 | DebugError d_err; |
||
78 | DebugObject d_obj; |
||
79 | } BSSLConnection; |
||
80 | |||
81 | struct BSSLConnection_backend { |
||
82 | StreamPassInterface *send_if; |
||
83 | StreamRecvInterface *recv_if; |
||
84 | BThreadWorkDispatcher *twd; |
||
85 | int flags; |
||
86 | BSSLConnection *con; |
||
87 | uint8_t send_buf[BSSLCONNECTION_BUF_SIZE]; |
||
88 | int send_busy; |
||
89 | int send_pos; |
||
90 | int send_len; |
||
91 | uint8_t recv_buf[BSSLCONNECTION_BUF_SIZE]; |
||
92 | int recv_busy; |
||
93 | int recv_pos; |
||
94 | int recv_len; |
||
95 | int threadwork_state; |
||
96 | int threadwork_want_recv; |
||
97 | int threadwork_want_send; |
||
98 | BThreadWork threadwork; |
||
99 | SECStatus threadwork_result_sec; |
||
100 | PRInt32 threadwork_result_pr; |
||
101 | PRErrorCode threadwork_error; |
||
102 | BMutex send_buf_mutex; |
||
103 | BMutex recv_buf_mutex; |
||
104 | }; |
||
105 | |||
106 | int BSSLConnection_GlobalInit (void) WARN_UNUSED; |
||
107 | int BSSLConnection_MakeBackend (PRFileDesc *prfd, StreamPassInterface *send_if, StreamRecvInterface *recv_if, BThreadWorkDispatcher *twd, int flags) WARN_UNUSED; |
||
108 | |||
109 | void BSSLConnection_Init (BSSLConnection *o, PRFileDesc *prfd, int force_handshake, BPendingGroup *pg, void *user, |
||
110 | BSSLConnection_handler handler); |
||
111 | void BSSLConnection_Free (BSSLConnection *o); |
||
112 | void BSSLConnection_ReleaseBuffers (BSSLConnection *o); |
||
113 | StreamPassInterface * BSSLConnection_GetSendIf (BSSLConnection *o); |
||
114 | StreamRecvInterface * BSSLConnection_GetRecvIf (BSSLConnection *o); |
||
115 | |||
116 | #endif |