Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tls: improve TLS handshake error message #4561

Merged
merged 6 commits into from
Mar 11, 2022
Merged
Changes from 3 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
20 changes: 20 additions & 0 deletions src/tls/openssl.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ static int tls_init(void)
OPENSSL_add_all_algorithms_noconf();
SSL_load_error_strings();
SSL_library_init();
#else
SSL_load_error_strings();
#endif
return 0;
}
Expand Down Expand Up @@ -347,6 +349,7 @@ static int tls_net_read(struct flb_upstream_conn *u_conn,
void *buf, size_t len)
{
int ret;
char errbuf[256];
struct tls_session *session = (struct tls_session *) u_conn->tls_session;
struct tls_context *ctx;

Expand All @@ -363,6 +366,10 @@ static int tls_net_read(struct flb_upstream_conn *u_conn,
else if (ret == SSL_ERROR_WANT_WRITE) {
ret = FLB_TLS_WANT_WRITE;
}
else if (ret < 0) {
ERR_error_string(ret, errbuf);
pwhelan marked this conversation as resolved.
Show resolved Hide resolved
flb_error("[tls] error: %s", errbuf);
}
else {
ret = -1;
}
Expand All @@ -376,6 +383,7 @@ static int tls_net_write(struct flb_upstream_conn *u_conn,
const void *data, size_t len)
{
int ret;
char errbuf[256];
size_t total = 0;
struct tls_session *session = (struct tls_session *) u_conn->tls_session;
struct tls_context *ctx;
Expand All @@ -396,6 +404,8 @@ static int tls_net_write(struct flb_upstream_conn *u_conn,
ret = FLB_TLS_WANT_READ;
}
else {
ERR_error_string(ret, errbuf);
pwhelan marked this conversation as resolved.
Show resolved Hide resolved
flb_error("[tls] error: %s", errbuf);
ret = -1;
}
}
Expand All @@ -409,6 +419,7 @@ static int tls_net_write(struct flb_upstream_conn *u_conn,
static int tls_net_handshake(struct flb_tls *tls, void *ptr_session)
{
int ret = 0;
char errbuf[256];
struct tls_session *session = ptr_session;
struct tls_context *ctx;

Expand All @@ -426,6 +437,15 @@ static int tls_net_handshake(struct flb_tls *tls, void *ptr_session)
if (ret != SSL_ERROR_WANT_READ &&
ret != SSL_ERROR_WANT_WRITE) {
ret = SSL_get_error(session->ssl, ret);
// The SSL_ERROR_SYSCALL with errno value of 0
pwhelan marked this conversation as resolved.
Show resolved Hide resolved
pwhelan marked this conversation as resolved.
Show resolved Hide resolved
// indicates unexpected EOF from the peer.
// This is fixed in OpenSSL 3.0.
if (ret == 0) {
flb_error("[tls] error: unexpected EOF");
} else {
ERR_error_string(ret, errbuf);
pwhelan marked this conversation as resolved.
Show resolved Hide resolved
flb_error("[tls] error: %s", errbuf);
}
pthread_mutex_unlock(&ctx->mutex);
return -1;
}
Expand Down