netwerk/protocol/http/nsHttpDigestAuth.h

branch
TOR_BUG_9701
changeset 11
deefc01c0e14
equal deleted inserted replaced
-1:000000000000 0:d3cc51b3ad5e
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 *
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6
7 #ifndef nsDigestAuth_h__
8 #define nsDigestAuth_h__
9
10 #include "nsIHttpAuthenticator.h"
11 #include "nsStringFwd.h"
12 #include "nsCOMPtr.h"
13 #include "mozilla/Attributes.h"
14
15 class nsICryptoHash;
16
17 namespace mozilla { namespace net {
18
19 #define ALGO_SPECIFIED 0x01
20 #define ALGO_MD5 0x02
21 #define ALGO_MD5_SESS 0x04
22 #define QOP_AUTH 0x01
23 #define QOP_AUTH_INT 0x02
24
25 #define DIGEST_LENGTH 16
26 #define EXPANDED_DIGEST_LENGTH 32
27 #define NONCE_COUNT_LENGTH 8
28
29 //-----------------------------------------------------------------------------
30 // nsHttpDigestAuth
31 //-----------------------------------------------------------------------------
32
33 class nsHttpDigestAuth MOZ_FINAL : public nsIHttpAuthenticator
34 {
35 public:
36 NS_DECL_ISUPPORTS
37 NS_DECL_NSIHTTPAUTHENTICATOR
38
39 nsHttpDigestAuth();
40 ~nsHttpDigestAuth();
41
42 protected:
43 nsresult ExpandToHex(const char * digest, char * result);
44
45 nsresult CalculateResponse(const char * ha1_digest,
46 const char * ha2_digest,
47 const nsAFlatCString & nonce,
48 uint16_t qop,
49 const char * nonce_count,
50 const nsAFlatCString & cnonce,
51 char * result);
52
53 nsresult CalculateHA1(const nsAFlatCString & username,
54 const nsAFlatCString & password,
55 const nsAFlatCString & realm,
56 uint16_t algorithm,
57 const nsAFlatCString & nonce,
58 const nsAFlatCString & cnonce,
59 char * result);
60
61 nsresult CalculateHA2(const nsAFlatCString & http_method,
62 const nsAFlatCString & http_uri_path,
63 uint16_t qop,
64 const char * body_digest,
65 char * result);
66
67 nsresult ParseChallenge(const char * challenge,
68 nsACString & realm,
69 nsACString & domain,
70 nsACString & nonce,
71 nsACString & opaque,
72 bool * stale,
73 uint16_t * algorithm,
74 uint16_t * qop);
75
76 // result is in mHashBuf
77 nsresult MD5Hash(const char *buf, uint32_t len);
78
79 nsresult GetMethodAndPath(nsIHttpAuthenticableChannel *,
80 bool, nsCString &, nsCString &);
81
82 // append the quoted version of value to aHeaderLine
83 nsresult AppendQuotedString(const nsACString & value,
84 nsACString & aHeaderLine);
85
86 protected:
87 nsCOMPtr<nsICryptoHash> mVerifier;
88 char mHashBuf[DIGEST_LENGTH];
89 };
90
91 }} // namespace mozilla::net
92
93 #endif // nsHttpDigestAuth_h__

mercurial