Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OpenSSL 1.1 compatibility #16

Merged
merged 2 commits into from
Mar 6, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 54 additions & 9 deletions crypto/rsa_pem_openssl.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,26 +31,71 @@
#include "meta.h"
#include "rsa_pem.h"

#if OPENSSL_VERSION_NUMBER < 0x10100000L

int RSA_set0_key(RSA *r, BIGNUM *n, BIGNUM *e, BIGNUM *d)
{
/* If the fields n and e in r are NULL, the corresponding input
* parameters MUST be non-NULL for n and e. d may be
* left NULL (in case only the public key is used).
*/
if ((r->n == NULL && n == NULL)
|| (r->e == NULL && e == NULL))
return 0;

if (n != NULL) {
BN_free(r->n);
r->n = n;
}
if (e != NULL) {
BN_free(r->e);
r->e = e;
}
if (d != NULL) {
BN_free(r->d);
r->d = d;
}

return 1;
}

void RSA_get0_key(const RSA *r,
const BIGNUM **n, const BIGNUM **e, const BIGNUM **d)
{
if (n != NULL)
*n = r->n;
if (e != NULL)
*e = r->e;
if (d != NULL)
*d = r->d;
}

#endif

TGLC_WRAPPER_ASSOC(rsa,RSA)

// TODO: Refactor crucial struct-identity into its own header.
TGLC_WRAPPER_ASSOC(bn,BIGNUM)

TGLC_rsa *TGLC_rsa_new (unsigned long e, int n_bytes, const unsigned char *n) {
RSA *ret = RSA_new ();
ret->e = unwrap_bn (TGLC_bn_new ());
TGLC_bn_set_word (wrap_bn (ret->e), e);
ret->n = unwrap_bn (TGLC_bn_bin2bn (n, n_bytes, NULL));
TGLC_bn* e_tglcbn = TGLC_bn_new ();
TGLC_bn_set_word (e_tglcbn, e);
RSA_set0_key(ret, unwrap_bn (TGLC_bn_bin2bn (n, n_bytes, NULL)), unwrap_bn(e_tglcbn), NULL);
return wrap_rsa (ret);
}

#define RSA_GETTER(M) \
TGLC_bn *TGLC_rsa_ ## M (TGLC_rsa *key) { \
return wrap_bn (unwrap_rsa (key)->M); \
} \
TGLC_bn *TGLC_rsa_n (TGLC_rsa * key) {
const BIGNUM *n;
RSA_get0_key( unwrap_rsa(key), &n, NULL, NULL);
return wrap_bn(n);
}

RSA_GETTER(n);
RSA_GETTER(e);
TGLC_bn *TGLC_rsa_e (TGLC_rsa * key) {
const BIGNUM *e;
RSA_get0_key( unwrap_rsa(key), NULL, &e, NULL);
return wrap_bn(e);
}

void TGLC_rsa_free (TGLC_rsa *p) {
RSA_free (unwrap_rsa (p));
Expand Down
5 changes: 3 additions & 2 deletions structures.c
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,7 @@ struct tgl_chat *tglf_fetch_alloc_chat (struct tgl_state *TLS, struct tl_ds_chat
if (DS_C->magic == CODE_chat_empty) {
return NULL;
}
if (DS_C->magic == CODE_channel) {
if (DS_C->magic == CODE_channel || DS_C->magic == CODE_channel_forbidden) {
return (void *)tglf_fetch_alloc_channel (TLS, DS_C);
}
tgl_peer_id_t chat_id = TGL_MK_CHAT (DS_LVAL (DS_C->id));
Expand Down Expand Up @@ -1548,7 +1548,8 @@ struct tgl_message *tglf_fetch_alloc_message (struct tgl_state *TLS, struct tl_d
tgl_peer_t *FF = NULL;

if (DS_M->fwd_from_id) {
FF = tgl_peer_get (TLS, tglf_fetch_peer_id (TLS, DS_M->fwd_from_id));
tgl_peer_id_t FF_id = tglf_fetch_peer_id (TLS, DS_M->fwd_from_id);
FF = tgl_peer_get (TLS, FF_id);
if (!FF) {
tgl_do_get_difference (TLS, 0, 0, 0);
vlogprintf (E_NOTICE, "unknown fwd_id\n");
Expand Down