Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/netwerk/protocol/http/nsHttpDigestAuth.h
Line
Count
Source (jump to first uncovered line)
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
0
#define ALGO_SPECIFIED 0x01
20
0
#define ALGO_MD5 0x02
21
0
#define ALGO_MD5_SESS 0x04
22
0
#define QOP_AUTH 0x01
23
0
#define QOP_AUTH_INT 0x02
24
25
0
#define DIGEST_LENGTH 16
26
0
#define EXPANDED_DIGEST_LENGTH 32
27
0
#define NONCE_COUNT_LENGTH 8
28
29
//-----------------------------------------------------------------------------
30
// nsHttpDigestAuth
31
//-----------------------------------------------------------------------------
32
33
class nsHttpDigestAuth final : public nsIHttpAuthenticator
34
{
35
  public:
36
    NS_DECL_ISUPPORTS
37
    NS_DECL_NSIHTTPAUTHENTICATOR
38
39
0
    nsHttpDigestAuth() = default;
40
41
  protected:
42
0
    ~nsHttpDigestAuth() = default;
43
44
    MOZ_MUST_USE nsresult ExpandToHex(const char * digest, char * result);
45
46
    MOZ_MUST_USE nsresult CalculateResponse(const char * ha1_digest,
47
                                            const char * ha2_digest,
48
                                            const nsCString&  nonce,
49
                                            uint16_t qop,
50
                                            const char * nonce_count,
51
                                            const nsCString&  cnonce,
52
                                            char * result);
53
54
    MOZ_MUST_USE nsresult CalculateHA1(const nsCString& username,
55
                                       const nsCString& password,
56
                                       const nsCString& realm,
57
                                       uint16_t algorithm,
58
                                       const nsCString& nonce,
59
                                       const nsCString& cnonce,
60
                                       char * result);
61
62
    MOZ_MUST_USE nsresult CalculateHA2(const nsCString& http_method,
63
                                       const nsCString& http_uri_path,
64
                                       uint16_t qop,
65
                                       const char * body_digest,
66
                                       char * result);
67
68
    MOZ_MUST_USE nsresult ParseChallenge(const char * challenge,
69
                                         nsACString & realm,
70
                                         nsACString & domain,
71
                                         nsACString & nonce,
72
                                         nsACString & opaque,
73
                                         bool * stale,
74
                                         uint16_t * algorithm,
75
                                         uint16_t * qop);
76
77
    // result is in mHashBuf
78
    MOZ_MUST_USE nsresult MD5Hash(const char *buf, uint32_t len);
79
80
    MOZ_MUST_USE nsresult GetMethodAndPath(nsIHttpAuthenticableChannel *,
81
                                           bool, nsCString &, nsCString &);
82
83
    // append the quoted version of value to aHeaderLine
84
    MOZ_MUST_USE nsresult AppendQuotedString(const nsACString & value,
85
                                             nsACString & aHeaderLine);
86
87
  protected:
88
    nsCOMPtr<nsICryptoHash>        mVerifier;
89
    char                           mHashBuf[DIGEST_LENGTH];
90
};
91
92
} // namespace net
93
} // namespace mozilla
94
95
#endif // nsHttpDigestAuth_h__