2003-07-24 09:15:20 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2005-10-14 22:57:26 +04:00
|
|
|
/* vim: set ts=2 sw=2 et tw=80: */
|
2012-05-21 15:12:37 +04: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/. */
|
2003-07-24 09:15:20 +04:00
|
|
|
|
2013-08-14 10:56:21 +04:00
|
|
|
#include "nsPrincipal.h"
|
|
|
|
|
2013-01-09 01:53:32 +04:00
|
|
|
#include "mozIThirdPartyUtil.h"
|
2003-07-24 09:15:20 +04:00
|
|
|
#include "nscore.h"
|
|
|
|
#include "nsScriptSecurityManager.h"
|
|
|
|
#include "nsString.h"
|
|
|
|
#include "nsReadableUtils.h"
|
2013-07-12 00:21:45 +04:00
|
|
|
#include "pratom.h"
|
2003-07-24 09:15:20 +04:00
|
|
|
#include "nsIURI.h"
|
|
|
|
#include "nsJSPrincipals.h"
|
|
|
|
#include "nsIObjectInputStream.h"
|
|
|
|
#include "nsIObjectOutputStream.h"
|
2006-03-15 07:59:42 +03:00
|
|
|
#include "nsIClassInfoImpl.h"
|
2012-07-27 18:03:27 +04:00
|
|
|
#include "nsError.h"
|
2010-01-23 00:38:21 +03:00
|
|
|
#include "nsIContentSecurityPolicy.h"
|
2013-05-22 20:05:26 +04:00
|
|
|
#include "nsCxPusher.h"
|
2012-07-12 12:10:15 +04:00
|
|
|
#include "jswrapper.h"
|
2003-07-24 09:15:20 +04:00
|
|
|
|
2011-06-20 07:00:16 +04:00
|
|
|
#include "mozilla/Preferences.h"
|
2012-03-13 02:53:18 +04:00
|
|
|
#include "mozilla/HashFunctions.h"
|
2009-06-16 15:00:06 +04:00
|
|
|
|
2012-08-28 06:43:57 +04:00
|
|
|
#include "nsIAppsService.h"
|
|
|
|
#include "mozIApplication.h"
|
|
|
|
|
2011-06-20 07:00:16 +04:00
|
|
|
using namespace mozilla;
|
2009-06-16 15:00:06 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
static bool gCodeBasePrincipalSupport = false;
|
|
|
|
static bool gIsObservingCodeBasePrincipalSupport = false;
|
2009-06-16 15:00:06 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
static bool URIIsImmutable(nsIURI* aURI)
|
2007-06-18 19:07:02 +04:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsIMutable> mutableObj(do_QueryInterface(aURI));
|
2011-09-29 10:19:26 +04:00
|
|
|
bool isMutable;
|
2007-06-18 19:07:02 +04:00
|
|
|
return
|
|
|
|
mutableObj &&
|
|
|
|
NS_SUCCEEDED(mutableObj->GetMutable(&isMutable)) &&
|
2013-06-01 01:33:51 +04:00
|
|
|
!isMutable;
|
2007-06-18 19:07:02 +04:00
|
|
|
}
|
2003-07-24 09:15:20 +04:00
|
|
|
|
|
|
|
// Static member variables
|
2012-06-10 02:19:26 +04:00
|
|
|
const char nsBasePrincipal::sInvalid[] = "Invalid";
|
2003-07-24 09:15:20 +04:00
|
|
|
|
2014-03-28 00:38:33 +04:00
|
|
|
NS_IMETHODIMP_(MozExternalRefCountType)
|
2012-06-10 02:19:26 +04:00
|
|
|
nsBasePrincipal::AddRef()
|
2003-07-24 09:15:20 +04:00
|
|
|
{
|
2012-08-22 19:56:38 +04:00
|
|
|
NS_PRECONDITION(int32_t(refcount) >= 0, "illegal refcnt");
|
2003-07-24 09:15:20 +04:00
|
|
|
// XXXcaa does this need to be threadsafe? See bug 143559.
|
2013-11-27 19:37:10 +04:00
|
|
|
nsrefcnt count = ++refcount;
|
2012-06-10 02:19:26 +04:00
|
|
|
NS_LOG_ADDREF(this, count, "nsBasePrincipal", sizeof(*this));
|
2003-07-24 09:15:20 +04:00
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
2014-03-28 00:38:33 +04:00
|
|
|
NS_IMETHODIMP_(MozExternalRefCountType)
|
2012-06-10 02:19:26 +04:00
|
|
|
nsBasePrincipal::Release()
|
2003-07-24 09:15:20 +04:00
|
|
|
{
|
2012-03-09 13:48:50 +04:00
|
|
|
NS_PRECONDITION(0 != refcount, "dup release");
|
2013-11-27 19:37:10 +04:00
|
|
|
nsrefcnt count = --refcount;
|
2012-06-10 02:19:26 +04:00
|
|
|
NS_LOG_RELEASE(this, count, "nsBasePrincipal");
|
2003-07-24 09:15:20 +04:00
|
|
|
if (count == 0) {
|
2010-07-05 13:42:18 +04:00
|
|
|
delete this;
|
2003-07-24 09:15:20 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
2013-12-14 07:15:43 +04:00
|
|
|
nsBasePrincipal::nsBasePrincipal()
|
2003-10-22 02:11:49 +04:00
|
|
|
{
|
2011-06-20 07:00:16 +04:00
|
|
|
if (!gIsObservingCodeBasePrincipalSupport) {
|
|
|
|
nsresult rv =
|
|
|
|
Preferences::AddBoolVarCache(&gCodeBasePrincipalSupport,
|
|
|
|
"signed.applets.codebase_principal_support",
|
2011-10-17 18:59:28 +04:00
|
|
|
false);
|
2011-06-20 07:00:16 +04:00
|
|
|
gIsObservingCodeBasePrincipalSupport = NS_SUCCEEDED(rv);
|
|
|
|
NS_WARN_IF_FALSE(gIsObservingCodeBasePrincipalSupport,
|
|
|
|
"Installing gCodeBasePrincipalSupport failed!");
|
2009-06-16 15:00:06 +04:00
|
|
|
}
|
2003-10-22 02:11:49 +04:00
|
|
|
}
|
|
|
|
|
2012-06-10 02:19:26 +04:00
|
|
|
nsBasePrincipal::~nsBasePrincipal(void)
|
2003-07-24 09:15:20 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-06-10 02:19:26 +04:00
|
|
|
NS_IMETHODIMP
|
2012-06-10 02:19:26 +04:00
|
|
|
nsBasePrincipal::GetCsp(nsIContentSecurityPolicy** aCsp)
|
2012-06-10 02:19:26 +04:00
|
|
|
{
|
|
|
|
NS_IF_ADDREF(*aCsp = mCSP);
|
2008-02-27 06:45:29 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2003-07-24 09:15:20 +04:00
|
|
|
NS_IMETHODIMP
|
2012-06-10 02:19:26 +04:00
|
|
|
nsBasePrincipal::SetCsp(nsIContentSecurityPolicy* aCsp)
|
2003-07-24 09:15:20 +04:00
|
|
|
{
|
2012-06-10 02:19:26 +04:00
|
|
|
// If CSP was already set, it should not be destroyed! Instead, it should
|
|
|
|
// get set anew when a new principal is created.
|
|
|
|
if (mCSP)
|
|
|
|
return NS_ERROR_ALREADY_INITIALIZED;
|
2003-07-24 09:15:20 +04:00
|
|
|
|
2012-06-10 02:19:26 +04:00
|
|
|
mCSP = aCsp;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
void nsPrincipal::dumpImpl()
|
|
|
|
{
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString str;
|
2012-06-10 02:19:26 +04:00
|
|
|
GetScriptLocation(str);
|
2012-07-20 09:44:03 +04:00
|
|
|
fprintf(stderr, "nsPrincipal (%p) = %s\n", static_cast<void*>(this), str.get());
|
2012-06-10 02:19:26 +04:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-04-03 04:16:25 +04:00
|
|
|
NS_IMPL_CLASSINFO(nsPrincipal, nullptr, nsIClassInfo::MAIN_THREAD_ONLY,
|
2012-06-10 02:19:26 +04:00
|
|
|
NS_PRINCIPAL_CID)
|
2014-04-27 11:06:00 +04:00
|
|
|
NS_IMPL_QUERY_INTERFACE_CI(nsPrincipal,
|
|
|
|
nsIPrincipal,
|
|
|
|
nsISerializable)
|
|
|
|
NS_IMPL_CI_INTERFACE_GETTER(nsPrincipal,
|
2012-06-10 02:19:26 +04:00
|
|
|
nsIPrincipal,
|
|
|
|
nsISerializable)
|
2012-06-10 23:25:17 +04:00
|
|
|
NS_IMPL_ADDREF_INHERITED(nsPrincipal, nsBasePrincipal)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(nsPrincipal, nsBasePrincipal)
|
2012-06-10 02:19:26 +04:00
|
|
|
|
|
|
|
nsPrincipal::nsPrincipal()
|
2012-07-20 09:44:03 +04:00
|
|
|
: mAppId(nsIScriptSecurityManager::UNKNOWN_APP_ID)
|
|
|
|
, mInMozBrowser(false)
|
|
|
|
, mCodebaseImmutable(false)
|
2012-06-10 23:25:17 +04:00
|
|
|
, mDomainImmutable(false)
|
|
|
|
, mInitialized(false)
|
2012-06-10 02:19:26 +04:00
|
|
|
{ }
|
|
|
|
|
|
|
|
nsPrincipal::~nsPrincipal()
|
|
|
|
{ }
|
|
|
|
|
2012-05-03 01:57:34 +04:00
|
|
|
nsresult
|
2012-10-22 10:29:56 +04:00
|
|
|
nsPrincipal::Init(nsIURI *aCodebase,
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t aAppId,
|
2012-07-20 09:44:03 +04:00
|
|
|
bool aInMozBrowser)
|
2012-06-10 02:19:26 +04:00
|
|
|
{
|
|
|
|
NS_ENSURE_STATE(!mInitialized);
|
2012-10-22 10:29:56 +04:00
|
|
|
NS_ENSURE_ARG(aCodebase);
|
2012-06-10 02:19:26 +04:00
|
|
|
|
|
|
|
mInitialized = true;
|
|
|
|
|
|
|
|
mCodebase = NS_TryToMakeImmutable(aCodebase);
|
|
|
|
mCodebaseImmutable = URIIsImmutable(mCodebase);
|
|
|
|
|
2012-07-20 09:44:03 +04:00
|
|
|
mAppId = aAppId;
|
|
|
|
mInMozBrowser = aInMozBrowser;
|
|
|
|
|
2012-10-22 10:29:56 +04:00
|
|
|
return NS_OK;
|
2012-06-10 02:19:26 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsPrincipal::GetScriptLocation(nsACString &aStr)
|
|
|
|
{
|
2012-10-22 10:29:56 +04:00
|
|
|
mCodebase->GetSpec(aStr);
|
2012-06-10 02:19:26 +04:00
|
|
|
}
|
|
|
|
|
2012-07-19 08:23:44 +04:00
|
|
|
/* static */ nsresult
|
|
|
|
nsPrincipal::GetOriginForURI(nsIURI* aURI, char **aOrigin)
|
2003-07-24 09:15:20 +04:00
|
|
|
{
|
2012-07-19 08:23:44 +04:00
|
|
|
if (!aURI) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
*aOrigin = nullptr;
|
2012-06-10 02:19:26 +04:00
|
|
|
|
2012-07-19 08:23:44 +04:00
|
|
|
nsCOMPtr<nsIURI> origin = NS_GetInnermostURI(aURI);
|
2012-06-10 02:19:26 +04:00
|
|
|
if (!origin) {
|
|
|
|
return NS_ERROR_FAILURE;
|
2007-09-28 18:31:04 +04:00
|
|
|
}
|
2003-07-24 09:15:20 +04:00
|
|
|
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString hostPort;
|
2012-06-10 02:19:26 +04:00
|
|
|
|
|
|
|
// chrome: URLs don't have a meaningful origin, so make
|
|
|
|
// sure we just get the full spec for them.
|
|
|
|
// XXX this should be removed in favor of the solution in
|
|
|
|
// bug 160042.
|
|
|
|
bool isChrome;
|
|
|
|
nsresult rv = origin->SchemeIs("chrome", &isChrome);
|
|
|
|
if (NS_SUCCEEDED(rv) && !isChrome) {
|
|
|
|
rv = origin->GetAsciiHost(hostPort);
|
|
|
|
// Some implementations return an empty string, treat it as no support
|
|
|
|
// for asciiHost by that implementation.
|
2012-07-19 08:23:44 +04:00
|
|
|
if (hostPort.IsEmpty()) {
|
2012-06-10 02:19:26 +04:00
|
|
|
rv = NS_ERROR_FAILURE;
|
2012-07-19 08:23:44 +04:00
|
|
|
}
|
2003-07-24 09:15:20 +04:00
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t port;
|
2012-06-10 02:19:26 +04:00
|
|
|
if (NS_SUCCEEDED(rv) && !isChrome) {
|
|
|
|
rv = origin->GetPort(&port);
|
2003-07-24 09:15:20 +04:00
|
|
|
}
|
|
|
|
|
2012-06-10 02:19:26 +04:00
|
|
|
if (NS_SUCCEEDED(rv) && !isChrome) {
|
|
|
|
if (port != -1) {
|
2014-05-22 07:48:51 +04:00
|
|
|
hostPort.Append(':');
|
2012-06-10 02:19:26 +04:00
|
|
|
hostPort.AppendInt(port, 10);
|
2003-07-24 09:15:20 +04:00
|
|
|
}
|
|
|
|
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString scheme;
|
2012-06-10 02:19:26 +04:00
|
|
|
rv = origin->GetScheme(scheme);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2012-07-19 08:23:44 +04:00
|
|
|
|
2012-06-10 02:19:26 +04:00
|
|
|
*aOrigin = ToNewCString(scheme + NS_LITERAL_CSTRING("://") + hostPort);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// Some URIs (e.g., nsSimpleURI) don't support asciiHost. Just
|
|
|
|
// get the full spec.
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString spec;
|
2012-06-10 02:19:26 +04:00
|
|
|
// XXX nsMozIconURI and nsJARURI don't implement this correctly, they
|
|
|
|
// both fall back to GetSpec. That needs to be fixed.
|
|
|
|
rv = origin->GetAsciiSpec(spec);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2012-07-19 08:23:44 +04:00
|
|
|
|
2012-06-10 02:19:26 +04:00
|
|
|
*aOrigin = ToNewCString(spec);
|
2003-07-24 09:15:20 +04:00
|
|
|
}
|
|
|
|
|
2012-06-10 02:19:26 +04:00
|
|
|
return *aOrigin ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
|
2003-07-24 09:15:20 +04:00
|
|
|
}
|
|
|
|
|
2012-07-19 08:23:44 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPrincipal::GetOrigin(char **aOrigin)
|
|
|
|
{
|
|
|
|
return GetOriginForURI(mCodebase, aOrigin);
|
|
|
|
}
|
|
|
|
|
2003-07-24 09:15:20 +04:00
|
|
|
NS_IMETHODIMP
|
2014-02-14 06:57:36 +04:00
|
|
|
nsPrincipal::EqualsConsideringDomain(nsIPrincipal *aOther, bool *aResult)
|
2003-07-24 09:15:20 +04:00
|
|
|
{
|
2012-10-24 21:50:25 +04:00
|
|
|
*aResult = false;
|
|
|
|
|
2012-06-10 02:19:26 +04:00
|
|
|
if (!aOther) {
|
|
|
|
NS_WARNING("Need a principal to compare this to!");
|
2003-07-24 09:15:20 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2012-06-10 02:19:26 +04:00
|
|
|
|
2012-10-24 21:50:25 +04:00
|
|
|
if (aOther == this) {
|
|
|
|
*aResult = true;
|
2012-06-10 02:19:26 +04:00
|
|
|
return NS_OK;
|
2003-07-24 09:15:20 +04:00
|
|
|
}
|
|
|
|
|
2014-02-14 06:57:36 +04:00
|
|
|
if (!nsScriptSecurityManager::AppAttributesEqual(this, aOther)) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If either the subject or the object has changed its principal by
|
|
|
|
// explicitly setting document.domain then the other must also have
|
|
|
|
// done so in order to be considered the same origin. This prevents
|
|
|
|
// DNS spoofing based on document.domain (154930)
|
|
|
|
|
|
|
|
nsCOMPtr<nsIURI> thisURI;
|
|
|
|
this->GetDomain(getter_AddRefs(thisURI));
|
|
|
|
bool thisSetDomain = !!thisURI;
|
|
|
|
if (!thisURI) {
|
|
|
|
this->GetURI(getter_AddRefs(thisURI));
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIURI> otherURI;
|
|
|
|
aOther->GetDomain(getter_AddRefs(otherURI));
|
|
|
|
bool otherSetDomain = !!otherURI;
|
|
|
|
if (!otherURI) {
|
|
|
|
aOther->GetURI(getter_AddRefs(otherURI));
|
|
|
|
}
|
|
|
|
|
|
|
|
*aResult = thisSetDomain == otherSetDomain &&
|
|
|
|
nsScriptSecurityManager::SecurityCompareURIs(thisURI, otherURI);
|
2003-07-24 09:15:20 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2014-02-14 06:57:36 +04:00
|
|
|
nsPrincipal::Equals(nsIPrincipal *aOther, bool *aResult)
|
2003-07-24 09:15:20 +04:00
|
|
|
{
|
2012-10-24 21:50:25 +04:00
|
|
|
*aResult = false;
|
|
|
|
|
|
|
|
if (!aOther) {
|
|
|
|
NS_WARNING("Need a principal to compare this to!");
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aOther == this) {
|
2012-06-10 02:19:26 +04:00
|
|
|
*aResult = true;
|
|
|
|
return NS_OK;
|
2003-07-24 09:15:20 +04:00
|
|
|
}
|
|
|
|
|
2012-10-24 21:50:25 +04:00
|
|
|
if (!nsScriptSecurityManager::AppAttributesEqual(this, aOther)) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2003-07-24 09:15:20 +04:00
|
|
|
|
2012-06-10 02:19:26 +04:00
|
|
|
nsCOMPtr<nsIURI> otherURI;
|
|
|
|
nsresult rv = aOther->GetURI(getter_AddRefs(otherURI));
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
2003-07-24 09:15:20 +04:00
|
|
|
}
|
|
|
|
|
2012-06-10 02:19:26 +04:00
|
|
|
NS_ASSERTION(mCodebase,
|
|
|
|
"shouldn't be calling this on principals from preferences");
|
|
|
|
|
|
|
|
// Compare codebases.
|
|
|
|
*aResult = nsScriptSecurityManager::SecurityCompareURIs(mCodebase,
|
|
|
|
otherURI);
|
2003-07-24 09:15:20 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-06-10 02:19:26 +04:00
|
|
|
nsPrincipal::Subsumes(nsIPrincipal *aOther, bool *aResult)
|
2003-07-24 09:15:20 +04:00
|
|
|
{
|
2012-06-10 02:19:26 +04:00
|
|
|
return Equals(aOther, aResult);
|
|
|
|
}
|
2003-07-24 09:15:20 +04:00
|
|
|
|
2014-02-14 06:57:34 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPrincipal::SubsumesConsideringDomain(nsIPrincipal *aOther, bool *aResult)
|
|
|
|
{
|
2014-02-14 06:57:36 +04:00
|
|
|
return EqualsConsideringDomain(aOther, aResult);
|
2014-02-14 06:57:34 +04:00
|
|
|
}
|
|
|
|
|
2003-07-24 09:15:20 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPrincipal::GetURI(nsIURI** aURI)
|
|
|
|
{
|
2007-06-18 19:07:02 +04:00
|
|
|
if (mCodebaseImmutable) {
|
|
|
|
NS_ADDREF(*aURI = mCodebase);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2006-06-20 07:17:41 +04:00
|
|
|
if (!mCodebase) {
|
2012-07-30 18:20:58 +04:00
|
|
|
*aURI = nullptr;
|
2006-06-20 07:17:41 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2003-07-24 09:15:20 +04:00
|
|
|
|
2006-06-20 07:17:41 +04:00
|
|
|
return NS_EnsureSafeToReturn(mCodebase, aURI);
|
2003-07-24 09:15:20 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-20 22:34:33 +04:00
|
|
|
nsPrincipal::CheckMayLoad(nsIURI* aURI, bool aReport, bool aAllowIfInheritsPrincipal)
|
2003-07-24 09:15:20 +04:00
|
|
|
{
|
2012-08-20 22:34:33 +04:00
|
|
|
if (aAllowIfInheritsPrincipal) {
|
|
|
|
// If the caller specified to allow loads of URIs that inherit
|
|
|
|
// our principal, allow the load if this URI inherits its principal
|
|
|
|
if (nsPrincipal::IsPrincipalInherited(aURI)) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-01 01:33:51 +04:00
|
|
|
if (nsScriptSecurityManager::SecurityCompareURIs(mCodebase, aURI)) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2013-01-09 01:53:32 +04:00
|
|
|
|
2013-06-01 01:33:51 +04:00
|
|
|
// If strict file origin policy is in effect, local files will always fail
|
|
|
|
// SecurityCompareURIs unless they are identical. Explicitly check file origin
|
|
|
|
// policy, in that case.
|
|
|
|
if (nsScriptSecurityManager::GetStrictFileOriginPolicy() &&
|
|
|
|
NS_URIIsLocalFile(aURI) &&
|
|
|
|
NS_RelaxStrictFileOriginPolicy(aURI, mCodebase)) {
|
|
|
|
return NS_OK;
|
2005-07-22 23:05:42 +04:00
|
|
|
}
|
2012-06-10 02:19:26 +04:00
|
|
|
|
2013-06-01 01:33:51 +04:00
|
|
|
if (aReport) {
|
|
|
|
nsScriptSecurityManager::ReportError(nullptr, NS_LITERAL_STRING("CheckSameOriginError"), mCodebase, aURI);
|
|
|
|
}
|
|
|
|
return NS_ERROR_DOM_BAD_URI;
|
2005-07-22 23:05:42 +04:00
|
|
|
}
|
2003-07-24 09:15:20 +04:00
|
|
|
|
2012-06-10 02:19:26 +04:00
|
|
|
void
|
|
|
|
nsPrincipal::SetURI(nsIURI* aURI)
|
2010-01-23 00:38:21 +03:00
|
|
|
{
|
2012-06-10 02:19:26 +04:00
|
|
|
mCodebase = NS_TryToMakeImmutable(aURI);
|
|
|
|
mCodebaseImmutable = URIIsImmutable(mCodebase);
|
2010-01-23 00:38:21 +03:00
|
|
|
}
|
|
|
|
|
2003-07-24 09:15:20 +04:00
|
|
|
NS_IMETHODIMP
|
2012-08-22 19:56:38 +04:00
|
|
|
nsPrincipal::GetHashValue(uint32_t* aValue)
|
2003-07-24 09:15:20 +04:00
|
|
|
{
|
2012-10-22 10:29:56 +04:00
|
|
|
NS_PRECONDITION(mCodebase, "Need a codebase");
|
2003-07-24 09:15:20 +04:00
|
|
|
|
2012-10-22 10:29:56 +04:00
|
|
|
*aValue = nsScriptSecurityManager::HashPrincipalByOrigin(this);
|
2003-07-24 09:15:20 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPrincipal::GetDomain(nsIURI** aDomain)
|
|
|
|
{
|
2006-06-20 07:17:41 +04:00
|
|
|
if (!mDomain) {
|
2012-07-30 18:20:58 +04:00
|
|
|
*aDomain = nullptr;
|
2006-06-20 07:17:41 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2003-07-24 09:15:20 +04:00
|
|
|
|
2007-06-18 19:07:02 +04:00
|
|
|
if (mDomainImmutable) {
|
|
|
|
NS_ADDREF(*aDomain = mDomain);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2006-06-20 07:17:41 +04:00
|
|
|
return NS_EnsureSafeToReturn(mDomain, aDomain);
|
2003-07-24 09:15:20 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPrincipal::SetDomain(nsIURI* aDomain)
|
|
|
|
{
|
2006-06-20 07:17:41 +04:00
|
|
|
mDomain = NS_TryToMakeImmutable(aDomain);
|
2007-06-18 19:07:02 +04:00
|
|
|
mDomainImmutable = URIIsImmutable(mDomain);
|
2013-01-09 01:53:32 +04:00
|
|
|
|
2012-07-12 12:10:15 +04:00
|
|
|
// Recompute all wrappers between compartments using this principal and other
|
|
|
|
// non-chrome compartments.
|
2013-05-06 17:04:17 +04:00
|
|
|
AutoSafeJSContext cx;
|
2012-07-12 12:10:15 +04:00
|
|
|
JSPrincipals *principals = nsJSPrincipals::get(static_cast<nsIPrincipal*>(this));
|
|
|
|
bool success = js::RecomputeWrappers(cx, js::ContentCompartmentsOnly(),
|
|
|
|
js::CompartmentsWithPrincipals(principals));
|
|
|
|
NS_ENSURE_TRUE(success, NS_ERROR_FAILURE);
|
|
|
|
success = js::RecomputeWrappers(cx, js::CompartmentsWithPrincipals(principals),
|
|
|
|
js::ContentCompartmentsOnly());
|
|
|
|
NS_ENSURE_TRUE(success, NS_ERROR_FAILURE);
|
|
|
|
|
2003-07-24 09:15:20 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-07-20 09:44:03 +04:00
|
|
|
NS_IMETHODIMP
|
2013-09-11 08:18:36 +04:00
|
|
|
nsPrincipal::GetJarPrefix(nsACString& aJarPrefix)
|
2012-07-20 09:44:03 +04:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(mAppId != nsIScriptSecurityManager::UNKNOWN_APP_ID);
|
|
|
|
|
2013-09-11 08:18:36 +04:00
|
|
|
mozilla::GetJarPrefix(mAppId, mInMozBrowser, aJarPrefix);
|
2012-07-20 09:44:03 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 19:56:38 +04:00
|
|
|
nsPrincipal::GetAppStatus(uint16_t* aAppStatus)
|
2012-07-20 09:44:03 +04:00
|
|
|
{
|
|
|
|
*aAppStatus = GetAppStatus();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 19:56:38 +04:00
|
|
|
nsPrincipal::GetAppId(uint32_t* aAppId)
|
2012-07-20 09:44:03 +04:00
|
|
|
{
|
|
|
|
if (mAppId == nsIScriptSecurityManager::UNKNOWN_APP_ID) {
|
|
|
|
MOZ_ASSERT(false);
|
|
|
|
*aAppId = nsIScriptSecurityManager::NO_APP_ID;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
*aAppId = mAppId;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-07-31 19:47:20 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPrincipal::GetIsInBrowserElement(bool* aIsInBrowserElement)
|
|
|
|
{
|
|
|
|
*aIsInBrowserElement = mInMozBrowser;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-09-26 03:28:17 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPrincipal::GetUnknownAppId(bool* aUnknownAppId)
|
|
|
|
{
|
|
|
|
*aUnknownAppId = mAppId == nsIScriptSecurityManager::UNKNOWN_APP_ID;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-10-23 20:31:19 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPrincipal::GetIsNullPrincipal(bool* aIsNullPrincipal)
|
|
|
|
{
|
|
|
|
*aIsNullPrincipal = false;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-01-09 01:53:32 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPrincipal::GetBaseDomain(nsACString& aBaseDomain)
|
|
|
|
{
|
|
|
|
// For a file URI, we return the file path.
|
2013-06-01 01:33:51 +04:00
|
|
|
if (NS_URIIsLocalFile(mCodebase)) {
|
2013-01-09 01:53:32 +04:00
|
|
|
nsCOMPtr<nsIURL> url = do_QueryInterface(mCodebase);
|
|
|
|
|
|
|
|
if (url) {
|
|
|
|
return url->GetFilePath(aBaseDomain);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// For everything else, we ask the TLD service via
|
|
|
|
// the ThirdPartyUtil.
|
|
|
|
nsCOMPtr<mozIThirdPartyUtil> thirdPartyUtil =
|
|
|
|
do_GetService(THIRDPARTYUTIL_CONTRACTID);
|
|
|
|
if (thirdPartyUtil) {
|
|
|
|
return thirdPartyUtil->GetBaseDomain(mCodebase, aBaseDomain);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2003-07-24 09:15:20 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPrincipal::Read(nsIObjectInputStream* aStream)
|
|
|
|
{
|
2014-03-15 23:00:17 +04:00
|
|
|
nsCOMPtr<nsISupports> supports;
|
2007-09-18 02:18:28 +04:00
|
|
|
nsCOMPtr<nsIURI> codebase;
|
2014-03-15 23:00:17 +04:00
|
|
|
nsresult rv = NS_ReadOptionalObject(aStream, true, getter_AddRefs(supports));
|
2007-09-18 02:18:28 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
2003-07-24 09:15:20 +04:00
|
|
|
}
|
|
|
|
|
2014-03-15 23:00:17 +04:00
|
|
|
codebase = do_QueryInterface(supports);
|
|
|
|
|
2012-07-26 04:12:03 +04:00
|
|
|
nsCOMPtr<nsIURI> domain;
|
2014-03-15 23:00:17 +04:00
|
|
|
rv = NS_ReadOptionalObject(aStream, true, getter_AddRefs(supports));
|
2012-07-26 04:12:03 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2014-03-15 23:00:17 +04:00
|
|
|
domain = do_QueryInterface(supports);
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t appId;
|
2012-07-20 09:44:03 +04:00
|
|
|
rv = aStream->Read32(&appId);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
bool inMozBrowser;
|
|
|
|
rv = aStream->ReadBoolean(&inMozBrowser);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2014-03-15 23:00:17 +04:00
|
|
|
rv = NS_ReadOptionalObject(aStream, true, getter_AddRefs(supports));
|
2014-01-24 03:34:59 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2014-03-15 23:00:17 +04:00
|
|
|
// This may be null.
|
|
|
|
nsCOMPtr<nsIContentSecurityPolicy> csp = do_QueryInterface(supports, &rv);
|
|
|
|
|
2012-10-22 10:29:56 +04:00
|
|
|
rv = Init(codebase, appId, inMozBrowser);
|
2007-09-18 02:18:28 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2014-01-24 03:34:59 +04:00
|
|
|
rv = SetCsp(csp);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
// need to link in the CSP context here (link in a reference to this
|
|
|
|
// nsIPrincipal and to the URI of the protected resource).
|
|
|
|
if (csp) {
|
|
|
|
csp->SetRequestContext(codebase, nullptr, this, nullptr);
|
|
|
|
}
|
|
|
|
|
2007-09-18 02:18:28 +04:00
|
|
|
SetDomain(domain);
|
|
|
|
|
2003-07-24 09:15:20 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPrincipal::Write(nsIObjectOutputStream* aStream)
|
|
|
|
{
|
2012-10-22 10:29:56 +04:00
|
|
|
NS_ENSURE_STATE(mCodebase);
|
2007-09-18 02:18:28 +04:00
|
|
|
|
2012-10-22 10:29:56 +04:00
|
|
|
nsresult rv = NS_WriteOptionalCompoundObject(aStream, mCodebase, NS_GET_IID(nsIURI),
|
|
|
|
true);
|
2007-09-18 02:18:28 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
2003-07-24 09:15:20 +04:00
|
|
|
}
|
|
|
|
|
2007-09-18 02:18:28 +04:00
|
|
|
rv = NS_WriteOptionalCompoundObject(aStream, mDomain, NS_GET_IID(nsIURI),
|
2011-10-17 18:59:28 +04:00
|
|
|
true);
|
2003-07-24 09:15:20 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2012-07-20 09:44:03 +04:00
|
|
|
aStream->Write32(mAppId);
|
|
|
|
aStream->WriteBoolean(mInMozBrowser);
|
|
|
|
|
2014-01-24 03:34:59 +04:00
|
|
|
rv = NS_WriteOptionalCompoundObject(aStream, mCSP,
|
|
|
|
NS_GET_IID(nsIContentSecurityPolicy),
|
|
|
|
true);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2007-09-18 02:18:28 +04:00
|
|
|
// mCodebaseImmutable and mDomainImmutable will be recomputed based
|
|
|
|
// on the deserialized URIs in Read().
|
|
|
|
|
2003-07-24 09:15:20 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2012-06-10 02:19:26 +04:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint16_t
|
2012-07-20 09:44:03 +04:00
|
|
|
nsPrincipal::GetAppStatus()
|
|
|
|
{
|
2014-07-28 23:08:51 +04:00
|
|
|
NS_WARN_IF_FALSE(mAppId != nsIScriptSecurityManager::UNKNOWN_APP_ID,
|
|
|
|
"Asking for app status on a principal with an unknown app id");
|
|
|
|
// Installed apps have a valid app id (not NO_APP_ID or UNKNOWN_APP_ID)
|
|
|
|
// and they are not inside a mozbrowser.
|
|
|
|
if (mAppId == nsIScriptSecurityManager::NO_APP_ID ||
|
|
|
|
mAppId == nsIScriptSecurityManager::UNKNOWN_APP_ID || mInMozBrowser) {
|
2012-08-28 06:43:57 +04:00
|
|
|
return nsIPrincipal::APP_STATUS_NOT_INSTALLED;
|
|
|
|
}
|
2014-07-28 23:08:51 +04:00
|
|
|
|
|
|
|
nsCOMPtr<nsIAppsService> appsService = do_GetService(APPS_SERVICE_CONTRACTID);
|
|
|
|
NS_ENSURE_TRUE(appsService, nsIPrincipal::APP_STATUS_NOT_INSTALLED);
|
|
|
|
|
|
|
|
nsCOMPtr<mozIApplication> app;
|
|
|
|
appsService->GetAppByLocalId(mAppId, getter_AddRefs(app));
|
|
|
|
NS_ENSURE_TRUE(app, nsIPrincipal::APP_STATUS_NOT_INSTALLED);
|
|
|
|
|
|
|
|
uint16_t status = nsIPrincipal::APP_STATUS_INSTALLED;
|
|
|
|
NS_ENSURE_SUCCESS(app->GetAppStatus(&status),
|
|
|
|
nsIPrincipal::APP_STATUS_NOT_INSTALLED);
|
|
|
|
|
|
|
|
nsAutoCString origin;
|
|
|
|
NS_ENSURE_SUCCESS(GetOrigin(getter_Copies(origin)),
|
|
|
|
nsIPrincipal::APP_STATUS_NOT_INSTALLED);
|
|
|
|
nsString appOrigin;
|
|
|
|
NS_ENSURE_SUCCESS(app->GetOrigin(appOrigin),
|
|
|
|
nsIPrincipal::APP_STATUS_NOT_INSTALLED);
|
|
|
|
|
|
|
|
// We go from string -> nsIURI -> origin to be sure we
|
|
|
|
// compare two punny-encoded origins.
|
|
|
|
nsCOMPtr<nsIURI> appURI;
|
|
|
|
NS_ENSURE_SUCCESS(NS_NewURI(getter_AddRefs(appURI), appOrigin),
|
|
|
|
nsIPrincipal::APP_STATUS_NOT_INSTALLED);
|
|
|
|
|
|
|
|
nsAutoCString appOriginPunned;
|
|
|
|
NS_ENSURE_SUCCESS(GetOriginForURI(appURI, getter_Copies(appOriginPunned)),
|
|
|
|
nsIPrincipal::APP_STATUS_NOT_INSTALLED);
|
|
|
|
|
|
|
|
if (!appOriginPunned.Equals(origin)) {
|
|
|
|
return nsIPrincipal::APP_STATUS_NOT_INSTALLED;
|
|
|
|
}
|
|
|
|
|
|
|
|
return status;
|
2012-07-20 09:44:03 +04:00
|
|
|
}
|
2012-06-10 02:19:26 +04:00
|
|
|
|
|
|
|
/************************************************************************************************************************/
|
|
|
|
|
|
|
|
static const char EXPANDED_PRINCIPAL_SPEC[] = "[Expanded Principal]";
|
|
|
|
|
2013-04-03 04:16:25 +04:00
|
|
|
NS_IMPL_CLASSINFO(nsExpandedPrincipal, nullptr, nsIClassInfo::MAIN_THREAD_ONLY,
|
2012-06-10 02:19:26 +04:00
|
|
|
NS_EXPANDEDPRINCIPAL_CID)
|
2014-04-27 11:06:00 +04:00
|
|
|
NS_IMPL_QUERY_INTERFACE_CI(nsExpandedPrincipal,
|
|
|
|
nsIPrincipal,
|
|
|
|
nsIExpandedPrincipal)
|
|
|
|
NS_IMPL_CI_INTERFACE_GETTER(nsExpandedPrincipal,
|
2012-06-10 02:19:26 +04:00
|
|
|
nsIPrincipal,
|
|
|
|
nsIExpandedPrincipal)
|
2012-06-10 23:25:17 +04:00
|
|
|
NS_IMPL_ADDREF_INHERITED(nsExpandedPrincipal, nsBasePrincipal)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(nsExpandedPrincipal, nsBasePrincipal)
|
2012-06-10 02:19:26 +04:00
|
|
|
|
|
|
|
nsExpandedPrincipal::nsExpandedPrincipal(nsTArray<nsCOMPtr <nsIPrincipal> > &aWhiteList)
|
|
|
|
{
|
|
|
|
mPrincipals.AppendElements(aWhiteList);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsExpandedPrincipal::~nsExpandedPrincipal()
|
|
|
|
{ }
|
|
|
|
|
2013-01-09 01:53:32 +04:00
|
|
|
NS_IMETHODIMP
|
2012-06-10 02:19:26 +04:00
|
|
|
nsExpandedPrincipal::GetDomain(nsIURI** aDomain)
|
|
|
|
{
|
2012-07-30 18:20:58 +04:00
|
|
|
*aDomain = nullptr;
|
2012-06-10 02:19:26 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-01-09 01:53:32 +04:00
|
|
|
NS_IMETHODIMP
|
2012-06-10 02:19:26 +04:00
|
|
|
nsExpandedPrincipal::SetDomain(nsIURI* aDomain)
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-01-09 01:53:32 +04:00
|
|
|
NS_IMETHODIMP
|
2012-06-10 02:19:26 +04:00
|
|
|
nsExpandedPrincipal::GetOrigin(char** aOrigin)
|
|
|
|
{
|
|
|
|
*aOrigin = ToNewCString(NS_LITERAL_CSTRING(EXPANDED_PRINCIPAL_SPEC));
|
|
|
|
return *aOrigin ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
typedef nsresult (NS_STDCALL nsIPrincipal::*nsIPrincipalMemFn)(nsIPrincipal* aOther,
|
|
|
|
bool* aResult);
|
|
|
|
#define CALL_MEMBER_FUNCTION(THIS,MEM_FN) ((THIS)->*(MEM_FN))
|
|
|
|
|
2014-02-14 06:57:36 +04:00
|
|
|
// nsExpandedPrincipal::Equals and nsExpandedPrincipal::EqualsConsideringDomain
|
2013-01-09 01:53:32 +04:00
|
|
|
// shares the same logic. The difference only that Equals requires 'this'
|
2014-02-14 06:57:36 +04:00
|
|
|
// and 'aOther' to Subsume each other while EqualsConsideringDomain requires
|
|
|
|
// bidirectional SubsumesConsideringDomain.
|
2013-01-09 01:53:32 +04:00
|
|
|
static nsresult
|
2012-06-10 02:19:26 +04:00
|
|
|
Equals(nsExpandedPrincipal* aThis, nsIPrincipalMemFn aFn, nsIPrincipal* aOther,
|
|
|
|
bool* aResult)
|
|
|
|
{
|
2014-02-14 06:57:36 +04:00
|
|
|
// If (and only if) 'aThis' and 'aOther' both Subsume/SubsumesConsideringDomain
|
2012-06-10 02:19:26 +04:00
|
|
|
// each other, then they are Equal.
|
|
|
|
*aResult = false;
|
|
|
|
// Calling the corresponding subsume function on this (aFn).
|
|
|
|
nsresult rv = CALL_MEMBER_FUNCTION(aThis, aFn)(aOther, aResult);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
if (!*aResult)
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
// Calling the corresponding subsume function on aOther (aFn).
|
|
|
|
rv = CALL_MEMBER_FUNCTION(aOther, aFn)(aThis, aResult);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsExpandedPrincipal::Equals(nsIPrincipal* aOther, bool* aResult)
|
|
|
|
{
|
|
|
|
return ::Equals(this, &nsIPrincipal::Subsumes, aOther, aResult);
|
|
|
|
}
|
|
|
|
|
2014-02-14 06:57:34 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsExpandedPrincipal::EqualsConsideringDomain(nsIPrincipal* aOther, bool* aResult)
|
|
|
|
{
|
|
|
|
return ::Equals(this, &nsIPrincipal::SubsumesConsideringDomain, aOther, aResult);
|
|
|
|
}
|
|
|
|
|
2014-02-14 06:57:36 +04:00
|
|
|
// nsExpandedPrincipal::Subsumes and nsExpandedPrincipal::SubsumesConsideringDomain
|
2012-06-10 02:19:26 +04:00
|
|
|
// shares the same logic. The difference only that Subsumes calls are replaced
|
2014-02-14 06:57:36 +04:00
|
|
|
//with SubsumesConsideringDomain calls in the second case.
|
2013-01-09 01:53:32 +04:00
|
|
|
static nsresult
|
|
|
|
Subsumes(nsExpandedPrincipal* aThis, nsIPrincipalMemFn aFn, nsIPrincipal* aOther,
|
2012-06-10 02:19:26 +04:00
|
|
|
bool* aResult)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
2013-01-09 01:53:32 +04:00
|
|
|
nsCOMPtr<nsIExpandedPrincipal> expanded = do_QueryInterface(aOther);
|
2012-06-10 02:19:26 +04:00
|
|
|
if (expanded) {
|
2013-01-09 01:53:32 +04:00
|
|
|
// If aOther is an ExpandedPrincipal too, check if all of its
|
2012-06-10 02:19:26 +04:00
|
|
|
// principals are subsumed.
|
|
|
|
nsTArray< nsCOMPtr<nsIPrincipal> >* otherList;
|
|
|
|
expanded->GetWhiteList(&otherList);
|
|
|
|
for (uint32_t i = 0; i < otherList->Length(); ++i){
|
|
|
|
rv = CALL_MEMBER_FUNCTION(aThis, aFn)((*otherList)[i], aResult);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
if (!*aResult) {
|
|
|
|
// If we don't subsume at least one principal of aOther, return false.
|
2013-01-09 01:53:32 +04:00
|
|
|
return NS_OK;
|
2012-06-10 02:19:26 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// For a regular aOther, one of our principals must subsume it.
|
|
|
|
nsTArray< nsCOMPtr<nsIPrincipal> >* list;
|
|
|
|
aThis->GetWhiteList(&list);
|
|
|
|
for (uint32_t i = 0; i < list->Length(); ++i){
|
|
|
|
rv = CALL_MEMBER_FUNCTION((*list)[i], aFn)(aOther, aResult);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
if (*aResult) {
|
|
|
|
// If one of our principal subsumes it, return true.
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
#undef CALL_MEMBER_FUNCTION
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsExpandedPrincipal::Subsumes(nsIPrincipal* aOther, bool* aResult)
|
|
|
|
{
|
|
|
|
return ::Subsumes(this, &nsIPrincipal::Subsumes, aOther, aResult);
|
|
|
|
}
|
|
|
|
|
2014-02-14 06:57:34 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsExpandedPrincipal::SubsumesConsideringDomain(nsIPrincipal* aOther, bool* aResult)
|
|
|
|
{
|
|
|
|
return ::Subsumes(this, &nsIPrincipal::SubsumesConsideringDomain, aOther, aResult);
|
|
|
|
}
|
|
|
|
|
2012-06-10 02:19:26 +04:00
|
|
|
NS_IMETHODIMP
|
2012-08-20 22:34:33 +04:00
|
|
|
nsExpandedPrincipal::CheckMayLoad(nsIURI* uri, bool aReport, bool aAllowIfInheritsPrincipal)
|
2012-06-10 02:19:26 +04:00
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
for (uint32_t i = 0; i < mPrincipals.Length(); ++i){
|
2012-08-20 22:34:33 +04:00
|
|
|
rv = mPrincipals[i]->CheckMayLoad(uri, aReport, aAllowIfInheritsPrincipal);
|
2012-06-10 02:19:26 +04:00
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_ERROR_DOM_BAD_URI;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 19:56:38 +04:00
|
|
|
nsExpandedPrincipal::GetHashValue(uint32_t* result)
|
2012-06-10 02:19:26 +04:00
|
|
|
{
|
2013-06-29 05:38:30 +04:00
|
|
|
MOZ_CRASH("extended principal should never be used as key in a hash map");
|
2012-06-10 02:19:26 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsExpandedPrincipal::GetURI(nsIURI** aURI)
|
|
|
|
{
|
2012-07-30 18:20:58 +04:00
|
|
|
*aURI = nullptr;
|
2012-06-10 02:19:26 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-01-09 01:53:32 +04:00
|
|
|
NS_IMETHODIMP
|
2012-06-10 02:19:26 +04:00
|
|
|
nsExpandedPrincipal::GetWhiteList(nsTArray<nsCOMPtr<nsIPrincipal> >** aWhiteList)
|
|
|
|
{
|
|
|
|
*aWhiteList = &mPrincipals;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-07-20 09:44:03 +04:00
|
|
|
NS_IMETHODIMP
|
2013-09-11 08:18:36 +04:00
|
|
|
nsExpandedPrincipal::GetJarPrefix(nsACString& aJarPrefix)
|
2012-07-20 09:44:03 +04:00
|
|
|
{
|
2013-09-11 08:18:36 +04:00
|
|
|
aJarPrefix.Truncate();
|
|
|
|
return NS_OK;
|
2012-07-20 09:44:03 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 19:56:38 +04:00
|
|
|
nsExpandedPrincipal::GetAppStatus(uint16_t* aAppStatus)
|
2012-07-20 09:44:03 +04:00
|
|
|
{
|
2012-10-09 16:47:46 +04:00
|
|
|
*aAppStatus = nsIPrincipal::APP_STATUS_NOT_INSTALLED;
|
|
|
|
return NS_OK;
|
2012-07-20 09:44:03 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 19:56:38 +04:00
|
|
|
nsExpandedPrincipal::GetAppId(uint32_t* aAppId)
|
2012-07-20 09:44:03 +04:00
|
|
|
{
|
2012-10-09 16:47:46 +04:00
|
|
|
*aAppId = nsIScriptSecurityManager::NO_APP_ID;
|
|
|
|
return NS_OK;
|
2012-07-20 09:44:03 +04:00
|
|
|
}
|
|
|
|
|
2012-07-31 19:47:20 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsExpandedPrincipal::GetIsInBrowserElement(bool* aIsInBrowserElement)
|
|
|
|
{
|
2012-10-09 16:47:46 +04:00
|
|
|
*aIsInBrowserElement = false;
|
|
|
|
return NS_OK;
|
2012-07-31 19:47:20 +04:00
|
|
|
}
|
|
|
|
|
2012-09-26 03:28:17 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsExpandedPrincipal::GetUnknownAppId(bool* aUnknownAppId)
|
|
|
|
{
|
|
|
|
*aUnknownAppId = false;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-10-23 20:31:19 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsExpandedPrincipal::GetIsNullPrincipal(bool* aIsNullPrincipal)
|
|
|
|
{
|
|
|
|
*aIsNullPrincipal = false;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-01-09 01:53:32 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsExpandedPrincipal::GetBaseDomain(nsACString& aBaseDomain)
|
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
}
|
|
|
|
|
2012-06-10 02:19:26 +04:00
|
|
|
void
|
|
|
|
nsExpandedPrincipal::GetScriptLocation(nsACString& aStr)
|
|
|
|
{
|
2012-10-22 10:29:56 +04:00
|
|
|
// Is that a good idea to list it's principals?
|
|
|
|
aStr.Assign(EXPANDED_PRINCIPAL_SPEC);
|
2012-06-10 02:19:26 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
void nsExpandedPrincipal::dumpImpl()
|
|
|
|
{
|
2012-07-20 09:44:03 +04:00
|
|
|
fprintf(stderr, "nsExpandedPrincipal (%p)\n", static_cast<void*>(this));
|
2012-06-10 02:19:26 +04:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
//////////////////////////////////////////
|
|
|
|
// Methods implementing nsISerializable //
|
|
|
|
//////////////////////////////////////////
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsExpandedPrincipal::Read(nsIObjectInputStream* aStream)
|
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsExpandedPrincipal::Write(nsIObjectOutputStream* aStream)
|
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|