Skip to content
This repository has been archived by the owner on May 24, 2022. It is now read-only.

SSL error queue fix #130

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion stud.c
Original file line number Diff line number Diff line change
Expand Up @@ -889,6 +889,13 @@ static void shutdown_proxy(proxystate *ps, SHUTDOWN_REQUESTOR req) {
close(ps->fd_up);
close(ps->fd_down);

// Clear the SSL error queue - it might contain details
// of errors that we haven't consumed for whatever reason.
// If we don't, future calls to SSL_get_error will lead to
// weird/confusing results that can throw off the handling
// of normal conditions like SSL_ERROR_WANT_READ.
ERR_clear_error();

SSL_set_shutdown(ps->ssl, SSL_SENT_SHUTDOWN);
SSL_free(ps->ssl);

Expand Down Expand Up @@ -1197,7 +1204,14 @@ static void client_handshake(struct ev_loop *loop, ev_io *w, int revents) {
shutdown_proxy(ps, SHUTDOWN_SSL);
}
else {
LOG("{%s} Unexpected SSL error (in handshake): %d\n", w->fd == ps->fd_up ? "client" : "backend", err);
// Try and get more detail on the error from the SSL
// error queue. ERR_error_string requires a char buffer
// of 120 bytes.
unsigned long err_detail = ERR_get_error();
char err_msg[120];
ERR_error_string(err_detail, err_msg);

LOG("{%s} Unexpected SSL error (in handshake): %d, %s\n", w->fd == ps->fd_up ? "client" : "backend", err, err_msg);
shutdown_proxy(ps, SHUTDOWN_SSL);
}
}
Expand Down