mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-28 23:31:56 +00:00
Bug 1250930 - Use SubtleCrypto's global when creating keys for an ImportKeyTask r=bz
This commit is contained in:
parent
cc52e6234b
commit
6eec770808
@ -104,8 +104,8 @@ SubtleCrypto::ImportKey(JSContext* cx,
|
||||
const Sequence<nsString>& keyUsages,
|
||||
ErrorResult& aRv)
|
||||
{
|
||||
SUBTLECRYPTO_METHOD_BODY(ImportKey, aRv, cx, format, keyData, algorithm,
|
||||
extractable, keyUsages)
|
||||
SUBTLECRYPTO_METHOD_BODY(ImportKey, aRv, mParent, cx, format, keyData,
|
||||
algorithm, extractable, keyUsages)
|
||||
}
|
||||
|
||||
already_AddRefed<Promise>
|
||||
@ -132,7 +132,7 @@ SubtleCrypto::DeriveKey(JSContext* cx,
|
||||
bool extractable, const Sequence<nsString>& keyUsages,
|
||||
ErrorResult& aRv)
|
||||
{
|
||||
SUBTLECRYPTO_METHOD_BODY(DeriveKey, aRv, cx, algorithm, baseKey,
|
||||
SUBTLECRYPTO_METHOD_BODY(DeriveKey, aRv, mParent, cx, algorithm, baseKey,
|
||||
derivedKeyType, extractable, keyUsages)
|
||||
}
|
||||
|
||||
@ -168,9 +168,9 @@ SubtleCrypto::UnwrapKey(JSContext* cx,
|
||||
const Sequence<nsString>& keyUsages,
|
||||
ErrorResult& aRv)
|
||||
{
|
||||
SUBTLECRYPTO_METHOD_BODY(UnwrapKey, aRv, cx, format, wrappedKey, unwrappingKey,
|
||||
unwrapAlgorithm, unwrappedKeyAlgorithm,
|
||||
extractable, keyUsages)
|
||||
SUBTLECRYPTO_METHOD_BODY(UnwrapKey, aRv, mParent, cx, format, wrappedKey,
|
||||
unwrappingKey, unwrapAlgorithm,
|
||||
unwrappedKeyAlgorithm, extractable, keyUsages)
|
||||
}
|
||||
|
||||
} // namespace dom
|
||||
|
@ -1332,24 +1332,16 @@ private:
|
||||
class ImportKeyTask : public WebCryptoTask
|
||||
{
|
||||
public:
|
||||
void Init(JSContext* aCx,
|
||||
const nsAString& aFormat,
|
||||
const ObjectOrString& aAlgorithm, bool aExtractable,
|
||||
const Sequence<nsString>& aKeyUsages)
|
||||
void Init(nsIGlobalObject* aGlobal, JSContext* aCx,
|
||||
const nsAString& aFormat, const ObjectOrString& aAlgorithm,
|
||||
bool aExtractable, const Sequence<nsString>& aKeyUsages)
|
||||
{
|
||||
mFormat = aFormat;
|
||||
mDataIsSet = false;
|
||||
mDataIsJwk = false;
|
||||
|
||||
// Get the current global object from the context
|
||||
nsIGlobalObject *global = xpc::NativeGlobal(JS::CurrentGlobalOrNull(aCx));
|
||||
if (!global) {
|
||||
mEarlyRv = NS_ERROR_DOM_UNKNOWN_ERR;
|
||||
return;
|
||||
}
|
||||
|
||||
// This stuff pretty much always happens, so we'll do it here
|
||||
mKey = new CryptoKey(global);
|
||||
mKey = new CryptoKey(aGlobal);
|
||||
mKey->SetExtractable(aExtractable);
|
||||
mKey->ClearUsages();
|
||||
for (uint32_t i = 0; i < aKeyUsages.Length(); ++i) {
|
||||
@ -1472,20 +1464,20 @@ private:
|
||||
class ImportSymmetricKeyTask : public ImportKeyTask
|
||||
{
|
||||
public:
|
||||
ImportSymmetricKeyTask(JSContext* aCx,
|
||||
ImportSymmetricKeyTask(nsIGlobalObject* aGlobal, JSContext* aCx,
|
||||
const nsAString& aFormat,
|
||||
const ObjectOrString& aAlgorithm, bool aExtractable,
|
||||
const Sequence<nsString>& aKeyUsages)
|
||||
{
|
||||
Init(aCx, aFormat, aAlgorithm, aExtractable, aKeyUsages);
|
||||
Init(aGlobal, aCx, aFormat, aAlgorithm, aExtractable, aKeyUsages);
|
||||
}
|
||||
|
||||
ImportSymmetricKeyTask(JSContext* aCx,
|
||||
ImportSymmetricKeyTask(nsIGlobalObject* aGlobal, JSContext* aCx,
|
||||
const nsAString& aFormat, const JS::Handle<JSObject*> aKeyData,
|
||||
const ObjectOrString& aAlgorithm, bool aExtractable,
|
||||
const Sequence<nsString>& aKeyUsages)
|
||||
{
|
||||
Init(aCx, aFormat, aAlgorithm, aExtractable, aKeyUsages);
|
||||
Init(aGlobal, aCx, aFormat, aAlgorithm, aExtractable, aKeyUsages);
|
||||
if (NS_FAILED(mEarlyRv)) {
|
||||
return;
|
||||
}
|
||||
@ -1498,12 +1490,11 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
void Init(JSContext* aCx,
|
||||
const nsAString& aFormat,
|
||||
void Init(nsIGlobalObject* aGlobal, JSContext* aCx, const nsAString& aFormat,
|
||||
const ObjectOrString& aAlgorithm, bool aExtractable,
|
||||
const Sequence<nsString>& aKeyUsages)
|
||||
{
|
||||
ImportKeyTask::Init(aCx, aFormat, aAlgorithm, aExtractable, aKeyUsages);
|
||||
ImportKeyTask::Init(aGlobal, aCx, aFormat, aAlgorithm, aExtractable, aKeyUsages);
|
||||
if (NS_FAILED(mEarlyRv)) {
|
||||
return;
|
||||
}
|
||||
@ -1630,20 +1621,20 @@ private:
|
||||
class ImportRsaKeyTask : public ImportKeyTask
|
||||
{
|
||||
public:
|
||||
ImportRsaKeyTask(JSContext* aCx,
|
||||
ImportRsaKeyTask(nsIGlobalObject* aGlobal, JSContext* aCx,
|
||||
const nsAString& aFormat,
|
||||
const ObjectOrString& aAlgorithm, bool aExtractable,
|
||||
const Sequence<nsString>& aKeyUsages)
|
||||
{
|
||||
Init(aCx, aFormat, aAlgorithm, aExtractable, aKeyUsages);
|
||||
Init(aGlobal, aCx, aFormat, aAlgorithm, aExtractable, aKeyUsages);
|
||||
}
|
||||
|
||||
ImportRsaKeyTask(JSContext* aCx,
|
||||
ImportRsaKeyTask(nsIGlobalObject* aGlobal, JSContext* aCx,
|
||||
const nsAString& aFormat, JS::Handle<JSObject*> aKeyData,
|
||||
const ObjectOrString& aAlgorithm, bool aExtractable,
|
||||
const Sequence<nsString>& aKeyUsages)
|
||||
{
|
||||
Init(aCx, aFormat, aAlgorithm, aExtractable, aKeyUsages);
|
||||
Init(aGlobal, aCx, aFormat, aAlgorithm, aExtractable, aKeyUsages);
|
||||
if (NS_FAILED(mEarlyRv)) {
|
||||
return;
|
||||
}
|
||||
@ -1656,12 +1647,12 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
void Init(JSContext* aCx,
|
||||
void Init(nsIGlobalObject* aGlobal, JSContext* aCx,
|
||||
const nsAString& aFormat,
|
||||
const ObjectOrString& aAlgorithm, bool aExtractable,
|
||||
const Sequence<nsString>& aKeyUsages)
|
||||
{
|
||||
ImportKeyTask::Init(aCx, aFormat, aAlgorithm, aExtractable, aKeyUsages);
|
||||
ImportKeyTask::Init(aGlobal, aCx, aFormat, aAlgorithm, aExtractable, aKeyUsages);
|
||||
if (NS_FAILED(mEarlyRv)) {
|
||||
return;
|
||||
}
|
||||
@ -1798,19 +1789,19 @@ private:
|
||||
class ImportEcKeyTask : public ImportKeyTask
|
||||
{
|
||||
public:
|
||||
ImportEcKeyTask(JSContext* aCx, const nsAString& aFormat,
|
||||
const ObjectOrString& aAlgorithm, bool aExtractable,
|
||||
const Sequence<nsString>& aKeyUsages)
|
||||
ImportEcKeyTask(nsIGlobalObject* aGlobal, JSContext* aCx,
|
||||
const nsAString& aFormat, const ObjectOrString& aAlgorithm,
|
||||
bool aExtractable, const Sequence<nsString>& aKeyUsages)
|
||||
{
|
||||
Init(aCx, aFormat, aAlgorithm, aExtractable, aKeyUsages);
|
||||
Init(aGlobal, aCx, aFormat, aAlgorithm, aExtractable, aKeyUsages);
|
||||
}
|
||||
|
||||
ImportEcKeyTask(JSContext* aCx, const nsAString& aFormat,
|
||||
JS::Handle<JSObject*> aKeyData,
|
||||
ImportEcKeyTask(nsIGlobalObject* aGlobal, JSContext* aCx,
|
||||
const nsAString& aFormat, JS::Handle<JSObject*> aKeyData,
|
||||
const ObjectOrString& aAlgorithm, bool aExtractable,
|
||||
const Sequence<nsString>& aKeyUsages)
|
||||
{
|
||||
Init(aCx, aFormat, aAlgorithm, aExtractable, aKeyUsages);
|
||||
Init(aGlobal, aCx, aFormat, aAlgorithm, aExtractable, aKeyUsages);
|
||||
if (NS_FAILED(mEarlyRv)) {
|
||||
return;
|
||||
}
|
||||
@ -1819,11 +1810,11 @@ public:
|
||||
NS_ENSURE_SUCCESS_VOID(mEarlyRv);
|
||||
}
|
||||
|
||||
void Init(JSContext* aCx, const nsAString& aFormat,
|
||||
void Init(nsIGlobalObject* aGlobal, JSContext* aCx, const nsAString& aFormat,
|
||||
const ObjectOrString& aAlgorithm, bool aExtractable,
|
||||
const Sequence<nsString>& aKeyUsages)
|
||||
{
|
||||
ImportKeyTask::Init(aCx, aFormat, aAlgorithm, aExtractable, aKeyUsages);
|
||||
ImportKeyTask::Init(aGlobal, aCx, aFormat, aAlgorithm, aExtractable, aKeyUsages);
|
||||
if (NS_FAILED(mEarlyRv)) {
|
||||
return;
|
||||
}
|
||||
@ -1951,30 +1942,30 @@ private:
|
||||
class ImportDhKeyTask : public ImportKeyTask
|
||||
{
|
||||
public:
|
||||
ImportDhKeyTask(JSContext* aCx, const nsAString& aFormat,
|
||||
const ObjectOrString& aAlgorithm, bool aExtractable,
|
||||
const Sequence<nsString>& aKeyUsages)
|
||||
ImportDhKeyTask(nsIGlobalObject* aGlobal, JSContext* aCx,
|
||||
const nsAString& aFormat, const ObjectOrString& aAlgorithm,
|
||||
bool aExtractable, const Sequence<nsString>& aKeyUsages)
|
||||
{
|
||||
Init(aCx, aFormat, aAlgorithm, aExtractable, aKeyUsages);
|
||||
Init(aGlobal, aCx, aFormat, aAlgorithm, aExtractable, aKeyUsages);
|
||||
}
|
||||
|
||||
ImportDhKeyTask(JSContext* aCx, const nsAString& aFormat,
|
||||
JS::Handle<JSObject*> aKeyData,
|
||||
ImportDhKeyTask(nsIGlobalObject* aGlobal, JSContext* aCx,
|
||||
const nsAString& aFormat, JS::Handle<JSObject*> aKeyData,
|
||||
const ObjectOrString& aAlgorithm, bool aExtractable,
|
||||
const Sequence<nsString>& aKeyUsages)
|
||||
{
|
||||
Init(aCx, aFormat, aAlgorithm, aExtractable, aKeyUsages);
|
||||
Init(aGlobal, aCx, aFormat, aAlgorithm, aExtractable, aKeyUsages);
|
||||
if (NS_SUCCEEDED(mEarlyRv)) {
|
||||
SetKeyData(aCx, aKeyData);
|
||||
NS_ENSURE_SUCCESS_VOID(mEarlyRv);
|
||||
}
|
||||
}
|
||||
|
||||
void Init(JSContext* aCx, const nsAString& aFormat,
|
||||
void Init(nsIGlobalObject* aGlobal, JSContext* aCx, const nsAString& aFormat,
|
||||
const ObjectOrString& aAlgorithm, bool aExtractable,
|
||||
const Sequence<nsString>& aKeyUsages)
|
||||
{
|
||||
ImportKeyTask::Init(aCx, aFormat, aAlgorithm, aExtractable, aKeyUsages);
|
||||
ImportKeyTask::Init(aGlobal, aCx, aFormat, aAlgorithm, aExtractable, aKeyUsages);
|
||||
if (NS_FAILED(mEarlyRv)) {
|
||||
return;
|
||||
}
|
||||
@ -2853,7 +2844,7 @@ template<class DeriveBitsTask>
|
||||
class DeriveKeyTask : public DeriveBitsTask
|
||||
{
|
||||
public:
|
||||
DeriveKeyTask(JSContext* aCx,
|
||||
DeriveKeyTask(nsIGlobalObject* aGlobal, JSContext* aCx,
|
||||
const ObjectOrString& aAlgorithm, CryptoKey& aBaseKey,
|
||||
const ObjectOrString& aDerivedKeyType, bool aExtractable,
|
||||
const Sequence<nsString>& aKeyUsages)
|
||||
@ -2865,7 +2856,7 @@ public:
|
||||
}
|
||||
|
||||
NS_NAMED_LITERAL_STRING(format, WEBCRYPTO_KEY_FORMAT_RAW);
|
||||
mTask = new ImportSymmetricKeyTask(aCx, format, aDerivedKeyType,
|
||||
mTask = new ImportSymmetricKeyTask(aGlobal, aCx, format, aDerivedKeyType,
|
||||
aExtractable, aKeyUsages);
|
||||
}
|
||||
|
||||
@ -3295,7 +3286,8 @@ WebCryptoTask::CreateDigestTask(JSContext* aCx,
|
||||
}
|
||||
|
||||
WebCryptoTask*
|
||||
WebCryptoTask::CreateImportKeyTask(JSContext* aCx,
|
||||
WebCryptoTask::CreateImportKeyTask(nsIGlobalObject* aGlobal,
|
||||
JSContext* aCx,
|
||||
const nsAString& aFormat,
|
||||
JS::Handle<JSObject*> aKeyData,
|
||||
const ObjectOrString& aAlgorithm,
|
||||
@ -3333,19 +3325,19 @@ WebCryptoTask::CreateImportKeyTask(JSContext* aCx,
|
||||
algName.EqualsLiteral(WEBCRYPTO_ALG_PBKDF2) ||
|
||||
algName.EqualsLiteral(WEBCRYPTO_ALG_HKDF) ||
|
||||
algName.EqualsLiteral(WEBCRYPTO_ALG_HMAC)) {
|
||||
return new ImportSymmetricKeyTask(aCx, aFormat, aKeyData, aAlgorithm,
|
||||
aExtractable, aKeyUsages);
|
||||
return new ImportSymmetricKeyTask(aGlobal, aCx, aFormat, aKeyData,
|
||||
aAlgorithm, aExtractable, aKeyUsages);
|
||||
} else if (algName.EqualsLiteral(WEBCRYPTO_ALG_RSASSA_PKCS1) ||
|
||||
algName.EqualsLiteral(WEBCRYPTO_ALG_RSA_OAEP) ||
|
||||
algName.EqualsLiteral(WEBCRYPTO_ALG_RSA_PSS)) {
|
||||
return new ImportRsaKeyTask(aCx, aFormat, aKeyData, aAlgorithm,
|
||||
return new ImportRsaKeyTask(aGlobal, aCx, aFormat, aKeyData, aAlgorithm,
|
||||
aExtractable, aKeyUsages);
|
||||
} else if (algName.EqualsLiteral(WEBCRYPTO_ALG_ECDH) ||
|
||||
algName.EqualsLiteral(WEBCRYPTO_ALG_ECDSA)) {
|
||||
return new ImportEcKeyTask(aCx, aFormat, aKeyData, aAlgorithm,
|
||||
return new ImportEcKeyTask(aGlobal, aCx, aFormat, aKeyData, aAlgorithm,
|
||||
aExtractable, aKeyUsages);
|
||||
} else if (algName.EqualsLiteral(WEBCRYPTO_ALG_DH)) {
|
||||
return new ImportDhKeyTask(aCx, aFormat, aKeyData, aAlgorithm,
|
||||
return new ImportDhKeyTask(aGlobal, aCx, aFormat, aKeyData, aAlgorithm,
|
||||
aExtractable, aKeyUsages);
|
||||
} else {
|
||||
return new FailureTask(NS_ERROR_DOM_NOT_SUPPORTED_ERR);
|
||||
@ -3434,7 +3426,8 @@ WebCryptoTask::CreateGenerateKeyTask(JSContext* aCx,
|
||||
}
|
||||
|
||||
WebCryptoTask*
|
||||
WebCryptoTask::CreateDeriveKeyTask(JSContext* aCx,
|
||||
WebCryptoTask::CreateDeriveKeyTask(nsIGlobalObject* aGlobal,
|
||||
JSContext* aCx,
|
||||
const ObjectOrString& aAlgorithm,
|
||||
CryptoKey& aBaseKey,
|
||||
const ObjectOrString& aDerivedKeyType,
|
||||
@ -3460,21 +3453,21 @@ WebCryptoTask::CreateDeriveKeyTask(JSContext* aCx,
|
||||
}
|
||||
|
||||
if (algName.EqualsASCII(WEBCRYPTO_ALG_HKDF)) {
|
||||
return new DeriveKeyTask<DeriveHkdfBitsTask>(aCx, aAlgorithm, aBaseKey,
|
||||
aDerivedKeyType, aExtractable,
|
||||
aKeyUsages);
|
||||
return new DeriveKeyTask<DeriveHkdfBitsTask>(aGlobal, aCx, aAlgorithm,
|
||||
aBaseKey, aDerivedKeyType,
|
||||
aExtractable, aKeyUsages);
|
||||
}
|
||||
|
||||
if (algName.EqualsASCII(WEBCRYPTO_ALG_PBKDF2)) {
|
||||
return new DeriveKeyTask<DerivePbkdfBitsTask>(aCx, aAlgorithm, aBaseKey,
|
||||
aDerivedKeyType, aExtractable,
|
||||
aKeyUsages);
|
||||
return new DeriveKeyTask<DerivePbkdfBitsTask>(aGlobal, aCx, aAlgorithm,
|
||||
aBaseKey, aDerivedKeyType,
|
||||
aExtractable, aKeyUsages);
|
||||
}
|
||||
|
||||
if (algName.EqualsASCII(WEBCRYPTO_ALG_ECDH)) {
|
||||
return new DeriveKeyTask<DeriveEcdhBitsTask>(aCx, aAlgorithm, aBaseKey,
|
||||
aDerivedKeyType, aExtractable,
|
||||
aKeyUsages);
|
||||
return new DeriveKeyTask<DeriveEcdhBitsTask>(aGlobal, aCx, aAlgorithm,
|
||||
aBaseKey, aDerivedKeyType,
|
||||
aExtractable, aKeyUsages);
|
||||
}
|
||||
|
||||
return new FailureTask(NS_ERROR_DOM_NOT_SUPPORTED_ERR);
|
||||
@ -3568,7 +3561,8 @@ WebCryptoTask::CreateWrapKeyTask(JSContext* aCx,
|
||||
}
|
||||
|
||||
WebCryptoTask*
|
||||
WebCryptoTask::CreateUnwrapKeyTask(JSContext* aCx,
|
||||
WebCryptoTask::CreateUnwrapKeyTask(nsIGlobalObject* aGlobal,
|
||||
JSContext* aCx,
|
||||
const nsAString& aFormat,
|
||||
const ArrayBufferViewOrArrayBuffer& aWrappedKey,
|
||||
CryptoKey& aUnwrappingKey,
|
||||
@ -3602,13 +3596,13 @@ WebCryptoTask::CreateUnwrapKeyTask(JSContext* aCx,
|
||||
keyAlgName.EqualsASCII(WEBCRYPTO_ALG_AES_GCM) ||
|
||||
keyAlgName.EqualsASCII(WEBCRYPTO_ALG_HKDF) ||
|
||||
keyAlgName.EqualsASCII(WEBCRYPTO_ALG_HMAC)) {
|
||||
importTask = new ImportSymmetricKeyTask(aCx, aFormat,
|
||||
importTask = new ImportSymmetricKeyTask(aGlobal, aCx, aFormat,
|
||||
aUnwrappedKeyAlgorithm,
|
||||
aExtractable, aKeyUsages);
|
||||
} else if (keyAlgName.EqualsASCII(WEBCRYPTO_ALG_RSASSA_PKCS1) ||
|
||||
keyAlgName.EqualsASCII(WEBCRYPTO_ALG_RSA_OAEP) ||
|
||||
keyAlgName.EqualsASCII(WEBCRYPTO_ALG_RSA_PSS)) {
|
||||
importTask = new ImportRsaKeyTask(aCx, aFormat,
|
||||
importTask = new ImportRsaKeyTask(aGlobal, aCx, aFormat,
|
||||
aUnwrappedKeyAlgorithm,
|
||||
aExtractable, aKeyUsages);
|
||||
} else {
|
||||
|
@ -122,7 +122,8 @@ public:
|
||||
const ObjectOrString& aAlgorithm,
|
||||
const CryptoOperationData& aData);
|
||||
|
||||
static WebCryptoTask* CreateImportKeyTask(JSContext* aCx,
|
||||
static WebCryptoTask* CreateImportKeyTask(nsIGlobalObject* aGlobal,
|
||||
JSContext* aCx,
|
||||
const nsAString& aFormat,
|
||||
JS::Handle<JSObject*> aKeyData,
|
||||
const ObjectOrString& aAlgorithm,
|
||||
@ -135,7 +136,8 @@ public:
|
||||
bool aExtractable,
|
||||
const Sequence<nsString>& aKeyUsages);
|
||||
|
||||
static WebCryptoTask* CreateDeriveKeyTask(JSContext* aCx,
|
||||
static WebCryptoTask* CreateDeriveKeyTask(nsIGlobalObject* aGlobal,
|
||||
JSContext* aCx,
|
||||
const ObjectOrString& aAlgorithm,
|
||||
CryptoKey& aBaseKey,
|
||||
const ObjectOrString& aDerivedKeyType,
|
||||
@ -151,7 +153,8 @@ public:
|
||||
CryptoKey& aKey,
|
||||
CryptoKey& aWrappingKey,
|
||||
const ObjectOrString& aWrapAlgorithm);
|
||||
static WebCryptoTask* CreateUnwrapKeyTask(JSContext* aCx,
|
||||
static WebCryptoTask* CreateUnwrapKeyTask(nsIGlobalObject* aGlobal,
|
||||
JSContext* aCx,
|
||||
const nsAString& aFormat,
|
||||
const ArrayBufferViewOrArrayBuffer& aWrappedKey,
|
||||
CryptoKey& aUnwrappingKey,
|
||||
|
Loading…
Reference in New Issue
Block a user