1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/netwerk/protocol/http/nsHttpDigestAuth.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,93 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- 1.5 + * 1.6 + * This Source Code Form is subject to the terms of the Mozilla Public 1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.9 + 1.10 +#ifndef nsDigestAuth_h__ 1.11 +#define nsDigestAuth_h__ 1.12 + 1.13 +#include "nsIHttpAuthenticator.h" 1.14 +#include "nsStringFwd.h" 1.15 +#include "nsCOMPtr.h" 1.16 +#include "mozilla/Attributes.h" 1.17 + 1.18 +class nsICryptoHash; 1.19 + 1.20 +namespace mozilla { namespace net { 1.21 + 1.22 +#define ALGO_SPECIFIED 0x01 1.23 +#define ALGO_MD5 0x02 1.24 +#define ALGO_MD5_SESS 0x04 1.25 +#define QOP_AUTH 0x01 1.26 +#define QOP_AUTH_INT 0x02 1.27 + 1.28 +#define DIGEST_LENGTH 16 1.29 +#define EXPANDED_DIGEST_LENGTH 32 1.30 +#define NONCE_COUNT_LENGTH 8 1.31 + 1.32 +//----------------------------------------------------------------------------- 1.33 +// nsHttpDigestAuth 1.34 +//----------------------------------------------------------------------------- 1.35 + 1.36 +class nsHttpDigestAuth MOZ_FINAL : public nsIHttpAuthenticator 1.37 +{ 1.38 + public: 1.39 + NS_DECL_ISUPPORTS 1.40 + NS_DECL_NSIHTTPAUTHENTICATOR 1.41 + 1.42 + nsHttpDigestAuth(); 1.43 + ~nsHttpDigestAuth(); 1.44 + 1.45 + protected: 1.46 + nsresult ExpandToHex(const char * digest, char * result); 1.47 + 1.48 + nsresult CalculateResponse(const char * ha1_digest, 1.49 + const char * ha2_digest, 1.50 + const nsAFlatCString & nonce, 1.51 + uint16_t qop, 1.52 + const char * nonce_count, 1.53 + const nsAFlatCString & cnonce, 1.54 + char * result); 1.55 + 1.56 + nsresult CalculateHA1(const nsAFlatCString & username, 1.57 + const nsAFlatCString & password, 1.58 + const nsAFlatCString & realm, 1.59 + uint16_t algorithm, 1.60 + const nsAFlatCString & nonce, 1.61 + const nsAFlatCString & cnonce, 1.62 + char * result); 1.63 + 1.64 + nsresult CalculateHA2(const nsAFlatCString & http_method, 1.65 + const nsAFlatCString & http_uri_path, 1.66 + uint16_t qop, 1.67 + const char * body_digest, 1.68 + char * result); 1.69 + 1.70 + nsresult ParseChallenge(const char * challenge, 1.71 + nsACString & realm, 1.72 + nsACString & domain, 1.73 + nsACString & nonce, 1.74 + nsACString & opaque, 1.75 + bool * stale, 1.76 + uint16_t * algorithm, 1.77 + uint16_t * qop); 1.78 + 1.79 + // result is in mHashBuf 1.80 + nsresult MD5Hash(const char *buf, uint32_t len); 1.81 + 1.82 + nsresult GetMethodAndPath(nsIHttpAuthenticableChannel *, 1.83 + bool, nsCString &, nsCString &); 1.84 + 1.85 + // append the quoted version of value to aHeaderLine 1.86 + nsresult AppendQuotedString(const nsACString & value, 1.87 + nsACString & aHeaderLine); 1.88 + 1.89 + protected: 1.90 + nsCOMPtr<nsICryptoHash> mVerifier; 1.91 + char mHashBuf[DIGEST_LENGTH]; 1.92 +}; 1.93 + 1.94 +}} // namespace mozilla::net 1.95 + 1.96 +#endif // nsHttpDigestAuth_h__