hnetd: add compatiblity with openssl 1.1.x
[feed/routing.git] / hnetd / patches / 0001-dtls.c-Update-openssl-API-to-1.1.0.patch
1 From a9d47c87115bf69c19e9263efb90d5753456f1b9 Mon Sep 17 00:00:00 2001
2 From: Eneas U de Queiroz <cote2004-github@yahoo.com>
3 Date: Thu, 13 Dec 2018 00:20:57 -0200
4 Subject: [PATCH] dtls.c: Update openssl API to 1.1.0
5
6 Use shims for compatiblity with previous versions.
7
8 Signed-off-by: Eneas U de Queiroz <cote2004-github@yahoo.com>
9 ---
10 src/dtls.c | 20 +++++++++++++++++---
11 1 file changed, 17 insertions(+), 3 deletions(-)
12
13 diff --git a/src/dtls.c b/src/dtls.c
14 index ed5d408..511f724 100644
15 --- a/src/dtls.c
16 +++ b/src/dtls.c
17 @@ -38,6 +38,7 @@
18 #include <string.h>
19 #include <openssl/crypto.h>
20 #include <openssl/err.h>
21 +#include <openssl/opensslv.h>
22 #include <openssl/ssl.h>
23 #include <openssl/rand.h>
24 #include <libubox/list.h>
25 @@ -168,6 +169,19 @@ static dtls_limits_s _default_limits = {
26
27 static bool _ssl_initialized = false;
28
29 +#if OPENSSL_VERSION_NUMBER < 0x10100000L \
30 + || (defined(LIBRESSL_VERSION_NUMBER) && LIBRESSL_VERSION_NUMBER < 0x20700000L)
31 +static inline void *X509_STORE_get_ex_data(X509_STORE *ctx, int idx)
32 +{
33 + return CRYPTO_get_ex_data(&ctx->ex_data, idx);
34 +}
35 +
36 +static inline int X509_STORE_set_ex_data(X509_STORE *ctx, int idx, void *data)
37 +{
38 + return CRYPTO_set_ex_data(&ctx->ex_data, idx, data);
39 +}
40 +#endif
41 +
42 static bool _drain_errors()
43 {
44 if (!ERR_peek_error())
45 @@ -863,7 +877,7 @@ ssize_t dtls_send(dtls d,
46
47 static int _verify_cert_cb(int ok, X509_STORE_CTX *ctx)
48 {
49 - dtls d = CRYPTO_get_ex_data(&ctx->ctx->ex_data, 0);
50 + dtls d = X509_STORE_get_ex_data(X509_STORE_CTX_get0_store(ctx), 0);
51
52 if (!d)
53 {
54 @@ -916,7 +930,7 @@ bool dtls_set_local_cert(dtls d, const char *certfile, const char *pkfile)
55 |SSL_VERIFY_FAIL_IF_NO_PEER_CERT
56 #endif /* DTLS_OPENSSL */
57 , _verify_cert_cb);
58 - CRYPTO_set_ex_data(&d->ssl_server_ctx->cert_store->ex_data, 0, d);
59 + X509_STORE_set_ex_data(SSL_CTX_get_cert_store(d->ssl_server_ctx), 0, d);
60
61 #ifndef USE_ONE_CONTEXT
62 R1("client cert",
63 @@ -928,7 +942,7 @@ bool dtls_set_local_cert(dtls d, const char *certfile, const char *pkfile)
64 |SSL_VERIFY_PEER_FAIL_IF_NO_PEER_CERT
65 #endif /* DTLS_OPENSSL */
66 , _verify_cert_cb);
67 - CRYPTO_set_ex_data(&d->ssl_client_ctx->cert_store->ex_data, 0, d);
68 + X509_STORE_set_ex_data(SSL_CTX_get_cert_store(d->ssl_client_ctx), 0, d);
69 #endif /* !USE_ONE_CONTEXT */
70
71 return true;