Wed, 31 Dec 2014 06:09:35 +0100
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: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /* vim:set et cin ts=4 sw=4 sts=4: */
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 nsHttpChannelAuthProvider_h__
8 #define nsHttpChannelAuthProvider_h__
10 #include "nsIHttpChannelAuthProvider.h"
11 #include "nsIAuthPromptCallback.h"
12 #include "nsString.h"
13 #include "nsCOMPtr.h"
14 #include "nsHttpAuthCache.h"
15 #include "nsProxyInfo.h"
16 #include "nsCRT.h"
18 class nsIHttpAuthenticableChannel;
19 class nsIHttpAuthenticator;
20 class nsIURI;
22 namespace mozilla { namespace net {
24 class nsHttpHandler;
26 class nsHttpChannelAuthProvider : public nsIHttpChannelAuthProvider
27 , public nsIAuthPromptCallback
28 {
29 public:
30 NS_DECL_ISUPPORTS
31 NS_DECL_NSICANCELABLE
32 NS_DECL_NSIHTTPCHANNELAUTHPROVIDER
33 NS_DECL_NSIAUTHPROMPTCALLBACK
35 nsHttpChannelAuthProvider();
36 virtual ~nsHttpChannelAuthProvider();
38 private:
39 const char *ProxyHost() const
40 { return mProxyInfo ? mProxyInfo->Host().get() : nullptr; }
42 int32_t ProxyPort() const
43 { return mProxyInfo ? mProxyInfo->Port() : -1; }
45 const char *Host() const { return mHost.get(); }
46 int32_t Port() const { return mPort; }
47 bool UsingSSL() const { return mUsingSSL; }
49 bool UsingHttpProxy() const
50 { return !!(mProxyInfo && !nsCRT::strcmp(mProxyInfo->Type(), "http")); }
52 nsresult PrepareForAuthentication(bool proxyAuth);
53 nsresult GenCredsAndSetEntry(nsIHttpAuthenticator *, bool proxyAuth,
54 const char *scheme, const char *host,
55 int32_t port, const char *dir,
56 const char *realm, const char *challenge,
57 const nsHttpAuthIdentity &ident,
58 nsCOMPtr<nsISupports> &session, char **result);
59 nsresult GetAuthenticator(const char *challenge, nsCString &scheme,
60 nsIHttpAuthenticator **auth);
61 void ParseRealm(const char *challenge, nsACString &realm);
62 void GetIdentityFromURI(uint32_t authFlags, nsHttpAuthIdentity&);
64 /**
65 * Following three methods return NS_ERROR_IN_PROGRESS when
66 * nsIAuthPrompt2.asyncPromptAuth method is called. This result indicates
67 * the user's decision will be gathered in a callback and is not an actual
68 * error.
69 */
70 nsresult GetCredentials(const char *challenges, bool proxyAuth,
71 nsAFlatCString &creds);
72 nsresult GetCredentialsForChallenge(const char *challenge,
73 const char *scheme, bool proxyAuth,
74 nsIHttpAuthenticator *auth,
75 nsAFlatCString &creds);
76 nsresult PromptForIdentity(uint32_t level, bool proxyAuth,
77 const char *realm, const char *authType,
78 uint32_t authFlags, nsHttpAuthIdentity &);
80 bool ConfirmAuth(const nsString &bundleKey, bool doYesNoPrompt);
81 void SetAuthorizationHeader(nsHttpAuthCache *, nsHttpAtom header,
82 const char *scheme, const char *host,
83 int32_t port, const char *path,
84 nsHttpAuthIdentity &ident);
85 nsresult GetCurrentPath(nsACString &);
86 /**
87 * Return all information needed to build authorization information,
88 * all parameters except proxyAuth are out parameters. proxyAuth specifies
89 * with what authorization we work (WWW or proxy).
90 */
91 nsresult GetAuthorizationMembers(bool proxyAuth, nsCSubstring& scheme,
92 const char*& host, int32_t& port,
93 nsCSubstring& path,
94 nsHttpAuthIdentity*& ident,
95 nsISupports**& continuationState);
96 /**
97 * Method called to resume suspended transaction after we got credentials
98 * from the user. Called from OnAuthAvailable callback or OnAuthCancelled
99 * when credentials for next challenge were obtained synchronously.
100 */
101 nsresult ContinueOnAuthAvailable(const nsCSubstring& creds);
103 nsresult DoRedirectChannelToHttps();
105 /**
106 * A function that takes care of reading STS headers and enforcing STS
107 * load rules. After a secure channel is erected, STS requires the channel
108 * to be trusted or any STS header data on the channel is ignored.
109 * This is called from ProcessResponse.
110 */
111 nsresult ProcessSTSHeader();
113 private:
114 nsIHttpAuthenticableChannel *mAuthChannel; // weak ref
116 nsCOMPtr<nsIURI> mURI;
117 nsCOMPtr<nsProxyInfo> mProxyInfo;
118 nsCString mHost;
119 int32_t mPort;
120 bool mUsingSSL;
121 bool mIsPrivate;
123 nsISupports *mProxyAuthContinuationState;
124 nsCString mProxyAuthType;
125 nsISupports *mAuthContinuationState;
126 nsCString mAuthType;
127 nsHttpAuthIdentity mIdent;
128 nsHttpAuthIdentity mProxyIdent;
130 // Reference to the prompt waiting in prompt queue. The channel is
131 // responsible to call its cancel method when user in any way cancels
132 // this request.
133 nsCOMPtr<nsICancelable> mAsyncPromptAuthCancelable;
134 // Saved in GetCredentials when prompt is asynchronous, the first challenge
135 // we obtained from the server with 401/407 response, will be processed in
136 // OnAuthAvailable callback.
137 nsCString mCurrentChallenge;
138 // Saved in GetCredentials when prompt is asynchronous, remaning challenges
139 // we have to process when user cancels the auth dialog for the current
140 // challenge.
141 nsCString mRemainingChallenges;
143 // True when we need to authenticate to proxy, i.e. when we get 407
144 // response. Used in OnAuthAvailable and OnAuthCancelled callbacks.
145 uint32_t mProxyAuth : 1;
146 uint32_t mTriedProxyAuth : 1;
147 uint32_t mTriedHostAuth : 1;
148 uint32_t mSuppressDefensiveAuth : 1;
150 nsRefPtr<nsHttpHandler> mHttpHandler; // keep gHttpHandler alive
151 };
153 }} // namespace mozilla::net
155 #endif // nsHttpChannelAuthProvider_h__