基於AES加密的RTSP/RTMP多路轉發設計方案

很多開發者最近諮詢我們,除了我們Windows推送端採集編碼的音視頻數據可以加密外,其他RTSP/RTMP流如果想更安全的轉推到RTMP服務器或相應CDN改怎麼辦?

實際上,我們在做RTMP整體加密方案的時候已經考慮到這種情況,SmartStreamRelayDemo在拉取RTSP或RTMP流,轉推RTMP的時候,可以選擇加密視頻,加密音頻或音視頻都加密,廢話不多說,參看代碼:

bool nt_stream_relay_wrapper::StartPush(const std::string& url)
{
	if ( is_pushing_ )
		return false;

	if ( url.empty() )
		return false;

	if ( !OpenPushHandle() )
		return false;

	auto push_handle = GetPushHandle();
	ASSERT(push_handle != nullptr);

	ASSERT(push_api_ != NULL);
	if ( NT_ERC_OK != push_api_->SetURL(push_handle, url.c_str(), NULL) )
	{
		if ( !is_started_rtsp_stream_ )
		{
			push_api_->Close(push_handle);
			SetPushHandle(nullptr);
		}

		return false;
	}

	// 加密測試 +++

	push_api_->SetRtmpEncryptionOption(push_handle, url.c_str(), 1, 1);

	NT_BYTE test_key[16] = {'1', '2', '3'};

	push_api_->SetRtmpEncryptionKey(push_handle, url.c_str(), test_key, 16);

	// 加密測試 --

	if ( NT_ERC_OK != push_api_->StartPublisher(push_handle, NULL) )
	{
		if ( !is_started_rtsp_stream_ )
		{
			push_api_->Close(push_handle);
			SetPushHandle(nullptr);
		}

		return false;
	}


	// // test push rtsp ++

	// push_api_->SetPushRtspTransportProtocol(push_handle, 1);
	// // push_api_->SetPushRtspTransportProtocol(push_handle, 2);

	// push_api_->SetPushRtspURL(push_handle, "rtsp://player.daniulive.com:554/liverelay111.sdp");

	// push_api_->StartPushRtsp(push_handle, 0);

	// // test push rtsp--

	is_pushing_ = true;

	return true;
}

上圖:

這個時候,輸入轉發設置的Key(支持aes 128, aes 192, aes 256加密,即將發佈SM4加密),方可正常播放音視頻數據。

此種方案的優勢在於基於AES音視頻逐幀數據加密音視頻數據,第三方即便是破解了URL,也沒法播放,通過抓包工具抓取到數據,也沒法正常顯示。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章