rtmpdump-openssl-1.1-v2.patch 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. https://raw.githubusercontent.com/xbmc/inputstream.rtmp/master/depends/common/librtmp/0003-openssl-1.1.patch
  2. See also https://github.com/xbmc/inputstream.rtmp/pull/46
  3. --- a/librtmp/dh.h
  4. +++ b/librtmp/dh.h
  5. @@ -253,20 +253,42 @@
  6. if (!dh)
  7. goto failed;
  8. +#if !defined(USE_OPENSSL) || !defined(OPENSSL_VERSION_NUMBER) || OPENSSL_VERSION_NUMBER < 0x10100000L
  9. MP_new(dh->g);
  10. if (!dh->g)
  11. goto failed;
  12. +#else
  13. + BIGNUM *g = NULL;
  14. + MP_new(g);
  15. + if (!g)
  16. + goto failed;
  17. +#endif
  18. +#if !defined(USE_OPENSSL) || !defined(OPENSSL_VERSION_NUMBER) || OPENSSL_VERSION_NUMBER < 0x10100000L
  19. MP_gethex(dh->p, P1024, res); /* prime P1024, see dhgroups.h */
  20. +#else
  21. + BIGNUM* p = NULL;
  22. + DH_get0_pqg(dh, (BIGNUM const**)&p, NULL, NULL);
  23. + MP_gethex(p, P1024, res); /* prime P1024, see dhgroups.h */
  24. +#endif
  25. if (!res)
  26. {
  27. goto failed;
  28. }
  29. +#if !defined(USE_OPENSSL) || !defined(OPENSSL_VERSION_NUMBER) || OPENSSL_VERSION_NUMBER < 0x10100000L
  30. MP_set_w(dh->g, 2); /* base 2 */
  31. +#else
  32. + MP_set_w(g, 2); /* base 2 */
  33. + DH_set0_pqg(dh, p, NULL, g);
  34. +#endif
  35. +#if !defined(USE_OPENSSL) || !defined(OPENSSL_VERSION_NUMBER) || OPENSSL_VERSION_NUMBER < 0x10100000L
  36. dh->length = nKeyBits;
  37. +#else
  38. + DH_set_length(dh, nKeyBits);
  39. +#endif
  40. return dh;
  41. failed:
  42. @@ -293,12 +315,24 @@
  43. MP_gethex(q1, Q1024, res);
  44. assert(res);
  45. +#if !defined(USE_OPENSSL) || !defined(OPENSSL_VERSION_NUMBER) || OPENSSL_VERSION_NUMBER < 0x10100000L
  46. res = isValidPublicKey(dh->pub_key, dh->p, q1);
  47. +#else
  48. + BIGNUM const* pub_key = NULL;
  49. + BIGNUM const* p = NULL;
  50. + DH_get0_key(dh, &pub_key, NULL);
  51. + DH_get0_pqg(dh, &p, NULL, NULL);
  52. + res = isValidPublicKey((BIGNUM*)pub_key, (BIGNUM*)p, q1);
  53. +#endif
  54. if (!res)
  55. {
  56. +#if !defined(USE_OPENSSL) || !defined(OPENSSL_VERSION_NUMBER) || OPENSSL_VERSION_NUMBER < 0x10100000L
  57. MP_free(dh->pub_key);
  58. MP_free(dh->priv_key);
  59. dh->pub_key = dh->priv_key = 0;
  60. +#else
  61. + DH_free(dh);
  62. +#endif
  63. }
  64. MP_free(q1);
  65. @@ -314,15 +348,29 @@
  66. DHGetPublicKey(MDH *dh, uint8_t *pubkey, size_t nPubkeyLen)
  67. {
  68. int len;
  69. +#if !defined(USE_OPENSSL) || !defined(OPENSSL_VERSION_NUMBER) || OPENSSL_VERSION_NUMBER < 0x10100000L
  70. if (!dh || !dh->pub_key)
  71. +#else
  72. + BIGNUM const* pub_key = NULL;
  73. + DH_get0_key(dh, &pub_key, NULL);
  74. + if (!dh || !pub_key)
  75. +#endif
  76. return 0;
  77. +#if !defined(USE_OPENSSL) || !defined(OPENSSL_VERSION_NUMBER) || OPENSSL_VERSION_NUMBER < 0x10100000L
  78. len = MP_bytes(dh->pub_key);
  79. +#else
  80. + len = MP_bytes(pub_key);
  81. +#endif
  82. if (len <= 0 || len > (int) nPubkeyLen)
  83. return 0;
  84. memset(pubkey, 0, nPubkeyLen);
  85. +#if !defined(USE_OPENSSL) || !defined(OPENSSL_VERSION_NUMBER) || OPENSSL_VERSION_NUMBER < 0x10100000L
  86. MP_setbin(dh->pub_key, pubkey + (nPubkeyLen - len), len);
  87. +#else
  88. + MP_setbin(pub_key, pubkey + (nPubkeyLen - len), len);
  89. +#endif
  90. return 1;
  91. }
  92. @@ -364,7 +412,13 @@
  93. MP_gethex(q1, Q1024, len);
  94. assert(len);
  95. +#if !defined(USE_OPENSSL) || !defined(OPENSSL_VERSION_NUMBER) || OPENSSL_VERSION_NUMBER < 0x10100000L
  96. if (isValidPublicKey(pubkeyBn, dh->p, q1))
  97. +#else
  98. + BIGNUM const* p = NULL;
  99. + DH_get0_pqg(dh, &p, NULL, NULL);
  100. + if (isValidPublicKey(pubkeyBn, (BIGNUM*)p, q1))
  101. +#endif
  102. res = MDH_compute_key(secret, nPubkeyLen, pubkeyBn, dh);
  103. else
  104. res = -1;
  105. --- a/librtmp/handshake.h
  106. +++ b/librtmp/handshake.h
  107. @@ -31,9 +31,9 @@
  108. #define SHA256_DIGEST_LENGTH 32
  109. #endif
  110. #define HMAC_CTX sha2_context
  111. -#define HMAC_setup(ctx, key, len) sha2_hmac_starts(&ctx, (unsigned char *)key, len, 0)
  112. -#define HMAC_crunch(ctx, buf, len) sha2_hmac_update(&ctx, buf, len)
  113. -#define HMAC_finish(ctx, dig, dlen) dlen = SHA256_DIGEST_LENGTH; sha2_hmac_finish(&ctx, dig)
  114. +#define HMAC_setup(ctx, key, len) sha2_hmac_starts(ctx, (unsigned char *)key, len, 0)
  115. +#define HMAC_crunch(ctx, buf, len) sha2_hmac_update(ctx, buf, len)
  116. +#define HMAC_finish(ctx, dig, dlen) dlen = SHA256_DIGEST_LENGTH; sha2_hmac_finish(ctx, dig)
  117. typedef arc4_context * RC4_handle;
  118. #define RC4_alloc(h) *h = malloc(sizeof(arc4_context))
  119. @@ -50,9 +50,9 @@
  120. #endif
  121. #undef HMAC_CTX
  122. #define HMAC_CTX struct hmac_sha256_ctx
  123. -#define HMAC_setup(ctx, key, len) hmac_sha256_set_key(&ctx, len, key)
  124. -#define HMAC_crunch(ctx, buf, len) hmac_sha256_update(&ctx, len, buf)
  125. -#define HMAC_finish(ctx, dig, dlen) dlen = SHA256_DIGEST_LENGTH; hmac_sha256_digest(&ctx, SHA256_DIGEST_LENGTH, dig)
  126. +#define HMAC_setup(ctx, key, len) hmac_sha256_set_key(ctx, len, key)
  127. +#define HMAC_crunch(ctx, buf, len) hmac_sha256_update(ctx, len, buf)
  128. +#define HMAC_finish(ctx, dig, dlen) dlen = SHA256_DIGEST_LENGTH; hmac_sha256_digest(ctx, SHA256_DIGEST_LENGTH, dig)
  129. #define HMAC_close(ctx)
  130. typedef struct arcfour_ctx* RC4_handle;
  131. @@ -64,14 +64,23 @@
  132. #else /* USE_OPENSSL */
  133. #include <openssl/sha.h>
  134. +#include <openssl/ossl_typ.h>
  135. #include <openssl/hmac.h>
  136. #include <openssl/rc4.h>
  137. #if OPENSSL_VERSION_NUMBER < 0x0090800 || !defined(SHA256_DIGEST_LENGTH)
  138. #error Your OpenSSL is too old, need 0.9.8 or newer with SHA256
  139. #endif
  140. -#define HMAC_setup(ctx, key, len) HMAC_CTX_init(&ctx); HMAC_Init_ex(&ctx, key, len, EVP_sha256(), 0)
  141. -#define HMAC_crunch(ctx, buf, len) HMAC_Update(&ctx, buf, len)
  142. -#define HMAC_finish(ctx, dig, dlen) HMAC_Final(&ctx, dig, &dlen); HMAC_CTX_cleanup(&ctx)
  143. +#if OPENSSL_VERSION_NUMBER < 0x10100000L
  144. +#define HMAC_setup(ctx, key, len) HMAC_CTX_init(ctx); HMAC_Init_ex(ctx, key, len, EVP_sha256(), 0)
  145. +#else
  146. +#define HMAC_setup(ctx, key, len) ctx = HMAC_CTX_new(); HMAC_CTX_reset(ctx); HMAC_Init_ex(ctx, key, len, EVP_sha256(), 0)
  147. +#endif
  148. +#define HMAC_crunch(ctx, buf, len) HMAC_Update(ctx, buf, len)
  149. +#if OPENSSL_VERSION_NUMBER < 0x10100000L
  150. +#define HMAC_finish(ctx, dig, dlen) HMAC_Final(ctx, dig, &dlen); HMAC_CTX_cleanup(ctx)
  151. +#else
  152. +#define HMAC_finish(ctx, dig, dlen) HMAC_Final(ctx, dig, &dlen); HMAC_CTX_free(ctx)
  153. +#endif
  154. typedef RC4_KEY * RC4_handle;
  155. #define RC4_alloc(h) *h = malloc(sizeof(RC4_KEY))
  156. @@ -117,7 +126,7 @@
  157. {
  158. uint8_t digest[SHA256_DIGEST_LENGTH];
  159. unsigned int digestLen = 0;
  160. - HMAC_CTX ctx;
  161. + HMAC_CTX* ctx = NULL;
  162. RC4_alloc(rc4keyIn);
  163. RC4_alloc(rc4keyOut);
  164. @@ -266,7 +275,7 @@
  165. size_t keylen, uint8_t *digest)
  166. {
  167. unsigned int digestLen;
  168. - HMAC_CTX ctx;
  169. + HMAC_CTX* ctx = NULL;
  170. HMAC_setup(ctx, key, keylen);
  171. HMAC_crunch(ctx, message, messageLen);
  172. --- a/librtmp/hashswf.c
  173. +++ b/librtmp/hashswf.c
  174. @@ -37,9 +37,9 @@
  175. #define SHA256_DIGEST_LENGTH 32
  176. #endif
  177. #define HMAC_CTX sha2_context
  178. -#define HMAC_setup(ctx, key, len) sha2_hmac_starts(&ctx, (unsigned char *)key, len, 0)
  179. -#define HMAC_crunch(ctx, buf, len) sha2_hmac_update(&ctx, buf, len)
  180. -#define HMAC_finish(ctx, dig, dlen) dlen = SHA256_DIGEST_LENGTH; sha2_hmac_finish(&ctx, dig)
  181. +#define HMAC_setup(ctx, key, len) sha2_hmac_starts(ctx, (unsigned char *)key, len, 0)
  182. +#define HMAC_crunch(ctx, buf, len) sha2_hmac_update(ctx, buf, len)
  183. +#define HMAC_finish(ctx, dig, dlen) dlen = SHA256_DIGEST_LENGTH; sha2_hmac_finish(ctx, dig)
  184. #define HMAC_close(ctx)
  185. #elif defined(USE_GNUTLS)
  186. #include <nettle/hmac.h>
  187. @@ -48,19 +48,27 @@
  188. #endif
  189. #undef HMAC_CTX
  190. #define HMAC_CTX struct hmac_sha256_ctx
  191. -#define HMAC_setup(ctx, key, len) hmac_sha256_set_key(&ctx, len, key)
  192. -#define HMAC_crunch(ctx, buf, len) hmac_sha256_update(&ctx, len, buf)
  193. -#define HMAC_finish(ctx, dig, dlen) dlen = SHA256_DIGEST_LENGTH; hmac_sha256_digest(&ctx, SHA256_DIGEST_LENGTH, dig)
  194. +#define HMAC_setup(ctx, key, len) hmac_sha256_set_key(ctx, len, key)
  195. +#define HMAC_crunch(ctx, buf, len) hmac_sha256_update(ctx, len, buf)
  196. +#define HMAC_finish(ctx, dig, dlen) dlen = SHA256_DIGEST_LENGTH; hmac_sha256_digest(ctx, SHA256_DIGEST_LENGTH, dig)
  197. #define HMAC_close(ctx)
  198. #else /* USE_OPENSSL */
  199. #include <openssl/ssl.h>
  200. #include <openssl/sha.h>
  201. #include <openssl/hmac.h>
  202. #include <openssl/rc4.h>
  203. -#define HMAC_setup(ctx, key, len) HMAC_CTX_init(&ctx); HMAC_Init_ex(&ctx, (unsigned char *)key, len, EVP_sha256(), 0)
  204. -#define HMAC_crunch(ctx, buf, len) HMAC_Update(&ctx, (unsigned char *)buf, len)
  205. -#define HMAC_finish(ctx, dig, dlen) HMAC_Final(&ctx, (unsigned char *)dig, &dlen);
  206. -#define HMAC_close(ctx) HMAC_CTX_cleanup(&ctx)
  207. +#if OPENSSL_VERSION_NUMBER < 0x10100000L
  208. +#define HMAC_setup(ctx, key, len) HMAC_CTX_init(ctx); HMAC_Init_ex(ctx, (unsigned char *)key, len, EVP_sha256(), 0)
  209. +#else
  210. +#define HMAC_setup(ctx, key, len) ctx = HMAC_CTX_new(); HMAC_CTX_reset(ctx); HMAC_Init_ex(ctx, key, len, EVP_sha256(), 0)
  211. +#endif
  212. +#define HMAC_crunch(ctx, buf, len) HMAC_Update(ctx, (unsigned char *)buf, len)
  213. +#define HMAC_finish(ctx, dig, dlen) HMAC_Final(ctx, (unsigned char *)dig, &dlen);
  214. +#if OPENSSL_VERSION_NUMBER < 0x10100000L
  215. +#define HMAC_close(ctx) HMAC_CTX_cleanup(ctx)
  216. +#else
  217. +#define HMAC_close(ctx) HMAC_CTX_reset(ctx); HMAC_CTX_free(ctx)
  218. +#endif
  219. #endif
  220. extern void RTMP_TLS_Init();
  221. @@ -289,7 +297,7 @@
  222. struct info
  223. {
  224. z_stream *zs;
  225. - HMAC_CTX ctx;
  226. + HMAC_CTX *ctx;
  227. int first;
  228. int zlib;
  229. int size;