From 26fea35fd74c402b4d5333f2664ae5fd86b7a016 Mon Sep 17 00:00:00 2001 From: funwaa <56044926+funwaa@users.noreply.github.com> Date: Tue, 1 Oct 2019 22:07:35 +0200 Subject: [PATCH 1/2] Update mtproto-utils.c Fix an issue caused with newer OS and library versions that causes the software to fail. --- mtproto-utils.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mtproto-utils.c b/mtproto-utils.c index 0948bc85..19f04b57 100644 --- a/mtproto-utils.c +++ b/mtproto-utils.c @@ -98,7 +98,7 @@ static unsigned long long BN2ull (TGLC_bn *b) { if (sizeof (unsigned long) == 8) { return TGLC_bn_get_word (b); } else if (sizeof (unsigned long long) == 8) { - assert (0); // As long as nobody ever uses this code, assume it is broken. + //assert (0); // As long as nobody ever uses this code, assume it is broken. unsigned long long tmp; /* Here be dragons, but it should be okay due to be64toh */ TGLC_bn_bn2bin (b, (unsigned char *) &tmp); @@ -112,7 +112,7 @@ static void ull2BN (TGLC_bn *b, unsigned long long val) { if (sizeof (unsigned long) == 8 || val < (1ll << 32)) { TGLC_bn_set_word (b, val); } else if (sizeof (unsigned long long) == 8) { - assert (0); // As long as nobody ever uses this code, assume it is broken. + //assert (0); // As long as nobody ever uses this code, assume it is broken. htobe64(val); /* Here be dragons, but it should be okay due to htobe64 */ TGLC_bn_bin2bn ((unsigned char *) &val, 8, b); From 360aa27f9697e9a6daadc07a0652c2b806ff8285 Mon Sep 17 00:00:00 2001 From: funwaa <56044926+funwaa@users.noreply.github.com> Date: Tue, 1 Oct 2019 22:19:27 +0200 Subject: [PATCH 2/2] Update rsa_pem_openssl.c Make this work with newer openSSL library versions. --- crypto/rsa_pem_openssl.c | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/crypto/rsa_pem_openssl.c b/crypto/rsa_pem_openssl.c index db653f25..a9f5a0b6 100644 --- a/crypto/rsa_pem_openssl.c +++ b/crypto/rsa_pem_openssl.c @@ -36,6 +36,7 @@ TGLC_WRAPPER_ASSOC(rsa,RSA) // TODO: Refactor crucial struct-identity into its own header. TGLC_WRAPPER_ASSOC(bn,BIGNUM) +#if (OPENSSL_VERSION_NUMBER < 0x10100000L) 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 ()); @@ -43,11 +44,32 @@ TGLC_rsa *TGLC_rsa_new (unsigned long e, int n_bytes, const unsigned char *n) { ret->n = unwrap_bn (TGLC_bn_bin2bn (n, n_bytes, NULL)); return wrap_rsa (ret); } - #define RSA_GETTER(M) \ TGLC_bn *TGLC_rsa_ ## M (TGLC_rsa *key) { \ return wrap_bn (unwrap_rsa (key)->M); \ } \ +#else // OPENSSL_VERSION_NUMBER + +TGLC_rsa *TGLC_rsa_new (unsigned long e, int n_bytes, const unsigned char *n) { + RSA *ret = RSA_new (); + BIGNUM *ret_e = unwrap_bn (TGLC_bn_new ()); + BIGNUM *ret_n = unwrap_bn (TGLC_bn_bin2bn (n, n_bytes, NULL)); + RSA_set0_key (ret, ret_n, ret_e, NULL); + TGLC_bn_set_word (wrap_bn (ret_e), e); + return wrap_rsa (ret); +} + +#define RSA_GETTER(M) \ +TGLC_bn *TGLC_rsa_ ## M (TGLC_rsa *key) { \ + BIGNUM *rsa_n, *rsa_e, *rsa_d; \ + RSA_get0_key(unwrap_rsa (key), \ + (const BIGNUM **) &rsa_n, \ + (const BIGNUM **) &rsa_e, \ + (const BIGNUM **) &rsa_d); \ + return wrap_bn (rsa_ ## M); \ +} + +#endif // OPENSSL_VERSION_NUMBER RSA_GETTER(n); RSA_GETTER(e); @@ -60,4 +82,4 @@ TGLC_rsa *TGLC_pem_read_RSAPublicKey (FILE *fp) { return wrap_rsa (PEM_read_RSAPublicKey (fp, NULL, NULL, NULL)); } -#endif +#endif // TGL_AVOID_OPENSSL