• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2     This file is part of libmicrospdy
3     Copyright 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 io_openssl.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 IO_OPENSSL_H
28 #define IO_OPENSSL_H
29 
30 #include "platform.h"
31 #include "io.h"
32 #include <openssl/err.h>
33 #include <openssl/ssl.h>
34 #include <openssl/rand.h>
35 
36 
37 /**
38  * Global initializing of openssl. Must be called only once in the program.
39  *
40  */
41 void
42 SPDYF_openssl_global_init();
43 
44 
45 /**
46  * Global deinitializing of openssl for the whole program. Should be called
47  * at the end of the program.
48  *
49  */
50 void
51 SPDYF_openssl_global_deinit();
52 
53 
54 /**
55  * Initializing of openssl for a specific daemon.
56  * Must be called when the daemon starts.
57  *
58  * @param daemon SPDY_Daemon for which openssl will be used. Daemon's
59  * 				certificate and key file are used.
60  * @return SPDY_YES on success or SPDY_NO on error
61  */
62 int
63 SPDYF_openssl_init(struct SPDY_Daemon *daemon);
64 
65 
66 /**
67  * Deinitializing openssl for a daemon. Should be called
68  * when the deamon is stopped.
69  *
70  * @param daemon SPDY_Daemon which is being stopped
71  */
72 void
73 SPDYF_openssl_deinit(struct SPDY_Daemon *daemon);
74 
75 
76 /**
77  * Initializing openssl for a specific connection. Must be called
78  * after the connection has been accepted.
79  *
80  * @param session SPDY_Session whose socket will be used by openssl
81  * @return SPDY_NO if some openssl funcs fail. SPDY_YES otherwise
82  */
83 int
84 SPDYF_openssl_new_session(struct SPDY_Session *session);
85 
86 
87 /**
88  * Deinitializing openssl for a specific connection. Should be called
89  * closing session's socket.
90  *
91  * @param session SPDY_Session whose socket is used by openssl
92  */
93 void
94 SPDYF_openssl_close_session(struct SPDY_Session *session);
95 
96 
97 /**
98  * Reading from a TLS socket. Reads available data and put it to the
99  * buffer.
100  *
101  * @param session for which data is received
102  * @param buffer where data from the socket will be written to
103  * @param size of the buffer
104  * @return number of bytes (at most size) read from the TLS connection
105  *         0 if the other party has closed the connection
106  *         SPDY_IO_ERROR code on error
107  */
108 int
109 SPDYF_openssl_recv(struct SPDY_Session *session,
110 				void * buffer,
111 				size_t size);
112 
113 
114 /**
115  * Writing to a TLS socket. Writes the data given into the buffer to the
116  * TLS socket.
117  *
118  * @param session whose context is used
119  * @param buffer from where data will be written to the socket
120  * @param size number of bytes to be taken from the buffer
121  * @return number of bytes (at most size) from the buffer that has been
122  * 			written to the TLS connection
123  *         0 if the other party has closed the connection
124  *         SPDY_IO_ERROR code on error
125  */
126 int
127 SPDYF_openssl_send(struct SPDY_Session *session,
128 				const void * buffer,
129 				size_t size);
130 
131 
132 /**
133  * Checks if there is data staying in the buffers of the underlying
134  * system that waits to be read.
135  *
136  * @param session which is checked
137  * @return SPDY_YES if data is pending or SPDY_NO otherwise
138  */
139 int
140 SPDYF_openssl_is_pending(struct SPDY_Session *session);
141 
142 
143 /**
144  * Nothing.
145  *
146  * @param session
147  * @return SPDY_NO if writing must not happen in the call;
148  *         SPDY_YES otherwise
149  */
150 int
151 SPDYF_openssl_before_write(struct SPDY_Session *session);
152 
153 
154 /**
155  * Nothing.
156  *
157  * @param session
158  * @param was_written has the same value as the write function for the
159  *        session will return
160  * @return returned value will be used by the write function to return
161  */
162 int
163 SPDYF_openssl_after_write(struct SPDY_Session *session, int was_written);
164 
165 
166 #endif
167