mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2024-10-31 00:37:39 +08:00
Rtmp: rtmp客户端支持复杂握手,兼容某些rtmp服务器
This commit is contained in:
parent
2e9ff3ed3c
commit
ab14585a81
@ -112,6 +112,9 @@ public:
|
||||
bytes[i] = cdata[rand() % (sizeof(cdata) - 1)];
|
||||
}
|
||||
}
|
||||
|
||||
void create_complex_c0c1();
|
||||
|
||||
}PACKED;
|
||||
|
||||
class RtmpHeader {
|
||||
|
@ -290,6 +290,7 @@ void RtmpProtocol::startClientSession(const function<void()> &func) {
|
||||
char handshake_head = HANDSHAKE_PLAINTEXT;
|
||||
onSendRawData(obtainBuffer(&handshake_head, 1));
|
||||
RtmpHandshake c1(0);
|
||||
c1.create_complex_c0c1();
|
||||
onSendRawData(obtainBuffer((char *) (&c1), sizeof(c1)));
|
||||
_next_step_func = [this, func](const char *data, size_t len) {
|
||||
//等待 S0+S1+S2
|
||||
@ -429,6 +430,22 @@ static u_int8_t FPKey[] = {
|
||||
0x93, 0xB8, 0xE6, 0x36, 0xCF, 0xEB, 0x31, 0xAE
|
||||
}; // 62
|
||||
|
||||
//发送复杂握手c0c1
|
||||
void RtmpHandshake::create_complex_c0c1() {
|
||||
memcpy(zero, "\x80\x00\x07\x02", 4);
|
||||
string str((char *) this, sizeof(*this));
|
||||
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;
|
||||
offset_ptr[0] = offset_ptr[1] = offset_ptr[2] = offset_value / 4;
|
||||
offset_ptr[3] = offset_value - 3 * (offset_value / 4);
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
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) {
|
||||
@ -692,7 +709,8 @@ void RtmpProtocol::handle_chunk(RtmpPacket::Ptr packet) {
|
||||
case CONTROL_STREAM_BEGIN: {
|
||||
//开始播放
|
||||
if (chunk_data.buffer.size() < 4) {
|
||||
throw std::runtime_error("CONTROL_STREAM_BEGIN: Not enough data.");
|
||||
WarnL << "CONTROL_STREAM_BEGIN: Not enough data:" << chunk_data.buffer.size();
|
||||
break;
|
||||
}
|
||||
uint32_t stream_index = load_be32(&chunk_data.buffer[0]);
|
||||
onStreamBegin(stream_index);
|
||||
|
Loading…
Reference in New Issue
Block a user