From 30d8861b5d506dd5a564640e4da53db1b7b58e62 Mon Sep 17 00:00:00 2001 From: Janos SUTO Date: Fri, 7 Jul 2017 21:46:35 +0200 Subject: [PATCH] src: added openssl 1.1 support Signed-off-by: Janos SUTO --- src/archive.c | 27 ++++++++++++++++++++++++++- src/smtp.c | 4 ++++ src/store.c | 21 +++++++++++++++++++++ 3 files changed, 51 insertions(+), 1 deletion(-) diff --git a/src/archive.c b/src/archive.c index 3160b6af..0759769c 100644 --- a/src/archive.c +++ b/src/archive.c @@ -135,7 +135,11 @@ int retrieve_file_from_archive(char *filename, int mode, char **buffer, FILE *de int rc=0, n, olen, tlen, len, fd=-1; unsigned char *s=NULL, *addr=NULL, inbuf[REALLYBIGBUFSIZE]; struct stat st; +#if OPENSSL_VERSION_NUMBER < 0x10100000L EVP_CIPHER_CTX ctx; +#else + EVP_CIPHER_CTX *ctx; +#endif if(filename == NULL) return 1; @@ -156,8 +160,16 @@ int retrieve_file_from_archive(char *filename, int mode, char **buffer, FILE *de if(cfg->encrypt_messages == 1){ + #if OPENSSL_VERSION_NUMBER < 0x10100000L EVP_CIPHER_CTX_init(&ctx); EVP_DecryptInit_ex(&ctx, EVP_bf_cbc(), NULL, cfg->key, cfg->iv); + #else + ctx = EVP_CIPHER_CTX_new(); + if(!ctx) goto CLEANUP; + + EVP_CIPHER_CTX_init(ctx); + EVP_DecryptInit_ex(ctx, EVP_bf_cbc(), NULL, cfg->key, cfg->iv); + #endif len = st.st_size+EVP_MAX_BLOCK_LENGTH; @@ -172,7 +184,11 @@ int retrieve_file_from_archive(char *filename, int mode, char **buffer, FILE *de while((n = read(fd, inbuf, sizeof(inbuf)))){ + #if OPENSSL_VERSION_NUMBER < 0x10100000L if(!EVP_DecryptUpdate(&ctx, s+tlen, &olen, inbuf, n)){ + #else + if(!EVP_DecryptUpdate(ctx, s+tlen, &olen, inbuf, n)){ + #endif syslog(LOG_PRIORITY, "%s: EVP_DecryptUpdate()", filename); goto CLEANUP; } @@ -181,7 +197,11 @@ int retrieve_file_from_archive(char *filename, int mode, char **buffer, FILE *de } + #if OPENSSL_VERSION_NUMBER < 0x10100000L if(EVP_DecryptFinal(&ctx, s + tlen, &olen) != 1){ + #else + if(EVP_DecryptFinal(ctx, s + tlen, &olen) != 1){ + #endif syslog(LOG_PRIORITY, "%s: EVP_DecryptFinal()", filename); goto CLEANUP; } @@ -203,7 +223,12 @@ int retrieve_file_from_archive(char *filename, int mode, char **buffer, FILE *de CLEANUP: if(fd != -1) close(fd); if(s) free(s); - if(cfg->encrypt_messages == 1) EVP_CIPHER_CTX_cleanup(&ctx); + if(cfg->encrypt_messages == 1) + #if OPENSSL_VERSION_NUMBER < 0x10100000L + EVP_CIPHER_CTX_cleanup(&ctx); + #else + EVP_CIPHER_CTX_cleanup(ctx); + #endif return 0; } diff --git a/src/smtp.c b/src/smtp.c index 499cd13c..256747f8 100644 --- a/src/smtp.c +++ b/src/smtp.c @@ -169,7 +169,11 @@ void process_command_ehlo_lhlo(struct smtp_session *session, char *buf, int bufl int init_ssl(struct smtp_session *session){ +#if OPENSSL_VERSION_NUMBER < 0x10100000L session->ctx = SSL_CTX_new(TLSv1_server_method()); +#else + session->ctx = SSL_CTX_new(TLS_server_method()); +#endif if(session->ctx == NULL){ syslog(LOG_PRIORITY, "SSL ctx is null"); diff --git a/src/store.c b/src/store.c index 1230a456..18c8784b 100644 --- a/src/store.c +++ b/src/store.c @@ -46,7 +46,11 @@ int store_file(struct session_data *sdata, char *filename, int len, struct __con Bytef *z=NULL; uLongf dstlen; +#if OPENSSL_VERSION_NUMBER < 0x10100000L EVP_CIPHER_CTX ctx; +#else + EVP_CIPHER_CTX *ctx; +#endif unsigned char *outbuf=NULL; int outlen=0, writelen, tmplen; @@ -101,16 +105,33 @@ int store_file(struct session_data *sdata, char *filename, int len, struct __con if(cfg->encrypt_messages == 1){ gettimeofday(&tv1, &tz); + #if OPENSSL_VERSION_NUMBER < 0x10100000L EVP_CIPHER_CTX_init(&ctx); EVP_EncryptInit_ex(&ctx, EVP_bf_cbc(), NULL, cfg->key, cfg->iv); + #else + ctx = EVP_CIPHER_CTX_new(); + if(!ctx) goto ENDE; + + EVP_CIPHER_CTX_init(ctx); + EVP_EncryptInit_ex(ctx, EVP_bf_cbc(), NULL, cfg->key, cfg->iv); + #endif outbuf = malloc(dstlen + EVP_MAX_BLOCK_LENGTH); if(outbuf == NULL) goto ENDE; + #if OPENSSL_VERSION_NUMBER < 0x10100000L if(!EVP_EncryptUpdate(&ctx, outbuf, &outlen, z, dstlen)) goto ENDE; if(!EVP_EncryptFinal_ex(&ctx, outbuf + outlen, &tmplen)) goto ENDE; + #else + if(!EVP_EncryptUpdate(ctx, outbuf, &outlen, z, dstlen)) goto ENDE; + if(!EVP_EncryptFinal_ex(ctx, outbuf + outlen, &tmplen)) goto ENDE; + #endif outlen += tmplen; + #if OPENSSL_VERSION_NUMBER < 0x10100000L EVP_CIPHER_CTX_cleanup(&ctx); + #else + EVP_CIPHER_CTX_cleanup(ctx); + #endif gettimeofday(&tv2, &tz); sdata->__encrypt += tvdiff(tv2, tv1);