Files
palemoon27/netwerk/protocol/http/nsHttpAuthManager.cpp
T
roytam1 33f0551ea5 import changes from `dev' branch of rmottola/Arctic-Fox:
- Bug 1172382 - Enable AccessibleCaret on B2G. r=roc (f5c58c2798)
- remove duplicated (8823cc4a43)
- Bug 1219310 - part 1 - ask the prefs file for its size directly; r=njn (93073cbc5e)
- Bug 1219310 - part 2 - keep track of how much pref file we have read; r=njn (6a2a10a8b1)
- Bug 1213123 - Make Preferences::SetString accept char16ptr_t instead of char16_t*. r=froydnj (a895a36861)
- Bug 1216901 - Make the FasterMake backend reticulate splines when moz.build or jar.mn files are modified. r=mshal (ed4ec93b18)
- Bug 1219122 - Move webapprt.ini definition to moz.build. - Add corresponding webpprt files. (da6bc91b5c)
- Bug 1219126 - Move greprefs.js definition in moz.build. r=mshal (52f404c935)
- code style (1b1e543834)
- Bug 1162690 - Remove malformed uri warning in nsURLParser::ParseURL r=mcmanus (8534fcebb7)
- Bug 1163028 - URL: stop escaping [ and ] in path r=mcmanus (f2f3deec40)
- Bug 1163030 - URL: stop escaping ` in query r=mcmanus (17d6c07640)
- Bug 1191423 - Disallow illegal characters in cookies set via HTTP. r=jduell (b1786d140f)
- Bug 1210235 - Skip package verification if pref out or no signature. The package would be treated unsigned. r=valentin (63870dd7ef)
- Bug 1216062 - Notify OnStartSignedPackagedRequest with package identifier. r=valentin. (81a14af3db)
- Bug 1214079 - Doom the package cache if the signature verification failed. r=valentin (83824c2d5d)
- Bug 1178448 - Use imported CA in developer mode. r=keeler,valentin (b9cf64b477)
- Bug 1216469 - Bypass verification for signed packages from trust origins. r=valentin (a36d0a6d2f)
- Bug 1218284 - Match signed packages' with trust origin without suffix. r=valentin (45529dc7df)
- Bug 412457 - should unescape hostname first, then perform IDNA r=mcmanus (23ebe47574)
- Bug 1217316 - Remove for-each from netwerk/. r=jduell (8d0ca69e9e)
- Bug 1208847 - Add telemetry to measure how often secure cookies are set from non-secure origins r=mcmanus (57ecf3651d)
- Bug 1165267 - Part 1: Replace appId and inBrowser by originAttributes v2. r=honzab (7710301407)
- Bug 1165267 - Fix downgrading issue by restoring appId and inBrowserElement columns v3. r=honzab (3e8b8e4dfb)
- Bug 1221049 - Use originAttributes from TabContext. r=kanru (5eaebe3b28)
- Bug 1197944 - Change pref so that the http auth dialog is presented for sub resources as well. r=jduell (e3a7e2a1a7)
- Bug 1202421 - Rename the network.auth.allow-subresource-auth pref. r=michal (87e29e1fdf)
- Bug 1213577 - Use OriginAttributes in nsHttpAuthManager, r=mcmanus (33d0a25ac4)
- Bug 961049 - Part 1: Remove unused members and methods; r=baku (0f3e6de06b)
2023-03-10 15:32:42 +08:00

152 lines
5.2 KiB
C++

/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* 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/. */
// HttpLog.h should generally be included first
#include "HttpLog.h"
#include "nsHttpHandler.h"
#include "nsHttpAuthManager.h"
#include "nsNetUtil.h"
#include "nsIPrincipal.h"
namespace mozilla {
namespace net {
NS_IMPL_ISUPPORTS(nsHttpAuthManager, nsIHttpAuthManager)
nsHttpAuthManager::nsHttpAuthManager()
{
}
nsresult nsHttpAuthManager::Init()
{
// get reference to the auth cache. we assume that we will live
// as long as gHttpHandler. instantiate it if necessary.
if (!gHttpHandler) {
nsresult rv;
nsCOMPtr<nsIIOService> ios = do_GetIOService(&rv);
if (NS_FAILED(rv))
return rv;
nsCOMPtr<nsIProtocolHandler> handler;
rv = ios->GetProtocolHandler("http", getter_AddRefs(handler));
if (NS_FAILED(rv))
return rv;
// maybe someone is overriding our HTTP handler implementation?
NS_ENSURE_TRUE(gHttpHandler, NS_ERROR_UNEXPECTED);
}
mAuthCache = gHttpHandler->AuthCache(false);
mPrivateAuthCache = gHttpHandler->AuthCache(true);
NS_ENSURE_TRUE(mAuthCache, NS_ERROR_FAILURE);
NS_ENSURE_TRUE(mPrivateAuthCache, NS_ERROR_FAILURE);
return NS_OK;
}
nsHttpAuthManager::~nsHttpAuthManager()
{
}
NS_IMETHODIMP
nsHttpAuthManager::GetAuthIdentity(const nsACString & aScheme,
const nsACString & aHost,
int32_t aPort,
const nsACString & aAuthType,
const nsACString & aRealm,
const nsACString & aPath,
nsAString & aUserDomain,
nsAString & aUserName,
nsAString & aUserPassword,
bool aIsPrivate,
nsIPrincipal* aPrincipal)
{
nsHttpAuthCache* auth_cache = aIsPrivate ? mPrivateAuthCache : mAuthCache;
nsHttpAuthEntry * entry = nullptr;
nsresult rv;
nsAutoCString originSuffix;
if (aPrincipal) {
BasePrincipal::Cast(aPrincipal)->OriginAttributesRef().CreateSuffix(originSuffix);
}
if (!aPath.IsEmpty())
rv = auth_cache->GetAuthEntryForPath(PromiseFlatCString(aScheme).get(),
PromiseFlatCString(aHost).get(),
aPort,
PromiseFlatCString(aPath).get(),
originSuffix,
&entry);
else
rv = auth_cache->GetAuthEntryForDomain(PromiseFlatCString(aScheme).get(),
PromiseFlatCString(aHost).get(),
aPort,
PromiseFlatCString(aRealm).get(),
originSuffix,
&entry);
if (NS_FAILED(rv))
return rv;
if (!entry)
return NS_ERROR_UNEXPECTED;
aUserDomain.Assign(entry->Domain());
aUserName.Assign(entry->User());
aUserPassword.Assign(entry->Pass());
return NS_OK;
}
NS_IMETHODIMP
nsHttpAuthManager::SetAuthIdentity(const nsACString & aScheme,
const nsACString & aHost,
int32_t aPort,
const nsACString & aAuthType,
const nsACString & aRealm,
const nsACString & aPath,
const nsAString & aUserDomain,
const nsAString & aUserName,
const nsAString & aUserPassword,
bool aIsPrivate,
nsIPrincipal* aPrincipal)
{
nsHttpAuthIdentity ident(PromiseFlatString(aUserDomain).get(),
PromiseFlatString(aUserName).get(),
PromiseFlatString(aUserPassword).get());
nsAutoCString originSuffix;
if (aPrincipal) {
BasePrincipal::Cast(aPrincipal)->OriginAttributesRef().CreateSuffix(originSuffix);
}
nsHttpAuthCache* auth_cache = aIsPrivate ? mPrivateAuthCache : mAuthCache;
return auth_cache->SetAuthEntry(PromiseFlatCString(aScheme).get(),
PromiseFlatCString(aHost).get(),
aPort,
PromiseFlatCString(aPath).get(),
PromiseFlatCString(aRealm).get(),
nullptr, // credentials
nullptr, // challenge
originSuffix,
&ident,
nullptr); // metadata
}
NS_IMETHODIMP
nsHttpAuthManager::ClearAll()
{
nsresult rv = mAuthCache->ClearAll();
nsresult rv2 = mPrivateAuthCache->ClearAll();
if (NS_FAILED(rv))
return rv;
if (NS_FAILED(rv2))
return rv2;
return NS_OK;
}
} // namespace net
} // namespace mozilla