src: added openssl 1.1 support

Signed-off-by: Janos SUTO <sj@acts.hu>
This commit is contained in:
Janos SUTO 2017-07-09 15:57:05 +02:00
parent bcd7233dc4
commit 0aff823c0a
6 changed files with 61 additions and 2 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;
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_free(ctx);
#endif
return 0;
}

View File

@ -12,7 +12,7 @@
#define PROGNAME "piler"
#define VERSION "1.3.0"
#define BUILD 955
#define BUILD 956
#define HOSTID "mailarchiver"

View File

@ -323,7 +323,11 @@ int connect_to_imap_server(int sd, int *seq, char *username, char *password, str
SSL_library_init();
SSL_load_error_strings();
#if OPENSSL_VERSION_NUMBER < 0x10100000L
data->ctx = SSL_CTX_new(TLSv1_client_method());
#else
data->ctx = SSL_CTX_new(TLS_client_method());
#endif
CHK_NULL(data->ctx, "internal SSL error");
data->ssl = SSL_new(data->ctx);

View File

@ -265,7 +265,11 @@ int init_ssl(){
SSL_library_init();
SSL_load_error_strings();
#if OPENSSL_VERSION_NUMBER < 0x10100000L
data.ctx = SSL_CTX_new(TLSv1_server_method());
#else
data.ctx = SSL_CTX_new(TLS_server_method());
#endif
if(data.ctx == NULL){ syslog(LOG_PRIORITY, "SSL_CTX_new() failed"); return ERR; }

View File

@ -48,7 +48,11 @@ int connect_to_pop3_server(int sd, char *username, char *password, struct __data
SSL_library_init();
SSL_load_error_strings();
#if OPENSSL_VERSION_NUMBER < 0x10100000L
data->ctx = SSL_CTX_new(TLSv1_client_method());
#else
data->ctx = SSL_CTX_new(TLS_client_method());
#endif
CHK_NULL(data->ctx, "internal SSL error");
data->ssl = SSL_new(data->ctx);

View File

@ -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,34 @@ 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_free(ctx);
#endif
gettimeofday(&tv2, &tz);
sdata->__encrypt += tvdiff(tv2, tv1);