From 7f649b94e5e973fa90b0f17e3fb0615218c5df90 Mon Sep 17 00:00:00 2001 From: xiongziliang <771730766@qq.com> Date: Sun, 26 Dec 2021 19:58:01 +0800 Subject: [PATCH] =?UTF-8?q?Rtmp:=20=E4=BF=AE=E5=A4=8Dopenssl=E6=9C=AA?= =?UTF-8?q?=E5=BC=80=E5=90=AF=E5=AF=BC=E8=87=B4=E9=93=BE=E6=8E=A5=E5=A4=B1?= =?UTF-8?q?=E8=B4=A5=E7=9A=84=E9=97=AE=E9=A2=98:=20#1301?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Rtmp/RtmpProtocol.cpp | 40 +++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/src/Rtmp/RtmpProtocol.cpp b/src/Rtmp/RtmpProtocol.cpp index bf5466f0..063e62f9 100644 --- a/src/Rtmp/RtmpProtocol.cpp +++ b/src/Rtmp/RtmpProtocol.cpp @@ -430,26 +430,6 @@ static u_int8_t FPKey[] = { 0x93, 0xB8, 0xE6, 0x36, 0xCF, 0xEB, 0x31, 0xAE }; // 62 -//发送复杂握手c0c1 -void RtmpHandshake::create_complex_c0c1() { -#ifdef ENABLE_OPENSSL - memcpy(zero, "\x80\x00\x07\x02", 4); - //digest随机偏移长度 - auto offset_value = rand() % (C1_SCHEMA_SIZE - C1_OFFSET_SIZE - C1_DIGEST_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()); - //插入摘要 - memcpy(random + C1_SCHEMA_SIZE + C1_OFFSET_SIZE + offset_value, digest_value.data(), digest_value.size()); -#endif -} - void RtmpProtocol::check_C1_Digest(const string &digest,const string &data){ auto sha256 = openssl_HMACsha256(FPKey, C1_FPKEY_SIZE, data.data(), data.size()); if (sha256 != digest) { @@ -541,6 +521,26 @@ void RtmpProtocol::send_complex_S0S1S2(int schemeType,const string &digest){ } #endif //ENABLE_OPENSSL +//发送复杂握手c0c1 +void RtmpHandshake::create_complex_c0c1() { +#ifdef ENABLE_OPENSSL + memcpy(zero, "\x80\x00\x07\x02", 4); + //digest随机偏移长度 + auto offset_value = rand() % (C1_SCHEMA_SIZE - C1_OFFSET_SIZE - C1_DIGEST_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()); + //插入摘要 + memcpy(random + C1_SCHEMA_SIZE + C1_OFFSET_SIZE + offset_value, digest_value.data(), digest_value.size()); +#endif +} + const char* RtmpProtocol::handle_C2(const char *data, size_t len) { if (len < C1_HANDSHARK_SIZE) { //need more data!