Changeset 159213 in webkit
- Timestamp:
- Nov 13, 2013, 11:33:15 AM (12 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 25 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r159211 r159213 1 2013-11-13 Alexey Proskuryakov <ap@apple.com> 2 3 Check WebCrypto parameter types when casting 4 https://bugs.webkit.org/show_bug.cgi?id=124297 5 6 Reviewed by Sam Weinig. 7 8 Also changed existing toCryptoXXX functions to use TYPE_CASTS_BASE mechanism. 9 10 * bindings/js/JSCryptoAlgorithmDictionary.cpp: 11 (WebCore::JSCryptoAlgorithmDictionary::createParametersForImportKey): 12 And sure enough, there was a bug caught by the added checks. 13 14 * bindings/js/JSCryptoKeySerializationJWK.cpp: 15 (WebCore::JSCryptoKeySerializationJWK::reconcileAlgorithm): 16 * crypto/CryptoAlgorithmParameters.h: 17 (WebCore::CryptoAlgorithmParameters::ENUM_CLASS): 18 (WebCore::CryptoAlgorithmParameters::parametersClass): 19 * crypto/CryptoKey.h: 20 * crypto/CryptoKeyData.h: 21 * crypto/CryptoKeySerialization.h: 22 * crypto/algorithms/CryptoAlgorithmAES_CBC.cpp: 23 (WebCore::CryptoAlgorithmAES_CBC::generateKey): 24 * crypto/algorithms/CryptoAlgorithmHMAC.cpp: 25 (WebCore::CryptoAlgorithmHMAC::generateKey): 26 (WebCore::CryptoAlgorithmHMAC::importKey): 27 * crypto/algorithms/CryptoAlgorithmRSASSA_PKCS1_v1_5.cpp: 28 (WebCore::CryptoAlgorithmRSASSA_PKCS1_v1_5::importKey): 29 (WebCore::CryptoAlgorithmRSASSA_PKCS1_v1_5::generateKey): 30 * crypto/keys/CryptoKeyAES.h: 31 * crypto/keys/CryptoKeyDataOctetSequence.h: 32 (WebCore::isCryptoKeyDataOctetSequence): 33 * crypto/keys/CryptoKeyDataRSAComponents.h: 34 (WebCore::isCryptoKeyDataRSAComponents): 35 * crypto/keys/CryptoKeyHMAC.h: 36 * crypto/keys/CryptoKeyRSA.h: 37 * crypto/keys/CryptoKeySerializationRaw.h: 38 * crypto/mac/CryptoAlgorithmAES_CBCMac.cpp: 39 (WebCore::CryptoAlgorithmAES_CBC::encrypt): 40 (WebCore::CryptoAlgorithmAES_CBC::decrypt): 41 * crypto/mac/CryptoAlgorithmHMACMac.cpp: 42 (WebCore::CryptoAlgorithmHMAC::sign): 43 (WebCore::CryptoAlgorithmHMAC::verify): 44 * crypto/parameters/CryptoAlgorithmAesCbcParams.h: 45 * crypto/parameters/CryptoAlgorithmAesKeyGenParams.h: 46 * crypto/parameters/CryptoAlgorithmHmacKeyParams.h: 47 * crypto/parameters/CryptoAlgorithmHmacParams.h: 48 * crypto/parameters/CryptoAlgorithmRsaKeyGenParams.h: 49 * crypto/parameters/CryptoAlgorithmRsaSsaKeyParams.h: 50 * crypto/parameters/CryptoAlgorithmRsaSsaParams.h: 51 1 52 2013-11-13 Alexey Proskuryakov <ap@apple.com> 2 53 -
trunk/Source/WebCore/bindings/js/JSCryptoAlgorithmDictionary.cpp
r159180 r159213 539 539 return std::make_unique<CryptoAlgorithmParameters>(); 540 540 case CryptoAlgorithmIdentifier::HMAC: 541 return createHmac KeyParams(exec, value);541 return createHmacParams(exec, value); 542 542 case CryptoAlgorithmIdentifier::DH: 543 543 return std::make_unique<CryptoAlgorithmParameters>(); -
trunk/Source/WebCore/bindings/js/JSCryptoKeySerializationJWK.cpp
r159180 r159213 213 213 214 214 if (algorithm->identifier() == CryptoAlgorithmIdentifier::HMAC) 215 return static_cast<CryptoAlgorithmHmacParams&>(*parameters).hash == static_cast<CryptoAlgorithmHmacParams&>(*suggestedParameters).hash;215 return toCryptoAlgorithmHmacParams(*parameters).hash == toCryptoAlgorithmHmacParams(*suggestedParameters).hash; 216 216 if (algorithm->identifier() == CryptoAlgorithmIdentifier::RSASSA_PKCS1_v1_5) { 217 CryptoAlgorithmRsaSsaKeyParams& rsaSSAParameters = static_cast<CryptoAlgorithmRsaSsaKeyParams&>(*parameters);218 CryptoAlgorithmRsaSsaKeyParams& suggestedRSASSAParameters = static_cast<CryptoAlgorithmRsaSsaKeyParams&>(*suggestedParameters);217 CryptoAlgorithmRsaSsaKeyParams& rsaSSAParameters = toCryptoAlgorithmRsaSsaKeyParams(*parameters); 218 CryptoAlgorithmRsaSsaKeyParams& suggestedRSASSAParameters = toCryptoAlgorithmRsaSsaKeyParams(*suggestedParameters); 219 219 ASSERT(rsaSSAParameters.hasHash); 220 220 if (suggestedRSASSAParameters.hasHash) -
trunk/Source/WebCore/crypto/CryptoAlgorithmParameters.h
r158363 r159213 38 38 CryptoAlgorithmParameters() { } 39 39 virtual ~CryptoAlgorithmParameters() { } 40 41 ENUM_CLASS(Class) { 42 None, 43 AesCbcParams, 44 AesKeyGenParams, 45 HmacKeyParams, 46 HmacParams, 47 RsaKeyGenParams, 48 RsaSsaKeyParams, 49 RsaSsaParams 50 }; 51 virtual Class parametersClass() const { return Class::None; } 40 52 }; 53 54 #define CRYPTO_ALGORITHM_PARAMETERS_CASTS(ToClassName) \ 55 TYPE_CASTS_BASE(CryptoAlgorithm##ToClassName, CryptoAlgorithmParameters, parameters, parameters->parametersClass() == CryptoAlgorithmParameters::Class::ToClassName, parameters.parametersClass() == CryptoAlgorithmParameters::Class::ToClassName) 41 56 42 57 } -
trunk/Source/WebCore/crypto/CryptoKey.h
r159180 r159213 69 69 }; 70 70 71 #define CRYPTO_KEY_TYPE_CASTS(ToClassName) \ 72 TYPE_CASTS_BASE(ToClassName, CryptoKey, key, WebCore::is##ToClassName(*key), WebCore::is##ToClassName(key)) 73 71 74 } // namespace WebCore 72 75 -
trunk/Source/WebCore/crypto/CryptoKeyData.h
r159180 r159213 34 34 35 35 class CryptoKeyData { 36 WTF_MAKE_NONCOPYABLE(CryptoKeyData);36 WTF_MAKE_NONCOPYABLE(CryptoKeyData); 37 37 public: 38 38 ENUM_CLASS(Format) { … … 53 53 }; 54 54 55 #define CRYPTO_KEY_DATA_CASTS(ToClassName) \ 56 TYPE_CASTS_BASE(ToClassName, CryptoKeyData, keyData, WebCore::is##ToClassName(*keyData), WebCore::is##ToClassName(keyData)) 57 55 58 } // namespace WebCore 56 59 -
trunk/Source/WebCore/crypto/CryptoKeySerialization.h
r158943 r159213 41 41 42 42 class CryptoKeySerialization { 43 WTF_MAKE_NONCOPYABLE(CryptoKeySerialization);43 WTF_MAKE_NONCOPYABLE(CryptoKeySerialization); 44 44 public: 45 45 CryptoKeySerialization() { } -
trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmAES_CBC.cpp
r159180 r159213 59 59 void CryptoAlgorithmAES_CBC::generateKey(const CryptoAlgorithmParameters& parameters, bool extractable, CryptoKeyUsage usages, std::unique_ptr<PromiseWrapper> promise, ExceptionCode&) 60 60 { 61 const CryptoAlgorithmAesKeyGenParams& aesParameters = static_cast<const CryptoAlgorithmAesKeyGenParams&>(parameters);61 const CryptoAlgorithmAesKeyGenParams& aesParameters = toCryptoAlgorithmAesKeyGenParams(parameters); 62 62 63 63 RefPtr<CryptoKeyAES> result = CryptoKeyAES::generate(CryptoAlgorithmIdentifier::AES_CBC, aesParameters.length, extractable, usages); -
trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmHMAC.cpp
r159180 r159213 60 60 void CryptoAlgorithmHMAC::generateKey(const CryptoAlgorithmParameters& parameters, bool extractable, CryptoKeyUsage usages, std::unique_ptr<PromiseWrapper> promise, ExceptionCode&) 61 61 { 62 const CryptoAlgorithmHmacKeyParams& hmacParameters = static_cast<const CryptoAlgorithmHmacKeyParams&>(parameters);62 const CryptoAlgorithmHmacKeyParams& hmacParameters = toCryptoAlgorithmHmacKeyParams(parameters); 63 63 64 64 RefPtr<CryptoKeyHMAC> result = CryptoKeyHMAC::generate(hmacParameters.hasLength ? hmacParameters.length : 0, hmacParameters.hash, extractable, usages); … … 79 79 const CryptoKeyDataOctetSequence& keyDataOctetSequence = toCryptoKeyDataOctetSequence(keyData); 80 80 81 const CryptoAlgorithmHmacParams& hmacParameters = static_cast<const CryptoAlgorithmHmacParams&>(parameters);81 const CryptoAlgorithmHmacParams& hmacParameters = toCryptoAlgorithmHmacParams(parameters); 82 82 83 83 RefPtr<CryptoKeyHMAC> result = CryptoKeyHMAC::create(keyDataOctetSequence.octetSequence(), hmacParameters.hash, extractable, usage); -
trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmRSASSA_PKCS1_v1_5.cpp
r159180 r159213 59 59 void CryptoAlgorithmRSASSA_PKCS1_v1_5::importKey(const CryptoAlgorithmParameters& parameters, const CryptoKeyData& keyData, bool extractable, CryptoKeyUsage usage, std::unique_ptr<PromiseWrapper> promise, ExceptionCode&) 60 60 { 61 const CryptoAlgorithmRsaSsaKeyParams& rsaSSAParameters = static_cast<const CryptoAlgorithmRsaSsaKeyParams&>(parameters);61 const CryptoAlgorithmRsaSsaKeyParams& rsaSSAParameters = toCryptoAlgorithmRsaSsaKeyParams(parameters); 62 62 const CryptoKeyDataRSAComponents& rsaComponents = toCryptoKeyDataRSAComponents(keyData); 63 63 … … 76 76 void CryptoAlgorithmRSASSA_PKCS1_v1_5::generateKey(const CryptoAlgorithmParameters& parameters, bool extractable, CryptoKeyUsage usages, std::unique_ptr<PromiseWrapper> promise, ExceptionCode&) 77 77 { 78 const CryptoAlgorithmRsaKeyGenParams& rsaParameters = static_cast<const CryptoAlgorithmRsaKeyGenParams&>(parameters);78 const CryptoAlgorithmRsaKeyGenParams& rsaParameters = toCryptoAlgorithmRsaKeyGenParams(parameters); 79 79 80 80 CryptoKeyRSA::generatePair(CryptoAlgorithmIdentifier::RSASSA_PKCS1_v1_5, rsaParameters.modulusLength, rsaParameters.publicExponent, extractable, usages, std::move(promise)); -
trunk/Source/WebCore/crypto/keys/CryptoKeyAES.h
r159180 r159213 62 62 } 63 63 64 inline const CryptoKeyAES& toCryptoKeyAES(const CryptoKey& key) 65 { 66 ASSERT_WITH_SECURITY_IMPLICATION(isCryptoKeyAES(key)); 67 return static_cast<const CryptoKeyAES&>(key); 68 } 69 70 inline CryptoKeyAES& toCryptoKeyAES(CryptoKey& key) 71 { 72 ASSERT_WITH_SECURITY_IMPLICATION(isCryptoKeyAES(key)); 73 return static_cast<CryptoKeyAES&>(key); 74 } 64 CRYPTO_KEY_TYPE_CASTS(CryptoKeyAES) 75 65 76 66 } // namespace WebCore -
trunk/Source/WebCore/crypto/keys/CryptoKeyDataOctetSequence.h
r159180 r159213 50 50 }; 51 51 52 inline const CryptoKeyDataOctetSequence& toCryptoKeyDataOctetSequence(const CryptoKeyData& data)52 inline bool isCryptoKeyDataOctetSequence(const CryptoKeyData& data) 53 53 { 54 ASSERT(data.format() == CryptoKeyData::Format::OctetSequence); 55 return static_cast<const CryptoKeyDataOctetSequence&>(data); 54 return data.format() == CryptoKeyData::Format::OctetSequence; 56 55 } 56 57 CRYPTO_KEY_DATA_CASTS(CryptoKeyDataOctetSequence) 57 58 58 59 } // namespace WebCore -
trunk/Source/WebCore/crypto/keys/CryptoKeyDataRSAComponents.h
r159180 r159213 96 96 }; 97 97 98 inline const CryptoKeyDataRSAComponents& toCryptoKeyDataRSAComponents(const CryptoKeyData& data)98 inline bool isCryptoKeyDataRSAComponents(const CryptoKeyData& data) 99 99 { 100 ASSERT(data.format() == CryptoKeyData::Format::RSAComponents); 101 return static_cast<const CryptoKeyDataRSAComponents&>(data); 100 return data.format() == CryptoKeyData::Format::RSAComponents; 102 101 } 102 103 CRYPTO_KEY_DATA_CASTS(CryptoKeyDataRSAComponents) 103 104 104 105 } // namespace WebCore -
trunk/Source/WebCore/crypto/keys/CryptoKeyHMAC.h
r159180 r159213 63 63 } 64 64 65 inline const CryptoKeyHMAC& toCryptoKeyHMAC(const CryptoKey& key) 66 { 67 ASSERT_WITH_SECURITY_IMPLICATION(isCryptoKeyHMAC(key)); 68 return static_cast<const CryptoKeyHMAC&>(key); 69 } 70 71 inline CryptoKeyHMAC& toCryptoKeyHMAC(CryptoKey& key) 72 { 73 ASSERT_WITH_SECURITY_IMPLICATION(isCryptoKeyHMAC(key)); 74 return static_cast<CryptoKeyHMAC&>(key); 75 } 65 CRYPTO_KEY_TYPE_CASTS(CryptoKeyHMAC) 76 66 77 67 } // namespace WebCore -
trunk/Source/WebCore/crypto/keys/CryptoKeyRSA.h
r159180 r159213 75 75 } 76 76 77 inline const CryptoKeyRSA& toCryptoKeyRSA(const CryptoKey& key) 78 { 79 ASSERT_WITH_SECURITY_IMPLICATION(isCryptoKeyRSA(key)); 80 return static_cast<const CryptoKeyRSA&>(key); 81 } 82 83 inline CryptoKeyRSA& asCryptoKeyRSA(CryptoKey& key) 84 { 85 ASSERT_WITH_SECURITY_IMPLICATION(isCryptoKeyRSA(key)); 86 return static_cast<CryptoKeyRSA&>(key); 87 } 77 CRYPTO_KEY_TYPE_CASTS(CryptoKeyRSA) 88 78 89 79 } // namespace WebCore -
trunk/Source/WebCore/crypto/keys/CryptoKeySerializationRaw.h
r158943 r159213 36 36 37 37 class CryptoKeySerializationRaw FINAL : public CryptoKeySerialization { 38 WTF_MAKE_NONCOPYABLE(CryptoKeySerializationRaw);38 WTF_MAKE_NONCOPYABLE(CryptoKeySerializationRaw); 39 39 public: 40 40 static std::unique_ptr<CryptoKeySerializationRaw> create(const CryptoOperationData& data) … … 45 45 virtual ~CryptoKeySerializationRaw(); 46 46 47 private: 48 CryptoKeySerializationRaw(const CryptoOperationData&); 49 47 50 virtual bool reconcileAlgorithm(std::unique_ptr<CryptoAlgorithm>&, std::unique_ptr<CryptoAlgorithmParameters>&) const OVERRIDE; 48 51 … … 51 54 52 55 virtual std::unique_ptr<CryptoKeyData> keyData() const OVERRIDE; 53 54 private:55 CryptoKeySerializationRaw(const CryptoOperationData&);56 56 57 57 Vector<char> m_data; -
trunk/Source/WebCore/crypto/mac/CryptoAlgorithmAES_CBCMac.cpp
r159180 r159213 92 92 void CryptoAlgorithmAES_CBC::encrypt(const CryptoAlgorithmParameters& parameters, const CryptoKey& key, const Vector<CryptoOperationData>& data, std::unique_ptr<PromiseWrapper> promise, ExceptionCode& ec) 93 93 { 94 const CryptoAlgorithmAesCbcParams& aesCBCParameters = static_cast<const CryptoAlgorithmAesCbcParams&>(parameters);94 const CryptoAlgorithmAesCbcParams& aesCBCParameters = toCryptoAlgorithmAesCbcParams(parameters); 95 95 96 96 if (!isCryptoKeyAES(key)) { … … 105 105 void CryptoAlgorithmAES_CBC::decrypt(const CryptoAlgorithmParameters& parameters, const CryptoKey& key, const Vector<CryptoOperationData>& data, std::unique_ptr<PromiseWrapper> promise, ExceptionCode& ec) 106 106 { 107 const CryptoAlgorithmAesCbcParams& aesCBCParameters = static_cast<const CryptoAlgorithmAesCbcParams&>(parameters);107 const CryptoAlgorithmAesCbcParams& aesCBCParameters = toCryptoAlgorithmAesCbcParams(parameters); 108 108 109 109 if (!isCryptoKeyAES(key)) { -
trunk/Source/WebCore/crypto/mac/CryptoAlgorithmHMACMac.cpp
r159180 r159213 95 95 void CryptoAlgorithmHMAC::sign(const CryptoAlgorithmParameters& parameters, const CryptoKey& key, const Vector<CryptoOperationData>& data, std::unique_ptr<PromiseWrapper> promise, ExceptionCode& ec) 96 96 { 97 const CryptoAlgorithmHmacParams& hmacParameters = static_cast<const CryptoAlgorithmHmacParams&>(parameters);97 const CryptoAlgorithmHmacParams& hmacParameters = toCryptoAlgorithmHmacParams(parameters); 98 98 99 99 if (!isCryptoKeyHMAC(key)) { … … 116 116 void CryptoAlgorithmHMAC::verify(const CryptoAlgorithmParameters& parameters, const CryptoKey& key, const CryptoOperationData& expectedSignature, const Vector<CryptoOperationData>& data, std::unique_ptr<PromiseWrapper> promise, ExceptionCode& ec) 117 117 { 118 const CryptoAlgorithmHmacParams& hmacParameters = static_cast<const CryptoAlgorithmHmacParams&>(parameters);118 const CryptoAlgorithmHmacParams& hmacParameters = toCryptoAlgorithmHmacParams(parameters); 119 119 120 120 if (!isCryptoKeyHMAC(key)) { -
trunk/Source/WebCore/crypto/parameters/CryptoAlgorithmAesCbcParams.h
r158945 r159213 38 38 // The initialization vector. MUST be 16 bytes. 39 39 FixedArray<char, 16> iv; 40 41 virtual Class parametersClass() const OVERRIDE { return Class::AesCbcParams; } 40 42 }; 43 44 CRYPTO_ALGORITHM_PARAMETERS_CASTS(AesCbcParams) 41 45 42 46 } -
trunk/Source/WebCore/crypto/parameters/CryptoAlgorithmAesKeyGenParams.h
r158945 r159213 37 37 // The length, in bits, of the key. 38 38 unsigned length; 39 40 virtual Class parametersClass() const OVERRIDE { return Class::AesKeyGenParams; } 39 41 }; 42 43 CRYPTO_ALGORITHM_PARAMETERS_CASTS(AesKeyGenParams) 40 44 41 45 } -
trunk/Source/WebCore/crypto/parameters/CryptoAlgorithmHmacKeyParams.h
r159180 r159213 48 48 bool hasLength; 49 49 unsigned length; 50 51 virtual Class parametersClass() const OVERRIDE { return Class::HmacKeyParams; } 50 52 }; 53 54 CRYPTO_ALGORITHM_PARAMETERS_CASTS(HmacKeyParams) 51 55 52 56 } -
trunk/Source/WebCore/crypto/parameters/CryptoAlgorithmHmacParams.h
r158366 r159213 38 38 // The inner hash function to use. 39 39 CryptoAlgorithmIdentifier hash; 40 41 virtual Class parametersClass() const OVERRIDE { return Class::HmacParams; } 40 42 }; 43 44 CRYPTO_ALGORITHM_PARAMETERS_CASTS(HmacParams) 41 45 42 46 } -
trunk/Source/WebCore/crypto/parameters/CryptoAlgorithmRsaKeyGenParams.h
r159180 r159213 39 39 // The RSA public exponent, encoded as BigInteger. 40 40 Vector<char> publicExponent; 41 42 virtual Class parametersClass() const OVERRIDE { return Class::RsaKeyGenParams; } 41 43 }; 44 45 CRYPTO_ALGORITHM_PARAMETERS_CASTS(RsaKeyGenParams) 42 46 43 47 } -
trunk/Source/WebCore/crypto/parameters/CryptoAlgorithmRsaSsaKeyParams.h
r159180 r159213 47 47 bool hasHash; 48 48 CryptoAlgorithmIdentifier hash; 49 50 virtual Class parametersClass() const OVERRIDE { return Class::RsaSsaKeyParams; } 49 51 }; 52 53 CRYPTO_ALGORITHM_PARAMETERS_CASTS(RsaSsaKeyParams) 50 54 51 55 } -
trunk/Source/WebCore/crypto/parameters/CryptoAlgorithmRsaSsaParams.h
r159180 r159213 38 38 // The hash algorithm to use. 39 39 CryptoAlgorithmIdentifier hash; 40 41 virtual Class parametersClass() const OVERRIDE { return Class::RsaSsaParams; } 40 42 }; 43 44 CRYPTO_ALGORITHM_PARAMETERS_CASTS(RsaSsaParams) 41 45 42 46 }
Note:
See TracChangeset
for help on using the changeset viewer.