zoneminder/src/zm_rtsp_auth.h

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

70 lines
2.1 KiB
C
Raw Normal View History

2014-04-29 05:37:31 +08:00
//
// ZoneMinder RTSP Authentication Class Interface, $Date$, $Revision$
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
2014-04-29 05:37:31 +08:00
//
#ifndef ZM_RTSP_AUTH_H
#define ZM_RTSP_AUTH_H
#include "zm_config.h"
#include <string>
2014-04-29 05:37:31 +08:00
#if HAVE_GNUTLS_GNUTLS_H
#include <gnutls/gnutls.h>
#endif
#if HAVE_GCRYPT_H
#include <gcrypt.h>
#elif HAVE_LIBCRYPTO
#include <openssl/md5.h>
#endif // HAVE_GCRYPT_H || HAVE_LIBCRYPTO
namespace zm {
enum AuthMethod { AUTH_UNDEFINED = 0, AUTH_BASIC = 1, AUTH_DIGEST = 2 };
class Authenticator {
2014-04-29 05:37:31 +08:00
public:
2017-11-17 20:52:26 +08:00
Authenticator(const std::string &username, const std::string &password);
virtual ~Authenticator();
void reset();
2014-04-29 05:37:31 +08:00
std::string realm() { return fRealm; }
std::string nonce() { return fNonce; }
std::string username() { return fUsername; }
AuthMethod auth_method() const { return fAuthMethod; }
2021-04-21 04:41:08 +08:00
std::string computeDigestResponse(const std::string &cmd, const std::string &url);
void authHandleHeader(std::string headerData);
std::string getAuthHeader(const std::string &method, const std::string &path);
2021-04-21 04:41:08 +08:00
void checkAuthResponse(const std::string &response);
2014-04-29 05:37:31 +08:00
private:
std::string password() { return fPassword; }
AuthMethod fAuthMethod;
2014-04-29 05:37:31 +08:00
std::string fRealm;
std::string fNonce;
std::string fCnonce;
std::string fQop;
2014-04-29 05:37:31 +08:00
std::string fUsername;
std::string fPassword;
2017-11-17 20:52:26 +08:00
std::string quote( const std::string &src );
int nc;
2014-04-29 05:37:31 +08:00
};
} // namespace zm
2014-04-29 05:37:31 +08:00
#endif // ZM_RTSP_AUTH_H