michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- michael@0: * michael@0: * This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef nsDigestAuth_h__ michael@0: #define nsDigestAuth_h__ michael@0: michael@0: #include "nsIHttpAuthenticator.h" michael@0: #include "nsStringFwd.h" michael@0: #include "nsCOMPtr.h" michael@0: #include "mozilla/Attributes.h" michael@0: michael@0: class nsICryptoHash; michael@0: michael@0: namespace mozilla { namespace net { michael@0: michael@0: #define ALGO_SPECIFIED 0x01 michael@0: #define ALGO_MD5 0x02 michael@0: #define ALGO_MD5_SESS 0x04 michael@0: #define QOP_AUTH 0x01 michael@0: #define QOP_AUTH_INT 0x02 michael@0: michael@0: #define DIGEST_LENGTH 16 michael@0: #define EXPANDED_DIGEST_LENGTH 32 michael@0: #define NONCE_COUNT_LENGTH 8 michael@0: michael@0: //----------------------------------------------------------------------------- michael@0: // nsHttpDigestAuth michael@0: //----------------------------------------------------------------------------- michael@0: michael@0: class nsHttpDigestAuth MOZ_FINAL : public nsIHttpAuthenticator michael@0: { michael@0: public: michael@0: NS_DECL_ISUPPORTS michael@0: NS_DECL_NSIHTTPAUTHENTICATOR michael@0: michael@0: nsHttpDigestAuth(); michael@0: ~nsHttpDigestAuth(); michael@0: michael@0: protected: michael@0: nsresult ExpandToHex(const char * digest, char * result); michael@0: michael@0: nsresult CalculateResponse(const char * ha1_digest, michael@0: const char * ha2_digest, michael@0: const nsAFlatCString & nonce, michael@0: uint16_t qop, michael@0: const char * nonce_count, michael@0: const nsAFlatCString & cnonce, michael@0: char * result); michael@0: michael@0: nsresult CalculateHA1(const nsAFlatCString & username, michael@0: const nsAFlatCString & password, michael@0: const nsAFlatCString & realm, michael@0: uint16_t algorithm, michael@0: const nsAFlatCString & nonce, michael@0: const nsAFlatCString & cnonce, michael@0: char * result); michael@0: michael@0: nsresult CalculateHA2(const nsAFlatCString & http_method, michael@0: const nsAFlatCString & http_uri_path, michael@0: uint16_t qop, michael@0: const char * body_digest, michael@0: char * result); michael@0: michael@0: nsresult ParseChallenge(const char * challenge, michael@0: nsACString & realm, michael@0: nsACString & domain, michael@0: nsACString & nonce, michael@0: nsACString & opaque, michael@0: bool * stale, michael@0: uint16_t * algorithm, michael@0: uint16_t * qop); michael@0: michael@0: // result is in mHashBuf michael@0: nsresult MD5Hash(const char *buf, uint32_t len); michael@0: michael@0: nsresult GetMethodAndPath(nsIHttpAuthenticableChannel *, michael@0: bool, nsCString &, nsCString &); michael@0: michael@0: // append the quoted version of value to aHeaderLine michael@0: nsresult AppendQuotedString(const nsACString & value, michael@0: nsACString & aHeaderLine); michael@0: michael@0: protected: michael@0: nsCOMPtr mVerifier; michael@0: char mHashBuf[DIGEST_LENGTH]; michael@0: }; michael@0: michael@0: }} // namespace mozilla::net michael@0: michael@0: #endif // nsHttpDigestAuth_h__