netwerk/protocol/http/nsHttpChannelAuthProvider.h

Thu, 15 Jan 2015 21:03:48 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 15 Jan 2015 21:03:48 +0100
branch
TOR_BUG_9701
changeset 11
deefc01c0e14
permissions
-rw-r--r--

Integrate friendly tips from Tor colleagues to make (or not) 4.5 alpha 3;
This includes removal of overloaded (but unused) methods, and addition of
a overlooked call to DataStruct::SetData(nsISupports, uint32_t, bool.)

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

mercurial