src: added openssl 1.1 support

Signed-off-by: Janos SUTO <sj@acts.hu>
This commit is contained in:
Janos SUTO 2017-07-07 21:46:35 +02:00
parent a7e885464b
commit 30d8861b5d
3 changed files with 51 additions and 1 deletions

View File

@ -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; int rc=0, n, olen, tlen, len, fd=-1;
unsigned char *s=NULL, *addr=NULL, inbuf[REALLYBIGBUFSIZE]; unsigned char *s=NULL, *addr=NULL, inbuf[REALLYBIGBUFSIZE];
struct stat st; struct stat st;
#if OPENSSL_VERSION_NUMBER < 0x10100000L
EVP_CIPHER_CTX ctx; EVP_CIPHER_CTX ctx;
#else
EVP_CIPHER_CTX *ctx;
#endif
if(filename == NULL) return 1; 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(cfg->encrypt_messages == 1){
#if OPENSSL_VERSION_NUMBER < 0x10100000L
EVP_CIPHER_CTX_init(&ctx); EVP_CIPHER_CTX_init(&ctx);
EVP_DecryptInit_ex(&ctx, EVP_bf_cbc(), NULL, cfg->key, cfg->iv); 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; 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)))){ while((n = read(fd, inbuf, sizeof(inbuf)))){
#if OPENSSL_VERSION_NUMBER < 0x10100000L
if(!EVP_DecryptUpdate(&ctx, s+tlen, &olen, inbuf, n)){ 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); syslog(LOG_PRIORITY, "%s: EVP_DecryptUpdate()", filename);
goto CLEANUP; 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){ 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); syslog(LOG_PRIORITY, "%s: EVP_DecryptFinal()", filename);
goto CLEANUP; goto CLEANUP;
} }
@ -203,7 +223,12 @@ int retrieve_file_from_archive(char *filename, int mode, char **buffer, FILE *de
CLEANUP: CLEANUP:
if(fd != -1) close(fd); if(fd != -1) close(fd);
if(s) free(s); 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; return 0;
} }

View File

@ -169,7 +169,11 @@ void process_command_ehlo_lhlo(struct smtp_session *session, char *buf, int bufl
int init_ssl(struct smtp_session *session){ int init_ssl(struct smtp_session *session){
#if OPENSSL_VERSION_NUMBER < 0x10100000L
session->ctx = SSL_CTX_new(TLSv1_server_method()); session->ctx = SSL_CTX_new(TLSv1_server_method());
#else
session->ctx = SSL_CTX_new(TLS_server_method());
#endif
if(session->ctx == NULL){ if(session->ctx == NULL){
syslog(LOG_PRIORITY, "SSL ctx is null"); syslog(LOG_PRIORITY, "SSL ctx is null");

View File

@ -46,7 +46,11 @@ int store_file(struct session_data *sdata, char *filename, int len, struct __con
Bytef *z=NULL; Bytef *z=NULL;
uLongf dstlen; uLongf dstlen;
#if OPENSSL_VERSION_NUMBER < 0x10100000L
EVP_CIPHER_CTX ctx; EVP_CIPHER_CTX ctx;
#else
EVP_CIPHER_CTX *ctx;
#endif
unsigned char *outbuf=NULL; unsigned char *outbuf=NULL;
int outlen=0, writelen, tmplen; 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){ if(cfg->encrypt_messages == 1){
gettimeofday(&tv1, &tz); gettimeofday(&tv1, &tz);
#if OPENSSL_VERSION_NUMBER < 0x10100000L
EVP_CIPHER_CTX_init(&ctx); EVP_CIPHER_CTX_init(&ctx);
EVP_EncryptInit_ex(&ctx, EVP_bf_cbc(), NULL, cfg->key, cfg->iv); 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); outbuf = malloc(dstlen + EVP_MAX_BLOCK_LENGTH);
if(outbuf == NULL) goto ENDE; if(outbuf == NULL) goto ENDE;
#if OPENSSL_VERSION_NUMBER < 0x10100000L
if(!EVP_EncryptUpdate(&ctx, outbuf, &outlen, z, dstlen)) goto ENDE; if(!EVP_EncryptUpdate(&ctx, outbuf, &outlen, z, dstlen)) goto ENDE;
if(!EVP_EncryptFinal_ex(&ctx, outbuf + outlen, &tmplen)) 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; outlen += tmplen;
#if OPENSSL_VERSION_NUMBER < 0x10100000L
EVP_CIPHER_CTX_cleanup(&ctx); EVP_CIPHER_CTX_cleanup(&ctx);
#else
EVP_CIPHER_CTX_cleanup(ctx);
#endif
gettimeofday(&tv2, &tz); gettimeofday(&tv2, &tz);
sdata->__encrypt += tvdiff(tv2, tv1); sdata->__encrypt += tvdiff(tv2, tv1);