aboutsummaryrefslogtreecommitdiffstats
path: root/main/kamailio/0002-fix-libressl.patch
blob: be7670eec12c76234cf871cc78285c73bf72806e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
diff -ru kamailio-5.0.1.orig/src/modules/tls/tls_bio.c kamailio-5.0.1/src/modules/tls/tls_bio.c
--- kamailio-5.0.1.orig/src/modules/tls/tls_bio.c	2017-04-05 13:32:39.000000000 +0000
+++ kamailio-5.0.1/src/modules/tls/tls_bio.c	2017-04-27 10:16:48.389532400 +0000
@@ -63,7 +63,7 @@
 static long tls_bio_mbuf_ctrl(BIO* b, int cmd, long arg1, void* arg2);
 
 
-#if OPENSSL_VERSION_NUMBER < 0x010100000L
+#if OPENSSL_VERSION_NUMBER < 0x010100000L || defined(LIBRESSL_VERSION_NUMBER)
 static BIO_METHOD tls_mbuf_method = {
 	BIO_TYPE_TLS_MBUF,	/* type */
 	"sr_tls_mbuf",		/* name */
@@ -76,6 +76,27 @@
 	tls_bio_mbuf_free,	/* destroy(free) function */
 	0					/* ctrl callback */
 };
+
+static void *CRYPTO_zalloc(size_t num, const char *file, int line)
+{
+	void *ret = CRYPTO_malloc(num, file, line);
+	if (ret != NULL)
+		memset(ret, 0, num);
+	return ret;
+}
+# define OPENSSL_zalloc(num) CRYPTO_zalloc(num, __FILE__, __LINE__)
+static void *BIO_get_data(BIO *b)
+{
+	return b->ptr;
+}
+static void BIO_set_data(BIO *b, void *ptr)
+{
+	b->ptr = ptr;
+}
+static void BIO_set_init(BIO *b, int init)
+{
+	b->init = init;
+}
 #else
 static BIO_METHOD *tls_mbuf_method = NULL;
 #endif
@@ -84,7 +105,7 @@
 /** returns a custom tls_mbuf BIO. */
 BIO_METHOD* tls_BIO_mbuf(void)
 {
-#if OPENSSL_VERSION_NUMBER < 0x010100000L
+#if OPENSSL_VERSION_NUMBER < 0x010100000L || defined(LIBRESSL_VERSION_NUMBER)
 	return &tls_mbuf_method;
 #else
 	if(tls_mbuf_method != NULL) {
@@ -137,22 +158,14 @@
 	struct tls_bio_mbuf_data* d;
 
 	TLS_BIO_DBG("tls_BIO_mbuf_set called (%p => %p, %p)\n", b, rd, wr);
-#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->rd = rd;
 	d->wr = wr;
-#if OPENSSL_VERSION_NUMBER < 0x010100000L
-	b->init = 1;
-#else
 	BIO_set_init(b, 1);
-#endif
 	return 1;
 }
 
@@ -167,25 +180,12 @@
 	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;
-	b->flags = 0;
-	d = OPENSSL_malloc(sizeof(*d));
-	if (unlikely(d == 0))
-		return 0;
-	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;
 }
 
@@ -200,13 +200,6 @@
 	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);
@@ -216,7 +209,6 @@
 			BIO_set_init(b, 0);
 		}
 	} while(0);
-#endif
 	return 1;
 }
 
@@ -235,11 +227,7 @@
 
 	ret = 0;
 	if (likely(dst)) {
-#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)
@@ -291,11 +279,7 @@
 	int ret;
 
 	ret = 0;
-#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)
diff -ru kamailio-5.0.1.orig/src/modules/tls/tls_domain.c kamailio-5.0.1/src/modules/tls/tls_domain.c
--- kamailio-5.0.1.orig/src/modules/tls/tls_domain.c	2017-04-05 13:32:39.000000000 +0000
+++ kamailio-5.0.1/src/modules/tls/tls_domain.c	2017-04-27 10:15:10.447718361 +0000
@@ -124,7 +124,7 @@
 		return;
 	}
 
-#if (OPENSSL_VERSION_NUMBER >= 0x1010000fL)
+#if (OPENSSL_VERSION_NUMBER >= 0x1010000fL) && !defined(LIBRESSL_VERSION_NUMBER)
 	/* libssl >= v1.1.0 */
 	DH_set0_pqg(dh, p, NULL, g);
 #else