1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
3 * ***** BEGIN LICENSE BLOCK *****
4 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
6 * The contents of this file are subject to the Mozilla Public License Version
7 * 1.1 (the "License"); you may not use this file except in compliance with
8 * the License. You may obtain a copy of the License at
9 * http://www.mozilla.org/MPL/
11 * Software distributed under the License is distributed on an "AS IS" basis,
12 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13 * for the specific language governing rights and limitations under the
16 * The Original Code is mozilla.org code.
18 * The Initial Developer of the Original Code is
19 * Netscape Communications Corporation.
20 * Portions created by the Initial Developer are Copyright (C) 1998
21 * the Initial Developer. All Rights Reserved.
24 * Justin Bradford <jab@atdot.org> (original author of nsDigestAuth.h)
25 * An-Cheng Huang <pach@cs.cmu.edu>
26 * Darin Fisher <darin@netscape.com>
28 * Alternatively, the contents of this file may be used under the terms of
29 * either the GNU General Public License Version 2 or later (the "GPL"), or
30 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
31 * in which case the provisions of the GPL or the LGPL are applicable instead
32 * of those above. If you wish to allow use of your version of this file only
33 * under the terms of either the GPL or the LGPL, and not to allow others to
34 * use your version of this file under the terms of the MPL, indicate your
35 * decision by deleting the provisions above and replace them with the notice
36 * and other provisions required by the GPL or the LGPL. If you do not delete
37 * the provisions above, a recipient may use your version of this file under
38 * the terms of any one of the MPL, the GPL or the LGPL.
40 * ***** END LICENSE BLOCK ***** */
42 #ifndef nsDigestAuth_h__
43 #define nsDigestAuth_h__
45 #include "nsIHttpAuthenticator.h"
46 #include "nsICryptoHash.h"
50 #define ALGO_SPECIFIED 0x01
52 #define ALGO_MD5_SESS 0x04
54 #define QOP_AUTH_INT 0x02
56 #define DIGEST_LENGTH 16
57 #define EXPANDED_DIGEST_LENGTH 32
58 #define NONCE_COUNT_LENGTH 8
60 //-----------------------------------------------------------------------------
62 //-----------------------------------------------------------------------------
64 class nsHttpDigestAuth
: public nsIHttpAuthenticator
68 NS_DECL_NSIHTTPAUTHENTICATOR
74 nsresult
ExpandToHex(const char * digest
, char * result
);
76 nsresult
CalculateResponse(const char * ha1_digest
,
77 const char * ha2_digest
,
78 const nsAFlatCString
& nonce
,
80 const char * nonce_count
,
81 const nsAFlatCString
& cnonce
,
84 nsresult
CalculateHA1(const nsAFlatCString
& username
,
85 const nsAFlatCString
& password
,
86 const nsAFlatCString
& realm
,
88 const nsAFlatCString
& nonce
,
89 const nsAFlatCString
& cnonce
,
92 nsresult
CalculateHA2(const nsAFlatCString
& http_method
,
93 const nsAFlatCString
& http_uri_path
,
95 const char * body_digest
,
98 nsresult
ParseChallenge(const char * challenge
,
104 PRUint16
* algorithm
,
107 // result is in mHashBuf
108 nsresult
MD5Hash(const char *buf
, PRUint32 len
);
110 nsresult
GetMethodAndPath(nsIHttpChannel
*, PRBool
, nsCString
&, nsCString
&);
112 // append the quoted version of value to aHeaderLine
113 nsresult
AppendQuotedString(const nsACString
& value
,
114 nsACString
& aHeaderLine
);
117 nsCOMPtr
<nsICryptoHash
> mVerifier
;
118 char mHashBuf
[DIGEST_LENGTH
];
121 #endif // nsHttpDigestAuth_h__