From 4e01c298339c595f8808fa2c49688255f10c2336 Mon Sep 17 00:00:00 2001 From: ziyue <1213642868@qq.com> Date: Wed, 22 Dec 2021 22:20:28 +0800 Subject: [PATCH] =?UTF-8?q?Rtmp:=20=E4=BC=98=E5=8C=96=E5=A4=8D=E6=9D=82?= =?UTF-8?q?=E6=8F=A1=E6=89=8Bc0c1=E7=94=9F=E6=88=90=E7=AE=97=E6=B3=95?= =?UTF-8?q?=E6=80=A7=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Rtmp/RtmpProtocol.cpp | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/Rtmp/RtmpProtocol.cpp b/src/Rtmp/RtmpProtocol.cpp index 686b389b..a5ee61c1 100644 --- a/src/Rtmp/RtmpProtocol.cpp +++ b/src/Rtmp/RtmpProtocol.cpp @@ -433,17 +433,19 @@ static u_int8_t FPKey[] = { //发送复杂握手c0c1 void RtmpHandshake::create_complex_c0c1() { memcpy(zero, "\x80\x00\x07\x02", 4); - string str((char *) this, sizeof(*this)); + //digest随机偏移长度 auto offset_value = rand() % (C1_SCHEMA_SIZE - C1_OFFSET_SIZE - C1_DIGEST_SIZE); - str.erase(8 + C1_SCHEMA_SIZE + C1_OFFSET_SIZE + offset_value, C1_DIGEST_SIZE); - - auto offset_ptr = (uint8_t *) str.data() + 8 + C1_SCHEMA_SIZE; + //设置digest偏移长度 + auto offset_ptr = random + C1_SCHEMA_SIZE; offset_ptr[0] = offset_ptr[1] = offset_ptr[2] = offset_value / 4; offset_ptr[3] = offset_value - 3 * (offset_value / 4); - + //去除digest后的剩余随机数据 + string str((char *) this, sizeof(*this)); + str.erase(8 + C1_SCHEMA_SIZE + C1_OFFSET_SIZE + offset_value, C1_DIGEST_SIZE); + //获取摘要 auto digest_value = openssl_HMACsha256(FPKey, C1_FPKEY_SIZE, str.data(), str.size()); - str.insert(8 + C1_SCHEMA_SIZE + C1_OFFSET_SIZE + offset_value, digest_value); - memcpy(this, str.data(), sizeof(*this)); + //插入摘要 + memcpy(random + C1_SCHEMA_SIZE + C1_OFFSET_SIZE + offset_value, digest_value.data(), digest_value.size()); } void RtmpProtocol::check_C1_Digest(const string &digest,const string &data){