Merge pull request #459 from Natureshadow/openssl110

Fix ssl_calls for OpenSSL 1.1.0
master
metalefty 8 years ago committed by GitHub
commit cde340350c

@ -170,8 +170,7 @@ ssl_des3_encrypt_info_create(const char *key, const char* ivec)
const tui8 *lkey; const tui8 *lkey;
const tui8 *livec; const tui8 *livec;
des3_ctx = (EVP_CIPHER_CTX *) g_malloc(sizeof(EVP_CIPHER_CTX), 1); des3_ctx = EVP_CIPHER_CTX_new();
EVP_CIPHER_CTX_init(des3_ctx);
lkey = (const tui8 *) key; lkey = (const tui8 *) key;
livec = (const tui8 *) ivec; livec = (const tui8 *) ivec;
EVP_EncryptInit_ex(des3_ctx, EVP_des_ede3_cbc(), NULL, lkey, livec); EVP_EncryptInit_ex(des3_ctx, EVP_des_ede3_cbc(), NULL, lkey, livec);
@ -187,8 +186,7 @@ ssl_des3_decrypt_info_create(const char *key, const char* ivec)
const tui8 *lkey; const tui8 *lkey;
const tui8 *livec; const tui8 *livec;
des3_ctx = g_new0(EVP_CIPHER_CTX, 1); des3_ctx = EVP_CIPHER_CTX_new();
EVP_CIPHER_CTX_init(des3_ctx);
lkey = (const tui8 *) key; lkey = (const tui8 *) key;
livec = (const tui8 *) ivec; livec = (const tui8 *) ivec;
EVP_DecryptInit_ex(des3_ctx, EVP_des_ede3_cbc(), NULL, lkey, livec); EVP_DecryptInit_ex(des3_ctx, EVP_des_ede3_cbc(), NULL, lkey, livec);
@ -205,8 +203,7 @@ ssl_des3_info_delete(void *des3)
des3_ctx = (EVP_CIPHER_CTX *) des3; des3_ctx = (EVP_CIPHER_CTX *) des3;
if (des3_ctx != 0) if (des3_ctx != 0)
{ {
EVP_CIPHER_CTX_cleanup(des3_ctx); EVP_CIPHER_CTX_free(des3_ctx);
g_free(des3_ctx);
} }
} }
@ -250,8 +247,12 @@ ssl_hmac_info_create(void)
{ {
HMAC_CTX *hmac_ctx; HMAC_CTX *hmac_ctx;
#if OPENSSL_VERSION_NUMBER >= 0x10100000L
hmac_ctx = HMAC_CTX_new();
#else
hmac_ctx = (HMAC_CTX *) g_malloc(sizeof(HMAC_CTX), 1); hmac_ctx = (HMAC_CTX *) g_malloc(sizeof(HMAC_CTX), 1);
HMAC_CTX_init(hmac_ctx); HMAC_CTX_init(hmac_ctx);
#endif
return hmac_ctx; return hmac_ctx;
} }
@ -264,8 +265,12 @@ ssl_hmac_info_delete(void *hmac)
hmac_ctx = (HMAC_CTX *) hmac; hmac_ctx = (HMAC_CTX *) hmac;
if (hmac_ctx != 0) if (hmac_ctx != 0)
{ {
#if OPENSSL_VERSION_NUMBER >= 0x10100000L
HMAC_CTX_free(hmac_ctx);
#else
HMAC_CTX_cleanup(hmac_ctx); HMAC_CTX_cleanup(hmac_ctx);
g_free(hmac_ctx); g_free(hmac_ctx);
#endif
} }
} }
@ -332,10 +337,10 @@ ssl_mod_exp(char *out, int out_len, char *in, int in_len,
char *mod, int mod_len, char *exp, int exp_len) char *mod, int mod_len, char *exp, int exp_len)
{ {
BN_CTX *ctx; BN_CTX *ctx;
BIGNUM lmod; BIGNUM *lmod;
BIGNUM lexp; BIGNUM *lexp;
BIGNUM lin; BIGNUM *lin;
BIGNUM lout; BIGNUM *lout;
int rv; int rv;
char *l_out; char *l_out;
char *l_in; char *l_in;
@ -353,15 +358,15 @@ ssl_mod_exp(char *out, int out_len, char *in, int in_len,
ssl_reverse_it(l_mod, mod_len); ssl_reverse_it(l_mod, mod_len);
ssl_reverse_it(l_exp, exp_len); ssl_reverse_it(l_exp, exp_len);
ctx = BN_CTX_new(); ctx = BN_CTX_new();
BN_init(&lmod); lmod = BN_new();
BN_init(&lexp); lexp = BN_new();
BN_init(&lin); lin = BN_new();
BN_init(&lout); lout = BN_new();
BN_bin2bn((tui8 *)l_mod, mod_len, &lmod); BN_bin2bn((tui8 *)l_mod, mod_len, lmod);
BN_bin2bn((tui8 *)l_exp, exp_len, &lexp); BN_bin2bn((tui8 *)l_exp, exp_len, lexp);
BN_bin2bn((tui8 *)l_in, in_len, &lin); BN_bin2bn((tui8 *)l_in, in_len, lin);
BN_mod_exp(&lout, &lin, &lexp, &lmod, ctx); BN_mod_exp(lout, lin, lexp, lmod, ctx);
rv = BN_bn2bin(&lout, (tui8 *)l_out); rv = BN_bn2bin(lout, (tui8 *)l_out);
if (rv <= out_len) if (rv <= out_len)
{ {
@ -373,10 +378,10 @@ ssl_mod_exp(char *out, int out_len, char *in, int in_len,
rv = 0; rv = 0;
} }
BN_free(&lin); BN_free(lin);
BN_free(&lout); BN_free(lout);
BN_free(&lexp); BN_free(lexp);
BN_free(&lmod); BN_free(lmod);
BN_CTX_free(ctx); BN_CTX_free(ctx);
g_free(l_out); g_free(l_out);
g_free(l_in); g_free(l_in);
@ -494,29 +499,38 @@ ssl_gen_key_xrdp1(int key_size_in_bits, char *exp, int exp_len,
my_key = RSA_new(); my_key = RSA_new();
error = RSA_generate_key_ex(my_key, key_size_in_bits, my_e, 0) == 0; error = RSA_generate_key_ex(my_key, key_size_in_bits, my_e, 0) == 0;
const BIGNUM *n;
const BIGNUM *d;
#if OPENSSL_VERSION_NUMBER >= 0x10100000L
RSA_get0_key(my_key, &n, NULL, &d);
#else
n = my_key->n;
d = my_key->d;
#endif
if (error == 0) if (error == 0)
{ {
len = BN_num_bytes(my_key->n); len = BN_num_bytes(n);
error = (len < 1) || (len > mod_len); error = (len < 1) || (len > mod_len);
diff = mod_len - len; diff = mod_len - len;
} }
if (error == 0) if (error == 0)
{ {
BN_bn2bin(my_key->n, (tui8 *)(lmod + diff)); BN_bn2bin(n, (tui8 *)(lmod + diff));
ssl_reverse_it(lmod, mod_len); ssl_reverse_it(lmod, mod_len);
} }
if (error == 0) if (error == 0)
{ {
len = BN_num_bytes(my_key->d); len = BN_num_bytes(d);
error = (len < 1) || (len > pri_len); error = (len < 1) || (len > pri_len);
diff = pri_len - len; diff = pri_len - len;
} }
if (error == 0) if (error == 0)
{ {
BN_bn2bin(my_key->d, (tui8 *)(lpri + diff)); BN_bn2bin(d, (tui8 *)(lpri + diff));
ssl_reverse_it(lpri, pri_len); ssl_reverse_it(lpri, pri_len);
} }

Loading…
Cancel
Save