Added support for OpenSSL 1.1

Signed-off-by: Slávek Banko <slavek.banko@axis.cz>
pull/1/head
Slávek Banko 8 years ago
parent 4c0da96d74
commit 309256b74d

@ -37,6 +37,7 @@
#include <kmdcodec.h> #include <kmdcodec.h>
#include <ntqfile.h> #include <ntqfile.h>
#include <stdlib.h>
namespace KFTPGrabberBase { namespace KFTPGrabberBase {

@ -64,10 +64,15 @@ PUBLIC_KEY *publickey_make_dss(BUFFER *buffer){
return NULL; return NULL;
} }
key->dsa_pub=DSA_new(); key->dsa_pub=DSA_new();
#if OPENSSL_VERSION_NUMBER < 0x10100000L
key->dsa_pub->p=make_string_bn(p); key->dsa_pub->p=make_string_bn(p);
key->dsa_pub->q=make_string_bn(q); key->dsa_pub->q=make_string_bn(q);
key->dsa_pub->g=make_string_bn(g); key->dsa_pub->g=make_string_bn(g);
key->dsa_pub->pub_key=make_string_bn(pubkey); 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(p);
free(q); free(q);
free(g); free(g);
@ -93,11 +98,17 @@ PUBLIC_KEY *publickey_make_rsa(BUFFER *buffer){
return NULL; return NULL;
} }
key->rsa_pub=RSA_new(); key->rsa_pub=RSA_new();
key->rsa_pub->e=make_string_bn(e); BIGNUM *bn_e = make_string_bn(e);
key->rsa_pub->n=make_string_bn(n); 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 #ifdef DEBUG_CRYPTO
ssh_print_bignum("e",key->rsa_pub->e); ssh_print_bignum("e", bn_e);
ssh_print_bignum("n",key->rsa_pub->n); ssh_print_bignum("n", bn_n);
#endif #endif
free(e); free(e);
free(n); free(n);
@ -161,9 +172,17 @@ STRING *signature_to_string(SIGNATURE *sign){
buffer_add_ssh_string(tmpbuf,tmp); buffer_add_ssh_string(tmpbuf,tmp);
free(tmp); free(tmp);
switch(sign->type){ switch(sign->type){
case TYPE_DSS: case TYPE_DSS: {
r=make_bignum_string(sign->dsa_sign->r); BIGNUM *bn_r = 0L;
s=make_bignum_string(sign->dsa_sign->s); 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); rs=string_new(40);
memset(buffer,0,40); memset(buffer,0,40);
memcpy(buffer,r->string+string_len(r)-20,20); 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); buffer_add_ssh_string(tmpbuf,rs);
free(rs); free(rs);
break; break;
}
case TYPE_RSA: case TYPE_RSA:
case TYPE_RSA1: case TYPE_RSA1:
buffer_add_ssh_string(tmpbuf,sign->rsa_sign); 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); string_fill(s,rs->string+20,20);
free(rs); free(rs);
sig=DSA_SIG_new(); sig=DSA_SIG_new();
sig->r=make_string_bn(r); /* is that really portable ? Openssh's hack isn't better */ BIGNUM *bn_r = make_string_bn(r);
sig->s=make_string_bn(s); 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 #ifdef DEBUG_CRYPTO
ssh_print_bignum("r",sig->r); ssh_print_bignum("r", bn_r);
ssh_print_bignum("s",sig->s); ssh_print_bignum("s", bn_s);
#endif #endif
free(r); free(r);
free(s); free(s);

@ -78,9 +78,13 @@ void md5_final(unsigned char *md,MD5CTX *c){
HMACCTX *hmac_init(const void *key, int len,int type){ HMACCTX *hmac_init(const void *key, int len,int type){
HMAC_CTX *ctx; HMAC_CTX *ctx;
ctx=malloc(sizeof(HMAC_CTX)); #if (OPENSSL_VERSION_NUMBER < 0x10100000L)
ctx = OPENSSL_malloc(sizeof(HMAC_CTX));
#ifndef OLD_CRYPTO #ifndef OLD_CRYPTO
HMAC_CTX_init(ctx); HMAC_CTX_init(ctx);
#endif
#else
ctx = HMAC_CTX_new();
#endif #endif
switch(type){ switch(type){
case HMAC_SHA1: 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){ void hmac_final(HMACCTX *ctx,unsigned char *hashmacbuf,int *len){
HMAC_Final(ctx,hashmacbuf,len); HMAC_Final(ctx,hashmacbuf,len);
#if (OPENSSL_VERSION_NUMBER < 0x10100000L)
#ifndef OLD_CRYPTO #ifndef OLD_CRYPTO
HMAC_CTX_cleanup(ctx); HMAC_CTX_cleanup(ctx);
#else #else
HMAC_cleanup(ctx); HMAC_cleanup(ctx);
#endif #endif
free(ctx); OPENSSL_free(ctx);
#else
HMAC_CTX_free(ctx);
#endif
} }
static void alloc_key(struct crypto_struct *cipher){ static void alloc_key(struct crypto_struct *cipher){

Loading…
Cancel
Save