Bug 136993 - Put the "trusted codebase principals" feature back in.
r=harishd, sr=jst, a=valeski git-svn-id: svn://10.0.0.236/trunk@118900 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
@@ -80,12 +80,14 @@ public:
|
||||
|
||||
nsresult
|
||||
InitFromPersistent(const char* aPrefName, const char* aID,
|
||||
const char* aGrantedList, const char* aDeniedList);
|
||||
const char* aGrantedList, const char* aDeniedList,
|
||||
PRBool aTrusted);
|
||||
|
||||
virtual ~nsCodebasePrincipal(void);
|
||||
|
||||
protected:
|
||||
nsCOMPtr<nsIURI> mURI;
|
||||
PRBool mTrusted;
|
||||
};
|
||||
|
||||
#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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user