netwerk/protocol/http/nsHttpDigestAuth.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     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/. */
     7 #ifndef nsDigestAuth_h__
     8 #define nsDigestAuth_h__
    10 #include "nsIHttpAuthenticator.h"
    11 #include "nsStringFwd.h"
    12 #include "nsCOMPtr.h"
    13 #include "mozilla/Attributes.h"
    15 class nsICryptoHash;
    17 namespace mozilla { namespace net {
    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
    25 #define DIGEST_LENGTH 16
    26 #define EXPANDED_DIGEST_LENGTH 32
    27 #define NONCE_COUNT_LENGTH 8
    29 //-----------------------------------------------------------------------------
    30 // nsHttpDigestAuth
    31 //-----------------------------------------------------------------------------
    33 class nsHttpDigestAuth MOZ_FINAL : public nsIHttpAuthenticator
    34 {
    35   public:
    36     NS_DECL_ISUPPORTS
    37     NS_DECL_NSIHTTPAUTHENTICATOR
    39     nsHttpDigestAuth();
    40     ~nsHttpDigestAuth();
    42   protected:
    43     nsresult ExpandToHex(const char * digest, char * result);
    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);
    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);
    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);
    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);
    76     // result is in mHashBuf
    77     nsresult MD5Hash(const char *buf, uint32_t len);
    79     nsresult GetMethodAndPath(nsIHttpAuthenticableChannel *,
    80                               bool, nsCString &, nsCString &);
    82     // append the quoted version of value to aHeaderLine
    83     nsresult AppendQuotedString(const nsACString & value,
    84                                 nsACString & aHeaderLine);
    86   protected:
    87     nsCOMPtr<nsICryptoHash>        mVerifier;
    88     char                           mHashBuf[DIGEST_LENGTH];
    89 };
    91 }} // namespace mozilla::net
    93 #endif // nsHttpDigestAuth_h__

mercurial