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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
//
|
|
|
|
|
|
|
|
#ifndef ZM_RTSP_AUTH_H
|
|
|
|
#define ZM_RTSP_AUTH_H
|
|
|
|
|
|
|
|
#if HAVE_GNUTLS_OPENSSL_H
|
|
|
|
#include <gnutls/openssl.h>
|
|
|
|
#endif
|
|
|
|
#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
|
|
|
|
|
2015-12-17 22:47:10 +08:00
|
|
|
namespace zm {
|
|
|
|
|
2014-11-20 05:40:05 +08:00
|
|
|
enum AuthMethod { AUTH_UNDEFINED = 0, AUTH_BASIC = 1, AUTH_DIGEST = 2 };
|
|
|
|
class Authenticator {
|
2014-04-29 05:37:31 +08:00
|
|
|
public:
|
|
|
|
Authenticator(std::string &username, std::string password);
|
|
|
|
virtual ~Authenticator();
|
|
|
|
void reset();
|
|
|
|
|
|
|
|
std::string realm() { return fRealm; }
|
|
|
|
std::string nonce() { return fNonce; }
|
|
|
|
std::string username() { return fUsername; }
|
2014-11-20 05:40:05 +08:00
|
|
|
AuthMethod auth_method() const { return fAuthMethod; }
|
2014-04-29 05:37:31 +08:00
|
|
|
|
|
|
|
std::string computeDigestResponse( std::string &cmd, std::string &url );
|
|
|
|
void authHandleHeader( std::string headerData );
|
|
|
|
std::string getAuthHeader( std::string method, std::string path );
|
2014-11-20 23:44:31 +08:00
|
|
|
void checkAuthResponse(std::string &response);
|
2014-04-29 05:37:31 +08:00
|
|
|
|
|
|
|
private:
|
|
|
|
std::string password() { return fPassword; }
|
2014-11-20 05:40:05 +08:00
|
|
|
AuthMethod fAuthMethod;
|
2014-04-29 05:37:31 +08:00
|
|
|
std::string fRealm;
|
|
|
|
std::string fNonce;
|
2014-11-20 05:40:05 +08:00
|
|
|
std::string fCnonce;
|
|
|
|
std::string fQop;
|
2014-04-29 05:37:31 +08:00
|
|
|
std::string fUsername;
|
|
|
|
std::string fPassword;
|
2014-04-30 21:33:29 +08:00
|
|
|
std::string quote( std::string src );
|
2014-11-20 05:40:05 +08:00
|
|
|
int nc;
|
2014-04-29 05:37:31 +08:00
|
|
|
};
|
|
|
|
|
2015-12-17 22:47:10 +08:00
|
|
|
} // namespace zm
|
|
|
|
|
2014-04-29 05:37:31 +08:00
|
|
|
#endif // ZM_RTSP_AUTH_H
|