netwerk/protocol/http/nsHttpChannelAuthProvider.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/netwerk/protocol/http/nsHttpChannelAuthProvider.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,155 @@
     1.4 +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
     1.5 +/* vim:set et cin ts=4 sw=4 sts=4: */
     1.6 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.9 +
    1.10 +#ifndef nsHttpChannelAuthProvider_h__
    1.11 +#define nsHttpChannelAuthProvider_h__
    1.12 +
    1.13 +#include "nsIHttpChannelAuthProvider.h"
    1.14 +#include "nsIAuthPromptCallback.h"
    1.15 +#include "nsString.h"
    1.16 +#include "nsCOMPtr.h"
    1.17 +#include "nsHttpAuthCache.h"
    1.18 +#include "nsProxyInfo.h"
    1.19 +#include "nsCRT.h"
    1.20 +
    1.21 +class nsIHttpAuthenticableChannel;
    1.22 +class nsIHttpAuthenticator;
    1.23 +class nsIURI;
    1.24 +
    1.25 +namespace mozilla { namespace net {
    1.26 +
    1.27 +class nsHttpHandler;
    1.28 +
    1.29 +class nsHttpChannelAuthProvider : public nsIHttpChannelAuthProvider
    1.30 +                                , public nsIAuthPromptCallback
    1.31 +{
    1.32 +public:
    1.33 +    NS_DECL_ISUPPORTS
    1.34 +    NS_DECL_NSICANCELABLE
    1.35 +    NS_DECL_NSIHTTPCHANNELAUTHPROVIDER
    1.36 +    NS_DECL_NSIAUTHPROMPTCALLBACK
    1.37 +
    1.38 +    nsHttpChannelAuthProvider();
    1.39 +    virtual ~nsHttpChannelAuthProvider();
    1.40 +
    1.41 +private:
    1.42 +    const char *ProxyHost() const
    1.43 +    { return mProxyInfo ? mProxyInfo->Host().get() : nullptr; }
    1.44 +
    1.45 +    int32_t     ProxyPort() const
    1.46 +    { return mProxyInfo ? mProxyInfo->Port() : -1; }
    1.47 +
    1.48 +    const char *Host() const      { return mHost.get(); }
    1.49 +    int32_t     Port() const      { return mPort; }
    1.50 +    bool        UsingSSL() const  { return mUsingSSL; }
    1.51 +
    1.52 +    bool        UsingHttpProxy() const
    1.53 +    { return !!(mProxyInfo && !nsCRT::strcmp(mProxyInfo->Type(), "http")); }
    1.54 +
    1.55 +    nsresult PrepareForAuthentication(bool proxyAuth);
    1.56 +    nsresult GenCredsAndSetEntry(nsIHttpAuthenticator *, bool proxyAuth,
    1.57 +                                 const char *scheme, const char *host,
    1.58 +                                 int32_t port, const char *dir,
    1.59 +                                 const char *realm, const char *challenge,
    1.60 +                                 const nsHttpAuthIdentity &ident,
    1.61 +                                 nsCOMPtr<nsISupports> &session, char **result);
    1.62 +    nsresult GetAuthenticator(const char *challenge, nsCString &scheme,
    1.63 +                              nsIHttpAuthenticator **auth);
    1.64 +    void     ParseRealm(const char *challenge, nsACString &realm);
    1.65 +    void     GetIdentityFromURI(uint32_t authFlags, nsHttpAuthIdentity&);
    1.66 +
    1.67 +    /**
    1.68 +     * Following three methods return NS_ERROR_IN_PROGRESS when
    1.69 +     * nsIAuthPrompt2.asyncPromptAuth method is called. This result indicates
    1.70 +     * the user's decision will be gathered in a callback and is not an actual
    1.71 +     * error.
    1.72 +     */
    1.73 +    nsresult GetCredentials(const char *challenges, bool proxyAuth,
    1.74 +                            nsAFlatCString &creds);
    1.75 +    nsresult GetCredentialsForChallenge(const char *challenge,
    1.76 +                                        const char *scheme,  bool proxyAuth,
    1.77 +                                        nsIHttpAuthenticator *auth,
    1.78 +                                        nsAFlatCString &creds);
    1.79 +    nsresult PromptForIdentity(uint32_t level, bool proxyAuth,
    1.80 +                               const char *realm, const char *authType,
    1.81 +                               uint32_t authFlags, nsHttpAuthIdentity &);
    1.82 +
    1.83 +    bool     ConfirmAuth(const nsString &bundleKey, bool doYesNoPrompt);
    1.84 +    void     SetAuthorizationHeader(nsHttpAuthCache *, nsHttpAtom header,
    1.85 +                                    const char *scheme, const char *host,
    1.86 +                                    int32_t port, const char *path,
    1.87 +                                    nsHttpAuthIdentity &ident);
    1.88 +    nsresult GetCurrentPath(nsACString &);
    1.89 +    /**
    1.90 +     * Return all information needed to build authorization information,
    1.91 +     * all parameters except proxyAuth are out parameters. proxyAuth specifies
    1.92 +     * with what authorization we work (WWW or proxy).
    1.93 +     */
    1.94 +    nsresult GetAuthorizationMembers(bool proxyAuth, nsCSubstring& scheme,
    1.95 +                                     const char*& host, int32_t& port,
    1.96 +                                     nsCSubstring& path,
    1.97 +                                     nsHttpAuthIdentity*& ident,
    1.98 +                                     nsISupports**& continuationState);
    1.99 +    /**
   1.100 +     * Method called to resume suspended transaction after we got credentials
   1.101 +     * from the user. Called from OnAuthAvailable callback or OnAuthCancelled
   1.102 +     * when credentials for next challenge were obtained synchronously.
   1.103 +     */
   1.104 +    nsresult ContinueOnAuthAvailable(const nsCSubstring& creds);
   1.105 +
   1.106 +    nsresult DoRedirectChannelToHttps();
   1.107 +
   1.108 +    /**
   1.109 +     * A function that takes care of reading STS headers and enforcing STS
   1.110 +     * load rules.  After a secure channel is erected, STS requires the channel
   1.111 +     * to be trusted or any STS header data on the channel is ignored.
   1.112 +     * This is called from ProcessResponse.
   1.113 +     */
   1.114 +    nsresult ProcessSTSHeader();
   1.115 +
   1.116 +private:
   1.117 +    nsIHttpAuthenticableChannel      *mAuthChannel;  // weak ref
   1.118 +
   1.119 +    nsCOMPtr<nsIURI>                  mURI;
   1.120 +    nsCOMPtr<nsProxyInfo>             mProxyInfo;
   1.121 +    nsCString                         mHost;
   1.122 +    int32_t                           mPort;
   1.123 +    bool                              mUsingSSL;
   1.124 +    bool                              mIsPrivate;
   1.125 +
   1.126 +    nsISupports                      *mProxyAuthContinuationState;
   1.127 +    nsCString                         mProxyAuthType;
   1.128 +    nsISupports                      *mAuthContinuationState;
   1.129 +    nsCString                         mAuthType;
   1.130 +    nsHttpAuthIdentity                mIdent;
   1.131 +    nsHttpAuthIdentity                mProxyIdent;
   1.132 +
   1.133 +    // Reference to the prompt waiting in prompt queue. The channel is
   1.134 +    // responsible to call its cancel method when user in any way cancels
   1.135 +    // this request.
   1.136 +    nsCOMPtr<nsICancelable>           mAsyncPromptAuthCancelable;
   1.137 +    // Saved in GetCredentials when prompt is asynchronous, the first challenge
   1.138 +    // we obtained from the server with 401/407 response, will be processed in
   1.139 +    // OnAuthAvailable callback.
   1.140 +    nsCString                         mCurrentChallenge;
   1.141 +    // Saved in GetCredentials when prompt is asynchronous, remaning challenges
   1.142 +    // we have to process when user cancels the auth dialog for the current
   1.143 +    // challenge.
   1.144 +    nsCString                         mRemainingChallenges;
   1.145 +
   1.146 +    // True when we need to authenticate to proxy, i.e. when we get 407
   1.147 +    // response. Used in OnAuthAvailable and OnAuthCancelled callbacks.
   1.148 +    uint32_t                          mProxyAuth                : 1;
   1.149 +    uint32_t                          mTriedProxyAuth           : 1;
   1.150 +    uint32_t                          mTriedHostAuth            : 1;
   1.151 +    uint32_t                          mSuppressDefensiveAuth    : 1;
   1.152 +
   1.153 +    nsRefPtr<nsHttpHandler>           mHttpHandler;  // keep gHttpHandler alive
   1.154 +};
   1.155 +
   1.156 +}} // namespace mozilla::net
   1.157 +
   1.158 +#endif // nsHttpChannelAuthProvider_h__

mercurial