Check WebCrypto parameter types when casting
authorap@apple.com <ap@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 13 Nov 2013 19:33:15 +0000 (19:33 +0000)
committerap@apple.com <ap@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 13 Nov 2013 19:33:15 +0000 (19:33 +0000)
https://bugs.webkit.org/show_bug.cgi?id=124297

Reviewed by Sam Weinig.

Also changed existing toCryptoXXX functions to use TYPE_CASTS_BASE mechanism.

* bindings/js/JSCryptoAlgorithmDictionary.cpp:
(WebCore::JSCryptoAlgorithmDictionary::createParametersForImportKey):
And sure enough, there was a bug caught by the added checks.

* bindings/js/JSCryptoKeySerializationJWK.cpp:
(WebCore::JSCryptoKeySerializationJWK::reconcileAlgorithm):
* crypto/CryptoAlgorithmParameters.h:
(WebCore::CryptoAlgorithmParameters::ENUM_CLASS):
(WebCore::CryptoAlgorithmParameters::parametersClass):
* crypto/CryptoKey.h:
* crypto/CryptoKeyData.h:
* crypto/CryptoKeySerialization.h:
* crypto/algorithms/CryptoAlgorithmAES_CBC.cpp:
(WebCore::CryptoAlgorithmAES_CBC::generateKey):
* crypto/algorithms/CryptoAlgorithmHMAC.cpp:
(WebCore::CryptoAlgorithmHMAC::generateKey):
(WebCore::CryptoAlgorithmHMAC::importKey):
* crypto/algorithms/CryptoAlgorithmRSASSA_PKCS1_v1_5.cpp:
(WebCore::CryptoAlgorithmRSASSA_PKCS1_v1_5::importKey):
(WebCore::CryptoAlgorithmRSASSA_PKCS1_v1_5::generateKey):
* crypto/keys/CryptoKeyAES.h:
* crypto/keys/CryptoKeyDataOctetSequence.h:
(WebCore::isCryptoKeyDataOctetSequence):
* crypto/keys/CryptoKeyDataRSAComponents.h:
(WebCore::isCryptoKeyDataRSAComponents):
* crypto/keys/CryptoKeyHMAC.h:
* crypto/keys/CryptoKeyRSA.h:
* crypto/keys/CryptoKeySerializationRaw.h:
* crypto/mac/CryptoAlgorithmAES_CBCMac.cpp:
(WebCore::CryptoAlgorithmAES_CBC::encrypt):
(WebCore::CryptoAlgorithmAES_CBC::decrypt):
* crypto/mac/CryptoAlgorithmHMACMac.cpp:
(WebCore::CryptoAlgorithmHMAC::sign):
(WebCore::CryptoAlgorithmHMAC::verify):
* crypto/parameters/CryptoAlgorithmAesCbcParams.h:
* crypto/parameters/CryptoAlgorithmAesKeyGenParams.h:
* crypto/parameters/CryptoAlgorithmHmacKeyParams.h:
* crypto/parameters/CryptoAlgorithmHmacParams.h:
* crypto/parameters/CryptoAlgorithmRsaKeyGenParams.h:
* crypto/parameters/CryptoAlgorithmRsaSsaKeyParams.h:
* crypto/parameters/CryptoAlgorithmRsaSsaParams.h:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@159213 268f45cc-cd09-0410-ab3c-d52691b4dbfc

25 files changed:
Source/WebCore/ChangeLog
Source/WebCore/bindings/js/JSCryptoAlgorithmDictionary.cpp
Source/WebCore/bindings/js/JSCryptoKeySerializationJWK.cpp
Source/WebCore/crypto/CryptoAlgorithmParameters.h
Source/WebCore/crypto/CryptoKey.h
Source/WebCore/crypto/CryptoKeyData.h
Source/WebCore/crypto/CryptoKeySerialization.h
Source/WebCore/crypto/algorithms/CryptoAlgorithmAES_CBC.cpp
Source/WebCore/crypto/algorithms/CryptoAlgorithmHMAC.cpp
Source/WebCore/crypto/algorithms/CryptoAlgorithmRSASSA_PKCS1_v1_5.cpp
Source/WebCore/crypto/keys/CryptoKeyAES.h
Source/WebCore/crypto/keys/CryptoKeyDataOctetSequence.h
Source/WebCore/crypto/keys/CryptoKeyDataRSAComponents.h
Source/WebCore/crypto/keys/CryptoKeyHMAC.h
Source/WebCore/crypto/keys/CryptoKeyRSA.h
Source/WebCore/crypto/keys/CryptoKeySerializationRaw.h
Source/WebCore/crypto/mac/CryptoAlgorithmAES_CBCMac.cpp
Source/WebCore/crypto/mac/CryptoAlgorithmHMACMac.cpp
Source/WebCore/crypto/parameters/CryptoAlgorithmAesCbcParams.h
Source/WebCore/crypto/parameters/CryptoAlgorithmAesKeyGenParams.h
Source/WebCore/crypto/parameters/CryptoAlgorithmHmacKeyParams.h
Source/WebCore/crypto/parameters/CryptoAlgorithmHmacParams.h
Source/WebCore/crypto/parameters/CryptoAlgorithmRsaKeyGenParams.h
Source/WebCore/crypto/parameters/CryptoAlgorithmRsaSsaKeyParams.h
Source/WebCore/crypto/parameters/CryptoAlgorithmRsaSsaParams.h

index 221ab25..28654c3 100644 (file)
@@ -1,5 +1,56 @@
 2013-11-13  Alexey Proskuryakov  <ap@apple.com>
 
+        Check WebCrypto parameter types when casting
+        https://bugs.webkit.org/show_bug.cgi?id=124297
+
+        Reviewed by Sam Weinig.
+
+        Also changed existing toCryptoXXX functions to use TYPE_CASTS_BASE mechanism.
+
+        * bindings/js/JSCryptoAlgorithmDictionary.cpp:
+        (WebCore::JSCryptoAlgorithmDictionary::createParametersForImportKey):
+        And sure enough, there was a bug caught by the added checks.
+
+        * bindings/js/JSCryptoKeySerializationJWK.cpp:
+        (WebCore::JSCryptoKeySerializationJWK::reconcileAlgorithm):
+        * crypto/CryptoAlgorithmParameters.h:
+        (WebCore::CryptoAlgorithmParameters::ENUM_CLASS):
+        (WebCore::CryptoAlgorithmParameters::parametersClass):
+        * crypto/CryptoKey.h:
+        * crypto/CryptoKeyData.h:
+        * crypto/CryptoKeySerialization.h:
+        * crypto/algorithms/CryptoAlgorithmAES_CBC.cpp:
+        (WebCore::CryptoAlgorithmAES_CBC::generateKey):
+        * crypto/algorithms/CryptoAlgorithmHMAC.cpp:
+        (WebCore::CryptoAlgorithmHMAC::generateKey):
+        (WebCore::CryptoAlgorithmHMAC::importKey):
+        * crypto/algorithms/CryptoAlgorithmRSASSA_PKCS1_v1_5.cpp:
+        (WebCore::CryptoAlgorithmRSASSA_PKCS1_v1_5::importKey):
+        (WebCore::CryptoAlgorithmRSASSA_PKCS1_v1_5::generateKey):
+        * crypto/keys/CryptoKeyAES.h:
+        * crypto/keys/CryptoKeyDataOctetSequence.h:
+        (WebCore::isCryptoKeyDataOctetSequence):
+        * crypto/keys/CryptoKeyDataRSAComponents.h:
+        (WebCore::isCryptoKeyDataRSAComponents):
+        * crypto/keys/CryptoKeyHMAC.h:
+        * crypto/keys/CryptoKeyRSA.h:
+        * crypto/keys/CryptoKeySerializationRaw.h:
+        * crypto/mac/CryptoAlgorithmAES_CBCMac.cpp:
+        (WebCore::CryptoAlgorithmAES_CBC::encrypt):
+        (WebCore::CryptoAlgorithmAES_CBC::decrypt):
+        * crypto/mac/CryptoAlgorithmHMACMac.cpp:
+        (WebCore::CryptoAlgorithmHMAC::sign):
+        (WebCore::CryptoAlgorithmHMAC::verify):
+        * crypto/parameters/CryptoAlgorithmAesCbcParams.h:
+        * crypto/parameters/CryptoAlgorithmAesKeyGenParams.h:
+        * crypto/parameters/CryptoAlgorithmHmacKeyParams.h:
+        * crypto/parameters/CryptoAlgorithmHmacParams.h:
+        * crypto/parameters/CryptoAlgorithmRsaKeyGenParams.h:
+        * crypto/parameters/CryptoAlgorithmRsaSsaKeyParams.h:
+        * crypto/parameters/CryptoAlgorithmRsaSsaParams.h:
+
+2013-11-13  Alexey Proskuryakov  <ap@apple.com>
+
         crypto/subtle/rsassa-pkcs1-v1_5-import-jwk.html is failing on Maverics release bot
         https://bugs.webkit.org/show_bug.cgi?id=124280
 
index d9b354f..2b43997 100644 (file)
@@ -538,7 +538,7 @@ std::unique_ptr<CryptoAlgorithmParameters> JSCryptoAlgorithmDictionary::createPa
     case CryptoAlgorithmIdentifier::AES_CFB:
         return std::make_unique<CryptoAlgorithmParameters>();
     case CryptoAlgorithmIdentifier::HMAC:
-        return createHmacKeyParams(exec, value);
+        return createHmacParams(exec, value);
     case CryptoAlgorithmIdentifier::DH:
         return std::make_unique<CryptoAlgorithmParameters>();
     case CryptoAlgorithmIdentifier::SHA_1:
index 0226925..56cd308 100644 (file)
@@ -212,10 +212,10 @@ bool JSCryptoKeySerializationJWK::reconcileAlgorithm(std::unique_ptr<CryptoAlgor
         return false;
 
     if (algorithm->identifier() == CryptoAlgorithmIdentifier::HMAC)
-        return static_cast<CryptoAlgorithmHmacParams&>(*parameters).hash == static_cast<CryptoAlgorithmHmacParams&>(*suggestedParameters).hash;
+        return toCryptoAlgorithmHmacParams(*parameters).hash == toCryptoAlgorithmHmacParams(*suggestedParameters).hash;
     if (algorithm->identifier() == CryptoAlgorithmIdentifier::RSASSA_PKCS1_v1_5) {
-        CryptoAlgorithmRsaSsaKeyParams& rsaSSAParameters = static_cast<CryptoAlgorithmRsaSsaKeyParams&>(*parameters);
-        CryptoAlgorithmRsaSsaKeyParams& suggestedRSASSAParameters = static_cast<CryptoAlgorithmRsaSsaKeyParams&>(*suggestedParameters);
+        CryptoAlgorithmRsaSsaKeyParams& rsaSSAParameters = toCryptoAlgorithmRsaSsaKeyParams(*parameters);
+        CryptoAlgorithmRsaSsaKeyParams& suggestedRSASSAParameters = toCryptoAlgorithmRsaSsaKeyParams(*suggestedParameters);
         ASSERT(rsaSSAParameters.hasHash);
         if (suggestedRSASSAParameters.hasHash)
             return suggestedRSASSAParameters.hash == rsaSSAParameters.hash;
index fac08ce..b6fa77a 100644 (file)
@@ -37,8 +37,23 @@ class CryptoAlgorithmParameters {
 public:
     CryptoAlgorithmParameters() { }
     virtual ~CryptoAlgorithmParameters() { }
+
+    ENUM_CLASS(Class) {
+        None,
+        AesCbcParams,
+        AesKeyGenParams,
+        HmacKeyParams,
+        HmacParams,
+        RsaKeyGenParams,
+        RsaSsaKeyParams,
+        RsaSsaParams
+    };
+    virtual Class parametersClass() const { return Class::None; }
 };
 
+#define CRYPTO_ALGORITHM_PARAMETERS_CASTS(ToClassName) \
+    TYPE_CASTS_BASE(CryptoAlgorithm##ToClassName, CryptoAlgorithmParameters, parameters, parameters->parametersClass() == CryptoAlgorithmParameters::Class::ToClassName, parameters.parametersClass() == CryptoAlgorithmParameters::Class::ToClassName)
+
 }
 
 #endif // ENABLE(SUBTLE_CRYPTO)
index 7362dc7..17212e8 100644 (file)
@@ -68,6 +68,9 @@ private:
     CryptoKeyUsage m_usages;
 };
 
+#define CRYPTO_KEY_TYPE_CASTS(ToClassName) \
+    TYPE_CASTS_BASE(ToClassName, CryptoKey, key, WebCore::is##ToClassName(*key), WebCore::is##ToClassName(key))
+
 } // namespace WebCore
 
 #endif // ENABLE(SUBTLE_CRYPTO)
index 54106b3..0159311 100644 (file)
@@ -33,7 +33,7 @@
 namespace WebCore {
 
 class CryptoKeyData {
-WTF_MAKE_NONCOPYABLE(CryptoKeyData);
+    WTF_MAKE_NONCOPYABLE(CryptoKeyData);
 public:
     ENUM_CLASS(Format) {
         OctetSequence,
@@ -52,6 +52,9 @@ private:
     Format m_format;
 };
 
+#define CRYPTO_KEY_DATA_CASTS(ToClassName) \
+    TYPE_CASTS_BASE(ToClassName, CryptoKeyData, keyData, WebCore::is##ToClassName(*keyData), WebCore::is##ToClassName(keyData))
+
 } // namespace WebCore
 
 #endif // ENABLE(SUBTLE_CRYPTO)
index 585c75a..3bc8e53 100644 (file)
@@ -40,7 +40,7 @@ class CryptoKeyData;
 typedef std::pair<const char*, size_t> CryptoOperationData;
 
 class CryptoKeySerialization {
-WTF_MAKE_NONCOPYABLE(CryptoKeySerialization);
+    WTF_MAKE_NONCOPYABLE(CryptoKeySerialization);
 public:
     CryptoKeySerialization() { }
     virtual ~CryptoKeySerialization() { }
index 083a3fe..ef1c3af 100644 (file)
@@ -58,7 +58,7 @@ CryptoAlgorithmIdentifier CryptoAlgorithmAES_CBC::identifier() const
 
 void CryptoAlgorithmAES_CBC::generateKey(const CryptoAlgorithmParameters& parameters, bool extractable, CryptoKeyUsage usages, std::unique_ptr<PromiseWrapper> promise, ExceptionCode&)
 {
-    const CryptoAlgorithmAesKeyGenParams& aesParameters = static_cast<const CryptoAlgorithmAesKeyGenParams&>(parameters);
+    const CryptoAlgorithmAesKeyGenParams& aesParameters = toCryptoAlgorithmAesKeyGenParams(parameters);
 
     RefPtr<CryptoKeyAES> result = CryptoKeyAES::generate(CryptoAlgorithmIdentifier::AES_CBC, aesParameters.length, extractable, usages);
     if (!result) {
index 3c1a38c..d604382 100644 (file)
@@ -59,7 +59,7 @@ CryptoAlgorithmIdentifier CryptoAlgorithmHMAC::identifier() const
 
 void CryptoAlgorithmHMAC::generateKey(const CryptoAlgorithmParameters& parameters, bool extractable, CryptoKeyUsage usages, std::unique_ptr<PromiseWrapper> promise, ExceptionCode&)
 {
-    const CryptoAlgorithmHmacKeyParams& hmacParameters = static_cast<const CryptoAlgorithmHmacKeyParams&>(parameters);
+    const CryptoAlgorithmHmacKeyParams& hmacParameters = toCryptoAlgorithmHmacKeyParams(parameters);
 
     RefPtr<CryptoKeyHMAC> result = CryptoKeyHMAC::generate(hmacParameters.hasLength ? hmacParameters.length : 0, hmacParameters.hash, extractable, usages);
     if (!result) {
@@ -78,7 +78,7 @@ void CryptoAlgorithmHMAC::importKey(const CryptoAlgorithmParameters& parameters,
     }
     const CryptoKeyDataOctetSequence& keyDataOctetSequence = toCryptoKeyDataOctetSequence(keyData);
 
-    const CryptoAlgorithmHmacParams& hmacParameters = static_cast<const CryptoAlgorithmHmacParams&>(parameters);
+    const CryptoAlgorithmHmacParams& hmacParameters = toCryptoAlgorithmHmacParams(parameters);
 
     RefPtr<CryptoKeyHMAC> result = CryptoKeyHMAC::create(keyDataOctetSequence.octetSequence(), hmacParameters.hash, extractable, usage);
     promise->fulfill(result.release());
index c8c977f..3400be2 100644 (file)
@@ -58,7 +58,7 @@ CryptoAlgorithmIdentifier CryptoAlgorithmRSASSA_PKCS1_v1_5::identifier() const
 
 void CryptoAlgorithmRSASSA_PKCS1_v1_5::importKey(const CryptoAlgorithmParameters& parameters, const CryptoKeyData& keyData, bool extractable, CryptoKeyUsage usage, std::unique_ptr<PromiseWrapper> promise, ExceptionCode&)
 {
-    const CryptoAlgorithmRsaSsaKeyParams& rsaSSAParameters = static_cast<const CryptoAlgorithmRsaSsaKeyParams&>(parameters);
+    const CryptoAlgorithmRsaSsaKeyParams& rsaSSAParameters = toCryptoAlgorithmRsaSsaKeyParams(parameters);
     const CryptoKeyDataRSAComponents& rsaComponents = toCryptoKeyDataRSAComponents(keyData);
 
     RefPtr<CryptoKeyRSA> result = CryptoKeyRSA::create(CryptoAlgorithmIdentifier::RSASSA_PKCS1_v1_5, rsaComponents, extractable, usage);
@@ -75,7 +75,7 @@ void CryptoAlgorithmRSASSA_PKCS1_v1_5::importKey(const CryptoAlgorithmParameters
 
 void CryptoAlgorithmRSASSA_PKCS1_v1_5::generateKey(const CryptoAlgorithmParameters& parameters, bool extractable, CryptoKeyUsage usages, std::unique_ptr<PromiseWrapper> promise, ExceptionCode&)
 {
-    const CryptoAlgorithmRsaKeyGenParams& rsaParameters = static_cast<const CryptoAlgorithmRsaKeyGenParams&>(parameters);
+    const CryptoAlgorithmRsaKeyGenParams& rsaParameters = toCryptoAlgorithmRsaKeyGenParams(parameters);
 
     CryptoKeyRSA::generatePair(CryptoAlgorithmIdentifier::RSASSA_PKCS1_v1_5, rsaParameters.modulusLength, rsaParameters.publicExponent, extractable, usages, std::move(promise));
 }
index 9aa4b6b..abcdc5c 100644 (file)
@@ -61,17 +61,7 @@ inline bool isCryptoKeyAES(const CryptoKey& key)
     return key.keyClass() == CryptoKeyClass::AES;
 }
 
-inline const CryptoKeyAES& toCryptoKeyAES(const CryptoKey& key)
-{
-    ASSERT_WITH_SECURITY_IMPLICATION(isCryptoKeyAES(key));
-    return static_cast<const CryptoKeyAES&>(key);
-}
-
-inline CryptoKeyAES& toCryptoKeyAES(CryptoKey& key)
-{
-    ASSERT_WITH_SECURITY_IMPLICATION(isCryptoKeyAES(key));
-    return static_cast<CryptoKeyAES&>(key);
-}
+CRYPTO_KEY_TYPE_CASTS(CryptoKeyAES)
 
 } // namespace WebCore
 
index 2f559a6..76d84da 100644 (file)
@@ -49,12 +49,13 @@ private:
     Vector<char> m_keyData;
 };
 
-inline const CryptoKeyDataOctetSequence& toCryptoKeyDataOctetSequence(const CryptoKeyData& data)
+inline bool isCryptoKeyDataOctetSequence(const CryptoKeyData& data)
 {
-    ASSERT(data.format() == CryptoKeyData::Format::OctetSequence);
-    return static_cast<const CryptoKeyDataOctetSequence&>(data);
+    return data.format() == CryptoKeyData::Format::OctetSequence;
 }
 
+CRYPTO_KEY_DATA_CASTS(CryptoKeyDataOctetSequence)
+
 } // namespace WebCore
 
 #endif // ENABLE(SUBTLE_CRYPTO)
index 347e08d..33c6dd2 100644 (file)
@@ -95,12 +95,13 @@ private:
     Vector<PrimeInfo> m_otherPrimeInfos; // When three or more primes have been used, the number of array elements is be the number of primes used minus two.
 };
 
-inline const CryptoKeyDataRSAComponents& toCryptoKeyDataRSAComponents(const CryptoKeyData& data)
+inline bool isCryptoKeyDataRSAComponents(const CryptoKeyData& data)
 {
-    ASSERT(data.format() == CryptoKeyData::Format::RSAComponents);
-    return static_cast<const CryptoKeyDataRSAComponents&>(data);
+    return data.format() == CryptoKeyData::Format::RSAComponents;
 }
 
+CRYPTO_KEY_DATA_CASTS(CryptoKeyDataRSAComponents)
+
 } // namespace WebCore
 
 #endif // ENABLE(SUBTLE_CRYPTO)
index a0a60e0..a13aaf3 100644 (file)
@@ -62,17 +62,7 @@ inline bool isCryptoKeyHMAC(const CryptoKey& key)
     return key.keyClass() == CryptoKeyClass::HMAC;
 }
 
-inline const CryptoKeyHMAC& toCryptoKeyHMAC(const CryptoKey& key)
-{
-    ASSERT_WITH_SECURITY_IMPLICATION(isCryptoKeyHMAC(key));
-    return static_cast<const CryptoKeyHMAC&>(key);
-}
-
-inline CryptoKeyHMAC& toCryptoKeyHMAC(CryptoKey& key)
-{
-    ASSERT_WITH_SECURITY_IMPLICATION(isCryptoKeyHMAC(key));
-    return static_cast<CryptoKeyHMAC&>(key);
-}
+CRYPTO_KEY_TYPE_CASTS(CryptoKeyHMAC)
 
 } // namespace WebCore
 
index 6512930..ccb5a2d 100644 (file)
@@ -74,17 +74,7 @@ inline bool isCryptoKeyRSA(const CryptoKey& key)
     return key.keyClass() == CryptoKeyClass::RSA;
 }
 
-inline const CryptoKeyRSA& toCryptoKeyRSA(const CryptoKey& key)
-{
-    ASSERT_WITH_SECURITY_IMPLICATION(isCryptoKeyRSA(key));
-    return static_cast<const CryptoKeyRSA&>(key);
-}
-
-inline CryptoKeyRSA& asCryptoKeyRSA(CryptoKey& key)
-{
-    ASSERT_WITH_SECURITY_IMPLICATION(isCryptoKeyRSA(key));
-    return static_cast<CryptoKeyRSA&>(key);
-}
+CRYPTO_KEY_TYPE_CASTS(CryptoKeyRSA)
 
 } // namespace WebCore
 
index b09022e..21e6f5d 100644 (file)
@@ -35,7 +35,7 @@
 namespace WebCore {
 
 class CryptoKeySerializationRaw FINAL : public CryptoKeySerialization {
-WTF_MAKE_NONCOPYABLE(CryptoKeySerializationRaw);
+    WTF_MAKE_NONCOPYABLE(CryptoKeySerializationRaw);
 public:
     static std::unique_ptr<CryptoKeySerializationRaw> create(const CryptoOperationData& data)
     {
@@ -44,6 +44,9 @@ public:
 
     virtual ~CryptoKeySerializationRaw();
 
+private:
+    CryptoKeySerializationRaw(const CryptoOperationData&);
+
     virtual bool reconcileAlgorithm(std::unique_ptr<CryptoAlgorithm>&, std::unique_ptr<CryptoAlgorithmParameters>&) const OVERRIDE;
 
     virtual void reconcileUsages(CryptoKeyUsage&) const OVERRIDE;
@@ -51,9 +54,6 @@ public:
 
     virtual std::unique_ptr<CryptoKeyData> keyData() const OVERRIDE;
 
-private:
-    CryptoKeySerializationRaw(const CryptoOperationData&);
-
     Vector<char> m_data;
 };
 
index daab812..81e76c3 100644 (file)
@@ -91,7 +91,7 @@ static void transformAES_CBC(CCOperation operation, const CryptoAlgorithmAesCbcP
 
 void CryptoAlgorithmAES_CBC::encrypt(const CryptoAlgorithmParameters& parameters, const CryptoKey& key, const Vector<CryptoOperationData>& data, std::unique_ptr<PromiseWrapper> promise, ExceptionCode& ec)
 {
-    const CryptoAlgorithmAesCbcParams& aesCBCParameters = static_cast<const CryptoAlgorithmAesCbcParams&>(parameters);
+    const CryptoAlgorithmAesCbcParams& aesCBCParameters = toCryptoAlgorithmAesCbcParams(parameters);
 
     if (!isCryptoKeyAES(key)) {
         ec = NOT_SUPPORTED_ERR;
@@ -104,7 +104,7 @@ void CryptoAlgorithmAES_CBC::encrypt(const CryptoAlgorithmParameters& parameters
 
 void CryptoAlgorithmAES_CBC::decrypt(const CryptoAlgorithmParameters& parameters, const CryptoKey& key, const Vector<CryptoOperationData>& data, std::unique_ptr<PromiseWrapper> promise, ExceptionCode& ec)
 {
-    const CryptoAlgorithmAesCbcParams& aesCBCParameters = static_cast<const CryptoAlgorithmAesCbcParams&>(parameters);
+    const CryptoAlgorithmAesCbcParams& aesCBCParameters = toCryptoAlgorithmAesCbcParams(parameters);
 
     if (!isCryptoKeyAES(key)) {
         ec = NOT_SUPPORTED_ERR;
index c1c42b0..1cf58a0 100644 (file)
@@ -94,7 +94,7 @@ static Vector<unsigned char> calculateSignature(CCHmacAlgorithm algorithm, const
 
 void CryptoAlgorithmHMAC::sign(const CryptoAlgorithmParameters& parameters, const CryptoKey& key, const Vector<CryptoOperationData>& data, std::unique_ptr<PromiseWrapper> promise, ExceptionCode& ec)
 {
-    const CryptoAlgorithmHmacParams& hmacParameters = static_cast<const CryptoAlgorithmHmacParams&>(parameters);
+    const CryptoAlgorithmHmacParams& hmacParameters = toCryptoAlgorithmHmacParams(parameters);
 
     if (!isCryptoKeyHMAC(key)) {
         ec = NOT_SUPPORTED_ERR;
@@ -115,7 +115,7 @@ void CryptoAlgorithmHMAC::sign(const CryptoAlgorithmParameters& parameters, cons
 
 void CryptoAlgorithmHMAC::verify(const CryptoAlgorithmParameters& parameters, const CryptoKey& key, const CryptoOperationData& expectedSignature, const Vector<CryptoOperationData>& data, std::unique_ptr<PromiseWrapper> promise, ExceptionCode& ec)
 {
-    const CryptoAlgorithmHmacParams& hmacParameters = static_cast<const CryptoAlgorithmHmacParams&>(parameters);
+    const CryptoAlgorithmHmacParams& hmacParameters = toCryptoAlgorithmHmacParams(parameters);
 
     if (!isCryptoKeyHMAC(key)) {
         ec = NOT_SUPPORTED_ERR;
index ce65468..8aec52e 100644 (file)
@@ -37,8 +37,12 @@ class CryptoAlgorithmAesCbcParams FINAL : public CryptoAlgorithmParameters {
 public:
     // The initialization vector. MUST be 16 bytes.
     FixedArray<char, 16> iv;
+
+    virtual Class parametersClass() const OVERRIDE { return Class::AesCbcParams; }
 };
 
+CRYPTO_ALGORITHM_PARAMETERS_CASTS(AesCbcParams)
+
 }
 
 #endif // ENABLE(SUBTLE_CRYPTO)
index bcd35e9..21972d7 100644 (file)
@@ -36,8 +36,12 @@ class CryptoAlgorithmAesKeyGenParams FINAL : public CryptoAlgorithmParameters {
 public:
     // The length, in bits, of the key.
     unsigned length;
+
+    virtual Class parametersClass() const OVERRIDE { return Class::AesKeyGenParams; }
 };
 
+CRYPTO_ALGORITHM_PARAMETERS_CASTS(AesKeyGenParams)
+
 }
 
 #endif // ENABLE(SUBTLE_CRYPTO)
index cd23af1..086e11e 100644 (file)
@@ -47,8 +47,12 @@ public:
     // which is the size of the associated hash function's block size.
     bool hasLength;
     unsigned length;
+
+    virtual Class parametersClass() const OVERRIDE { return Class::HmacKeyParams; }
 };
 
+CRYPTO_ALGORITHM_PARAMETERS_CASTS(HmacKeyParams)
+
 }
 
 #endif // ENABLE(SUBTLE_CRYPTO)
index 9a76f84..4ce81c2 100644 (file)
@@ -37,8 +37,12 @@ class CryptoAlgorithmHmacParams FINAL : public CryptoAlgorithmParameters {
 public:
     // The inner hash function to use.
     CryptoAlgorithmIdentifier hash;
+
+    virtual Class parametersClass() const OVERRIDE { return Class::HmacParams; }
 };
 
+CRYPTO_ALGORITHM_PARAMETERS_CASTS(HmacParams)
+
 }
 
 #endif // ENABLE(SUBTLE_CRYPTO)
index c0e27dd..2fd7ac0 100644 (file)
@@ -38,8 +38,12 @@ public:
     unsigned modulusLength;
     // The RSA public exponent, encoded as BigInteger.
     Vector<char> publicExponent;
+
+    virtual Class parametersClass() const OVERRIDE { return Class::RsaKeyGenParams; }
 };
 
+CRYPTO_ALGORITHM_PARAMETERS_CASTS(RsaKeyGenParams)
+
 }
 
 #endif // ENABLE(SUBTLE_CRYPTO)
index 555a7bf..146cde2 100644 (file)
@@ -46,8 +46,12 @@ public:
     // The hash algorithm to use.
     bool hasHash;
     CryptoAlgorithmIdentifier hash;
+
+    virtual Class parametersClass() const OVERRIDE { return Class::RsaSsaKeyParams; }
 };
 
+CRYPTO_ALGORITHM_PARAMETERS_CASTS(RsaSsaKeyParams)
+
 }
 
 #endif // ENABLE(SUBTLE_CRYPTO)
index 6e8e0fd..3b2a27f 100644 (file)
@@ -37,8 +37,12 @@ class CryptoAlgorithmRsaSsaParams FINAL : public CryptoAlgorithmParameters {
 public:
     // The hash algorithm to use.
     CryptoAlgorithmIdentifier hash;
+
+    virtual Class parametersClass() const OVERRIDE { return Class::RsaSsaParams; }
 };
 
+CRYPTO_ALGORITHM_PARAMETERS_CASTS(RsaSsaParams)
+
 }
 
 #endif // ENABLE(SUBTLE_CRYPTO)