Backed out changeset 38831e922852 (bug 1026314) for test_interfaces.html failures

--HG--
rename : dom/crypto/CryptoKey.cpp => dom/crypto/Key.cpp
rename : dom/crypto/CryptoKey.h => dom/crypto/Key.h
rename : dom/crypto/CryptoKeyPair.cpp => dom/crypto/KeyPair.cpp
rename : dom/crypto/CryptoKeyPair.h => dom/crypto/KeyPair.h
This commit is contained in:
Ed Morley 2014-07-04 16:17:51 +01:00
parent 2708de01f4
commit f4b34b75ea
12 changed files with 178 additions and 178 deletions

View File

@ -46,7 +46,7 @@ SubtleCrypto::WrapObject(JSContext* aCx)
already_AddRefed<Promise>
SubtleCrypto::Encrypt(JSContext* cx,
const ObjectOrString& algorithm,
CryptoKey& key,
Key& key,
const CryptoOperationData& data)
{
SUBTLECRYPTO_METHOD_BODY(Encrypt, cx, algorithm, key, data)
@ -55,7 +55,7 @@ SubtleCrypto::Encrypt(JSContext* cx,
already_AddRefed<Promise>
SubtleCrypto::Decrypt(JSContext* cx,
const ObjectOrString& algorithm,
CryptoKey& key,
Key& key,
const CryptoOperationData& data)
{
SUBTLECRYPTO_METHOD_BODY(Decrypt, cx, algorithm, key, data)
@ -64,7 +64,7 @@ SubtleCrypto::Decrypt(JSContext* cx,
already_AddRefed<Promise>
SubtleCrypto::Sign(JSContext* cx,
const ObjectOrString& algorithm,
CryptoKey& key,
Key& key,
const CryptoOperationData& data)
{
SUBTLECRYPTO_METHOD_BODY(Sign, cx, algorithm, key, data)
@ -73,7 +73,7 @@ SubtleCrypto::Sign(JSContext* cx,
already_AddRefed<Promise>
SubtleCrypto::Verify(JSContext* cx,
const ObjectOrString& algorithm,
CryptoKey& key,
Key& key,
const CryptoOperationData& signature,
const CryptoOperationData& data)
{
@ -103,7 +103,7 @@ SubtleCrypto::ImportKey(JSContext* cx,
already_AddRefed<Promise>
SubtleCrypto::ExportKey(const nsAString& format,
CryptoKey& key)
Key& key)
{
SUBTLECRYPTO_METHOD_BODY(ExportKey, format, key)
}
@ -118,7 +118,7 @@ SubtleCrypto::GenerateKey(JSContext* cx, const ObjectOrString& algorithm,
already_AddRefed<Promise>
SubtleCrypto::DeriveKey(JSContext* cx,
const ObjectOrString& algorithm,
CryptoKey& baseKey,
Key& baseKey,
const ObjectOrString& derivedKeyType,
bool extractable, const Sequence<nsString>& keyUsages)
{
@ -129,7 +129,7 @@ SubtleCrypto::DeriveKey(JSContext* cx,
already_AddRefed<Promise>
SubtleCrypto::DeriveBits(JSContext* cx,
const ObjectOrString& algorithm,
CryptoKey& baseKey,
Key& baseKey,
uint32_t length)
{
SUBTLECRYPTO_METHOD_BODY(DeriveBits, cx, algorithm, baseKey, length)

View File

@ -11,7 +11,7 @@
#include "nsWrapperCache.h"
#include "nsPIDOMWindow.h"
#include "mozilla/dom/UnionTypes.h"
#include "mozilla/dom/CryptoKey.h"
#include "mozilla/dom/Key.h"
#include "js/TypeDecls.h"
namespace mozilla {
@ -43,22 +43,22 @@ public:
already_AddRefed<Promise> Encrypt(JSContext* cx,
const ObjectOrString& algorithm,
CryptoKey& key,
Key& key,
const CryptoOperationData& data);
already_AddRefed<Promise> Decrypt(JSContext* cx,
const ObjectOrString& algorithm,
CryptoKey& key,
Key& key,
const CryptoOperationData& data);
already_AddRefed<Promise> Sign(JSContext* cx,
const ObjectOrString& algorithm,
CryptoKey& key,
Key& key,
const CryptoOperationData& data);
already_AddRefed<Promise> Verify(JSContext* cx,
const ObjectOrString& algorithm,
CryptoKey& key,
Key& key,
const CryptoOperationData& signature,
const CryptoOperationData& data);
@ -73,7 +73,7 @@ public:
bool extractable,
const Sequence<nsString>& keyUsages);
already_AddRefed<Promise> ExportKey(const nsAString& format, CryptoKey& key);
already_AddRefed<Promise> ExportKey(const nsAString& format, Key& key);
already_AddRefed<Promise> GenerateKey(JSContext* cx,
const ObjectOrString& algorithm,
@ -82,14 +82,14 @@ public:
already_AddRefed<Promise> DeriveKey(JSContext* cx,
const ObjectOrString& algorithm,
CryptoKey& baseKey,
Key& baseKey,
const ObjectOrString& derivedKeyType,
bool extractable,
const Sequence<nsString>& keyUsages);
already_AddRefed<Promise> DeriveBits(JSContext* cx,
const ObjectOrString& algorithm,
CryptoKey& baseKey,
Key& baseKey,
uint32_t length);
private:

View File

@ -56,7 +56,7 @@
#include "mozilla/AutoRestore.h"
#include "mozilla/dom/ErrorEvent.h"
#include "mozilla/dom/ImageData.h"
#include "mozilla/dom/CryptoKey.h"
#include "mozilla/dom/Key.h"
#include "mozilla/dom/ImageDataBinding.h"
#include "mozilla/dom/SubtleCryptoBinding.h"
#include "nsAXPCNativeCallContext.h"
@ -2821,7 +2821,7 @@ NS_DOMReadStructuredClone(JSContext* cx,
// Prevent the return value from being trashed by a GC during ~nsRefPtr.
JS::Rooted<JSObject*> result(cx);
{
nsRefPtr<CryptoKey> key = new CryptoKey(global);
nsRefPtr<Key> key = new Key(global);
if (!key->ReadStructuredClone(reader)) {
result = nullptr;
} else {
@ -2859,8 +2859,8 @@ NS_DOMWriteStructuredClone(JSContext* cx,
}
// Handle Key cloning
CryptoKey* key;
if (NS_SUCCEEDED(UNWRAP_OBJECT(CryptoKey, obj, key))) {
Key* key;
if (NS_SUCCEEDED(UNWRAP_OBJECT(Key, obj, key))) {
return JS_WriteUint32Pair(writer, SCTAG_DOM_WEBCRYPTO_KEY, 0) &&
key->WriteStructuredClone(writer);
}

View File

@ -7,47 +7,47 @@
#include "pk11pub.h"
#include "cryptohi.h"
#include "ScopedNSSTypes.h"
#include "mozilla/dom/CryptoKey.h"
#include "mozilla/dom/Key.h"
#include "mozilla/dom/WebCryptoCommon.h"
#include "mozilla/dom/SubtleCryptoBinding.h"
namespace mozilla {
namespace dom {
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(CryptoKey, mGlobal, mAlgorithm)
NS_IMPL_CYCLE_COLLECTING_ADDREF(CryptoKey)
NS_IMPL_CYCLE_COLLECTING_RELEASE(CryptoKey)
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(CryptoKey)
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(Key, mGlobal, mAlgorithm)
NS_IMPL_CYCLE_COLLECTING_ADDREF(Key)
NS_IMPL_CYCLE_COLLECTING_RELEASE(Key)
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(Key)
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
NS_INTERFACE_MAP_ENTRY(nsISupports)
NS_INTERFACE_MAP_END
nsresult
StringToUsage(const nsString& aUsage, CryptoKey::KeyUsage& aUsageOut)
StringToUsage(const nsString& aUsage, Key::KeyUsage& aUsageOut)
{
if (aUsage.EqualsLiteral(WEBCRYPTO_KEY_USAGE_ENCRYPT)) {
aUsageOut = CryptoKey::ENCRYPT;
aUsageOut = Key::ENCRYPT;
} else if (aUsage.EqualsLiteral(WEBCRYPTO_KEY_USAGE_DECRYPT)) {
aUsageOut = CryptoKey::DECRYPT;
aUsageOut = Key::DECRYPT;
} else if (aUsage.EqualsLiteral(WEBCRYPTO_KEY_USAGE_SIGN)) {
aUsageOut = CryptoKey::SIGN;
aUsageOut = Key::SIGN;
} else if (aUsage.EqualsLiteral(WEBCRYPTO_KEY_USAGE_VERIFY)) {
aUsageOut = CryptoKey::VERIFY;
aUsageOut = Key::VERIFY;
} else if (aUsage.EqualsLiteral(WEBCRYPTO_KEY_USAGE_DERIVEKEY)) {
aUsageOut = CryptoKey::DERIVEKEY;
aUsageOut = Key::DERIVEKEY;
} else if (aUsage.EqualsLiteral(WEBCRYPTO_KEY_USAGE_DERIVEBITS)) {
aUsageOut = CryptoKey::DERIVEBITS;
aUsageOut = Key::DERIVEBITS;
} else if (aUsage.EqualsLiteral(WEBCRYPTO_KEY_USAGE_WRAPKEY)) {
aUsageOut = CryptoKey::WRAPKEY;
aUsageOut = Key::WRAPKEY;
} else if (aUsage.EqualsLiteral(WEBCRYPTO_KEY_USAGE_UNWRAPKEY)) {
aUsageOut = CryptoKey::UNWRAPKEY;
aUsageOut = Key::UNWRAPKEY;
} else {
return NS_ERROR_DOM_SYNTAX_ERR;
}
return NS_OK;
}
CryptoKey::CryptoKey(nsIGlobalObject* aGlobal)
Key::Key(nsIGlobalObject* aGlobal)
: mGlobal(aGlobal)
, mAttributes(0)
, mSymKey()
@ -57,7 +57,7 @@ CryptoKey::CryptoKey(nsIGlobalObject* aGlobal)
SetIsDOMBinding();
}
CryptoKey::~CryptoKey()
Key::~Key()
{
nsNSSShutDownPreventionLock locker;
if (isAlreadyShutDown()) {
@ -68,13 +68,13 @@ CryptoKey::~CryptoKey()
}
JSObject*
CryptoKey::WrapObject(JSContext* aCx)
Key::WrapObject(JSContext* aCx)
{
return CryptoKeyBinding::Wrap(aCx, this);
return KeyBinding::Wrap(aCx, this);
}
void
CryptoKey::GetType(nsString& aRetVal) const
Key::GetType(nsString& aRetVal) const
{
uint32_t type = mAttributes & TYPE_MASK;
switch (type) {
@ -85,19 +85,19 @@ CryptoKey::GetType(nsString& aRetVal) const
}
bool
CryptoKey::Extractable() const
Key::Extractable() const
{
return (mAttributes & EXTRACTABLE);
}
KeyAlgorithm*
CryptoKey::Algorithm() const
Key::Algorithm() const
{
return mAlgorithm;
}
void
CryptoKey::GetUsages(nsTArray<nsString>& aRetVal) const
Key::GetUsages(nsTArray<nsString>& aRetVal) const
{
if (mAttributes & ENCRYPT) {
aRetVal.AppendElement(NS_LITERAL_STRING(WEBCRYPTO_KEY_USAGE_ENCRYPT));
@ -125,14 +125,14 @@ CryptoKey::GetUsages(nsTArray<nsString>& aRetVal) const
}
}
CryptoKey::KeyType
CryptoKey::GetKeyType() const
Key::KeyType
Key::GetKeyType() const
{
return static_cast<CryptoKey::KeyType>(mAttributes & TYPE_MASK);
return static_cast<Key::KeyType>(mAttributes & TYPE_MASK);
}
nsresult
CryptoKey::SetType(const nsString& aType)
Key::SetType(const nsString& aType)
{
mAttributes &= CLEAR_TYPE;
if (aType.EqualsLiteral(WEBCRYPTO_KEY_TYPE_SECRET)) {
@ -150,14 +150,14 @@ CryptoKey::SetType(const nsString& aType)
}
void
CryptoKey::SetType(CryptoKey::KeyType aType)
Key::SetType(Key::KeyType aType)
{
mAttributes &= CLEAR_TYPE;
mAttributes |= aType;
}
void
CryptoKey::SetExtractable(bool aExtractable)
Key::SetExtractable(bool aExtractable)
{
mAttributes &= CLEAR_EXTRACTABLE;
if (aExtractable) {
@ -166,25 +166,25 @@ CryptoKey::SetExtractable(bool aExtractable)
}
void
CryptoKey::SetAlgorithm(KeyAlgorithm* aAlgorithm)
Key::SetAlgorithm(KeyAlgorithm* aAlgorithm)
{
mAlgorithm = aAlgorithm;
}
void
CryptoKey::ClearUsages()
Key::ClearUsages()
{
mAttributes &= CLEAR_USAGES;
}
nsresult
CryptoKey::AddUsage(const nsString& aUsage)
Key::AddUsage(const nsString& aUsage)
{
return AddUsageIntersecting(aUsage, USAGES_MASK);
}
nsresult
CryptoKey::AddUsageIntersecting(const nsString& aUsage, uint32_t aUsageMask)
Key::AddUsageIntersecting(const nsString& aUsage, uint32_t aUsageMask)
{
KeyUsage usage;
if (NS_FAILED(StringToUsage(aUsage, usage))) {
@ -200,30 +200,30 @@ CryptoKey::AddUsageIntersecting(const nsString& aUsage, uint32_t aUsageMask)
}
void
CryptoKey::AddUsage(CryptoKey::KeyUsage aUsage)
Key::AddUsage(Key::KeyUsage aUsage)
{
mAttributes |= aUsage;
}
bool
CryptoKey::HasUsage(CryptoKey::KeyUsage aUsage)
Key::HasUsage(Key::KeyUsage aUsage)
{
return !!(mAttributes & aUsage);
}
bool
CryptoKey::HasUsageOtherThan(uint32_t aUsages)
Key::HasUsageOtherThan(uint32_t aUsages)
{
return !!(mAttributes & USAGES_MASK & ~aUsages);
}
void CryptoKey::SetSymKey(const CryptoBuffer& aSymKey)
void Key::SetSymKey(const CryptoBuffer& aSymKey)
{
mSymKey = aSymKey;
}
void
CryptoKey::SetPrivateKey(SECKEYPrivateKey* aPrivateKey)
Key::SetPrivateKey(SECKEYPrivateKey* aPrivateKey)
{
nsNSSShutDownPreventionLock locker;
if (!aPrivateKey || isAlreadyShutDown()) {
@ -234,7 +234,7 @@ CryptoKey::SetPrivateKey(SECKEYPrivateKey* aPrivateKey)
}
void
CryptoKey::SetPublicKey(SECKEYPublicKey* aPublicKey)
Key::SetPublicKey(SECKEYPublicKey* aPublicKey)
{
nsNSSShutDownPreventionLock locker;
if (!aPublicKey || isAlreadyShutDown()) {
@ -245,13 +245,13 @@ CryptoKey::SetPublicKey(SECKEYPublicKey* aPublicKey)
}
const CryptoBuffer&
CryptoKey::GetSymKey() const
Key::GetSymKey() const
{
return mSymKey;
}
SECKEYPrivateKey*
CryptoKey::GetPrivateKey() const
Key::GetPrivateKey() const
{
nsNSSShutDownPreventionLock locker;
if (!mPrivateKey || isAlreadyShutDown()) {
@ -261,7 +261,7 @@ CryptoKey::GetPrivateKey() const
}
SECKEYPublicKey*
CryptoKey::GetPublicKey() const
Key::GetPublicKey() const
{
nsNSSShutDownPreventionLock locker;
if (!mPublicKey || isAlreadyShutDown()) {
@ -270,12 +270,12 @@ CryptoKey::GetPublicKey() const
return SECKEY_CopyPublicKey(mPublicKey.get());
}
void CryptoKey::virtualDestroyNSSReference()
void Key::virtualDestroyNSSReference()
{
destructorSafeDestroyNSSReference();
}
void CryptoKey::destructorSafeDestroyNSSReference()
void Key::destructorSafeDestroyNSSReference()
{
mPrivateKey.dispose();
mPublicKey.dispose();
@ -285,7 +285,7 @@ void CryptoKey::destructorSafeDestroyNSSReference()
// Serialization and deserialization convenience methods
SECKEYPrivateKey*
CryptoKey::PrivateKeyFromPkcs8(CryptoBuffer& aKeyData,
Key::PrivateKeyFromPkcs8(CryptoBuffer& aKeyData,
const nsNSSShutDownPreventionLock& /*proofOfLock*/)
{
SECKEYPrivateKey* privKey;
@ -309,7 +309,7 @@ CryptoKey::PrivateKeyFromPkcs8(CryptoBuffer& aKeyData,
}
SECKEYPublicKey*
CryptoKey::PublicKeyFromSpki(CryptoBuffer& aKeyData,
Key::PublicKeyFromSpki(CryptoBuffer& aKeyData,
const nsNSSShutDownPreventionLock& /*proofOfLock*/)
{
ScopedSECItem spkiItem(aKeyData.ToSECItem());
@ -326,7 +326,7 @@ CryptoKey::PublicKeyFromSpki(CryptoBuffer& aKeyData,
}
nsresult
CryptoKey::PrivateKeyToPkcs8(SECKEYPrivateKey* aPrivKey,
Key::PrivateKeyToPkcs8(SECKEYPrivateKey* aPrivKey,
CryptoBuffer& aRetVal,
const nsNSSShutDownPreventionLock& /*proofOfLock*/)
{
@ -339,7 +339,7 @@ CryptoKey::PrivateKeyToPkcs8(SECKEYPrivateKey* aPrivKey,
}
nsresult
CryptoKey::PublicKeyToSpki(SECKEYPublicKey* aPubKey,
Key::PublicKeyToSpki(SECKEYPublicKey* aPubKey,
CryptoBuffer& aRetVal,
const nsNSSShutDownPreventionLock& /*proofOfLock*/)
{
@ -353,7 +353,7 @@ CryptoKey::PublicKeyToSpki(SECKEYPublicKey* aPubKey,
}
bool
CryptoKey::WriteStructuredClone(JSStructuredCloneWriter* aWriter) const
Key::WriteStructuredClone(JSStructuredCloneWriter* aWriter) const
{
nsNSSShutDownPreventionLock locker;
if (isAlreadyShutDown()) {
@ -369,11 +369,11 @@ CryptoKey::WriteStructuredClone(JSStructuredCloneWriter* aWriter) const
CryptoBuffer priv, pub;
if (mPrivateKey) {
CryptoKey::PrivateKeyToPkcs8(mPrivateKey, priv, locker);
Key::PrivateKeyToPkcs8(mPrivateKey, priv, locker);
}
if (mPublicKey) {
CryptoKey::PublicKeyToSpki(mPublicKey, pub, locker);
Key::PublicKeyToSpki(mPublicKey, pub, locker);
}
return JS_WriteUint32Pair(aWriter, mAttributes, 0) &&
@ -384,7 +384,7 @@ CryptoKey::WriteStructuredClone(JSStructuredCloneWriter* aWriter) const
}
bool
CryptoKey::ReadStructuredClone(JSStructuredCloneReader* aReader)
Key::ReadStructuredClone(JSStructuredCloneReader* aReader)
{
nsNSSShutDownPreventionLock locker;
if (isAlreadyShutDown()) {
@ -408,10 +408,10 @@ CryptoKey::ReadStructuredClone(JSStructuredCloneReader* aReader)
mSymKey = sym;
}
if (priv.Length() > 0) {
mPrivateKey = CryptoKey::PrivateKeyFromPkcs8(priv, locker);
mPrivateKey = Key::PrivateKeyFromPkcs8(priv, locker);
}
if (pub.Length() > 0) {
mPublicKey = CryptoKey::PublicKeyFromSpki(pub, locker);
mPublicKey = Key::PublicKeyFromSpki(pub, locker);
}
mAlgorithm = algorithm;

View File

@ -4,8 +4,8 @@
* 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/. */
#ifndef mozilla_dom_CryptoKey_h
#define mozilla_dom_CryptoKey_h
#ifndef mozilla_dom_Key_h
#define mozilla_dom_Key_h
#include "nsCycleCollectionParticipant.h"
#include "nsWrapperCache.h"
@ -49,17 +49,17 @@ In the order of a hex value for a uint32_t
Thus, internally, a key has the following fields:
* uint32_t - flags for extractable, usage, type
* KeyAlgorithm - the algorithm (which must serialize/deserialize itself)
* The actual keys (which the CryptoKey must serialize)
* The actual keys (which the Key must serialize)
*/
class CryptoKey MOZ_FINAL : public nsISupports,
public nsWrapperCache,
public nsNSSShutDownObject
class Key MOZ_FINAL : public nsISupports,
public nsWrapperCache,
public nsNSSShutDownObject
{
public:
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(CryptoKey)
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(Key)
static const uint32_t CLEAR_EXTRACTABLE = 0xFFFFFFE;
static const uint32_t EXTRACTABLE = 0x00000001;
@ -86,7 +86,7 @@ public:
UNWRAPKEY = 0x00800000
};
CryptoKey(nsIGlobalObject* aWindow);
Key(nsIGlobalObject* aWindow);
nsIGlobalObject* GetParentObject() const
{
@ -154,7 +154,7 @@ public:
bool ReadStructuredClone(JSStructuredCloneReader* aReader);
private:
~CryptoKey();
~Key();
nsRefPtr<nsIGlobalObject> mGlobal;
uint32_t mAttributes; // see above
@ -169,4 +169,4 @@ private:
} // namespace dom
} // namespace mozilla
#endif // mozilla_dom_CryptoKey_h
#endif // mozilla_dom_Key_h

View File

@ -18,7 +18,7 @@
namespace mozilla {
namespace dom {
class CryptoKey;
class Key;
class KeyAlgorithm;
enum KeyAlgorithmStructuredCloneTags {

View File

@ -4,7 +4,7 @@
* 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/. */
#include "mozilla/dom/CryptoKeyPair.h"
#include "mozilla/dom/KeyPair.h"
#include "mozilla/dom/SubtleCryptoBinding.h"
#include "nsContentUtils.h"
@ -12,18 +12,18 @@ namespace mozilla {
namespace dom {
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(CryptoKeyPair, mGlobal, mPublicKey, mPrivateKey)
NS_IMPL_CYCLE_COLLECTING_ADDREF(CryptoKeyPair)
NS_IMPL_CYCLE_COLLECTING_RELEASE(CryptoKeyPair)
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(CryptoKeyPair)
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(KeyPair, mGlobal, mPublicKey, mPrivateKey)
NS_IMPL_CYCLE_COLLECTING_ADDREF(KeyPair)
NS_IMPL_CYCLE_COLLECTING_RELEASE(KeyPair)
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(KeyPair)
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
NS_INTERFACE_MAP_ENTRY(nsISupports)
NS_INTERFACE_MAP_END
JSObject*
CryptoKeyPair::WrapObject(JSContext* aCx)
KeyPair::WrapObject(JSContext* aCx)
{
return CryptoKeyPairBinding::Wrap(aCx, this);
return KeyPairBinding::Wrap(aCx, this);
}

View File

@ -4,30 +4,30 @@
* 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/. */
#ifndef mozilla_dom_CryptoKeyPair_h
#define mozilla_dom_CryptoKeyPair_h
#ifndef mozilla_dom_KeyPair_h
#define mozilla_dom_KeyPair_h
#include "nsCycleCollectionParticipant.h"
#include "nsWrapperCache.h"
#include "nsIGlobalObject.h"
#include "mozilla/dom/CryptoKey.h"
#include "mozilla/dom/Key.h"
#include "js/TypeDecls.h"
namespace mozilla {
namespace dom {
class CryptoKeyPair MOZ_FINAL : public nsISupports,
public nsWrapperCache
class KeyPair MOZ_FINAL : public nsISupports,
public nsWrapperCache
{
public:
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(CryptoKeyPair)
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(KeyPair)
public:
CryptoKeyPair(nsIGlobalObject* aGlobal)
KeyPair(nsIGlobalObject* aGlobal)
: mGlobal(aGlobal)
, mPublicKey(new CryptoKey(aGlobal))
, mPrivateKey(new CryptoKey(aGlobal))
, mPublicKey(new Key(aGlobal))
, mPrivateKey(new Key(aGlobal))
{
SetIsDOMBinding();
}
@ -39,25 +39,25 @@ public:
virtual JSObject* WrapObject(JSContext* aCx) MOZ_OVERRIDE;
CryptoKey* PublicKey() const
Key* PublicKey() const
{
return mPublicKey;
}
CryptoKey* PrivateKey() const
Key* PrivateKey() const
{
return mPrivateKey;
}
private:
~CryptoKeyPair() {}
~KeyPair() {}
nsRefPtr<nsIGlobalObject> mGlobal;
nsRefPtr<CryptoKey> mPublicKey;
nsRefPtr<CryptoKey> mPrivateKey;
nsRefPtr<Key> mPublicKey;
nsRefPtr<Key> mPrivateKey;
};
} // namespace dom
} // namespace mozilla
#endif // mozilla_dom_CryptoKeyPair_h
#endif // mozilla_dom_KeyPair_h

View File

@ -11,9 +11,9 @@
#include "mozilla/dom/WebCryptoTask.h"
#include "mozilla/dom/TypedArray.h"
#include "mozilla/dom/CryptoKey.h"
#include "mozilla/dom/Key.h"
#include "mozilla/dom/KeyAlgorithm.h"
#include "mozilla/dom/CryptoKeyPair.h"
#include "mozilla/dom/KeyPair.h"
#include "mozilla/dom/AesKeyAlgorithm.h"
#include "mozilla/dom/HmacKeyAlgorithm.h"
#include "mozilla/dom/RsaKeyAlgorithm.h"
@ -231,7 +231,7 @@ class AesTask : public ReturnArrayBufferViewTask
{
public:
AesTask(JSContext* aCx, const ObjectOrString& aAlgorithm,
mozilla::dom::CryptoKey& aKey, const CryptoOperationData& aData,
mozilla::dom::Key& aKey, const CryptoOperationData& aData,
bool aEncrypt)
: mSymKey(aKey.GetSymKey())
, mEncrypt(aEncrypt)
@ -408,7 +408,7 @@ class RsaesPkcs1Task : public ReturnArrayBufferViewTask
{
public:
RsaesPkcs1Task(JSContext* aCx, const ObjectOrString& aAlgorithm,
mozilla::dom::CryptoKey& aKey, const CryptoOperationData& aData,
mozilla::dom::Key& aKey, const CryptoOperationData& aData,
bool aEncrypt)
: mPrivKey(aKey.GetPrivateKey())
, mPubKey(aKey.GetPublicKey())
@ -481,7 +481,7 @@ class HmacTask : public WebCryptoTask
{
public:
HmacTask(JSContext* aCx, const ObjectOrString& aAlgorithm,
mozilla::dom::CryptoKey& aKey,
mozilla::dom::Key& aKey,
const CryptoOperationData& aSignature,
const CryptoOperationData& aData,
bool aSign)
@ -584,7 +584,7 @@ class RsassaPkcs1Task : public WebCryptoTask
{
public:
RsassaPkcs1Task(JSContext* aCx, const ObjectOrString& aAlgorithm,
mozilla::dom::CryptoKey& aKey,
mozilla::dom::Key& aKey,
const CryptoOperationData& aSignature,
const CryptoOperationData& aData,
bool aSign)
@ -775,7 +775,7 @@ public:
}
// This stuff pretty much always happens, so we'll do it here
mKey = new CryptoKey(global);
mKey = new Key(global);
mKey->SetExtractable(aExtractable);
mKey->ClearUsages();
for (uint32_t i = 0; i < aKeyUsages.Length(); ++i) {
@ -793,7 +793,7 @@ public:
}
protected:
nsRefPtr<CryptoKey> mKey;
nsRefPtr<Key> mKey;
nsString mAlgName;
private:
@ -867,7 +867,7 @@ public:
if (mAlgName.EqualsLiteral(WEBCRYPTO_ALG_AES_CBC) ||
mAlgName.EqualsLiteral(WEBCRYPTO_ALG_AES_CTR) ||
mAlgName.EqualsLiteral(WEBCRYPTO_ALG_AES_GCM)) {
if (mKey->HasUsageOtherThan(CryptoKey::ENCRYPT | CryptoKey::DECRYPT)) {
if (mKey->HasUsageOtherThan(Key::ENCRYPT | Key::DECRYPT)) {
return NS_ERROR_DOM_DATA_ERR;
}
@ -876,7 +876,7 @@ public:
}
algorithm = new AesKeyAlgorithm(global, mAlgName, length);
} else if (mAlgName.EqualsLiteral(WEBCRYPTO_ALG_HMAC)) {
if (mKey->HasUsageOtherThan(CryptoKey::SIGN | CryptoKey::VERIFY)) {
if (mKey->HasUsageOtherThan(Key::SIGN | Key::VERIFY)) {
return NS_ERROR_DOM_DATA_ERR;
}
@ -890,7 +890,7 @@ public:
mKey->SetAlgorithm(algorithm);
mKey->SetSymKey(mKeyData);
mKey->SetType(CryptoKey::SECRET);
mKey->SetType(Key::SECRET);
mEarlyComplete = true;
return NS_OK;
}
@ -957,19 +957,19 @@ private:
// Import the key data itself
ScopedSECKEYPublicKey pubKey;
if (mFormat.EqualsLiteral(WEBCRYPTO_KEY_FORMAT_PKCS8)) {
ScopedSECKEYPrivateKey privKey(CryptoKey::PrivateKeyFromPkcs8(mKeyData, locker));
ScopedSECKEYPrivateKey privKey(Key::PrivateKeyFromPkcs8(mKeyData, locker));
if (!privKey.get()) {
return NS_ERROR_DOM_DATA_ERR;
}
mKey->SetPrivateKey(privKey.get());
mKey->SetType(CryptoKey::PRIVATE);
mKey->SetType(Key::PRIVATE);
pubKey = SECKEY_ConvertToPublicKey(privKey.get());
if (!pubKey) {
return NS_ERROR_DOM_UNKNOWN_ERR;
}
} else if (mFormat.EqualsLiteral(WEBCRYPTO_KEY_FORMAT_SPKI)) {
pubKey = CryptoKey::PublicKeyFromSpki(mKeyData, locker);
pubKey = Key::PublicKeyFromSpki(mKeyData, locker);
if (!pubKey.get()) {
return NS_ERROR_DOM_DATA_ERR;
}
@ -979,7 +979,7 @@ private:
}
mKey->SetPublicKey(pubKey.get());
mKey->SetType(CryptoKey::PUBLIC);
mKey->SetType(Key::PUBLIC);
} else if (mFormat.EqualsLiteral(WEBCRYPTO_KEY_FORMAT_JWK)) {
return NS_ERROR_DOM_NOT_SUPPORTED_ERR;
} else {
@ -999,19 +999,19 @@ private:
// Construct an appropriate KeyAlgorithm
nsIGlobalObject* global = mKey->GetParentObject();
if (mAlgName.EqualsLiteral(WEBCRYPTO_ALG_RSAES_PKCS1)) {
if ((mKey->GetKeyType() == CryptoKey::PUBLIC &&
mKey->HasUsageOtherThan(CryptoKey::ENCRYPT)) ||
(mKey->GetKeyType() == CryptoKey::PRIVATE &&
mKey->HasUsageOtherThan(CryptoKey::DECRYPT))) {
if ((mKey->GetKeyType() == Key::PUBLIC &&
mKey->HasUsageOtherThan(Key::ENCRYPT)) ||
(mKey->GetKeyType() == Key::PRIVATE &&
mKey->HasUsageOtherThan(Key::DECRYPT))) {
return NS_ERROR_DOM_DATA_ERR;
}
mKey->SetAlgorithm(new RsaKeyAlgorithm(global, mAlgName, mModulusLength, mPublicExponent));
} else if (mAlgName.EqualsLiteral(WEBCRYPTO_ALG_RSASSA_PKCS1)) {
if ((mKey->GetKeyType() == CryptoKey::PUBLIC &&
mKey->HasUsageOtherThan(CryptoKey::VERIFY)) ||
(mKey->GetKeyType() == CryptoKey::PRIVATE &&
mKey->HasUsageOtherThan(CryptoKey::SIGN))) {
if ((mKey->GetKeyType() == Key::PUBLIC &&
mKey->HasUsageOtherThan(Key::VERIFY)) ||
(mKey->GetKeyType() == Key::PRIVATE &&
mKey->HasUsageOtherThan(Key::SIGN))) {
return NS_ERROR_DOM_DATA_ERR;
}
@ -1035,7 +1035,7 @@ private:
class UnifiedExportKeyTask : public ReturnArrayBufferViewTask
{
public:
UnifiedExportKeyTask(const nsAString& aFormat, CryptoKey& aKey)
UnifiedExportKeyTask(const nsAString& aFormat, Key& aKey)
: mFormat(aFormat)
, mSymKey(aKey.GetSymKey())
, mPrivateKey(aKey.GetPrivateKey())
@ -1078,7 +1078,7 @@ private:
switch (mPrivateKey->keyType) {
case rsaKey:
CryptoKey::PrivateKeyToPkcs8(mPrivateKey.get(), mResult, locker);
Key::PrivateKeyToPkcs8(mPrivateKey.get(), mResult, locker);
return NS_OK;
default:
return NS_ERROR_DOM_NOT_SUPPORTED_ERR;
@ -1088,7 +1088,7 @@ private:
return NS_ERROR_DOM_NOT_SUPPORTED_ERR;
}
return CryptoKey::PublicKeyToSpki(mPublicKey.get(), mResult, locker);
return Key::PublicKeyToSpki(mPublicKey.get(), mResult, locker);
} else if (mFormat.EqualsLiteral(WEBCRYPTO_KEY_FORMAT_JWK)) {
return NS_ERROR_DOM_NOT_SUPPORTED_ERR;
}
@ -1111,9 +1111,9 @@ public:
}
// Create an empty key and set easy attributes
mKey = new CryptoKey(global);
mKey = new Key(global);
mKey->SetExtractable(aExtractable);
mKey->SetType(CryptoKey::SECRET);
mKey->SetType(Key::SECRET);
// Extract algorithm name
nsString algName;
@ -1142,7 +1142,7 @@ public:
return;
}
algorithm = new AesKeyAlgorithm(global, algName, mLength);
allowedUsages = CryptoKey::ENCRYPT | CryptoKey::DECRYPT;
allowedUsages = Key::ENCRYPT | Key::DECRYPT;
} else if (algName.EqualsLiteral(WEBCRYPTO_ALG_HMAC)) {
RootedDictionary<HmacKeyGenParams> params(aCx);
mEarlyRv = Coerce(aCx, params, aAlgorithm);
@ -1189,7 +1189,7 @@ public:
}
algorithm = new HmacKeyAlgorithm(global, algName, mLength, hashName);
allowedUsages = CryptoKey::SIGN | CryptoKey::VERIFY;
allowedUsages = Key::SIGN | Key::VERIFY;
} else {
mEarlyRv = NS_ERROR_DOM_NOT_SUPPORTED_ERR;
return;
@ -1211,7 +1211,7 @@ public:
}
private:
nsRefPtr<CryptoKey> mKey;
nsRefPtr<Key> mKey;
size_t mLength;
CK_MECHANISM_TYPE mMechanism;
CryptoBuffer mKeyData;
@ -1263,7 +1263,7 @@ public:
}
// Create an empty key and set easy attributes
mKeyPair = new CryptoKeyPair(global);
mKeyPair = new KeyPair(global);
// Extract algorithm name
nsString algName;
@ -1312,8 +1312,8 @@ public:
return;
}
privateAllowedUsages = CryptoKey::SIGN;
publicAllowedUsages = CryptoKey::VERIFY;
privateAllowedUsages = Key::SIGN;
publicAllowedUsages = Key::VERIFY;
} else if (algName.EqualsLiteral(WEBCRYPTO_ALG_RSAES_PKCS1)) {
RootedDictionary<RsaKeyGenParams> params(aCx);
mEarlyRv = Coerce(aCx, params, aAlgorithm);
@ -1343,18 +1343,18 @@ public:
return;
}
privateAllowedUsages = CryptoKey::DECRYPT | CryptoKey::UNWRAPKEY;
publicAllowedUsages = CryptoKey::ENCRYPT | CryptoKey::WRAPKEY;
privateAllowedUsages = Key::DECRYPT | Key::UNWRAPKEY;
publicAllowedUsages = Key::ENCRYPT | Key::WRAPKEY;
} else {
mEarlyRv = NS_ERROR_DOM_NOT_SUPPORTED_ERR;
return;
}
mKeyPair->PrivateKey()->SetExtractable(aExtractable);
mKeyPair->PrivateKey()->SetType(CryptoKey::PRIVATE);
mKeyPair->PrivateKey()->SetType(Key::PRIVATE);
mKeyPair->PublicKey()->SetExtractable(true);
mKeyPair->PublicKey()->SetType(CryptoKey::PUBLIC);
mKeyPair->PublicKey()->SetType(Key::PUBLIC);
mKeyPair->PrivateKey()->ClearUsages();
mKeyPair->PublicKey()->ClearUsages();
@ -1374,7 +1374,7 @@ public:
}
private:
nsRefPtr<CryptoKeyPair> mKeyPair;
nsRefPtr<KeyPair> mKeyPair;
CK_MECHANISM_TYPE mMechanism;
PK11RSAGenParams mRsaParams;
ScopedSECKEYPublicKey mPublicKey;
@ -1427,7 +1427,7 @@ private:
WebCryptoTask*
WebCryptoTask::EncryptDecryptTask(JSContext* aCx,
const ObjectOrString& aAlgorithm,
CryptoKey& aKey,
Key& aKey,
const CryptoOperationData& aData,
bool aEncrypt)
{
@ -1442,8 +1442,8 @@ WebCryptoTask::EncryptDecryptTask(JSContext* aCx,
}
// Ensure key is usable for this operation
if ((aEncrypt && !aKey.HasUsage(CryptoKey::ENCRYPT)) ||
(!aEncrypt && !aKey.HasUsage(CryptoKey::DECRYPT))) {
if ((aEncrypt && !aKey.HasUsage(Key::ENCRYPT)) ||
(!aEncrypt && !aKey.HasUsage(Key::DECRYPT))) {
return new FailureTask(NS_ERROR_DOM_INVALID_ACCESS_ERR);
}
@ -1461,7 +1461,7 @@ WebCryptoTask::EncryptDecryptTask(JSContext* aCx,
WebCryptoTask*
WebCryptoTask::SignVerifyTask(JSContext* aCx,
const ObjectOrString& aAlgorithm,
CryptoKey& aKey,
Key& aKey,
const CryptoOperationData& aSignature,
const CryptoOperationData& aData,
bool aSign)
@ -1477,8 +1477,8 @@ WebCryptoTask::SignVerifyTask(JSContext* aCx,
}
// Ensure key is usable for this operation
if ((aSign && !aKey.HasUsage(CryptoKey::SIGN)) ||
(!aSign && !aKey.HasUsage(CryptoKey::VERIFY))) {
if ((aSign && !aKey.HasUsage(Key::SIGN)) ||
(!aSign && !aKey.HasUsage(Key::VERIFY))) {
return new FailureTask(NS_ERROR_DOM_INVALID_ACCESS_ERR);
}
@ -1534,7 +1534,7 @@ WebCryptoTask::ImportKeyTask(JSContext* aCx,
WebCryptoTask*
WebCryptoTask::ExportKeyTask(const nsAString& aFormat,
CryptoKey& aKey)
Key& aKey)
{
Telemetry::Accumulate(Telemetry::WEBCRYPTO_METHOD, TM_EXPORTKEY);
@ -1576,7 +1576,7 @@ WebCryptoTask::GenerateKeyTask(JSContext* aCx,
WebCryptoTask*
WebCryptoTask::DeriveKeyTask(JSContext* aCx,
const ObjectOrString& aAlgorithm,
CryptoKey& aBaseKey,
Key& aBaseKey,
const ObjectOrString& aDerivedKeyType,
bool aExtractable,
const Sequence<nsString>& aKeyUsages)
@ -1588,7 +1588,7 @@ WebCryptoTask::DeriveKeyTask(JSContext* aCx,
WebCryptoTask*
WebCryptoTask::DeriveBitsTask(JSContext* aCx,
const ObjectOrString& aAlgorithm,
CryptoKey& aKey,
Key& aKey,
uint32_t aLength)
{
Telemetry::Accumulate(Telemetry::WEBCRYPTO_METHOD, TM_DERIVEBITS);

View File

@ -13,7 +13,7 @@
#include "mozilla/dom/Promise.h"
#include "mozilla/dom/DOMException.h"
#include "mozilla/dom/SubtleCryptoBinding.h"
#include "mozilla/dom/CryptoKey.h"
#include "mozilla/dom/Key.h"
namespace mozilla {
namespace dom {
@ -87,13 +87,13 @@ public:
protected:
static WebCryptoTask* EncryptDecryptTask(JSContext* aCx,
const ObjectOrString& aAlgorithm,
CryptoKey& aKey,
Key& aKey,
const CryptoOperationData& aData,
bool aEncrypt);
static WebCryptoTask* SignVerifyTask(JSContext* aCx,
const ObjectOrString& aAlgorithm,
CryptoKey& aKey,
Key& aKey,
const CryptoOperationData& aSignature,
const CryptoOperationData& aData,
bool aSign);
@ -101,7 +101,7 @@ protected:
public:
static WebCryptoTask* EncryptTask(JSContext* aCx,
const ObjectOrString& aAlgorithm,
CryptoKey& aKey,
Key& aKey,
const CryptoOperationData& aData)
{
return EncryptDecryptTask(aCx, aAlgorithm, aKey, aData, true);
@ -109,7 +109,7 @@ public:
static WebCryptoTask* DecryptTask(JSContext* aCx,
const ObjectOrString& aAlgorithm,
CryptoKey& aKey,
Key& aKey,
const CryptoOperationData& aData)
{
return EncryptDecryptTask(aCx, aAlgorithm, aKey, aData, false);
@ -117,7 +117,7 @@ public:
static WebCryptoTask* SignTask(JSContext* aCx,
const ObjectOrString& aAlgorithm,
CryptoKey& aKey,
Key& aKey,
const CryptoOperationData& aData)
{
CryptoOperationData dummy;
@ -127,7 +127,7 @@ public:
static WebCryptoTask* VerifyTask(JSContext* aCx,
const ObjectOrString& aAlgorithm,
CryptoKey& aKey,
Key& aKey,
const CryptoOperationData& aSignature,
const CryptoOperationData& aData)
{
@ -145,7 +145,7 @@ public:
bool aExtractable,
const Sequence<nsString>& aKeyUsages);
static WebCryptoTask* ExportKeyTask(const nsAString& aFormat,
CryptoKey& aKey);
Key& aKey);
static WebCryptoTask* GenerateKeyTask(JSContext* aCx,
const ObjectOrString& aAlgorithm,
bool aExtractable,
@ -153,13 +153,13 @@ public:
static WebCryptoTask* DeriveKeyTask(JSContext* aCx,
const ObjectOrString& aAlgorithm,
CryptoKey& aBaseKey,
Key& aBaseKey,
const ObjectOrString& aDerivedKeyType,
bool extractable,
const Sequence<nsString>& aKeyUsages);
static WebCryptoTask* DeriveBitsTask(JSContext* aCx,
const ObjectOrString& aAlgorithm,
CryptoKey& aKey,
Key& aKey,
uint32_t aLength);
protected:

View File

@ -9,10 +9,10 @@ TEST_DIRS += ['test']
EXPORTS.mozilla.dom += [
'AesKeyAlgorithm.h',
'CryptoBuffer.h',
'CryptoKey.h',
'CryptoKeyPair.h',
'HmacKeyAlgorithm.h',
'Key.h',
'KeyAlgorithm.h',
'KeyPair.h',
'RsaHashedKeyAlgorithm.h',
'RsaKeyAlgorithm.h',
'WebCryptoCommon.h',
@ -22,10 +22,10 @@ EXPORTS.mozilla.dom += [
UNIFIED_SOURCES += [
'AesKeyAlgorithm.cpp',
'CryptoBuffer.cpp',
'CryptoKey.cpp',
'CryptoKeyPair.cpp',
'HmacKeyAlgorithm.cpp',
'Key.cpp',
'KeyAlgorithm.cpp',
'KeyPair.cpp',
'RsaHashedKeyAlgorithm.cpp',
'RsaKeyAlgorithm.cpp',
'WebCryptoTask.cpp',

View File

@ -102,7 +102,7 @@ dictionary EcKeyGenParams : Algorithm {
/***** The Main API *****/
[Pref="dom.webcrypto.enabled"]
interface CryptoKey {
interface Key {
readonly attribute KeyType type;
readonly attribute boolean extractable;
readonly attribute KeyAlgorithm algorithm;
@ -110,9 +110,9 @@ interface CryptoKey {
};
[Pref="dom.webcrypto.enabled"]
interface CryptoKeyPair {
readonly attribute CryptoKey publicKey;
readonly attribute CryptoKey privateKey;
interface KeyPair {
readonly attribute Key publicKey;
readonly attribute Key privateKey;
};
typedef DOMString KeyFormat;
@ -123,16 +123,16 @@ typedef (object or DOMString) AlgorithmIdentifier;
[Pref="dom.webcrypto.enabled"]
interface SubtleCrypto {
Promise encrypt(AlgorithmIdentifier algorithm,
CryptoKey key,
Key key,
CryptoOperationData data);
Promise decrypt(AlgorithmIdentifier algorithm,
CryptoKey key,
Key key,
CryptoOperationData data);
Promise sign(AlgorithmIdentifier algorithm,
CryptoKey key,
Key key,
CryptoOperationData data);
Promise verify(AlgorithmIdentifier algorithm,
CryptoKey key,
Key key,
CryptoOperationData signature,
CryptoOperationData data);
Promise digest(AlgorithmIdentifier algorithm,
@ -142,12 +142,12 @@ interface SubtleCrypto {
boolean extractable,
sequence<KeyUsage> keyUsages );
Promise deriveKey(AlgorithmIdentifier algorithm,
CryptoKey baseKey,
Key baseKey,
AlgorithmIdentifier derivedKeyType,
boolean extractable,
sequence<KeyUsage> keyUsages );
Promise deriveBits(AlgorithmIdentifier algorithm,
CryptoKey baseKey,
Key baseKey,
unsigned long length);
Promise importKey(KeyFormat format,
@ -155,6 +155,6 @@ interface SubtleCrypto {
AlgorithmIdentifier algorithm,
boolean extractable,
sequence<KeyUsage> keyUsages );
Promise exportKey(KeyFormat format, CryptoKey key);
Promise exportKey(KeyFormat format, Key key);
};