2010-06-17 11:33:42 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
|
|
|
/* vim:set et cin ts=4 sw=4 sts=4: */
|
2012-05-21 04:12:37 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2010-06-17 11:33:42 -07:00
|
|
|
|
|
|
|
#ifndef nsHttpChannelAuthProvider_h__
|
|
|
|
#define nsHttpChannelAuthProvider_h__
|
|
|
|
|
|
|
|
#include "nsIHttpChannelAuthProvider.h"
|
|
|
|
#include "nsIAuthPromptCallback.h"
|
|
|
|
#include "nsString.h"
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsHttpAuthCache.h"
|
|
|
|
#include "nsProxyInfo.h"
|
2013-09-22 20:35:52 -07:00
|
|
|
#include "nsCRT.h"
|
2010-06-17 11:33:42 -07:00
|
|
|
|
2013-09-22 20:35:52 -07:00
|
|
|
class nsIHttpAuthenticableChannel;
|
2010-06-17 11:33:42 -07:00
|
|
|
class nsIHttpAuthenticator;
|
2013-09-22 20:35:52 -07:00
|
|
|
class nsIURI;
|
2010-06-17 11:33:42 -07:00
|
|
|
|
2014-01-07 14:05:56 -08:00
|
|
|
namespace mozilla { namespace net {
|
|
|
|
|
|
|
|
class nsHttpHandler;
|
|
|
|
|
2010-06-17 11:33:42 -07:00
|
|
|
class nsHttpChannelAuthProvider : public nsIHttpChannelAuthProvider
|
|
|
|
, public nsIAuthPromptCallback
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_NSICANCELABLE
|
|
|
|
NS_DECL_NSIHTTPCHANNELAUTHPROVIDER
|
|
|
|
NS_DECL_NSIAUTHPROMPTCALLBACK
|
|
|
|
|
|
|
|
nsHttpChannelAuthProvider();
|
|
|
|
virtual ~nsHttpChannelAuthProvider();
|
|
|
|
|
|
|
|
private:
|
|
|
|
const char *ProxyHost() const
|
2012-07-30 07:20:58 -07:00
|
|
|
{ return mProxyInfo ? mProxyInfo->Host().get() : nullptr; }
|
2010-06-17 11:33:42 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t ProxyPort() const
|
2010-06-17 11:33:42 -07:00
|
|
|
{ return mProxyInfo ? mProxyInfo->Port() : -1; }
|
|
|
|
|
|
|
|
const char *Host() const { return mHost.get(); }
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t Port() const { return mPort; }
|
2011-09-28 23:19:26 -07:00
|
|
|
bool UsingSSL() const { return mUsingSSL; }
|
2010-06-17 11:33:42 -07:00
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool UsingHttpProxy() const
|
2010-06-17 11:33:42 -07:00
|
|
|
{ return !!(mProxyInfo && !nsCRT::strcmp(mProxyInfo->Type(), "http")); }
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
nsresult PrepareForAuthentication(bool proxyAuth);
|
|
|
|
nsresult GenCredsAndSetEntry(nsIHttpAuthenticator *, bool proxyAuth,
|
2010-06-17 11:33:42 -07:00
|
|
|
const char *scheme, const char *host,
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t port, const char *dir,
|
2010-06-17 11:33:42 -07:00
|
|
|
const char *realm, const char *challenge,
|
|
|
|
const nsHttpAuthIdentity &ident,
|
|
|
|
nsCOMPtr<nsISupports> &session, char **result);
|
|
|
|
nsresult GetAuthenticator(const char *challenge, nsCString &scheme,
|
|
|
|
nsIHttpAuthenticator **auth);
|
|
|
|
void ParseRealm(const char *challenge, nsACString &realm);
|
2012-08-22 08:56:38 -07:00
|
|
|
void GetIdentityFromURI(uint32_t authFlags, nsHttpAuthIdentity&);
|
2012-07-26 08:09:05 -07:00
|
|
|
|
2010-06-17 11:33:42 -07:00
|
|
|
/**
|
|
|
|
* Following three methods return NS_ERROR_IN_PROGRESS when
|
|
|
|
* nsIAuthPrompt2.asyncPromptAuth method is called. This result indicates
|
|
|
|
* the user's decision will be gathered in a callback and is not an actual
|
|
|
|
* error.
|
|
|
|
*/
|
2011-09-28 23:19:26 -07:00
|
|
|
nsresult GetCredentials(const char *challenges, bool proxyAuth,
|
2010-06-17 11:33:42 -07:00
|
|
|
nsAFlatCString &creds);
|
|
|
|
nsresult GetCredentialsForChallenge(const char *challenge,
|
2011-09-28 23:19:26 -07:00
|
|
|
const char *scheme, bool proxyAuth,
|
2010-06-17 11:33:42 -07:00
|
|
|
nsIHttpAuthenticator *auth,
|
|
|
|
nsAFlatCString &creds);
|
2012-08-22 08:56:38 -07:00
|
|
|
nsresult PromptForIdentity(uint32_t level, bool proxyAuth,
|
2010-06-17 11:33:42 -07:00
|
|
|
const char *realm, const char *authType,
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t authFlags, nsHttpAuthIdentity &);
|
2010-06-17 11:33:42 -07:00
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool ConfirmAuth(const nsString &bundleKey, bool doYesNoPrompt);
|
2010-06-17 11:33:42 -07:00
|
|
|
void SetAuthorizationHeader(nsHttpAuthCache *, nsHttpAtom header,
|
|
|
|
const char *scheme, const char *host,
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t port, const char *path,
|
2010-06-17 11:33:42 -07:00
|
|
|
nsHttpAuthIdentity &ident);
|
|
|
|
nsresult GetCurrentPath(nsACString &);
|
|
|
|
/**
|
|
|
|
* Return all information needed to build authorization information,
|
|
|
|
* all parameters except proxyAuth are out parameters. proxyAuth specifies
|
|
|
|
* with what authorization we work (WWW or proxy).
|
|
|
|
*/
|
2011-09-28 23:19:26 -07:00
|
|
|
nsresult GetAuthorizationMembers(bool proxyAuth, nsCSubstring& scheme,
|
2012-08-22 08:56:38 -07:00
|
|
|
const char*& host, int32_t& port,
|
2010-06-17 11:33:42 -07:00
|
|
|
nsCSubstring& path,
|
|
|
|
nsHttpAuthIdentity*& ident,
|
|
|
|
nsISupports**& continuationState);
|
|
|
|
/**
|
|
|
|
* Method called to resume suspended transaction after we got credentials
|
|
|
|
* from the user. Called from OnAuthAvailable callback or OnAuthCancelled
|
|
|
|
* when credentials for next challenge were obtained synchronously.
|
|
|
|
*/
|
|
|
|
nsresult ContinueOnAuthAvailable(const nsCSubstring& creds);
|
|
|
|
|
2010-06-03 14:03:17 -07:00
|
|
|
nsresult DoRedirectChannelToHttps();
|
|
|
|
|
|
|
|
/**
|
2013-05-16 06:30:42 -07:00
|
|
|
* A function that takes care of reading STS headers and enforcing STS
|
2010-06-03 14:03:17 -07:00
|
|
|
* load rules. After a secure channel is erected, STS requires the channel
|
|
|
|
* to be trusted or any STS header data on the channel is ignored.
|
|
|
|
* This is called from ProcessResponse.
|
|
|
|
*/
|
|
|
|
nsresult ProcessSTSHeader();
|
|
|
|
|
2010-06-17 11:33:42 -07:00
|
|
|
private:
|
|
|
|
nsIHttpAuthenticableChannel *mAuthChannel; // weak ref
|
|
|
|
|
|
|
|
nsCOMPtr<nsIURI> mURI;
|
|
|
|
nsCOMPtr<nsProxyInfo> mProxyInfo;
|
|
|
|
nsCString mHost;
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t mPort;
|
2011-09-28 23:19:26 -07:00
|
|
|
bool mUsingSSL;
|
2012-10-29 13:20:03 -07:00
|
|
|
bool mIsPrivate;
|
2010-06-17 11:33:42 -07:00
|
|
|
|
|
|
|
nsISupports *mProxyAuthContinuationState;
|
|
|
|
nsCString mProxyAuthType;
|
|
|
|
nsISupports *mAuthContinuationState;
|
|
|
|
nsCString mAuthType;
|
|
|
|
nsHttpAuthIdentity mIdent;
|
|
|
|
nsHttpAuthIdentity mProxyIdent;
|
|
|
|
|
2010-06-22 17:33:57 -07:00
|
|
|
// Reference to the prompt waiting in prompt queue. The channel is
|
2010-06-17 11:33:42 -07:00
|
|
|
// responsible to call its cancel method when user in any way cancels
|
|
|
|
// this request.
|
|
|
|
nsCOMPtr<nsICancelable> mAsyncPromptAuthCancelable;
|
|
|
|
// Saved in GetCredentials when prompt is asynchronous, the first challenge
|
|
|
|
// we obtained from the server with 401/407 response, will be processed in
|
|
|
|
// OnAuthAvailable callback.
|
|
|
|
nsCString mCurrentChallenge;
|
|
|
|
// Saved in GetCredentials when prompt is asynchronous, remaning challenges
|
|
|
|
// we have to process when user cancels the auth dialog for the current
|
|
|
|
// challenge.
|
|
|
|
nsCString mRemainingChallenges;
|
|
|
|
|
|
|
|
// True when we need to authenticate to proxy, i.e. when we get 407
|
|
|
|
// response. Used in OnAuthAvailable and OnAuthCancelled callbacks.
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t mProxyAuth : 1;
|
|
|
|
uint32_t mTriedProxyAuth : 1;
|
|
|
|
uint32_t mTriedHostAuth : 1;
|
|
|
|
uint32_t mSuppressDefensiveAuth : 1;
|
2013-08-13 12:36:58 -07:00
|
|
|
|
|
|
|
nsRefPtr<nsHttpHandler> mHttpHandler; // keep gHttpHandler alive
|
2010-06-17 11:33:42 -07:00
|
|
|
};
|
|
|
|
|
2014-01-07 14:05:56 -08:00
|
|
|
}} // namespace mozilla::net
|
|
|
|
|
2010-06-17 11:33:42 -07:00
|
|
|
#endif // nsHttpChannelAuthProvider_h__
|