bufferevent_ssl.h revision 1.1.1.1
1/*	$NetBSD: bufferevent_ssl.h,v 1.1.1.1 2013/04/11 16:43:34 christos Exp $	*/
2/*
3 * Copyright (c) 2009-2012 Niels Provos and Nick Mathewson
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 *    notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 *    notice, this list of conditions and the following disclaimer in the
12 *    documentation and/or other materials provided with the distribution.
13 * 3. The name of the author may not be used to endorse or promote products
14 *    derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27#ifndef _EVENT2_BUFFEREVENT_SSL_H_
28#define _EVENT2_BUFFEREVENT_SSL_H_
29
30/** @file event2/bufferevent_ssl.h
31
32    OpenSSL support for bufferevents.
33 */
34
35#include <event2/event-config.h>
36#include <event2/bufferevent.h>
37#include <event2/util.h>
38
39#ifdef __cplusplus
40extern "C" {
41#endif
42
43/* This is what openssl's SSL objects are underneath. */
44struct ssl_st;
45
46/**
47   The state of an SSL object to be used when creating a new
48   SSL bufferevent.
49 */
50enum bufferevent_ssl_state {
51	BUFFEREVENT_SSL_OPEN = 0,
52	BUFFEREVENT_SSL_CONNECTING = 1,
53	BUFFEREVENT_SSL_ACCEPTING = 2
54};
55
56#if defined(_EVENT_HAVE_OPENSSL) || defined(_EVENT_IN_DOXYGEN)
57/**
58   Create a new SSL bufferevent to send its data over another bufferevent.
59
60   @param base An event_base to use to detect reading and writing.  It
61      must also be the base for the underlying bufferevent.
62   @param underlying A socket to use for this SSL
63   @param ssl A SSL* object from openssl.
64   @param state The current state of the SSL connection
65   @param options One or more bufferevent_options
66   @return A new bufferevent on success, or NULL on failure
67*/
68struct bufferevent *
69bufferevent_openssl_filter_new(struct event_base *base,
70    struct bufferevent *underlying,
71    struct ssl_st *ssl,
72    enum bufferevent_ssl_state state,
73    int options);
74
75/**
76   Create a new SSL bufferevent to send its data over an SSL * on a socket.
77
78   @param base An event_base to use to detect reading and writing
79   @param fd A socket to use for this SSL
80   @param ssl A SSL* object from openssl.
81   @param state The current state of the SSL connection
82   @param options One or more bufferevent_options
83   @return A new bufferevent on success, or NULL on failure.
84*/
85struct bufferevent *
86bufferevent_openssl_socket_new(struct event_base *base,
87    evutil_socket_t fd,
88    struct ssl_st *ssl,
89    enum bufferevent_ssl_state state,
90    int options);
91
92/** Return the underlying openssl SSL * object for an SSL bufferevent. */
93struct ssl_st *
94bufferevent_openssl_get_ssl(struct bufferevent *bufev);
95
96/** Tells a bufferevent to begin SSL renegotiation. */
97int bufferevent_ssl_renegotiate(struct bufferevent *bev);
98
99/** Return the most recent OpenSSL error reported on an SSL bufferevent. */
100unsigned long bufferevent_get_openssl_error(struct bufferevent *bev);
101
102#endif
103
104#ifdef __cplusplus
105}
106#endif
107
108#endif /* _EVENT2_BUFFEREVENT_SSL_H_ */
109