mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2026-06-18 06:02:21 +08:00
修复rtsp basic鉴权相关bug: #2087
This commit is contained in:
@@ -580,16 +580,16 @@ void RtspPlayer::sendRtspRequest(const string &cmd, const string &url, const std
|
||||
|
||||
void RtspPlayer::sendRtspRequest(const string &cmd, const string &url,const StrCaseMap &header_const) {
|
||||
auto header = header_const;
|
||||
header.emplace("CSeq",StrPrinter << _cseq_send++);
|
||||
header.emplace("User-Agent",kServerName);
|
||||
header.emplace("CSeq", StrPrinter << _cseq_send++);
|
||||
header.emplace("User-Agent", kServerName);
|
||||
|
||||
if(!_session_id.empty()){
|
||||
if (!_session_id.empty()) {
|
||||
header.emplace("Session", _session_id);
|
||||
}
|
||||
|
||||
if(!_realm.empty() && !(*this)[Client::kRtspUser].empty()){
|
||||
if(!_md5_nonce.empty()){
|
||||
//MD5认证
|
||||
if (!_realm.empty() && !(*this)[Client::kRtspUser].empty()) {
|
||||
if (!_md5_nonce.empty()) {
|
||||
// MD5认证
|
||||
/*
|
||||
response计算方法如下:
|
||||
RTSP客户端应该使用username + password并计算response如下:
|
||||
@@ -599,7 +599,7 @@ void RtspPlayer::sendRtspRequest(const string &cmd, const string &url,const StrC
|
||||
response= md5( md5(username:realm:password):nonce:md5(public_method:url) );
|
||||
*/
|
||||
string encrypted_pwd = (*this)[Client::kRtspPwd];
|
||||
if(!(*this)[Client::kRtspPwdIsMD5].as<bool>()){
|
||||
if (!(*this)[Client::kRtspPwdIsMD5].as<bool>()) {
|
||||
encrypted_pwd = MD5((*this)[Client::kRtspUser] + ":" + _realm + ":" + encrypted_pwd).hexdigest();
|
||||
}
|
||||
auto response = MD5(encrypted_pwd + ":" + _md5_nonce + ":" + MD5(cmd + ":" + url).hexdigest()).hexdigest();
|
||||
@@ -610,13 +610,11 @@ void RtspPlayer::sendRtspRequest(const string &cmd, const string &url,const StrC
|
||||
printer << "nonce=\"" << _md5_nonce << "\", ";
|
||||
printer << "uri=\"" << url << "\", ";
|
||||
printer << "response=\"" << response << "\"";
|
||||
header.emplace("Authorization",printer);
|
||||
}else if(!(*this)[Client::kRtspPwdIsMD5].as<bool>()){
|
||||
//base64认证
|
||||
string authStr = StrPrinter << (*this)[Client::kRtspUser] << ":" << (*this)[Client::kRtspPwd];
|
||||
char authStrBase64[1024] = {0};
|
||||
av_base64_encode(authStrBase64, sizeof(authStrBase64), (uint8_t *) authStr.data(), (int) authStr.size());
|
||||
header.emplace("Authorization",StrPrinter << "Basic " << authStrBase64 );
|
||||
header.emplace("Authorization", printer);
|
||||
} else if (!(*this)[Client::kRtspPwdIsMD5].as<bool>()) {
|
||||
// base64认证
|
||||
auto authStrBase64 = encodeBase64((*this)[Client::kRtspUser] + ":" + (*this)[Client::kRtspPwd]);
|
||||
header.emplace("Authorization", StrPrinter << "Basic " << authStrBase64);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user