From 78fe605e7ce7b93f28e02c14ff4a92be7cb20ad8 Mon Sep 17 00:00:00 2001
From: He Zhaojiang <hezhaojiang2012@foxmail.com>
Date: Mon, 19 Oct 2020 22:13:39 +0800
Subject: [PATCH] =?utf-8?q?=E3=80=90MOD=E3=80=91=E6=94=AF=E6=8C=81=20Opens?=
 =?utf-8?q?sl=201.1.1?=
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit

---
 librtmp/dh.h        | 36 +++++++++++++++++++++++-------------
 librtmp/handshake.h | 10 +++++-----
 librtmp/hashswf.c   | 10 +++++-----
 librtmp/rtmp.c      |  9 ++++-----
 rtmpsrv.c           |  6 +++---
 rtmpsuck.c          | 16 ++++++++--------
 6 files changed, 48 insertions(+), 39 deletions(-)

diff --git a/librtmp/dh.h b/librtmp/dh.h
index 5fc3f32..2e96992 100644
--- a/librtmp/dh.h
+++ b/librtmp/dh.h
@@ -253,20 +253,23 @@ DHInit(int nKeyBits)
   if (!dh)
     goto failed;
 
-  MP_new(dh->g);
+  BIGNUM *p;
+  BIGNUM *g;
+  DH_get0_pqg(dh, (const BIGNUM **)&p, NULL, (const BIGNUM **)&g);
+  MP_new(g);
 
-  if (!dh->g)
+  if (!g)
     goto failed;
 
-  MP_gethex(dh->p, P1024, res);	/* prime P1024, see dhgroups.h */
+  MP_gethex(p, P1024, res);	/* prime P1024, see dhgroups.h */
   if (!res)
     {
       goto failed;
     }
 
-  MP_set_w(dh->g, 2);	/* base 2 */
+  MP_set_w(g, 2);	/* base 2 */
 
-  dh->length = nKeyBits;
+  DH_set_length(dh, nKeyBits);
   return dh;
 
 failed:
@@ -293,12 +296,15 @@ DHGenerateKey(MDH *dh)
       MP_gethex(q1, Q1024, res);
       assert(res);
 
-      res = isValidPublicKey(dh->pub_key, dh->p, q1);
+      BIGNUM *pub_key, *priv_key, *p;
+      DH_get0_key(dh, (const BIGNUM **)&pub_key, (const BIGNUM **)&priv_key);
+      DH_get0_pqg(dh, (const BIGNUM **)&p, NULL, NULL);
+      res = isValidPublicKey(pub_key, p, q1);
       if (!res)
 	{
-	  MP_free(dh->pub_key);
-	  MP_free(dh->priv_key);
-	  dh->pub_key = dh->priv_key = 0;
+	  MP_free(pub_key);
+	  MP_free(priv_key);
+          DH_set0_key(dh, 0, 0);
 	}
 
       MP_free(q1);
@@ -314,15 +320,17 @@ static int
 DHGetPublicKey(MDH *dh, uint8_t *pubkey, size_t nPubkeyLen)
 {
   int len;
-  if (!dh || !dh->pub_key)
+  BIGNUM *pub_key;
+  DH_get0_key(dh, (const BIGNUM **)&pub_key, NULL);
+  if (!dh || !pub_key)
     return 0;
 
-  len = MP_bytes(dh->pub_key);
+  len = MP_bytes(pub_key);
   if (len <= 0 || len > (int) nPubkeyLen)
     return 0;
 
   memset(pubkey, 0, nPubkeyLen);
-  MP_setbin(dh->pub_key, pubkey + (nPubkeyLen - len), len);
+  MP_setbin(pub_key, pubkey + (nPubkeyLen - len), len);
   return 1;
 }
 
@@ -364,7 +372,9 @@ DHComputeSharedSecretKey(MDH *dh, uint8_t *pubkey, size_t nPubkeyLen,
   MP_gethex(q1, Q1024, len);
   assert(len);
 
-  if (isValidPublicKey(pubkeyBn, dh->p, q1))
+  BIGNUM *p;
+  DH_get0_pqg(dh, (const BIGNUM **)&p, NULL, NULL);
+  if (isValidPublicKey(pubkeyBn, p, q1))
     res = MDH_compute_key(secret, nPubkeyLen, pubkeyBn, dh);
   else
     res = -1;
diff --git a/librtmp/handshake.h b/librtmp/handshake.h
index 0438486..355a655 100644
--- a/librtmp/handshake.h
+++ b/librtmp/handshake.h
@@ -69,9 +69,9 @@ typedef struct arcfour_ctx*	RC4_handle;
 #if OPENSSL_VERSION_NUMBER < 0x0090800 || !defined(SHA256_DIGEST_LENGTH)
 #error Your OpenSSL is too old, need 0.9.8 or newer with SHA256
 #endif
-#define HMAC_setup(ctx, key, len)	HMAC_CTX_init(&ctx); HMAC_Init_ex(&ctx, key, len, EVP_sha256(), 0)
-#define HMAC_crunch(ctx, buf, len)	HMAC_Update(&ctx, buf, len)
-#define HMAC_finish(ctx, dig, dlen)	HMAC_Final(&ctx, dig, &dlen); HMAC_CTX_cleanup(&ctx)
+#define HMAC_setup(ctx, key, len)	HMAC_Init_ex(ctx, key, len, EVP_sha256(), 0)
+#define HMAC_crunch(ctx, buf, len)	HMAC_Update(ctx, buf, len)
+#define HMAC_finish(ctx, dig, dlen)	HMAC_Final(ctx, dig, &dlen); HMAC_CTX_free(ctx)
 
 typedef RC4_KEY *	RC4_handle;
 #define RC4_alloc(h)	*h = malloc(sizeof(RC4_KEY))
@@ -117,7 +117,7 @@ static void InitRC4Encryption
 {
   uint8_t digest[SHA256_DIGEST_LENGTH];
   unsigned int digestLen = 0;
-  HMAC_CTX ctx;
+  HMAC_CTX *ctx = HMAC_CTX_new();
 
   RC4_alloc(rc4keyIn);
   RC4_alloc(rc4keyOut);
@@ -266,7 +266,7 @@ HMACsha256(const uint8_t *message, size_t messageLen, const uint8_t *key,
 	   size_t keylen, uint8_t *digest)
 {
   unsigned int digestLen;
-  HMAC_CTX ctx;
+  HMAC_CTX *ctx = HMAC_CTX_new();
 
   HMAC_setup(ctx, key, keylen);
   HMAC_crunch(ctx, message, messageLen);
diff --git a/librtmp/hashswf.c b/librtmp/hashswf.c
index 32b2eed..110d18e 100644
--- a/librtmp/hashswf.c
+++ b/librtmp/hashswf.c
@@ -57,10 +57,10 @@
 #include <openssl/sha.h>
 #include <openssl/hmac.h>
 #include <openssl/rc4.h>
-#define HMAC_setup(ctx, key, len)	HMAC_CTX_init(&ctx); HMAC_Init_ex(&ctx, (unsigned char *)key, len, EVP_sha256(), 0)
-#define HMAC_crunch(ctx, buf, len)	HMAC_Update(&ctx, (unsigned char *)buf, len)
-#define HMAC_finish(ctx, dig, dlen)	HMAC_Final(&ctx, (unsigned char *)dig, &dlen);
-#define HMAC_close(ctx)	HMAC_CTX_cleanup(&ctx)
+#define HMAC_setup(ctx, key, len)	HMAC_Init_ex(ctx, (unsigned char *)key, len, EVP_sha256(), 0)
+#define HMAC_crunch(ctx, buf, len)	HMAC_Update(ctx, (unsigned char *)buf, len)
+#define HMAC_finish(ctx, dig, dlen)	HMAC_Final(ctx, (unsigned char *)dig, &dlen);
+#define HMAC_close(ctx)	HMAC_CTX_free(ctx)
 #endif
 
 extern void RTMP_TLS_Init();
@@ -298,7 +298,7 @@ leave:
 struct info
 {
   z_stream *zs;
-  HMAC_CTX ctx;
+  HMAC_CTX *ctx;
   int first;
   int zlib;
   int size;
diff --git a/librtmp/rtmp.c b/librtmp/rtmp.c
index 0865689..0938db3 100644
--- a/librtmp/rtmp.c
+++ b/librtmp/rtmp.c
@@ -1902,7 +1902,7 @@ SendFCUnpublish(RTMP *r)
 
 SAVC(publish);
 SAVC(live);
-SAVC(record);
+//SAVC(record);
 
 static int
 SendPublish(RTMP *r)
@@ -2904,8 +2904,7 @@ AVC("NetStream.Play.PublishNotify");
 static const AVal av_NetStream_Play_UnpublishNotify =
 AVC("NetStream.Play.UnpublishNotify");
 static const AVal av_NetStream_Publish_Start = AVC("NetStream.Publish.Start");
-static const AVal av_NetConnection_Connect_Rejected =
-AVC("NetConnection.Connect.Rejected");
+//static const AVal av_NetConnection_Connect_Rejected = AVC("NetConnection.Connect.Rejected");
 
 /* Returns 0 for OK/Failed/error, 1 for 'Stop or Complete' */
 static int
@@ -3552,7 +3551,7 @@ RTMP_ReadPacket(RTMP *r, RTMPPacket *packet)
   uint8_t hbuf[RTMP_MAX_HEADER_SIZE] = { 0 };
   char *header = (char *)hbuf;
   int nSize, hSize, nToRead, nChunk;
-  int didAlloc = FALSE;
+  //int didAlloc = FALSE;
   int extendedTimestamp;
 
   RTMP_Log(RTMP_LOGDEBUG2, "%s: fd=%d", __FUNCTION__, r->m_sb.sb_socket);
@@ -3679,7 +3678,7 @@ RTMP_ReadPacket(RTMP *r, RTMPPacket *packet)
 	  RTMP_Log(RTMP_LOGDEBUG, "%s, failed to allocate packet", __FUNCTION__);
 	  return FALSE;
 	}
-      didAlloc = TRUE;
+      //didAlloc = TRUE;
       packet->m_headerType = (hbuf[0] & 0xc0) >> 6;
     }
 
diff --git a/rtmpsrv.c b/rtmpsrv.c
index 5df4d3a..d70ce7a 100644
--- a/rtmpsrv.c
+++ b/rtmpsrv.c
@@ -152,11 +152,11 @@ SAVC(flashVer);
 SAVC(swfUrl);
 SAVC(pageUrl);
 SAVC(tcUrl);
-SAVC(fpad);
+//SAVC(fpad);
 SAVC(capabilities);
 SAVC(audioCodecs);
 SAVC(videoCodecs);
-SAVC(videoFunction);
+//SAVC(videoFunction);
 SAVC(objectEncoding);
 SAVC(_result);
 SAVC(createStream);
@@ -167,7 +167,7 @@ SAVC(mode);
 SAVC(level);
 SAVC(code);
 SAVC(description);
-SAVC(secureToken);
+//SAVC(secureToken);
 
 static int
 SendConnectResult(RTMP *r, double txn)
diff --git a/rtmpsuck.c b/rtmpsuck.c
index e886179..89adf12 100644
--- a/rtmpsuck.c
+++ b/rtmpsuck.c
@@ -124,21 +124,21 @@ SAVC(flashVer);
 SAVC(swfUrl);
 SAVC(pageUrl);
 SAVC(tcUrl);
-SAVC(fpad);
-SAVC(capabilities);
+//SAVC(fpad);
+//SAVC(capabilities);
 SAVC(audioCodecs);
 SAVC(videoCodecs);
-SAVC(videoFunction);
+//SAVC(videoFunction);
 SAVC(objectEncoding);
-SAVC(_result);
-SAVC(createStream);
+//SAVC(_result);
+//SAVC(createStream);
 SAVC(play);
 SAVC(closeStream);
-SAVC(fmsVer);
-SAVC(mode);
+//SAVC(fmsVer);
+//SAVC(mode);
 SAVC(level);
 SAVC(code);
-SAVC(secureToken);
+//SAVC(secureToken);
 SAVC(onStatus);
 SAVC(close);
 static const AVal av_NetStream_Failed = AVC("NetStream.Failed");
-- 
2.28.0.windows.1

