[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[Libevent-users] [PATCH] bev_ssl: Allow users to set allow_dirty_shutdown
By default, allow_dirty_shutdown is 0, reporting
TCP-close-before-SSL-close as BEV_EVENT_ERROR.
But many https servers out there do dirty shutdowns, so clients need
to be able to set this flag.
This patch simply adds a getter/setter for the flag. Default behaviour
of bev_ssl does not change.
From 9632ddb90393fcb4a8b537644d932e8eedd08c1c Mon Sep 17 00:00:00 2001
From: Catalin Patulea <catalinp@xxxxxxxxxx>
Date: Mon, 21 Nov 2011 19:57:19 -0500
Subject: [PATCH 2/2] Allow users to set allow_dirty_shutdown
---
bufferevent_openssl.c | 23 ++++++++++++++++++++++-
include/event2/bufferevent_ssl.h | 16 ++++++++++++++++
2 files changed, 38 insertions(+), 1 deletions(-)
diff --git a/bufferevent_openssl.c b/bufferevent_openssl.c
index 3ca906b..6f13159 100644
--- a/bufferevent_openssl.c
+++ b/bufferevent_openssl.c
@@ -313,7 +313,7 @@ struct bufferevent_openssl {
unsigned read_blocked_on_write : 1;
/* When we next get data, we should say "write" instead of "read". */
unsigned write_blocked_on_read : 1;
- /* XXX */
+ /* Treat TCP close before SSL close on SSL >= v3 as clean EOF. */
unsigned allow_dirty_shutdown : 1;
/* XXXX */
unsigned fd_is_set : 1;
@@ -1389,6 +1389,27 @@ bufferevent_openssl_socket_new(struct event_base *base,
base, NULL, fd, ssl, state, options);
}
+int bufferevent_openssl_get_allow_dirty_shutdown(struct bufferevent *bev)
+{
+ int allow_dirty_shutdown = 0;
+ struct bufferevent_openssl *bev_ssl;
+ BEV_LOCK(bev);
+ bev_ssl = upcast(bev);
+ allow_dirty_shutdown = bev_ssl->allow_dirty_shutdown;
+ BEV_UNLOCK(bev);
+ return allow_dirty_shutdown;
+}
+
+void bufferevent_openssl_set_allow_dirty_shutdown(struct bufferevent *bev,
+ int allow_dirty_shutdown)
+{
+ struct bufferevent_openssl *bev_ssl;
+ BEV_LOCK(bev);
+ bev_ssl = upcast(bev);
+ bev_ssl->allow_dirty_shutdown = allow_dirty_shutdown;
+ BEV_UNLOCK(bev);
+}
+
unsigned long
bufferevent_get_openssl_error(struct bufferevent *bev)
{
diff --git a/include/event2/bufferevent_ssl.h b/include/event2/bufferevent_ssl.h
index bf6009a..30bf2d3 100644
--- a/include/event2/bufferevent_ssl.h
+++ b/include/event2/bufferevent_ssl.h
@@ -88,6 +88,22 @@ bufferevent_openssl_socket_new(struct event_base *base,
enum bufferevent_ssl_state state,
int options);
+/** Control whether to report dirty SSL shutdowns.
+
+If the peer closes the TCP connection before closing the SSL channel, the
+protocol is SSL >= v3, and allow_dirty_shutdown=0 (default), you will receive
+BEV_EVENT_ERROR.
+
+If instead allow_dirty_shutdown=1, you will receive BEV_EVENT_EOF.
+
+On the other hand, if the protocol is < SSLv3, you will always receive
+BEV_EVENT_EOF.
+*/
+
+int bufferevent_openssl_get_allow_dirty_shutdown(struct bufferevent *bev);
+void bufferevent_openssl_set_allow_dirty_shutdown(struct bufferevent *bev,
+ int allow_dirty_shutdown);
+
/** Return the underlying openssl SSL * object for an SSL bufferevent. */
struct ssl_st *
bufferevent_openssl_get_ssl(struct bufferevent *bufev);
--
1.7.3.1