DigestAuthentication.hh 3.0 KB

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