| 1 | /********** | 
|---|
| 2 | This library is free software; you can redistribute it and/or modify it under | 
|---|
| 3 | the terms of the GNU Lesser General Public License as published by the | 
|---|
| 4 | Free Software Foundation; either version 3 of the License, or (at your | 
|---|
| 5 | option) any later version. (See <http://www.gnu.org/copyleft/lesser.html>.) | 
|---|
| 6 |  | 
|---|
| 7 | This library is distributed in the hope that it will be useful, but WITHOUT | 
|---|
| 8 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | 
|---|
| 9 | FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for | 
|---|
| 10 | more details. | 
|---|
| 11 |  | 
|---|
| 12 | You should have received a copy of the GNU Lesser General Public License | 
|---|
| 13 | along with this library; if not, write to the Free Software Foundation, Inc., | 
|---|
| 14 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA | 
|---|
| 15 | **********/ | 
|---|
| 16 | // "liveMedia" | 
|---|
| 17 | // Copyright (c) 1996-2020 Live Networks, Inc.  All rights reserved. | 
|---|
| 18 | // A class used for digest authentication. | 
|---|
| 19 | // C++ header | 
|---|
| 20 |  | 
|---|
| 21 | #ifndef _DIGEST_AUTHENTICATION_HH | 
|---|
| 22 | #define _DIGEST_AUTHENTICATION_HH | 
|---|
| 23 |  | 
|---|
| 24 | #ifndef _BOOLEAN_HH | 
|---|
| 25 | #include <Boolean.hh> | 
|---|
| 26 | #endif | 
|---|
| 27 |  | 
|---|
| 28 | // A class used for digest authentication. | 
|---|
| 29 | // The "realm", and "nonce" fields are supplied by the server | 
|---|
| 30 | // (in a "401 Unauthorized" response). | 
|---|
| 31 | // The "username" and "password" fields are supplied by the client. | 
|---|
| 32 | class Authenticator { | 
|---|
| 33 | public: | 
|---|
| 34 | Authenticator(); | 
|---|
| 35 | Authenticator(char const* username, char const* password, Boolean passwordIsMD5 = False); | 
|---|
| 36 | // If "passwordIsMD5" is True, then "password" is actually the value computed | 
|---|
| 37 | // by md5(<username>:<realm>:<actual-password>) | 
|---|
| 38 | Authenticator(const Authenticator& orig); | 
|---|
| 39 | Authenticator& operator=(const Authenticator& rightSide); | 
|---|
| 40 | Boolean operator<(const Authenticator* rightSide); | 
|---|
| 41 | virtual ~Authenticator(); | 
|---|
| 42 |  | 
|---|
| 43 | void reset(); | 
|---|
| 44 | void setRealmAndNonce(char const* realm, char const* nonce); | 
|---|
| 45 | void setRealmAndRandomNonce(char const* realm); | 
|---|
| 46 | // as above, except that the nonce is created randomly. | 
|---|
| 47 | // (This is used by servers.) | 
|---|
| 48 | void setUsernameAndPassword(char const* username, char const* password, Boolean passwordIsMD5 = False); | 
|---|
| 49 | // If "passwordIsMD5" is True, then "password" is actually the value computed | 
|---|
| 50 | // by md5(<username>:<realm>:<actual-password>) | 
|---|
| 51 |  | 
|---|
| 52 | char const* realm() const { return fRealm; } | 
|---|
| 53 | char const* nonce() const { return fNonce; } | 
|---|
| 54 | char const* username() const { return fUsername; } | 
|---|
| 55 | char const* password() const { return fPassword; } | 
|---|
| 56 |  | 
|---|
| 57 | char const* computeDigestResponse(char const* cmd, char const* url) const; | 
|---|
| 58 | // The returned string from this function must later be freed by calling: | 
|---|
| 59 | void reclaimDigestResponse(char const* responseStr) const; | 
|---|
| 60 |  | 
|---|
| 61 | private: | 
|---|
| 62 | void resetRealmAndNonce(); | 
|---|
| 63 | void resetUsernameAndPassword(); | 
|---|
| 64 | void assignRealmAndNonce(char const* realm, char const* nonce); | 
|---|
| 65 | void assignUsernameAndPassword(char const* username, char const* password, Boolean passwordIsMD5); | 
|---|
| 66 | void assign(char const* realm, char const* nonce, | 
|---|
| 67 | char const* username, char const* password, Boolean passwordIsMD5); | 
|---|
| 68 |  | 
|---|
| 69 | private: | 
|---|
| 70 | char* fRealm; char* fNonce; | 
|---|
| 71 | char* fUsername; char* fPassword; | 
|---|
| 72 | Boolean fPasswordIsMD5; | 
|---|
| 73 | }; | 
|---|
| 74 |  | 
|---|
| 75 | #endif | 
|---|
| 76 |  | 
|---|