telegram-cli.patch 3.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. diff --git a/tgl/crypto/rsa_pem_openssl.c b/tgl/crypto/rsa_pem_openssl.c
  2. index db653f2..5e6a697 100644
  3. --- a/tgl/crypto/rsa_pem_openssl.c
  4. +++ b/tgl/crypto/rsa_pem_openssl.c
  5. @@ -36,6 +36,12 @@ TGLC_WRAPPER_ASSOC(rsa,RSA)
  6. // TODO: Refactor crucial struct-identity into its own header.
  7. TGLC_WRAPPER_ASSOC(bn,BIGNUM)
  8. +/*
  9. + * Since OpenSSL version 1.1.0 the RSA struct (rsa_st) is opaque,
  10. + * see also https://wiki.openssl.org/index.php/OpenSSL_1.1.0_Changes
  11. + */
  12. +#if (OPENSSL_VERSION_NUMBER < 0x10100000L)
  13. +
  14. TGLC_rsa *TGLC_rsa_new (unsigned long e, int n_bytes, const unsigned char *n) {
  15. RSA *ret = RSA_new ();
  16. ret->e = unwrap_bn (TGLC_bn_new ());
  17. @@ -47,7 +53,30 @@ TGLC_rsa *TGLC_rsa_new (unsigned long e, int n_bytes, const unsigned char *n) {
  18. #define RSA_GETTER(M) \
  19. TGLC_bn *TGLC_rsa_ ## M (TGLC_rsa *key) { \
  20. return wrap_bn (unwrap_rsa (key)->M); \
  21. - } \
  22. + }
  23. +
  24. +#else // OPENSSL_VERSION_NUMBER
  25. +
  26. +TGLC_rsa *TGLC_rsa_new (unsigned long e, int n_bytes, const unsigned char *n) {
  27. + RSA *ret = RSA_new ();
  28. + BIGNUM *ret_e = unwrap_bn (TGLC_bn_new ());
  29. + BIGNUM *ret_n = unwrap_bn (TGLC_bn_bin2bn (n, n_bytes, NULL));
  30. + RSA_set0_key (ret, ret_n, ret_e, NULL);
  31. + TGLC_bn_set_word (wrap_bn (ret_e), e);
  32. + return wrap_rsa (ret);
  33. +}
  34. +
  35. +#define RSA_GETTER(M) \
  36. +TGLC_bn *TGLC_rsa_ ## M (TGLC_rsa *key) { \
  37. + BIGNUM *rsa_n, *rsa_e, *rsa_d; \
  38. + RSA_get0_key(unwrap_rsa (key), \
  39. + (const BIGNUM **) &rsa_n, \
  40. + (const BIGNUM **) &rsa_e, \
  41. + (const BIGNUM **) &rsa_d); \
  42. + return wrap_bn (rsa_ ## M); \
  43. +}
  44. +
  45. +#endif // OPENSSL_VERSION_NUMBER
  46. RSA_GETTER(n);
  47. RSA_GETTER(e);
  48. @@ -60,4 +89,4 @@ TGLC_rsa *TGLC_pem_read_RSAPublicKey (FILE *fp) {
  49. return wrap_rsa (PEM_read_RSAPublicKey (fp, NULL, NULL, NULL));
  50. }
  51. -#endif
  52. +#endif // TGL_AVOID_OPENSSL
  53. diff --git a/tgl/mtproto-utils.c b/tgl/mtproto-utils.c
  54. index 0948bc8..cfdb216 100644
  55. --- a/tgl/mtproto-utils.c
  56. +++ b/tgl/mtproto-utils.c
  57. @@ -98,7 +98,7 @@ static unsigned long long BN2ull (TGLC_bn *b) {
  58. if (sizeof (unsigned long) == 8) {
  59. return TGLC_bn_get_word (b);
  60. } else if (sizeof (unsigned long long) == 8) {
  61. - assert (0); // As long as nobody ever uses this code, assume it is broken.
  62. +// assert (0); // As long as nobody ever uses this code, assume it is broken.
  63. unsigned long long tmp;
  64. /* Here be dragons, but it should be okay due to be64toh */
  65. TGLC_bn_bn2bin (b, (unsigned char *) &tmp);
  66. @@ -112,7 +112,7 @@ static void ull2BN (TGLC_bn *b, unsigned long long val) {
  67. if (sizeof (unsigned long) == 8 || val < (1ll << 32)) {
  68. TGLC_bn_set_word (b, val);
  69. } else if (sizeof (unsigned long long) == 8) {
  70. - assert (0); // As long as nobody ever uses this code, assume it is broken.
  71. +// assert (0); // As long as nobody ever uses this code, assume it is broken.
  72. htobe64(val);
  73. /* Here be dragons, but it should be okay due to htobe64 */
  74. TGLC_bn_bin2bn ((unsigned char *) &val, 8, b);
  75. diff --git a/tgl/tl-parser/tl-parser.c b/tgl/tl-parser/tl-parser.c
  76. index 524b196..aeadbd2 100644
  77. --- a/tgl/tl-parser/tl-parser.c
  78. +++ b/tgl/tl-parser/tl-parser.c
  79. @@ -1903,7 +1903,7 @@ struct tl_combinator_tree *tl_parse_args134 (struct tree *T) {
  80. //assert (S->data);
  81. char *name = S->data;
  82. if (!name) {
  83. - static char s[20];
  84. + static char s[21];
  85. sprintf (s, "%lld", lrand48 () * (1ll << 32) + lrand48 ());
  86. name = s;
  87. }