зеркало из https://github.com/mozilla/pjs.git
Bug 136993 - Put the "trusted codebase principals" feature back in.
r=harishd, sr=jst, a=valeski
This commit is contained in:
Родитель
9eca3ff832
Коммит
1163f76b50
|
@ -1,91 +0,0 @@
|
|||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.1 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 1998-2000
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the NPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the NPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
/* describes principals by their orginating URIs */
|
||||
|
||||
#ifndef _NS_CODEBASE_PRINCIPAL_H_
|
||||
#define _NS_CODEBASE_PRINCIPAL_H_
|
||||
|
||||
#include "jsapi.h"
|
||||
#include "nsBasePrincipal.h"
|
||||
#include "nsICodebasePrincipal.h"
|
||||
#include "nsIURI.h"
|
||||
#include "nsCOMPtr.h"
|
||||
|
||||
#define NS_CODEBASEPRINCIPAL_CID \
|
||||
{ 0x7ee2a400, 0x0b91, 0xaad3, \
|
||||
{ 0xba, 0x18, 0xd7, 0x60, 0xb0, 0xf1, 0x99, 0xa2 }}
|
||||
|
||||
class nsCodebasePrincipal : public nsBasePrincipal, public nsICodebasePrincipal {
|
||||
public:
|
||||
|
||||
NS_DEFINE_STATIC_CID_ACCESSOR(NS_CODEBASEPRINCIPAL_CID)
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSISERIALIZABLE
|
||||
NS_DECL_NSICODEBASEPRINCIPAL
|
||||
|
||||
NS_IMETHOD ToString(char **result);
|
||||
|
||||
NS_IMETHOD ToUserVisibleString(char **result);
|
||||
|
||||
NS_IMETHOD GetPreferences(char** aPrefName, char** aID,
|
||||
char** aGrantedList, char** aDeniedList);
|
||||
|
||||
NS_IMETHOD Equals(nsIPrincipal *other, PRBool *result);
|
||||
|
||||
NS_IMETHOD HashValue(PRUint32 *result);
|
||||
|
||||
NS_IMETHOD CanEnableCapability(const char *capability, PRInt16 *result);
|
||||
|
||||
nsCodebasePrincipal();
|
||||
|
||||
nsresult
|
||||
Init(nsIURI *uri);
|
||||
|
||||
nsresult
|
||||
InitFromPersistent(const char* aPrefName, const char* aID,
|
||||
const char* aGrantedList, const char* aDeniedList);
|
||||
|
||||
virtual ~nsCodebasePrincipal(void);
|
||||
|
||||
protected:
|
||||
nsCOMPtr<nsIURI> mURI;
|
||||
};
|
||||
|
||||
#endif // _NS_CODEBASE_PRINCIPAL_H_
|
|
@ -106,24 +106,29 @@ NS_IMETHODIMP
|
|||
nsCodebasePrincipal::CanEnableCapability(const char *capability,
|
||||
PRInt16 *result)
|
||||
{
|
||||
static char pref[] = "signed.applets.codebase_principal_support";
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIPref> prefs(do_GetService("@mozilla.org/preferences;1", &rv));
|
||||
if (NS_FAILED(rv))
|
||||
return NS_ERROR_FAILURE;
|
||||
PRBool enabled;
|
||||
if (NS_FAILED(prefs->GetBoolPref(pref, &enabled)) || !enabled)
|
||||
{
|
||||
// Deny unless subject is executing from file: or resource:
|
||||
PRBool isFile = PR_FALSE;
|
||||
PRBool isRes = PR_FALSE;
|
||||
// Either this principal must be preconfigured as a trusted source
|
||||
// (mTrusted), or else the codebase principal pref must be enabled
|
||||
if (!mTrusted)
|
||||
{
|
||||
static char pref[] = "signed.applets.codebase_principal_support";
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIPref> prefs(do_GetService("@mozilla.org/preferences;1", &rv));
|
||||
if (NS_FAILED(rv))
|
||||
return NS_ERROR_FAILURE;
|
||||
PRBool enabled;
|
||||
if (NS_FAILED(prefs->GetBoolPref(pref, &enabled)) || !enabled)
|
||||
{
|
||||
// Deny unless subject is executing from file: or resource:
|
||||
PRBool isFile = PR_FALSE;
|
||||
PRBool isRes = PR_FALSE;
|
||||
|
||||
if (NS_FAILED(mURI->SchemeIs("file", &isFile)) ||
|
||||
NS_FAILED(mURI->SchemeIs("resource", &isRes)) ||
|
||||
(!isFile && !isRes))
|
||||
{
|
||||
*result = nsIPrincipal::ENABLE_DENIED;
|
||||
return NS_OK;
|
||||
if (NS_FAILED(mURI->SchemeIs("file", &isFile)) ||
|
||||
NS_FAILED(mURI->SchemeIs("resource", &isRes)) ||
|
||||
(!isFile && !isRes))
|
||||
{
|
||||
*result = nsIPrincipal::ENABLE_DENIED;
|
||||
return NS_OK;
|
||||
}
|
||||
}
|
||||
}
|
||||
nsBasePrincipal::CanEnableCapability(capability, result);
|
||||
|
@ -328,7 +333,7 @@ nsCodebasePrincipal::Write(nsIObjectOutputStream* aStream)
|
|||
// Constructor, Destructor, initialization //
|
||||
/////////////////////////////////////////////
|
||||
|
||||
nsCodebasePrincipal::nsCodebasePrincipal()
|
||||
nsCodebasePrincipal::nsCodebasePrincipal() : mTrusted(PR_FALSE)
|
||||
{
|
||||
NS_INIT_ISUPPORTS();
|
||||
}
|
||||
|
@ -349,7 +354,8 @@ nsCodebasePrincipal::Init(nsIURI *uri)
|
|||
// This method overrides nsBasePrincipal::InitFromPersistent
|
||||
nsresult
|
||||
nsCodebasePrincipal::InitFromPersistent(const char* aPrefName, const char* aURLStr,
|
||||
const char* aGrantedList, const char* aDeniedList)
|
||||
const char* aGrantedList, const char* aDeniedList,
|
||||
PRBool aTrusted)
|
||||
{
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIURI> uri;
|
||||
|
@ -358,6 +364,8 @@ nsCodebasePrincipal::InitFromPersistent(const char* aPrefName, const char* aURLS
|
|||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
if (NS_FAILED(Init(uri))) return NS_ERROR_FAILURE;
|
||||
// XXX: Add check for trusted = SSL only here?
|
||||
mTrusted = aTrusted;
|
||||
|
||||
return nsBasePrincipal::InitFromPersistent(aPrefName, aURLStr,
|
||||
aGrantedList, aDeniedList);
|
||||
|
|
|
@ -2527,13 +2527,18 @@ nsScriptSecurityManager::InitPrincipals(PRUint32 aPrefCount, const char** aPrefN
|
|||
nsISecurityPref* aSecurityPref)
|
||||
{
|
||||
/* This is the principal preference syntax:
|
||||
* capability.principal.[codebase|certificate].<name>.[id|granted|denied]
|
||||
* capability.principal.[codebase|codebaseTrusted|certificate].<name>.[id|granted|denied]
|
||||
* For example:
|
||||
* user_pref("capability.principal.certificate.p1.id","12:34:AB:CD");
|
||||
* user_pref("capability.principal.certificate.p1.granted","Capability1 Capability2");
|
||||
* user_pref("capability.principal.certificate.p1.denied","Capability3");
|
||||
*/
|
||||
|
||||
/* codebaseTrusted means a codebase principal that can enable capabilities even if
|
||||
* codebase principals are disabled. Don't use trustedCodebase except with unspoofable
|
||||
* URLs such as HTTPS URLs.
|
||||
*/
|
||||
|
||||
static const char idSuffix[] = ".id";
|
||||
for (PRUint32 c = 0; c < aPrefCount; c++)
|
||||
{
|
||||
|
@ -2573,8 +2578,9 @@ nsScriptSecurityManager::InitPrincipals(PRUint32 aPrefCount, const char** aPrefN
|
|||
}
|
||||
|
||||
//-- Create a principal based on the prefs
|
||||
static const char certificateName[] = "capability.principal.certificate.";
|
||||
static const char codebaseName[] = "capability.principal.codebase.";
|
||||
static const char certificateName[] = "capability.principal.certificate";
|
||||
static const char codebaseName[] = "capability.principal.codebase";
|
||||
static const char codebaseTrustedName[] = "capability.principal.codebaseTrusted";
|
||||
nsCOMPtr<nsIPrincipal> principal;
|
||||
if (PL_strncmp(aPrefNames[c], certificateName,
|
||||
sizeof(certificateName)-1) == 0)
|
||||
|
@ -2593,8 +2599,11 @@ nsScriptSecurityManager::InitPrincipals(PRUint32 aPrefCount, const char** aPrefN
|
|||
nsCodebasePrincipal *codebase = new nsCodebasePrincipal();
|
||||
if (codebase) {
|
||||
NS_ADDREF(codebase);
|
||||
PRBool trusted = (PL_strncmp(aPrefNames[c], codebaseTrustedName,
|
||||
sizeof(codebaseTrustedName)-1) == 0);
|
||||
if (NS_SUCCEEDED(codebase->InitFromPersistent(aPrefNames[c], id,
|
||||
grantedList, deniedList)))
|
||||
grantedList, deniedList,
|
||||
trusted)))
|
||||
principal = do_QueryInterface((nsBasePrincipal*)codebase);
|
||||
NS_RELEASE(codebase);
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче