From d7fc615837f841083aef68e1e919fec13a6b43be Mon Sep 17 00:00:00 2001 From: Sebastian Andrzej Siewior Date: Wed, 8 Nov 2017 14:40:12 +0100 Subject: [PATCH] crypto: Add a tiny OpenSSL compat level This header file provides a few OpenSSL 1.1 functions which are not available in OpenSSL 1.0.2 and earlier. The body of the function implements the pre-1.1 version of the function provided in 1.1. Signed-off-by: Sebastian Andrzej Siewior --- bacula/src/lib/crypto.c | 2 ++ bacula/src/lib/tls.c | 2 ++ src/lib/openssl-compat.h | 43 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 47 insertions(+) create mode 100644 src/lib/openssl-compat.h diff --git a/bacula/src/lib/crypto.c b/bacula/src/lib/crypto.c index b4403eb456..c172efb2b5 100644 --- a/bacula/src/lib/crypto.c +++ b/bacula/src/lib/crypto.c @@ -131,6 +131,8 @@ #ifdef HAVE_CRYPTO /* Is encryption enabled? */ #ifdef HAVE_OPENSSL /* How about OpenSSL? */ +#include "openssl-compat.h" + /* ASN.1 Declarations */ #define BACULA_ASN1_VERSION 0 diff --git a/bacula/src/lib/tls.c b/bacula/src/lib/tls.c index 992265b38a..c71a4ad525 100644 --- a/bacula/src/lib/tls.c +++ b/bacula/src/lib/tls.c @@ -45,6 +45,8 @@ #ifdef HAVE_OPENSSL /* How about OpenSSL? */ +#include "openssl-compat.h" + /* No anonymous ciphers, no <128 bit ciphers, no export ciphers, no MD5 ciphers */ #define TLS_DEFAULT_CIPHERS "ALL:!ADH:!LOW:!EXP:!MD5:@STRENGTH" diff --git a/src/lib/openssl-compat.h b/src/lib/openssl-compat.h new file mode 100644 index 0000000000..e811a4b976 --- /dev/null +++ b/src/lib/openssl-compat.h @@ -0,0 +1,43 @@ +#ifndef __OPENSSL_COPMAT__H__ +#define __OPENSSL_COPMAT__H__ + +#if (OPENSSL_VERSION_NUMBER < 0x10100000L) +static inline int EVP_PKEY_up_ref(EVP_PKEY *pkey) +{ + CRYPTO_add(&pkey->references, 1, CRYPTO_LOCK_EVP_PKEY); + return 1; +} + +static inline void EVP_CIPHER_CTX_reset(EVP_CIPHER_CTX *ctx) +{ + EVP_CIPHER_CTX_init(ctx); +} + +static inline void EVP_MD_CTX_reset(EVP_MD_CTX *ctx) +{ + EVP_MD_CTX_init(ctx); +} + +static inline EVP_MD_CTX *EVP_MD_CTX_new(void) +{ + EVP_MD_CTX *ctx; + + ctx = (EVP_MD_CTX *)OPENSSL_malloc(sizeof(EVP_MD_CTX)); + if (ctx) + memset(ctx, 0, sizeof(EVP_MD_CTX)); + return ctx; +} + +static inline void EVP_MD_CTX_free(EVP_MD_CTX *ctx) +{ + EVP_MD_CTX_reset(ctx); + OPENSSL_free(ctx); +} + +static inline const unsigned char *ASN1_STRING_get0_data(const ASN1_STRING *asn1) +{ + return asn1->data; +} +#endif + +#endif -- 2.39.2