Skip to content

Commit f434765

Browse files
Merge pull request #11 from roleoroleo/auth
Fix digest authentication
2 parents 7ea6e5f + dd6d3fd commit f434765

File tree

4 files changed

+11
-18
lines changed

4 files changed

+11
-18
lines changed

src/xop/Authenticator.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class Authenticator
1313
Authenticator() {};
1414
virtual ~Authenticator() {};
1515

16-
virtual bool Authenticate(std::shared_ptr<RtspRequest> request, std::string &nonce) = 0;
16+
virtual bool Authenticate(std::shared_ptr<RtspRequest> request) = 0;
1717
virtual size_t GetFailedResponse(std::shared_ptr<RtspRequest> request, std::shared_ptr<char> buf, size_t size) = 0;
1818

1919
private:

src/xop/DigestAuthenticator.cpp

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,6 @@ DigestAuthenticator::~DigestAuthenticator()
1616

1717
}
1818

19-
std::string DigestAuthenticator::GetNonce()
20-
{
21-
return md5::generate_nonce();
22-
}
23-
2419
std::string DigestAuthenticator::GetResponse(std::string nonce, std::string cmd, std::string url)
2520
{
2621
//md5(md5(<username>:<realm> : <password>) :<nonce> : md5(<cmd>:<url>))
@@ -32,13 +27,12 @@ std::string DigestAuthenticator::GetResponse(std::string nonce, std::string cmd,
3227
}
3328

3429
bool DigestAuthenticator::Authenticate(
35-
std::shared_ptr<RtspRequest> rtsp_request,
36-
std::string &nonce)
30+
std::shared_ptr<RtspRequest> rtsp_request)
3731
{
3832
std::string cmd = rtsp_request->MethodToString[rtsp_request->GetMethod()];
3933
std::string url = rtsp_request->GetRtspUrl();
4034

41-
if (nonce.size() > 0 && (GetResponse(nonce, cmd, url) == rtsp_request->GetAuthResponse())) {
35+
if (nonce_.size() > 0 && (GetResponse(nonce_, cmd, url) == rtsp_request->GetAuthResponse())) {
4236
return true;
4337
} else {
4438
#if 0
@@ -52,6 +46,6 @@ size_t DigestAuthenticator::GetFailedResponse(
5246
std::shared_ptr<char> buf,
5347
size_t size)
5448
{
55-
std::string nonce = md5::generate_nonce();
56-
return rtsp_request->BuildUnauthorizedRes(buf.get(), size, realm_.c_str(), nonce.c_str());
49+
nonce_ = md5::generate_nonce();
50+
return rtsp_request->BuildUnauthorizedRes(buf.get(), size, realm_.c_str(), nonce_.c_str());
5751
}

src/xop/DigestAuthenticator.h

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
//PHZ
22
//2019-10-6
33

4-
#ifndef RTSP_DIGEST_AUTHENTICATION_H
5-
#define RTSP_DIGEST_AUTHENTICATION_H
4+
#ifndef RTSP_DIGEST_AUTHENTICATOR_H
5+
#define RTSP_DIGEST_AUTHENTICATOR_H
66

77
#include "Authenticator.h"
88

@@ -27,17 +27,16 @@ class DigestAuthenticator : public Authenticator
2727
std::string GetPassword() const
2828
{ return password_; }
2929

30-
std::string GetNonce();
3130
std::string GetResponse(std::string nonce, std::string cmd, std::string url);
3231

33-
bool Authenticate(std::shared_ptr<RtspRequest> request, std::string &nonce);
34-
size_t GetFailedResponse(std::shared_ptr<RtspRequest> request, std::shared_ptr<char> buf, size_t size);
32+
bool Authenticate(std::shared_ptr<RtspRequest> request);
33+
size_t GetFailedResponse(std::shared_ptr<RtspRequest> request, std::shared_ptr<char> buf, size_t size);
3534

3635
private:
3736
std::string realm_;
3837
std::string username_;
3938
std::string password_;
40-
39+
std::string nonce_;
4140
};
4241

4342
}

src/xop/RtspConnection.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ void RtspConnection::HandleCmdGetParamter()
412412
bool RtspConnection::HandleAuthentication()
413413
{
414414
if (authenticator_ != nullptr && !has_auth_) {
415-
if (authenticator_->Authenticate(rtsp_request_, _nonce)) {
415+
if (authenticator_->Authenticate(rtsp_request_)) {
416416
has_auth_ = true;
417417
} else {
418418
std::shared_ptr<char> res(new char[4096], std::default_delete<char[]>());

0 commit comments

Comments
 (0)