aboutsummaryrefslogtreecommitdiff
path: root/src/microspdy/tls.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/microspdy/tls.h')
-rw-r--r--src/microspdy/tls.h171
1 files changed, 171 insertions, 0 deletions
diff --git a/src/microspdy/tls.h b/src/microspdy/tls.h
new file mode 100644
index 00000000..5fb4371a
--- /dev/null
+++ b/src/microspdy/tls.h
@@ -0,0 +1,171 @@
1/*
2 This file is part of libmicrospdy
3 Copyright (C) 2012 Andrey Uzunov
4
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17*/
18
19/**
20 * @file tls.h
21 * @brief TLS handling. openssl with NPN is used, but as long as the
22 * functions conform to this interface file, other libraries
23 * can be used.
24 * @author Andrey Uzunov
25 */
26
27#ifndef TLS_H
28#define TLS_H
29
30#include "platform.h"
31#include <openssl/err.h>
32#include <openssl/ssl.h>
33#include <openssl/rand.h>
34
35/* macros used in other files instead of types.
36 * useful in case of changing openssl to something else */
37#define SPDYF_TLS_SESSION_CONTEXT SSL
38#define SPDYF_TLS_DAEMON_CONTEXT SSL_CTX
39
40
41/**
42 * Used for return code when reading and writing to the TLS socket.
43 */
44enum SPDY_TLS_ERROR
45{
46 /**
47 * The connection was closed by the other party.
48 */
49 SPDY_TLS_ERROR_CLOSED = 0,
50
51 /**
52 * Any kind of error ocurred. The session has to be closed.
53 */
54 SPDY_TLS_ERROR_ERROR = -2,
55
56 /**
57 * The function had to return without processing any data. The whole
58 * cycle of events has to be called again (SPDY_run) as something
59 * either has to be written or read or the the syscall was
60 * interrupted by a signal.
61 */
62 SPDY_TLS_ERROR_AGAIN = -3,
63};
64
65
66/**
67 * Global initializing of openssl. Must be called only once in the program.
68 *
69 */
70void
71SPDYF_tls_global_init();
72
73
74/**
75 * Global deinitializing of openssl for the whole program. Should be called
76 * at the end of the program.
77 *
78 */
79void
80SPDYF_tls_global_deinit();
81
82
83/**
84 * Initializing of openssl for a specific daemon.
85 * Must be called when the daemon starts.
86 *
87 * @param daemon SPDY_Daemon for which openssl will be used. Daemon's
88 * certificate and key file are used.
89 * @return SPDY_YES on success or SPDY_NO on error
90 */
91int
92SPDYF_tls_init(struct SPDY_Daemon *daemon);
93
94
95/**
96 * Deinitializing openssl for a daemon. Should be called
97 * when the deamon is stopped.
98 *
99 * @param daemon SPDY_Daemon which is being stopped
100 */
101void
102SPDYF_tls_deinit(struct SPDY_Daemon *daemon);
103
104
105/**
106 * Initializing openssl for a specific connection. Must be called
107 * after the connection has been accepted.
108 *
109 * @param session SPDY_Session whose socket will be used by openssl
110 * @return SPDY_NO if some openssl funcs fail. SPDY_YES otherwise
111 */
112int
113SPDYF_tls_new_session(struct SPDY_Session *session);
114
115
116/**
117 * Deinitializing openssl for a specific connection. Should be called
118 * closing session's socket.
119 *
120 * @param session SPDY_Session whose socket is used by openssl
121 */
122void
123SPDYF_tls_close_session(struct SPDY_Session *session);
124
125
126/**
127 * Reading from a TLS socket. Reads available data and put it to the
128 * buffer.
129 *
130 * @param session for which data is received
131 * @param buffer where data from the socket will be written to
132 * @param size of the buffer
133 * @return number of bytes (at most size) read from the TLS connection
134 * 0 if the other party has closed the connection
135 * SPDY_TLS_ERROR code on error
136 */
137int
138SPDYF_tls_recv(struct SPDY_Session *session,
139 void * buffer,
140 size_t size);
141
142
143/**
144 * Writing to a TLS socket. Writes the data given into the buffer to the
145 * TLS socket.
146 *
147 * @param session whose context is used
148 * @param buffer from where data will be written to the socket
149 * @param size number of bytes to be taken from the buffer
150 * @return number of bytes (at most size) from the buffer that has been
151 * written to the TLS connection
152 * 0 if the other party has closed the connection
153 * SPDY_TLS_ERROR code on error
154 */
155int
156SPDYF_tls_send(struct SPDY_Session *session,
157 const void * buffer,
158 size_t size);
159
160
161/**
162 * Checks if there is data staying in the buffers of the underlying
163 * system that waits to be read.
164 *
165 * @param session which is checked
166 * @return SPDY_YES if data is pending or SPDY_NO otherwise
167 */
168int
169SPDYF_tls_is_pending(struct SPDY_Session *session);
170
171#endif