Changeset 159717 in webkit
- Timestamp:
- Nov 22, 2013 3:43:54 PM (10 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 15 edited
- 2 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r159714 r159717 1 2013-11-22 Alexey Proskuryakov <ap@apple.com> 2 3 WebCrypto algorithms should check that key algorithm matches 4 https://bugs.webkit.org/show_bug.cgi?id=123628 5 6 Reviewed by Anders Carlsson. 7 8 No change in behavior yet, because we have one algorithm per key class. 9 Will be tested once more algorithms are added. 10 11 * WebCore.xcodeproj/project.pbxproj: Updated for file renames. 12 13 * bindings/js/JSCryptoAlgorithmDictionary.cpp: 14 (WebCore::createRsaKeyParamsWithHash): 15 (WebCore::JSCryptoAlgorithmDictionary::createParametersForImportKey): 16 * bindings/js/JSCryptoKeySerializationJWK.cpp: 17 (WebCore::createRSAKeyParametersWithHash): 18 (WebCore::JSCryptoKeySerializationJWK::reconcileAlgorithm): 19 * crypto/CryptoAlgorithmParameters.h: 20 (WebCore::CryptoAlgorithmParameters::ENUM_CLASS): 21 * crypto/parameters/CryptoAlgorithmRsaKeyParamsWithHash.h: Copied from Source/WebCore/crypto/parameters/CryptoAlgorithmRsaSsaKeyParams.h. 22 * crypto/parameters/CryptoAlgorithmRsaSsaKeyParams.h: Removed. 23 Renamed RsaSsaKeyParams to RsaKeyParamsWithHash, because other algorithms (like RSA-OAEP) 24 are in the same boat. Depending on where the spec goes, we might need to introduce 25 algorithm specific RSA parameter classes later, but let's reduce copy/pasted code at 26 least for now. 27 28 * crypto/CryptoAlgorithmRSASSA_PKCS1_v1_5Mac.cpp: Moved to the correct directory. 29 * crypto/mac/CryptoAlgorithmRSASSA_PKCS1_v1_5Mac.cpp: Copied from Source/WebCore/crypto/CryptoAlgorithmRSASSA_PKCS1_v1_5Mac.cpp. 30 (WebCore::CryptoAlgorithmRSASSA_PKCS1_v1_5::platformSign): Factored out Mac specific 31 code, leaving type casting to cross-platform files. 32 (WebCore::CryptoAlgorithmRSASSA_PKCS1_v1_5::platformVerify): Ditto. 33 34 * crypto/CryptoAlgorithmRegistry.h: 35 (WebCore::CryptoAlgorithmRegistry::registerAlgorithm): 36 * crypto/mac/CryptoAlgorithmRegistryMac.cpp: 37 (WebCore::CryptoAlgorithmRegistry::platformRegisterAlgorithms): 38 Reduce copy/pasting in registration code. 39 40 * crypto/algorithms/CryptoAlgorithmAES_CBC.cpp: 41 (WebCore::CryptoAlgorithmAES_CBC::keyAlgorithmMatches): Check key type and algorithm. 42 (WebCore::CryptoAlgorithmAES_CBC::encrypt): Cross platform type casting code. 43 Maybe we'll find a way to autogenerate or eliminate it one day. 44 (WebCore::CryptoAlgorithmAES_CBC::decrypt): Ditto. 45 46 * crypto/algorithms/CryptoAlgorithmAES_CBC.h: 47 * crypto/algorithms/CryptoAlgorithmHMAC.cpp: 48 (WebCore::CryptoAlgorithmHMAC::keyAlgorithmMatches): 49 (WebCore::CryptoAlgorithmHMAC::sign): 50 (WebCore::CryptoAlgorithmHMAC::verify): 51 * crypto/algorithms/CryptoAlgorithmHMAC.h: 52 * crypto/algorithms/CryptoAlgorithmRSASSA_PKCS1_v1_5.cpp: 53 (WebCore::CryptoAlgorithmRSASSA_PKCS1_v1_5::keyAlgorithmMatches): 54 (WebCore::CryptoAlgorithmRSASSA_PKCS1_v1_5::sign): 55 (WebCore::CryptoAlgorithmRSASSA_PKCS1_v1_5::verify): 56 (WebCore::CryptoAlgorithmRSASSA_PKCS1_v1_5::importKey): 57 * crypto/algorithms/CryptoAlgorithmRSASSA_PKCS1_v1_5.h: 58 * crypto/mac/CryptoAlgorithmAES_CBCMac.cpp: 59 (WebCore::CryptoAlgorithmAES_CBC::platformEncrypt): 60 (WebCore::CryptoAlgorithmAES_CBC::platformDecrypt): 61 * crypto/mac/CryptoAlgorithmHMACMac.cpp: 62 (WebCore::CryptoAlgorithmHMAC::platformSign): 63 (WebCore::CryptoAlgorithmHMAC::platformVerify): 64 Same changes for all algorithms that have keys. 65 1 66 2013-11-22 Brendan Long <b.long@cablelabs.com> 2 67 -
trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj
r159583 r159717 5682 5682 E1BE512E0CF6C512002EA959 /* XSLTUnicodeSort.h in Headers */ = {isa = PBXBuildFile; fileRef = E1BE512C0CF6C512002EA959 /* XSLTUnicodeSort.h */; }; 5683 5683 E1C266D818317AB4003F8B33 /* CryptoAlgorithmRSASSA_PKCS1_v1_5Mac.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E1C266D618317AB4003F8B33 /* CryptoAlgorithmRSASSA_PKCS1_v1_5Mac.cpp */; }; 5684 E1C266DB18319935003F8B33 /* CryptoAlgorithmRsa SsaKeyParams.h in Headers */ = {isa = PBXBuildFile; fileRef = E1C266DA18319935003F8B33 /* CryptoAlgorithmRsaSsaKeyParams.h */; };5684 E1C266DB18319935003F8B33 /* CryptoAlgorithmRsaKeyParamsWithHash.h in Headers */ = {isa = PBXBuildFile; fileRef = E1C266DA18319935003F8B33 /* CryptoAlgorithmRsaKeyParamsWithHash.h */; }; 5685 5685 E1C266DE18319F31003F8B33 /* CryptoKeyDataRSAComponents.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E1C266DC18319F31003F8B33 /* CryptoKeyDataRSAComponents.cpp */; }; 5686 5686 E1C266DF18319F31003F8B33 /* CryptoKeyDataRSAComponents.h in Headers */ = {isa = PBXBuildFile; fileRef = E1C266DD18319F31003F8B33 /* CryptoKeyDataRSAComponents.h */; }; … … 12790 12790 E1BE512B0CF6C512002EA959 /* XSLTUnicodeSort.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = XSLTUnicodeSort.cpp; sourceTree = "<group>"; }; 12791 12791 E1BE512C0CF6C512002EA959 /* XSLTUnicodeSort.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = XSLTUnicodeSort.h; sourceTree = "<group>"; }; 12792 E1C266D618317AB4003F8B33 /* CryptoAlgorithmRSASSA_PKCS1_v1_5Mac.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path =CryptoAlgorithmRSASSA_PKCS1_v1_5Mac.cpp; sourceTree = "<group>"; };12793 E1C266DA18319935003F8B33 /* CryptoAlgorithmRsa SsaKeyParams.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CryptoAlgorithmRsaSsaKeyParams.h; path = parameters/CryptoAlgorithmRsaSsaKeyParams.h; sourceTree = "<group>"; };12792 E1C266D618317AB4003F8B33 /* CryptoAlgorithmRSASSA_PKCS1_v1_5Mac.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = CryptoAlgorithmRSASSA_PKCS1_v1_5Mac.cpp; path = mac/CryptoAlgorithmRSASSA_PKCS1_v1_5Mac.cpp; sourceTree = "<group>"; }; 12793 E1C266DA18319935003F8B33 /* CryptoAlgorithmRsaKeyParamsWithHash.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CryptoAlgorithmRsaKeyParamsWithHash.h; path = parameters/CryptoAlgorithmRsaKeyParamsWithHash.h; sourceTree = "<group>"; }; 12794 12794 E1C266DC18319F31003F8B33 /* CryptoKeyDataRSAComponents.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = CryptoKeyDataRSAComponents.cpp; path = keys/CryptoKeyDataRSAComponents.cpp; sourceTree = "<group>"; }; 12795 12795 E1C266DD18319F31003F8B33 /* CryptoKeyDataRSAComponents.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CryptoKeyDataRSAComponents.h; path = keys/CryptoKeyDataRSAComponents.h; sourceTree = "<group>"; }; … … 20435 20435 E1C6571E1816E50300256CDD /* CryptoAlgorithmHmacParams.h */, 20436 20436 E1BD331D182D8F4200C05D9F /* CryptoAlgorithmRsaKeyGenParams.h */, 20437 E1C266DA18319935003F8B33 /* CryptoAlgorithmRsaSsaKeyParams.h */, 20437 E1C266DA18319935003F8B33 /* CryptoAlgorithmRsaKeyParamsWithHash.h */, 20438 E1FE136C183FE21D00892F13 /* CryptoAlgorithmRsaOaepParams.h */, 20438 20439 E1BD331B182D8EE900C05D9F /* CryptoAlgorithmRsaSsaParams.h */, 20439 20440 ); … … 23753 23754 B2FA3DDF0AB75A6F000E5AC4 /* JSSVGPathSegMovetoRel.h in Headers */, 23754 23755 0705852117FDC140005F2BCB /* MediaTrackConstraint.h in Headers */, 23755 E1C266DB18319935003F8B33 /* CryptoAlgorithmRsa SsaKeyParams.h in Headers */,23756 E1C266DB18319935003F8B33 /* CryptoAlgorithmRsaKeyParamsWithHash.h in Headers */, 23756 23757 CD8B5A46180DFF4E008B8E65 /* VideoTrackMediaSource.h in Headers */, 23757 23758 B2FA3DE10AB75A6F000E5AC4 /* JSSVGPatternElement.h in Headers */, -
trunk/Source/WebCore/bindings/js/JSCryptoAlgorithmDictionary.cpp
r159637 r159717 35 35 #include "CryptoAlgorithmRegistry.h" 36 36 #include "CryptoAlgorithmRsaKeyGenParams.h" 37 #include "CryptoAlgorithmRsa SsaKeyParams.h"37 #include "CryptoAlgorithmRsaKeyParamsWithHash.h" 38 38 #include "CryptoAlgorithmRsaSsaParams.h" 39 39 #include "ExceptionCode.h" … … 239 239 } 240 240 241 static std::unique_ptr<CryptoAlgorithmParameters> createRsa SsaKeyParams(ExecState*, JSValue)242 { 243 // WebCrypto RSA SSA-PKCS1-v1_5 algorithm currently doesnot take any parameters to importKey.244 return std::make_unique<CryptoAlgorithmRsa SsaKeyParams>();241 static std::unique_ptr<CryptoAlgorithmParameters> createRsaKeyParamsWithHash(ExecState*, JSValue) 242 { 243 // WebCrypto RSA algorithms currently do not take any parameters to importKey. 244 return std::make_unique<CryptoAlgorithmRsaKeyParamsWithHash>(); 245 245 } 246 246 … … 527 527 return std::make_unique<CryptoAlgorithmParameters>(); 528 528 case CryptoAlgorithmIdentifier::RSASSA_PKCS1_v1_5: 529 return createRsa SsaKeyParams(exec, value);529 return createRsaKeyParamsWithHash(exec, value); 530 530 case CryptoAlgorithmIdentifier::RSA_PSS: 531 531 case CryptoAlgorithmIdentifier::RSA_OAEP: -
trunk/Source/WebCore/bindings/js/JSCryptoKeySerializationJWK.cpp
r159403 r159717 32 32 #include "CryptoAlgorithmHmacParams.h" 33 33 #include "CryptoAlgorithmRegistry.h" 34 #include "CryptoAlgorithmRsa SsaKeyParams.h"34 #include "CryptoAlgorithmRsaKeyParamsWithHash.h" 35 35 #include "CryptoKey.h" 36 36 #include "CryptoKeyAES.h" … … 156 156 } 157 157 158 static std::unique_ptr<CryptoAlgorithmParameters> createRSASSAKeyParameters(CryptoAlgorithmIdentifier hashFunction) 159 { 160 std::unique_ptr<CryptoAlgorithmRsaSsaKeyParams> rsaSSAParameters = std::make_unique<CryptoAlgorithmRsaSsaKeyParams>(); 161 rsaSSAParameters->hasHash = true; 162 rsaSSAParameters->hash = hashFunction; 163 return std::move(rsaSSAParameters); 164 } 165 158 static std::unique_ptr<CryptoAlgorithmParameters> createRSAKeyParametersWithHash(CryptoAlgorithmIdentifier hashFunction) 159 { 160 std::unique_ptr<CryptoAlgorithmRsaKeyParamsWithHash> rsaKeyParameters = std::make_unique<CryptoAlgorithmRsaKeyParamsWithHash>(); 161 rsaKeyParameters->hasHash = true; 162 rsaKeyParameters->hash = hashFunction; 163 return std::move(rsaKeyParameters); 164 } 166 165 167 166 bool JSCryptoKeySerializationJWK::reconcileAlgorithm(std::unique_ptr<CryptoAlgorithm>& suggestedAlgorithm, std::unique_ptr<CryptoAlgorithmParameters>& suggestedParameters) const … … 185 184 } else if (m_jwkAlgorithmName == "RS256") { 186 185 algorithm = CryptoAlgorithmRegistry::shared().create(CryptoAlgorithmIdentifier::RSASSA_PKCS1_v1_5); 187 parameters = createRSA SSAKeyParameters(CryptoAlgorithmIdentifier::SHA_256);186 parameters = createRSAKeyParametersWithHash(CryptoAlgorithmIdentifier::SHA_256); 188 187 } else if (m_jwkAlgorithmName == "RS384") { 189 188 algorithm = CryptoAlgorithmRegistry::shared().create(CryptoAlgorithmIdentifier::RSASSA_PKCS1_v1_5); 190 parameters = createRSA SSAKeyParameters(CryptoAlgorithmIdentifier::SHA_384);189 parameters = createRSAKeyParametersWithHash(CryptoAlgorithmIdentifier::SHA_384); 191 190 } else if (m_jwkAlgorithmName == "RS512") { 192 191 algorithm = CryptoAlgorithmRegistry::shared().create(CryptoAlgorithmIdentifier::RSASSA_PKCS1_v1_5); 193 parameters = createRSA SSAKeyParameters(CryptoAlgorithmIdentifier::SHA_512);192 parameters = createRSAKeyParametersWithHash(CryptoAlgorithmIdentifier::SHA_512); 194 193 } else if (m_jwkAlgorithmName == "A128CBC") { 195 194 algorithm = CryptoAlgorithmRegistry::shared().create(CryptoAlgorithmIdentifier::AES_CBC); … … 221 220 return toCryptoAlgorithmHmacParams(*parameters).hash == toCryptoAlgorithmHmacParams(*suggestedParameters).hash; 222 221 if (algorithm->identifier() == CryptoAlgorithmIdentifier::RSASSA_PKCS1_v1_5) { 223 CryptoAlgorithmRsa SsaKeyParams& rsaSSAParameters = toCryptoAlgorithmRsaSsaKeyParams(*parameters);224 CryptoAlgorithmRsa SsaKeyParams& suggestedRSASSAParameters = toCryptoAlgorithmRsaSsaKeyParams(*suggestedParameters);225 ASSERT(rsa SSAParameters.hasHash);226 if (suggestedRSA SSAParameters.hasHash)227 return suggestedRSA SSAParameters.hash == rsaSSAParameters.hash;228 suggestedRSA SSAParameters.hasHash = true;229 suggestedRSA SSAParameters.hash = rsaSSAParameters.hash;222 CryptoAlgorithmRsaKeyParamsWithHash& rsaKeyParameters = toCryptoAlgorithmRsaKeyParamsWithHash(*parameters); 223 CryptoAlgorithmRsaKeyParamsWithHash& suggestedRSAKeyParameters = toCryptoAlgorithmRsaKeyParamsWithHash(*suggestedParameters); 224 ASSERT(rsaKeyParameters.hasHash); 225 if (suggestedRSAKeyParameters.hasHash) 226 return suggestedRSAKeyParameters.hash == rsaKeyParameters.hash; 227 suggestedRSAKeyParameters.hasHash = true; 228 suggestedRSAKeyParameters.hash = rsaKeyParameters.hash; 230 229 } 231 230 -
trunk/Source/WebCore/crypto/CryptoAlgorithmParameters.h
r159213 r159717 46 46 HmacParams, 47 47 RsaKeyGenParams, 48 Rsa SsaKeyParams,48 RsaKeyParamsWithHash, 49 49 RsaSsaParams 50 50 }; -
trunk/Source/WebCore/crypto/CryptoAlgorithmRegistry.h
r158366 r159717 58 58 typedef std::unique_ptr<CryptoAlgorithm> (*CryptoAlgorithmConstructor)(); 59 59 60 template<typename AlgorithmClass> void registerAlgorithm() 61 { 62 registerAlgorithm(AlgorithmClass::s_name, AlgorithmClass::s_identifier, AlgorithmClass::create); 63 } 64 60 65 void registerAlgorithm(const String& name, CryptoAlgorithmIdentifier, CryptoAlgorithmConstructor); 61 66 HashMap<String, CryptoAlgorithmIdentifier> m_nameToIdentifierMap; -
trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmAES_CBC.cpp
r159578 r159717 29 29 #if ENABLE(SUBTLE_CRYPTO) 30 30 31 #include "CryptoAlgorithmAesCbcParams.h" 31 32 #include "CryptoAlgorithmAesKeyGenParams.h" 32 33 #include "CryptoKeyAES.h" … … 54 55 { 55 56 return s_identifier; 57 } 58 59 bool CryptoAlgorithmAES_CBC::keyAlgorithmMatches(const CryptoAlgorithmAesCbcParams&, const CryptoKey& key) const 60 { 61 if (key.algorithmIdentifier() != s_identifier) 62 return false; 63 ASSERT(isCryptoKeyAES(key)); 64 65 return true; 66 } 67 68 void CryptoAlgorithmAES_CBC::encrypt(const CryptoAlgorithmParameters& parameters, const CryptoKey& key, const CryptoOperationData& data, VectorCallback callback, VoidCallback failureCallback, ExceptionCode& ec) 69 { 70 const CryptoAlgorithmAesCbcParams& aesCBCParameters = toCryptoAlgorithmAesCbcParams(parameters); 71 72 if (!keyAlgorithmMatches(aesCBCParameters, key)) { 73 ec = NOT_SUPPORTED_ERR; 74 return; 75 } 76 77 platformEncrypt(aesCBCParameters, toCryptoKeyAES(key), data, std::move(callback), std::move(failureCallback), ec); 78 } 79 80 void CryptoAlgorithmAES_CBC::decrypt(const CryptoAlgorithmParameters& parameters, const CryptoKey& key, const CryptoOperationData& data, VectorCallback callback, VoidCallback failureCallback, ExceptionCode& ec) 81 { 82 const CryptoAlgorithmAesCbcParams& aesCBCParameters = toCryptoAlgorithmAesCbcParams(parameters); 83 84 if (!keyAlgorithmMatches(aesCBCParameters, key)) { 85 ec = NOT_SUPPORTED_ERR; 86 return; 87 } 88 89 platformDecrypt(aesCBCParameters, toCryptoKeyAES(key), data, std::move(callback), std::move(failureCallback), ec); 56 90 } 57 91 -
trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmAES_CBC.h
r159578 r159717 33 33 namespace WebCore { 34 34 35 class CryptoAlgorithmAesCbcParams; 36 class CryptoKeyAES; 37 35 38 class CryptoAlgorithmAES_CBC FINAL : public CryptoAlgorithm { 36 39 public: … … 50 53 CryptoAlgorithmAES_CBC(); 51 54 virtual ~CryptoAlgorithmAES_CBC(); 55 56 bool keyAlgorithmMatches(const CryptoAlgorithmAesCbcParams& algorithmParameters, const CryptoKey&) const; 57 void platformEncrypt(const CryptoAlgorithmAesCbcParams&, const CryptoKeyAES&, const CryptoOperationData&, VectorCallback, VoidCallback failureCallback, ExceptionCode&); 58 void platformDecrypt(const CryptoAlgorithmAesCbcParams&, const CryptoKeyAES&, const CryptoOperationData&, VectorCallback, VoidCallback failureCallback, ExceptionCode&); 52 59 }; 53 60 -
trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmHMAC.cpp
r159578 r159717 57 57 } 58 58 59 bool CryptoAlgorithmHMAC::keyAlgorithmMatches(const CryptoAlgorithmHmacParams&, const CryptoKey& key) const 60 { 61 if (key.algorithmIdentifier() != s_identifier) 62 return false; 63 ASSERT(isCryptoKeyHMAC(key)); 64 65 return true; 66 } 67 68 void CryptoAlgorithmHMAC::sign(const CryptoAlgorithmParameters& parameters, const CryptoKey& key, const CryptoOperationData& data, VectorCallback callback, VoidCallback failureCallback, ExceptionCode& ec) 69 { 70 const CryptoAlgorithmHmacParams& hmacParameters = toCryptoAlgorithmHmacParams(parameters); 71 72 if (!keyAlgorithmMatches(hmacParameters, key)) { 73 ec = NOT_SUPPORTED_ERR; 74 return; 75 } 76 77 platformSign(hmacParameters, toCryptoKeyHMAC(key), data, std::move(callback), std::move(failureCallback), ec); 78 } 79 80 void CryptoAlgorithmHMAC::verify(const CryptoAlgorithmParameters& parameters, const CryptoKey& key, const CryptoOperationData& expectedSignature, const CryptoOperationData& data, BoolCallback callback, VoidCallback failureCallback, ExceptionCode& ec) 81 { 82 const CryptoAlgorithmHmacParams& hmacParameters = toCryptoAlgorithmHmacParams(parameters); 83 84 if (!keyAlgorithmMatches(hmacParameters, key)) { 85 ec = NOT_SUPPORTED_ERR; 86 return; 87 } 88 89 platformVerify(hmacParameters, toCryptoKeyHMAC(key), expectedSignature, data, std::move(callback), std::move(failureCallback), ec); 90 } 91 59 92 void CryptoAlgorithmHMAC::generateKey(const CryptoAlgorithmParameters& parameters, bool extractable, CryptoKeyUsage usages, KeyOrKeyPairCallback callback, VoidCallback failureCallback, ExceptionCode&) 60 93 { -
trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmHMAC.h
r159578 r159717 33 33 namespace WebCore { 34 34 35 class CryptoAlgorithmHmacParams; 36 class CryptoKeyHMAC; 37 35 38 class CryptoAlgorithmHMAC FINAL : public CryptoAlgorithm { 36 39 public: … … 50 53 CryptoAlgorithmHMAC(); 51 54 virtual ~CryptoAlgorithmHMAC(); 55 56 bool keyAlgorithmMatches(const CryptoAlgorithmHmacParams& algorithmParameters, const CryptoKey&) const; 57 void platformSign(const CryptoAlgorithmHmacParams&, const CryptoKeyHMAC&, const CryptoOperationData&, VectorCallback, VoidCallback failureCallback, ExceptionCode&); 58 void platformVerify(const CryptoAlgorithmHmacParams&, const CryptoKeyHMAC&, const CryptoOperationData& signature, const CryptoOperationData& data, BoolCallback, VoidCallback failureCallback, ExceptionCode&); 52 59 }; 53 60 -
trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmRSASSA_PKCS1_v1_5.cpp
r159578 r159717 30 30 31 31 #include "CryptoAlgorithmRsaKeyGenParams.h" 32 #include "CryptoAlgorithmRsaSsaKeyParams.h" 32 #include "CryptoAlgorithmRsaKeyParamsWithHash.h" 33 #include "CryptoAlgorithmRsaSsaParams.h" 33 34 #include "CryptoKeyDataRSAComponents.h" 34 35 #include "CryptoKeyRSA.h" 36 #include "ExceptionCode.h" 35 37 36 38 namespace WebCore { … … 56 58 } 57 59 60 bool CryptoAlgorithmRSASSA_PKCS1_v1_5::keyAlgorithmMatches(const CryptoAlgorithmRsaSsaParams& algorithmParameters, const CryptoKey& key) const 61 { 62 if (key.algorithmIdentifier() != s_identifier) 63 return false; 64 ASSERT(isCryptoKeyRSA(key)); 65 66 CryptoAlgorithmIdentifier keyHash; 67 if (toCryptoKeyRSA(key).isRestrictedToHash(keyHash) && keyHash != algorithmParameters.hash) 68 return false; 69 70 return true; 71 } 72 73 void CryptoAlgorithmRSASSA_PKCS1_v1_5::sign(const CryptoAlgorithmParameters& parameters, const CryptoKey& key, const CryptoOperationData& data, VectorCallback callback, VoidCallback failureCallback, ExceptionCode& ec) 74 { 75 const CryptoAlgorithmRsaSsaParams& rsaSSAParameters = toCryptoAlgorithmRsaSsaParams(parameters); 76 77 if (!keyAlgorithmMatches(rsaSSAParameters, key)) { 78 ec = NOT_SUPPORTED_ERR; 79 return; 80 } 81 82 platformSign(rsaSSAParameters, toCryptoKeyRSA(key), data, std::move(callback), std::move(failureCallback), ec); 83 } 84 85 void CryptoAlgorithmRSASSA_PKCS1_v1_5::verify(const CryptoAlgorithmParameters& parameters, const CryptoKey& key, const CryptoOperationData& signature, const CryptoOperationData& data, BoolCallback callback, VoidCallback failureCallback, ExceptionCode& ec) 86 { 87 const CryptoAlgorithmRsaSsaParams& rsaSSAParameters = toCryptoAlgorithmRsaSsaParams(parameters); 88 89 if (!keyAlgorithmMatches(rsaSSAParameters, key)) { 90 ec = NOT_SUPPORTED_ERR; 91 return; 92 } 93 94 platformVerify(rsaSSAParameters, toCryptoKeyRSA(key), signature, data, std::move(callback), std::move(failureCallback), ec); 95 } 96 58 97 void CryptoAlgorithmRSASSA_PKCS1_v1_5::generateKey(const CryptoAlgorithmParameters& parameters, bool extractable, CryptoKeyUsage usages, KeyOrKeyPairCallback callback, VoidCallback failureCallback, ExceptionCode&) 59 98 { … … 69 108 void CryptoAlgorithmRSASSA_PKCS1_v1_5::importKey(const CryptoAlgorithmParameters& parameters, const CryptoKeyData& keyData, bool extractable, CryptoKeyUsage usage, KeyCallback callback, VoidCallback failureCallback, ExceptionCode&) 70 109 { 71 const CryptoAlgorithmRsa SsaKeyParams& rsaSSAParameters = toCryptoAlgorithmRsaSsaKeyParams(parameters);110 const CryptoAlgorithmRsaKeyParamsWithHash& rsaKeyParameters = toCryptoAlgorithmRsaKeyParamsWithHash(parameters); 72 111 const CryptoKeyDataRSAComponents& rsaComponents = toCryptoKeyDataRSAComponents(keyData); 73 112 … … 78 117 } 79 118 80 if (rsa SSAParameters.hasHash)81 result->restrictToHash(rsa SSAParameters.hash);119 if (rsaKeyParameters.hasHash) 120 result->restrictToHash(rsaKeyParameters.hash); 82 121 83 122 callback(*result); -
trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmRSASSA_PKCS1_v1_5.h
r159578 r159717 33 33 namespace WebCore { 34 34 35 class CryptoAlgorithmRsaSsaParams; 36 class CryptoKeyRSA; 37 35 38 class CryptoAlgorithmRSASSA_PKCS1_v1_5 FINAL : public CryptoAlgorithm { 36 39 public: … … 50 53 CryptoAlgorithmRSASSA_PKCS1_v1_5(); 51 54 virtual ~CryptoAlgorithmRSASSA_PKCS1_v1_5(); 55 56 bool keyAlgorithmMatches(const CryptoAlgorithmRsaSsaParams& algorithmParameters, const CryptoKey&) const; 57 void platformSign(const CryptoAlgorithmRsaSsaParams&, const CryptoKeyRSA&, const CryptoOperationData&, VectorCallback, VoidCallback failureCallback, ExceptionCode&); 58 void platformVerify(const CryptoAlgorithmRsaSsaParams&, const CryptoKeyRSA&, const CryptoOperationData& signature, const CryptoOperationData& data, BoolCallback, VoidCallback failureCallback, ExceptionCode&); 52 59 }; 53 60 -
trunk/Source/WebCore/crypto/mac/CryptoAlgorithmAES_CBCMac.cpp
r159578 r159717 83 83 } 84 84 85 void CryptoAlgorithmAES_CBC:: encrypt(const CryptoAlgorithmParameters& parameters, const CryptoKey& key, const CryptoOperationData& data, VectorCallback callback, VoidCallback failureCallback, ExceptionCode& ec)85 void CryptoAlgorithmAES_CBC::platformEncrypt(const CryptoAlgorithmAesCbcParams& parameters, const CryptoKeyAES& key, const CryptoOperationData& data, VectorCallback callback, VoidCallback failureCallback, ExceptionCode&) 86 86 { 87 const CryptoAlgorithmAesCbcParams& aesCBCParameters = toCryptoAlgorithmAesCbcParams(parameters); 88 89 if (!isCryptoKeyAES(key)) { 90 ec = NOT_SUPPORTED_ERR; 91 return; 92 } 93 const CryptoKeyAES& aesKey = toCryptoKeyAES(key); 94 95 transformAES_CBC(kCCEncrypt, aesCBCParameters, aesKey, data, std::move(callback), std::move(failureCallback)); 87 transformAES_CBC(kCCEncrypt, parameters, key, data, std::move(callback), std::move(failureCallback)); 96 88 } 97 89 98 void CryptoAlgorithmAES_CBC:: decrypt(const CryptoAlgorithmParameters& parameters, const CryptoKey& key, const CryptoOperationData& data, VectorCallback callback, VoidCallback failureCallback, ExceptionCode& ec)90 void CryptoAlgorithmAES_CBC::platformDecrypt(const CryptoAlgorithmAesCbcParams& parameters, const CryptoKeyAES& key, const CryptoOperationData& data, VectorCallback callback, VoidCallback failureCallback, ExceptionCode&) 99 91 { 100 const CryptoAlgorithmAesCbcParams& aesCBCParameters = toCryptoAlgorithmAesCbcParams(parameters); 101 102 if (!isCryptoKeyAES(key)) { 103 ec = NOT_SUPPORTED_ERR; 104 return; 105 } 106 const CryptoKeyAES& aesKey = toCryptoKeyAES(key); 107 108 transformAES_CBC(kCCDecrypt, aesCBCParameters, aesKey, data, std::move(callback), std::move(failureCallback)); 92 transformAES_CBC(kCCDecrypt, parameters, key, data, std::move(callback), std::move(failureCallback)); 109 93 } 110 94 -
trunk/Source/WebCore/crypto/mac/CryptoAlgorithmHMACMac.cpp
r159578 r159717 89 89 } 90 90 91 void CryptoAlgorithmHMAC:: sign(const CryptoAlgorithmParameters& parameters, const CryptoKey& key, const CryptoOperationData& data, VectorCallback callback, VoidCallback, ExceptionCode& ec)91 void CryptoAlgorithmHMAC::platformSign(const CryptoAlgorithmHmacParams& parameters, const CryptoKeyHMAC& key, const CryptoOperationData& data, VectorCallback callback, VoidCallback, ExceptionCode& ec) 92 92 { 93 const CryptoAlgorithmHmacParams& hmacParameters = toCryptoAlgorithmHmacParams(parameters);94 95 if (!isCryptoKeyHMAC(key)) {96 ec = NOT_SUPPORTED_ERR;97 return;98 }99 const CryptoKeyHMAC& hmacKey = toCryptoKeyHMAC(key);100 101 93 CCHmacAlgorithm algorithm; 102 if (!getCommonCryptoAlgorithm( hmacParameters.hash, algorithm)) {94 if (!getCommonCryptoAlgorithm(parameters.hash, algorithm)) { 103 95 ec = NOT_SUPPORTED_ERR; 104 96 return; 105 97 } 106 98 107 Vector<uint8_t> signature = calculateSignature(algorithm, hmacKey.key(), data);99 Vector<uint8_t> signature = calculateSignature(algorithm, key.key(), data); 108 100 109 101 callback(signature); 110 102 } 111 103 112 void CryptoAlgorithmHMAC:: verify(const CryptoAlgorithmParameters& parameters, const CryptoKey& key, const CryptoOperationData& expectedSignature, const CryptoOperationData& data, BoolCallback callback, VoidCallback, ExceptionCode& ec)104 void CryptoAlgorithmHMAC::platformVerify(const CryptoAlgorithmHmacParams& parameters, const CryptoKeyHMAC& key, const CryptoOperationData& expectedSignature, const CryptoOperationData& data, BoolCallback callback, VoidCallback, ExceptionCode& ec) 113 105 { 114 const CryptoAlgorithmHmacParams& hmacParameters = toCryptoAlgorithmHmacParams(parameters);115 116 if (!isCryptoKeyHMAC(key)) {117 ec = NOT_SUPPORTED_ERR;118 return;119 }120 const CryptoKeyHMAC& hmacKey = toCryptoKeyHMAC(key);121 122 106 CCHmacAlgorithm algorithm; 123 if (!getCommonCryptoAlgorithm( hmacParameters.hash, algorithm)) {107 if (!getCommonCryptoAlgorithm(parameters.hash, algorithm)) { 124 108 ec = NOT_SUPPORTED_ERR; 125 109 return; 126 110 } 127 111 128 Vector<uint8_t> signature = calculateSignature(algorithm, hmacKey.key(), data);112 Vector<uint8_t> signature = calculateSignature(algorithm, key.key(), data); 129 113 130 114 bool result = signature.size() == expectedSignature.second && !memcmp(signature.data(), expectedSignature.first, signature.size()); -
trunk/Source/WebCore/crypto/mac/CryptoAlgorithmRSASSA_PKCS1_v1_5Mac.cpp
r159636 r159717 89 89 } 90 90 91 void CryptoAlgorithmRSASSA_PKCS1_v1_5:: sign(const CryptoAlgorithmParameters& parameters, const CryptoKey& key, const CryptoOperationData& data, VectorCallback callback, VoidCallback failureCallback, ExceptionCode& ec)91 void CryptoAlgorithmRSASSA_PKCS1_v1_5::platformSign(const CryptoAlgorithmRsaSsaParams& parameters, const CryptoKeyRSA& key, const CryptoOperationData& data, VectorCallback callback, VoidCallback failureCallback, ExceptionCode& ec) 92 92 { 93 const CryptoAlgorithmRsaSsaParams& rsaSSAParameters = toCryptoAlgorithmRsaSsaParams(parameters);94 95 if (!isCryptoKeyRSA(key)) {96 ec = NOT_SUPPORTED_ERR;97 return;98 }99 const CryptoKeyRSA& rsaKey = toCryptoKeyRSA(key);100 101 93 CCDigestAlgorithm digestAlgorithm; 102 if (!getCommonCryptoDigestAlgorithm( rsaSSAParameters.hash, digestAlgorithm)) {94 if (!getCommonCryptoDigestAlgorithm(parameters.hash, digestAlgorithm)) { 103 95 ec = NOT_SUPPORTED_ERR; 104 96 return; 105 97 } 106 98 107 std::unique_ptr<CryptoDigest> digest = CryptoDigest::create( rsaSSAParameters.hash);99 std::unique_ptr<CryptoDigest> digest = CryptoDigest::create(parameters.hash); 108 100 if (!digest) { 109 101 ec = NOT_SUPPORTED_ERR; … … 118 110 size_t signatureSize = signature.size(); 119 111 120 CCCryptorStatus status = CCRSACryptorSign( rsaKey.platformKey(), ccPKCS1Padding, digestData.data(), digestData.size(), digestAlgorithm, 0, signature.data(), &signatureSize);112 CCCryptorStatus status = CCRSACryptorSign(key.platformKey(), ccPKCS1Padding, digestData.data(), digestData.size(), digestAlgorithm, 0, signature.data(), &signatureSize); 121 113 if (status) { 122 114 failureCallback(); … … 128 120 } 129 121 130 void CryptoAlgorithmRSASSA_PKCS1_v1_5:: verify(const CryptoAlgorithmParameters& parameters, const CryptoKey& key, const CryptoOperationData& signature, const CryptoOperationData& data, BoolCallback callback, VoidCallback failureCallback, ExceptionCode& ec)122 void CryptoAlgorithmRSASSA_PKCS1_v1_5::platformVerify(const CryptoAlgorithmRsaSsaParams& parameters, const CryptoKeyRSA& key, const CryptoOperationData& signature, const CryptoOperationData& data, BoolCallback callback, VoidCallback failureCallback, ExceptionCode& ec) 131 123 { 132 const CryptoAlgorithmRsaSsaParams& rsaSSAParameters = toCryptoAlgorithmRsaSsaParams(parameters);133 134 if (!isCryptoKeyRSA(key)) {135 ec = NOT_SUPPORTED_ERR;136 return;137 }138 const CryptoKeyRSA& rsaKey = toCryptoKeyRSA(key);139 140 124 CCDigestAlgorithm digestAlgorithm; 141 if (!getCommonCryptoDigestAlgorithm( rsaSSAParameters.hash, digestAlgorithm)) {125 if (!getCommonCryptoDigestAlgorithm(parameters.hash, digestAlgorithm)) { 142 126 ec = NOT_SUPPORTED_ERR; 143 127 return; 144 128 } 145 129 146 std::unique_ptr<CryptoDigest> digest = CryptoDigest::create( rsaSSAParameters.hash);130 std::unique_ptr<CryptoDigest> digest = CryptoDigest::create(parameters.hash); 147 131 if (!digest) { 148 132 ec = NOT_SUPPORTED_ERR; … … 154 138 Vector<uint8_t> digestData = digest->computeHash(); 155 139 156 CCCryptorStatus status = CCRSACryptorVerify( rsaKey.platformKey(), ccPKCS1Padding, digestData.data(), digestData.size(), digestAlgorithm, 0, signature.first, signature.second);140 CCCryptorStatus status = CCRSACryptorVerify(key.platformKey(), ccPKCS1Padding, digestData.data(), digestData.size(), digestAlgorithm, 0, signature.first, signature.second); 157 141 if (!status) 158 142 callback(true); -
trunk/Source/WebCore/crypto/mac/CryptoAlgorithmRegistryMac.cpp
r159180 r159717 42 42 void CryptoAlgorithmRegistry::platformRegisterAlgorithms() 43 43 { 44 registerAlgorithm (CryptoAlgorithmAES_CBC::s_name, CryptoAlgorithmAES_CBC::s_identifier, CryptoAlgorithmAES_CBC::create);45 registerAlgorithm (CryptoAlgorithmHMAC::s_name, CryptoAlgorithmHMAC::s_identifier, CryptoAlgorithmHMAC::create);46 registerAlgorithm (CryptoAlgorithmRSASSA_PKCS1_v1_5::s_name, CryptoAlgorithmRSASSA_PKCS1_v1_5::s_identifier, CryptoAlgorithmRSASSA_PKCS1_v1_5::create);47 registerAlgorithm (CryptoAlgorithmSHA1::s_name, CryptoAlgorithmSHA1::s_identifier, CryptoAlgorithmSHA1::create);48 registerAlgorithm (CryptoAlgorithmSHA224::s_name, CryptoAlgorithmSHA224::s_identifier, CryptoAlgorithmSHA224::create);49 registerAlgorithm (CryptoAlgorithmSHA256::s_name, CryptoAlgorithmSHA256::s_identifier, CryptoAlgorithmSHA256::create);50 registerAlgorithm (CryptoAlgorithmSHA384::s_name, CryptoAlgorithmSHA384::s_identifier, CryptoAlgorithmSHA384::create);51 registerAlgorithm (CryptoAlgorithmSHA512::s_name, CryptoAlgorithmSHA512::s_identifier, CryptoAlgorithmSHA512::create);44 registerAlgorithm<CryptoAlgorithmAES_CBC>(); 45 registerAlgorithm<CryptoAlgorithmHMAC>(); 46 registerAlgorithm<CryptoAlgorithmRSASSA_PKCS1_v1_5>(); 47 registerAlgorithm<CryptoAlgorithmSHA1>(); 48 registerAlgorithm<CryptoAlgorithmSHA224>(); 49 registerAlgorithm<CryptoAlgorithmSHA256>(); 50 registerAlgorithm<CryptoAlgorithmSHA384>(); 51 registerAlgorithm<CryptoAlgorithmSHA512>(); 52 52 } 53 53 -
trunk/Source/WebCore/crypto/parameters/CryptoAlgorithmRsaKeyParamsWithHash.h
r159636 r159717 24 24 */ 25 25 26 #ifndef CryptoAlgorithmRsa SsaKeyParams_h26 #ifndef CryptoAlgorithmRsaKeyParamsWithHash_h 27 27 #define CryptoAlgorithmRsaSsaKey 28 28 … … 37 37 // It is necessary to support import from JWK, which treats hash function as part of algorithm 38 38 // identifier, so we need to remember it to compare with one passed to sign or verify functions. 39 class CryptoAlgorithmRsa SsaKeyParamsFINAL : public CryptoAlgorithmParameters {39 class CryptoAlgorithmRsaKeyParamsWithHash FINAL : public CryptoAlgorithmParameters { 40 40 public: 41 CryptoAlgorithmRsa SsaKeyParams()41 CryptoAlgorithmRsaKeyParamsWithHash() 42 42 : hasHash(false) 43 43 { … … 48 48 CryptoAlgorithmIdentifier hash; 49 49 50 virtual Class parametersClass() const OVERRIDE { return Class::Rsa SsaKeyParams; }50 virtual Class parametersClass() const OVERRIDE { return Class::RsaKeyParamsWithHash; } 51 51 }; 52 52 53 CRYPTO_ALGORITHM_PARAMETERS_CASTS(Rsa SsaKeyParams)53 CRYPTO_ALGORITHM_PARAMETERS_CASTS(RsaKeyParamsWithHash) 54 54 55 55 }
Note: See TracChangeset
for help on using the changeset viewer.