mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-24 05:11:16 +00:00
Bug 1163254 - Add signedPkg to OriginAttributes. r=bholley
This commit is contained in:
parent
5d406f0ff6
commit
b6b5862949
@ -62,6 +62,10 @@ OriginAttributes::CreateSuffix(nsACString& aStr) const
|
||||
params->Set(NS_LITERAL_STRING("userContextId"), value);
|
||||
}
|
||||
|
||||
if (!mSignedPkg.IsEmpty()) {
|
||||
params->Set(NS_LITERAL_STRING("signedPkg"), mSignedPkg);
|
||||
}
|
||||
|
||||
aStr.Truncate();
|
||||
|
||||
params->Serialize(value);
|
||||
@ -132,6 +136,12 @@ public:
|
||||
return true;
|
||||
}
|
||||
|
||||
if (aName.EqualsLiteral("signedPkg")) {
|
||||
MOZ_RELEASE_ASSERT(mOriginAttributes->mSignedPkg.IsEmpty());
|
||||
mOriginAttributes->mSignedPkg.Assign(aValue);
|
||||
return true;
|
||||
}
|
||||
|
||||
// No other attributes are supported.
|
||||
return false;
|
||||
}
|
||||
|
@ -36,7 +36,8 @@ public:
|
||||
return mAppId == aOther.mAppId &&
|
||||
mInBrowser == aOther.mInBrowser &&
|
||||
mAddonId == aOther.mAddonId &&
|
||||
mUserContextId == aOther.mUserContextId;
|
||||
mUserContextId == aOther.mUserContextId &&
|
||||
mSignedPkg == aOther.mSignedPkg;
|
||||
}
|
||||
bool operator!=(const OriginAttributes& aOther) const
|
||||
{
|
||||
@ -88,6 +89,10 @@ public:
|
||||
return false;
|
||||
}
|
||||
|
||||
if (mSignedPkg.WasPassed() && mSignedPkg.Value() != aAttrs.mSignedPkg) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
@ -136,6 +136,19 @@ function run_test() {
|
||||
checkOriginAttributes(nullPrin_userContextApp, {appId: 24, userContextId: 42}, '^appId=24&userContextId=42');
|
||||
do_check_eq(exampleOrg_userContextApp.origin, 'http://example.org^appId=24&userContextId=42');
|
||||
|
||||
// Just signedPkg
|
||||
var exampleOrg_signedPkg = ssm.createCodebasePrincipal(makeURI('http://example.org'), {signedPkg: 'whatever'});
|
||||
checkOriginAttributes(exampleOrg_signedPkg, { signedPkg: 'id' }, '^signedPkg=whatever');
|
||||
do_check_eq(exampleOrg_signedPkg.origin, 'http://example.org^signedPkg=whatever');
|
||||
|
||||
// signedPkg and browser
|
||||
var exampleOrg_signedPkg_browser = ssm.createCodebasePrincipal(makeURI('http://example.org'), {signedPkg: 'whatever', inBrowser: true});
|
||||
checkOriginAttributes(exampleOrg_signedPkg_browser, { signedPkg: 'whatever', inBrowser: true }, '^inBrowser=1&signedPkg=whatever');
|
||||
do_check_eq(exampleOrg_signedPkg_browser.origin, 'http://example.org^inBrowser=1&signedPkg=whatever');
|
||||
|
||||
// Just signedPkg (but different value from 'exampleOrg_signedPkg_app')
|
||||
var exampleOrg_signedPkg_another = ssm.createCodebasePrincipal(makeURI('http://example.org'), {signedPkg: 'whatup'});
|
||||
|
||||
// Check that all of the above are cross-origin.
|
||||
checkCrossOrigin(exampleOrg_app, exampleOrg);
|
||||
checkCrossOrigin(exampleOrg_app, nullPrin_app);
|
||||
@ -149,4 +162,7 @@ function run_test() {
|
||||
checkCrossOrigin(exampleOrg_userContextAddon, exampleOrg);
|
||||
checkCrossOrigin(exampleOrg_userContext, exampleOrg_userContextAddon);
|
||||
checkCrossOrigin(exampleOrg_userContext, exampleOrg_userContextApp);
|
||||
checkCrossOrigin(exampleOrg_signedPkg, exampleOrg);
|
||||
checkCrossOrigin(exampleOrg_signedPkg, exampleOrg_signedPkg_browser);
|
||||
checkCrossOrigin(exampleOrg_signedPkg, exampleOrg_signedPkg_another);
|
||||
}
|
||||
|
@ -432,14 +432,25 @@ StructuredCloneHelper::ReadFullySerializableObjects(JSContext* aCx,
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
uint32_t signedPkgLength, dummy;
|
||||
if (!JS_ReadUint32Pair(aReader, &signedPkgLength, &dummy)) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
nsAutoCString spec;
|
||||
spec.SetLength(specLength);
|
||||
if (!JS_ReadBytes(aReader, spec.BeginWriting(), specLength)) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
nsAutoCString signedPkg;
|
||||
signedPkg.SetLength(signedPkgLength);
|
||||
if (!JS_ReadBytes(aReader, signedPkg.BeginWriting(), signedPkgLength)) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
info = mozilla::ipc::ContentPrincipalInfo(appId, isInBrowserElement,
|
||||
spec);
|
||||
spec, signedPkg);
|
||||
}
|
||||
|
||||
nsresult rv;
|
||||
@ -570,7 +581,9 @@ StructuredCloneHelper::WriteFullySerializableObjects(JSContext* aCx,
|
||||
cInfo.appId()) &&
|
||||
JS_WriteUint32Pair(aWriter, cInfo.isInBrowserElement(),
|
||||
cInfo.spec().Length()) &&
|
||||
JS_WriteBytes(aWriter, cInfo.spec().get(), cInfo.spec().Length());
|
||||
JS_WriteUint32Pair(aWriter, cInfo.signedPkg().Length(), 0) &&
|
||||
JS_WriteBytes(aWriter, cInfo.spec().get(), cInfo.spec().Length()) &&
|
||||
JS_WriteBytes(aWriter, cInfo.signedPkg().get(), cInfo.signedPkg().Length());
|
||||
}
|
||||
}
|
||||
|
||||
|
3
dom/cache/DBSchema.cpp
vendored
3
dom/cache/DBSchema.cpp
vendored
@ -1913,8 +1913,9 @@ ReadResponse(mozIStorageConnection* aConn, EntryId aEntryId,
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
nsCString signedPkg = NS_ConvertUTF16toUTF8(attrs.mSignedPkg);
|
||||
aSavedResponseOut->mValue.principalInfo() =
|
||||
mozilla::ipc::ContentPrincipalInfo(attrs.mAppId, attrs.mInBrowser, originNoSuffix);
|
||||
mozilla::ipc::ContentPrincipalInfo(attrs.mAppId, attrs.mInBrowser, originNoSuffix, signedPkg);
|
||||
}
|
||||
|
||||
int32_t redirected;
|
||||
|
@ -41,18 +41,18 @@ interface ChromeUtils : ThreadSafeChromeUtils {
|
||||
* (2) Update the methods on mozilla::OriginAttributes, including equality,
|
||||
* serialization, and deserialization.
|
||||
* (3) Update the methods on mozilla::OriginAttributesPattern, including matching.
|
||||
* (4) Bump the CIDs (_not_ IIDs) of all the principal implementations that
|
||||
* use OriginAttributes in their nsISerializable implementations.
|
||||
*/
|
||||
dictionary OriginAttributesDictionary {
|
||||
unsigned long appId = 0;
|
||||
unsigned long userContextId = 0;
|
||||
boolean inBrowser = false;
|
||||
DOMString addonId = "";
|
||||
DOMString signedPkg = "";
|
||||
};
|
||||
dictionary OriginAttributesPatternDictionary {
|
||||
unsigned long appId;
|
||||
unsigned long userContextId;
|
||||
boolean inBrowser;
|
||||
DOMString addonId;
|
||||
DOMString signedPkg;
|
||||
};
|
||||
|
@ -332,8 +332,9 @@ ServiceWorkerRegistrar::ReadData()
|
||||
}
|
||||
|
||||
GET_LINE(line);
|
||||
nsCString signedPkg = NS_ConvertUTF16toUTF8(attrs.mSignedPkg);
|
||||
entry->principal() =
|
||||
mozilla::ipc::ContentPrincipalInfo(attrs.mAppId, attrs.mInBrowser, line);
|
||||
mozilla::ipc::ContentPrincipalInfo(attrs.mAppId, attrs.mInBrowser, line, signedPkg);
|
||||
|
||||
GET_LINE(entry->scope());
|
||||
GET_LINE(entry->scriptSpec());
|
||||
|
@ -221,7 +221,7 @@ TEST(ServiceWorkerRegistrar, TestWriteData)
|
||||
|
||||
nsAutoCString spec;
|
||||
spec.AppendPrintf("spec write %d", i);
|
||||
d->principal() = mozilla::ipc::ContentPrincipalInfo(i, i % 2, spec);
|
||||
d->principal() = mozilla::ipc::ContentPrincipalInfo(i, i % 2, spec, EmptyCString());
|
||||
d->scope().AppendPrintf("scope write %d", i);
|
||||
d->scriptSpec().AppendPrintf("scriptSpec write %d", i);
|
||||
d->currentWorkerURL().AppendPrintf("currentWorkerURL write %d", i);
|
||||
|
@ -82,6 +82,7 @@ PrincipalInfoToPrincipal(const PrincipalInfo& aPrincipalInfo,
|
||||
} else {
|
||||
// TODO: Bug 1167100 - User nsIPrincipal.originAttribute in ContentPrincipalInfo
|
||||
OriginAttributes attrs(info.appId(), info.isInBrowserElement());
|
||||
attrs.mSignedPkg = NS_ConvertUTF8toUTF16(info.signedPkg());
|
||||
principal = BasePrincipal::CreateCodebasePrincipal(uri, attrs);
|
||||
rv = principal ? NS_OK : NS_ERROR_FAILURE;
|
||||
}
|
||||
@ -202,6 +203,10 @@ PrincipalToPrincipalInfo(nsIPrincipal* aPrincipal,
|
||||
return rv;
|
||||
}
|
||||
|
||||
const mozilla::OriginAttributes& attr =
|
||||
mozilla::BasePrincipal::Cast(aPrincipal)->OriginAttributesRef();
|
||||
nsCString signedPkg = NS_ConvertUTF16toUTF8(attr.mSignedPkg);
|
||||
|
||||
bool isUnknownAppId;
|
||||
rv = aPrincipal->GetUnknownAppId(&isUnknownAppId);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
@ -224,7 +229,7 @@ PrincipalToPrincipalInfo(nsIPrincipal* aPrincipal,
|
||||
return rv;
|
||||
}
|
||||
|
||||
*aPrincipalInfo = ContentPrincipalInfo(appId, isInBrowserElement, spec);
|
||||
*aPrincipalInfo = ContentPrincipalInfo(appId, isInBrowserElement, spec, signedPkg);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -12,6 +12,7 @@ struct ContentPrincipalInfo
|
||||
uint32_t appId;
|
||||
bool isInBrowserElement;
|
||||
nsCString spec;
|
||||
nsCString signedPkg;
|
||||
};
|
||||
|
||||
struct SystemPrincipalInfo
|
||||
|
Loading…
Reference in New Issue
Block a user