summaryrefslogtreecommitdiff
path: root/sockets.c
diff options
context:
space:
mode:
authorLuke Bratch <luke@bratch.co.uk>2019-06-16 19:31:51 +0100
committerLuke Bratch <luke@bratch.co.uk>2019-06-16 19:31:51 +0100
commitde11f8cdc5817fd2ea79886c4899d2fbe04c94c2 (patch)
tree4e22b67cd007298bd7b5504c0c7a733893854581 /sockets.c
parentdb0ab741a43a56ed898112fa09af6e465272cd25 (diff)
Log OpenSSL errors properly instead of printing to stderr.
Diffstat (limited to 'sockets.c')
-rw-r--r--sockets.c19
1 files changed, 16 insertions, 3 deletions
diff --git a/sockets.c b/sockets.c
index 9f3563f..bf83176 100644
--- a/sockets.c
+++ b/sockets.c
@@ -173,9 +173,9 @@ SSL_CTX *create_openssl_context(int type) {
ctx = SSL_CTX_new(method);
if (!ctx) {
- perror("Unable to create SSL context");
- ERR_print_errors_fp(stderr);
- debugprint(DEBUG_CRIT, "Unable to create SSL context, errno '%d'.\n", errno);
+ char* errstr = openssl_error_string();
+ debugprint(DEBUG_CRIT, "Unable to create SSL context, errno '%d', type '%d' - %s", errno, type, errstr);
+ if (errstr != NULL) free(errstr);
exit(EXIT_FAILURE);
}
@@ -227,3 +227,16 @@ int socksend(SSL *fd, char *buf, int bufsize, int tls) {
return send((long int)fd, buf, bufsize, 0);
}
}
+
+char *openssl_error_string() {
+ BIO *bio = BIO_new (BIO_s_mem ());
+ ERR_print_errors (bio);
+ char *buf = NULL;
+ size_t len = BIO_get_mem_data (bio, &buf);
+ char *ret = (char *)calloc(1, 1 + len);
+ if (ret) {
+ memcpy(ret, buf, len);
+ }
+ BIO_free (bio);
+ return ret;
+}