[sr-dev] git:4.4:81df84b8: tls: updated bio functions to support libssl v1.1.0 api

Victor Seva linuxmaniac at torreviejawireless.org
Thu Oct 27 17:11:42 CEST 2016


Module: kamailio
Branch: 4.4
Commit: 81df84b840bcb053400063f5b96d3d84179b11c5
URL: https://github.com/kamailio/kamailio/commit/81df84b840bcb053400063f5b96d3d84179b11c5

Author: Daniel-Constantin Mierla <miconda at gmail.com>
Committer: Victor Seva <linuxmaniac at torreviejawireless.org>
Date: 2016-10-27T17:04:13+02:00

tls: updated bio functions to support libssl v1.1.0 api

(cherry picked from commit fe99687608929b19be62412c334cf41e84845f81)

---

Modified: modules/tls/tls_bio.c

---

Diff:  https://github.com/kamailio/kamailio/commit/81df84b840bcb053400063f5b96d3d84179b11c5.diff
Patch: https://github.com/kamailio/kamailio/commit/81df84b840bcb053400063f5b96d3d84179b11c5.patch

---

diff --git a/modules/tls/tls_bio.c b/modules/tls/tls_bio.c
index d2c2107..b0aae5b 100644
--- a/modules/tls/tls_bio.c
+++ b/modules/tls/tls_bio.c
@@ -1,4 +1,4 @@
-/* 
+/*
  * Kamailio TLS module
  *
  * Copyright (C) 2010 iptelorg GmbH
@@ -137,14 +137,22 @@ int tls_BIO_mbuf_set(BIO* b, struct tls_mbuf* rd, struct tls_mbuf* wr)
 	struct tls_bio_mbuf_data* d;
 
 	TLS_BIO_DBG("tls_BIO_mbuf_set called (%p => %p, %p)\n", b, rd, wr);
-	if (unlikely(b->ptr == 0)){
-		BUG("null BIO ptr\n");
+#if OPENSSL_VERSION_NUMBER < 0x010100000L
+	d = b->ptr;
+#else
+	d = BIO_get_data(b);
+#endif
+	if (unlikely(d == 0)){
+		BUG("null BIO ptr data\n");
 		return 0;
 	}
-	d = b->ptr;
 	d->rd = rd;
 	d->wr = wr;
+#if OPENSSL_VERSION_NUMBER < 0x010100000L
 	b->init = 1;
+#else
+	BIO_set_init(b, 1);
+#endif
 	return 1;
 }
 
@@ -157,8 +165,9 @@ int tls_BIO_mbuf_set(BIO* b, struct tls_mbuf* rd, struct tls_mbuf* wr)
 static int tls_bio_mbuf_new(BIO* b)
 {
 	struct tls_bio_mbuf_data* d;
-	
+
 	TLS_BIO_DBG("tls_bio_mbuf_new called (%p)\n", b);
+#if OPENSSL_VERSION_NUMBER < 0x010100000L
 	b->init = 0; /* not initialized yet */
 	b->num = 0;
 	b->ptr = 0;
@@ -169,6 +178,14 @@ static int tls_bio_mbuf_new(BIO* b)
 	d->rd = 0;
 	d->wr = 0;
 	b->ptr = d;
+#else
+	BIO_set_init(b, 0);
+	BIO_set_data(b, NULL);
+	d = OPENSSL_zalloc(sizeof(*d));
+	if (unlikely(d == 0))
+		return 0;
+	BIO_set_data(b, d);
+#endif
 	return 1;
 }
 
@@ -183,11 +200,23 @@ static int tls_bio_mbuf_free(BIO* b)
 	TLS_BIO_DBG("tls_bio_mbuf_free called (%p)\n", b);
 	if (unlikely( b == 0))
 			return 0;
+#if OPENSSL_VERSION_NUMBER < 0x010100000L
 	if (likely(b->ptr)){
 		OPENSSL_free(b->ptr);
 		b->ptr = 0;
 		b->init = 0;
 	}
+#else
+	do {
+		struct tls_bio_mbuf_data* d;
+		d = BIO_get_data(b);
+		if (likely(d)) {
+			OPENSSL_free(d);
+			BIO_set_data(b, NULL);
+			BIO_set_init(b, 0);
+		}
+	} while(0);
+#endif
 	return 1;
 }
 
@@ -203,10 +232,14 @@ static int tls_bio_mbuf_read(BIO* b, char* dst, int dst_len)
 	struct tls_bio_mbuf_data* d;
 	struct tls_mbuf* rd;
 	int ret;
-	
+
 	ret = 0;
 	if (likely(dst)) {
-		d= b->ptr;
+#if OPENSSL_VERSION_NUMBER < 0x010100000L
+		d = b->ptr;
+#else
+		d = BIO_get_data(b);
+#endif
 		BIO_clear_retry_flags(b);
 		if (unlikely(d == 0 || d->rd->buf == 0)) {
 			if (d == 0)
@@ -256,9 +289,13 @@ static int tls_bio_mbuf_write(BIO* b, const char* src, int src_len)
 	struct tls_bio_mbuf_data* d;
 	struct tls_mbuf* wr;
 	int ret;
-	
+
 	ret = 0;
-	d= b->ptr;
+#if OPENSSL_VERSION_NUMBER < 0x010100000L
+	d = b->ptr;
+#else
+	d = BIO_get_data(b);
+#endif
 	BIO_clear_retry_flags(b);
 	if (unlikely(d == 0 || d->wr->buf == 0)) {
 		if (d == 0)
@@ -330,12 +367,10 @@ static long tls_bio_mbuf_ctrl(BIO* b, int cmd, long arg1, void* arg2)
 static int tls_bio_mbuf_puts(BIO* b, const char* s)
 {
 	int len;
-	
+
 	TLS_BIO_DBG("puts called (%p, %s)\n", b, s);
 	len=strlen(s);
 	return tls_bio_mbuf_write(b, s, len);
 }
 
-
-
 /* vi: set ts=4 sw=4 tw=79:ai:cindent: */




More information about the sr-dev mailing list