xref: /netbsd-src/external/bsd/ntp/dist/sntp/libevent/include/event2/bufferevent_ssl.h (revision cdfa2a7ef92791ba9db70a584a1d904730e6fb46)
1 /*	$NetBSD: bufferevent_ssl.h,v 1.5 2020/05/25 20:47:34 christos Exp $	*/
2 
3 /*
4  * Copyright (c) 2009-2012 Niels Provos and Nick Mathewson
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * 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. The name of the author may not be used to endorse or promote products
15  *    derived from this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  */
28 #ifndef EVENT2_BUFFEREVENT_SSL_H_INCLUDED_
29 #define EVENT2_BUFFEREVENT_SSL_H_INCLUDED_
30 
31 /** @file event2/bufferevent_ssl.h
32 
33     OpenSSL support for bufferevents.
34  */
35 #include <event2/visibility.h>
36 #include <event2/event-config.h>
37 #include <event2/bufferevent.h>
38 #include <event2/util.h>
39 
40 #ifdef __cplusplus
41 extern "C" {
42 #endif
43 
44 /* This is what openssl's SSL objects are underneath. */
45 struct ssl_st;
46 
47 /**
48    The state of an SSL object to be used when creating a new
49    SSL bufferevent.
50  */
51 enum bufferevent_ssl_state {
52 	BUFFEREVENT_SSL_OPEN = 0,
53 	BUFFEREVENT_SSL_CONNECTING = 1,
54 	BUFFEREVENT_SSL_ACCEPTING = 2
55 };
56 
57 #if defined(EVENT__HAVE_OPENSSL) || defined(EVENT_IN_DOXYGEN_)
58 /**
59    Create a new SSL bufferevent to send its data over another bufferevent.
60 
61    @param base An event_base to use to detect reading and writing.  It
62       must also be the base for the underlying bufferevent.
63    @param underlying A socket to use for this SSL
64    @param ssl A SSL* object from openssl.
65    @param state The current state of the SSL connection
66    @param options One or more bufferevent_options
67    @return A new bufferevent on success, or NULL on failure
68 */
69 EVENT2_EXPORT_SYMBOL
70 struct bufferevent *
71 bufferevent_openssl_filter_new(struct event_base *base,
72     struct bufferevent *underlying,
73     struct ssl_st *ssl,
74     enum bufferevent_ssl_state state,
75     int options);
76 
77 /**
78    Create a new SSL bufferevent to send its data over an SSL * on a socket.
79 
80    @param base An event_base to use to detect reading and writing
81    @param fd A socket to use for this SSL
82    @param ssl A SSL* object from openssl.
83    @param state The current state of the SSL connection
84    @param options One or more bufferevent_options
85    @return A new bufferevent on success, or NULL on failure.
86 */
87 EVENT2_EXPORT_SYMBOL
88 struct bufferevent *
89 bufferevent_openssl_socket_new(struct event_base *base,
90     evutil_socket_t fd,
91     struct ssl_st *ssl,
92     enum bufferevent_ssl_state state,
93     int options);
94 
95 /** Control how to report dirty SSL shutdowns.
96 
97     If the peer (or the network, or an attacker) closes the TCP
98     connection before closing the SSL channel, and the protocol is SSL >= v3,
99     this is a "dirty" shutdown.  If allow_dirty_shutdown is 0 (default),
100     this is reported as BEV_EVENT_ERROR.
101 
102     If instead allow_dirty_shutdown=1, a dirty shutdown is reported as
103     BEV_EVENT_EOF.
104 
105     (Note that if the protocol is < SSLv3, you will always receive
106     BEV_EVENT_EOF, since SSL 2 and earlier cannot distinguish a secure
107     connection close from a dirty one.  This is one reason (among many)
108     not to use SSL 2.)
109 */
110 
111 EVENT2_EXPORT_SYMBOL
112 int bufferevent_openssl_get_allow_dirty_shutdown(struct bufferevent *bev);
113 EVENT2_EXPORT_SYMBOL
114 void bufferevent_openssl_set_allow_dirty_shutdown(struct bufferevent *bev,
115     int allow_dirty_shutdown);
116 
117 /** Return the underlying openssl SSL * object for an SSL bufferevent. */
118 EVENT2_EXPORT_SYMBOL
119 struct ssl_st *
120 bufferevent_openssl_get_ssl(struct bufferevent *bufev);
121 
122 /** Tells a bufferevent to begin SSL renegotiation. */
123 EVENT2_EXPORT_SYMBOL
124 int bufferevent_ssl_renegotiate(struct bufferevent *bev);
125 
126 /** Return the most recent OpenSSL error reported on an SSL bufferevent. */
127 EVENT2_EXPORT_SYMBOL
128 unsigned long bufferevent_get_openssl_error(struct bufferevent *bev);
129 
130 #endif
131 
132 #ifdef __cplusplus
133 }
134 #endif
135 
136 #endif /* EVENT2_BUFFEREVENT_SSL_H_INCLUDED_ */
137