From 0b0e251bbbaa4d83d36a4b6d383cd5750f67d777 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sl=C3=A1vek=20Banko?= Date: Sat, 7 Jan 2017 16:23:50 +0100 Subject: [PATCH] Added support for OpenSSL 1.1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Slávek Banko (cherry picked from commit 309256b74d57b5ba7a4a7a10cfca671cf8fbafd8) --- kftpgrabber/src/misc/desencryptor.cpp | 1 + kftpgrabber/src/misc/libs/ssh/keys.c | 48 +++++++++++++++++++------ kftpgrabber/src/misc/libs/ssh/wrapper.c | 12 +++++-- 3 files changed, 48 insertions(+), 13 deletions(-) diff --git a/kftpgrabber/src/misc/desencryptor.cpp b/kftpgrabber/src/misc/desencryptor.cpp index 126fad7..a66a5ef 100644 --- a/kftpgrabber/src/misc/desencryptor.cpp +++ b/kftpgrabber/src/misc/desencryptor.cpp @@ -37,6 +37,7 @@ #include #include +#include namespace KFTPGrabberBase { diff --git a/kftpgrabber/src/misc/libs/ssh/keys.c b/kftpgrabber/src/misc/libs/ssh/keys.c index f404f4b..2d7541b 100644 --- a/kftpgrabber/src/misc/libs/ssh/keys.c +++ b/kftpgrabber/src/misc/libs/ssh/keys.c @@ -64,10 +64,15 @@ PUBLIC_KEY *publickey_make_dss(BUFFER *buffer){ return NULL; } key->dsa_pub=DSA_new(); +#if OPENSSL_VERSION_NUMBER < 0x10100000L key->dsa_pub->p=make_string_bn(p); key->dsa_pub->q=make_string_bn(q); key->dsa_pub->g=make_string_bn(g); key->dsa_pub->pub_key=make_string_bn(pubkey); +#else + DSA_set0_pqg(key->dsa_pub, make_string_bn(p), make_string_bn(q), make_string_bn(g)); + DSA_set0_key(key->dsa_pub, make_string_bn(pubkey), NULL); +#endif free(p); free(q); free(g); @@ -93,11 +98,17 @@ PUBLIC_KEY *publickey_make_rsa(BUFFER *buffer){ return NULL; } key->rsa_pub=RSA_new(); - key->rsa_pub->e=make_string_bn(e); - key->rsa_pub->n=make_string_bn(n); + BIGNUM *bn_e = make_string_bn(e); + BIGNUM *bn_n = make_string_bn(n); +#if (OPENSSL_VERSION_NUMBER < 0x10100000L) + key->rsa_pub->e = bn_e; + key->rsa_pub->n = bn_n; +#else + RSA_set0_key(key->rsa_pub, bn_n, bn_e, NULL); +#endif #ifdef DEBUG_CRYPTO - ssh_print_bignum("e",key->rsa_pub->e); - ssh_print_bignum("n",key->rsa_pub->n); + ssh_print_bignum("e", bn_e); + ssh_print_bignum("n", bn_n); #endif free(e); free(n); @@ -161,9 +172,17 @@ STRING *signature_to_string(SIGNATURE *sign){ buffer_add_ssh_string(tmpbuf,tmp); free(tmp); switch(sign->type){ - case TYPE_DSS: - r=make_bignum_string(sign->dsa_sign->r); - s=make_bignum_string(sign->dsa_sign->s); + case TYPE_DSS: { + BIGNUM *bn_r = 0L; + BIGNUM *bn_s = 0L; +#if OPENSSL_VERSION_NUMBER < 0x10100000L + bn_r = sign->dsa_sign->r; + bn_s = sign->dsa_sign->s; +#else + DSA_SIG_get0(sign->dsa_sign, &bn_r, &bn_s); +#endif + r = make_bignum_string(bn_r); + s = make_bignum_string(bn_s); rs=string_new(40); memset(buffer,0,40); memcpy(buffer,r->string+string_len(r)-20,20); @@ -174,6 +193,7 @@ STRING *signature_to_string(SIGNATURE *sign){ buffer_add_ssh_string(tmpbuf,rs); free(rs); break; + } case TYPE_RSA: case TYPE_RSA1: buffer_add_ssh_string(tmpbuf,sign->rsa_sign); @@ -243,11 +263,17 @@ SIGNATURE *signature_from_string(STRING *signature,PUBLIC_KEY *pubkey,int needed string_fill(s,rs->string+20,20); free(rs); sig=DSA_SIG_new(); - sig->r=make_string_bn(r); /* is that really portable ? Openssh's hack isn't better */ - sig->s=make_string_bn(s); + BIGNUM *bn_r = make_string_bn(r); + BIGNUM *bn_s = make_string_bn(s); +#if OPENSSL_VERSION_NUMBER < 0x10100000L + sig->r = bn_r; /* is that really portable ? Openssh's hack isn't better */ + sig->s = bn_s; +#else + DSA_SIG_set0(sig, bn_r, bn_s); +#endif #ifdef DEBUG_CRYPTO - ssh_print_bignum("r",sig->r); - ssh_print_bignum("s",sig->s); + ssh_print_bignum("r", bn_r); + ssh_print_bignum("s", bn_s); #endif free(r); free(s); diff --git a/kftpgrabber/src/misc/libs/ssh/wrapper.c b/kftpgrabber/src/misc/libs/ssh/wrapper.c index c47d4cc..36bdd15 100644 --- a/kftpgrabber/src/misc/libs/ssh/wrapper.c +++ b/kftpgrabber/src/misc/libs/ssh/wrapper.c @@ -78,9 +78,13 @@ void md5_final(unsigned char *md,MD5CTX *c){ HMACCTX *hmac_init(const void *key, int len,int type){ HMAC_CTX *ctx; - ctx=malloc(sizeof(HMAC_CTX)); +#if (OPENSSL_VERSION_NUMBER < 0x10100000L) + ctx = OPENSSL_malloc(sizeof(HMAC_CTX)); #ifndef OLD_CRYPTO HMAC_CTX_init(ctx); +#endif +#else + ctx = HMAC_CTX_new(); #endif switch(type){ case HMAC_SHA1: @@ -100,12 +104,16 @@ void hmac_update(HMACCTX *ctx,const void *data, unsigned long len){ } void hmac_final(HMACCTX *ctx,unsigned char *hashmacbuf,int *len){ HMAC_Final(ctx,hashmacbuf,len); +#if (OPENSSL_VERSION_NUMBER < 0x10100000L) #ifndef OLD_CRYPTO HMAC_CTX_cleanup(ctx); #else HMAC_cleanup(ctx); #endif - free(ctx); + OPENSSL_free(ctx); +#else + HMAC_CTX_free(ctx); +#endif } static void alloc_key(struct crypto_struct *cipher){