Changeset 159292 in webkit
- Timestamp:
- Nov 14, 2013 10:26:36 AM (10 years ago)
- Location:
- trunk
- Files:
-
- 3 added
- 5 deleted
- 9 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r159291 r159292 1 2013-11-14 Alexey Proskuryakov <ap@apple.com> 2 3 Implement RSASSA-PKCS1-v1_5 sign/verify 4 https://bugs.webkit.org/show_bug.cgi?id=124335 5 6 Reviewed by Sam Weinig. 7 8 * crypto/subtle/rsassa-pkcs1-v1_5-sign-verify-expected.txt: Added. 9 * crypto/subtle/rsassa-pkcs1-v1_5-sign-verify.html: Added. 10 1 11 2013-11-14 Hans Muller <hmuller@adobe.com> 2 12 -
trunk/Source/WebCore/ChangeLog
r159291 r159292 1 2013-11-14 Alexey Proskuryakov <ap@apple.com> 2 3 Implement RSASSA-PKCS1-v1_5 sign/verify 4 https://bugs.webkit.org/show_bug.cgi?id=124335 5 6 Reviewed by Sam Weinig. 7 8 Test: crypto/subtle/rsassa-pkcs1-v1_5-sign-verify.html 9 10 * WebCore.xcodeproj/project.pbxproj: Added new files, removed Mac SHA algorithm files. 11 12 * crypto/CryptoAlgorithmRSASSA_PKCS1_v1_5Mac.cpp: 13 (WebCore::getCommonCryptoDigestAlgorithm): 14 (WebCore::CryptoAlgorithmRSASSA_PKCS1_v1_5::sign): 15 (WebCore::CryptoAlgorithmRSASSA_PKCS1_v1_5::verify): 16 Implemented. These take two steps, first a digest is computed, and then it's signed. 17 18 * crypto/CryptoDigest.h: Added. 19 * crypto/mac/CryptoDigestMac.cpp: Added. 20 (WebCore::CryptoDigest::CryptoDigest): 21 (WebCore::CryptoDigest::~CryptoDigest): 22 (WebCore::CryptoDigest::create): 23 (WebCore::CryptoDigest::addBytes): 24 (WebCore::CryptoDigest::computeHash): 25 Added a cross-platform interface and Mac implementation to compute a digest. It 26 should be possible to use it outside WebCrypto if we need to (perhaps even merge 27 with WTF SHA-1 class). 28 The Mac implementation is kind of ugly, but at least it encapsulates the ugliness. 29 30 * crypto/algorithms/CryptoAlgorithmSHA1.cpp: (WebCore::CryptoAlgorithmSHA1::digest): 31 * crypto/algorithms/CryptoAlgorithmSHA224.cpp: (WebCore::CryptoAlgorithmSHA224::digest): 32 * crypto/algorithms/CryptoAlgorithmSHA256.cpp: (WebCore::CryptoAlgorithmSHA256::digest): 33 * crypto/algorithms/CryptoAlgorithmSHA384.cpp: (WebCore::CryptoAlgorithmSHA384::digest): 34 * crypto/algorithms/CryptoAlgorithmSHA512.cpp: (WebCore::CryptoAlgorithmSHA512::digest): 35 * crypto/mac/CryptoAlgorithmSHA1Mac.cpp: Removed. 36 * crypto/mac/CryptoAlgorithmSHA224Mac.cpp: Removed. 37 * crypto/mac/CryptoAlgorithmSHA256Mac.cpp: Removed. 38 * crypto/mac/CryptoAlgorithmSHA384Mac.cpp: Removed. 39 * crypto/mac/CryptoAlgorithmSHA512Mac.cpp: Removed. 40 These are all cross-platform now. 41 1 42 2013-11-14 Hans Muller <hmuller@adobe.com> 2 43 -
trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj
r159268 r159292 5533 5533 E125F82B1822CFEC00D84CD9 /* CryptoAlgorithmSHA1.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E125F8291822CFEC00D84CD9 /* CryptoAlgorithmSHA1.cpp */; }; 5534 5534 E125F82C1822CFEC00D84CD9 /* CryptoAlgorithmSHA1.h in Headers */ = {isa = PBXBuildFile; fileRef = E125F82A1822CFEC00D84CD9 /* CryptoAlgorithmSHA1.h */; }; 5535 E125F82E1822CFFF00D84CD9 /* CryptoAlgorithmSHA1Mac.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E125F82D1822CFFF00D84CD9 /* CryptoAlgorithmSHA1Mac.cpp */; };5536 5535 E125F8311822F11B00D84CD9 /* CryptoAlgorithmHMAC.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E125F82F1822F11B00D84CD9 /* CryptoAlgorithmHMAC.cpp */; }; 5537 5536 E125F8321822F11B00D84CD9 /* CryptoAlgorithmHMAC.h in Headers */ = {isa = PBXBuildFile; fileRef = E125F8301822F11B00D84CD9 /* CryptoAlgorithmHMAC.h */; }; … … 5627 5626 E18772F1126E2629003DD586 /* Language.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E18772F0126E2629003DD586 /* Language.cpp */; }; 5628 5627 E19727161820549E00592D51 /* CryptoKeyType.h in Headers */ = {isa = PBXBuildFile; fileRef = E19727151820549E00592D51 /* CryptoKeyType.h */; }; 5629 E19AC3E21824DC6900349426 /* CryptoAlgorithmSHA224Mac.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E19AC3DE1824DC6900349426 /* CryptoAlgorithmSHA224Mac.cpp */; };5630 E19AC3E31824DC6900349426 /* CryptoAlgorithmSHA256Mac.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E19AC3DF1824DC6900349426 /* CryptoAlgorithmSHA256Mac.cpp */; };5631 E19AC3E41824DC6900349426 /* CryptoAlgorithmSHA384Mac.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E19AC3E01824DC6900349426 /* CryptoAlgorithmSHA384Mac.cpp */; };5632 E19AC3E51824DC6900349426 /* CryptoAlgorithmSHA512Mac.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E19AC3E11824DC6900349426 /* CryptoAlgorithmSHA512Mac.cpp */; };5633 5628 E19AC3EE1824DC7900349426 /* CryptoAlgorithmSHA224.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E19AC3E61824DC7900349426 /* CryptoAlgorithmSHA224.cpp */; }; 5634 5629 E19AC3EF1824DC7900349426 /* CryptoAlgorithmSHA224.h in Headers */ = {isa = PBXBuildFile; fileRef = E19AC3E71824DC7900349426 /* CryptoAlgorithmSHA224.h */; }; … … 5722 5717 E1F80B8D183172B5007885C3 /* JSCryptoKeyPair.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E1F80B8B183172B5007885C3 /* JSCryptoKeyPair.cpp */; }; 5723 5718 E1F80B8E183172B5007885C3 /* JSCryptoKeyPair.h in Headers */ = {isa = PBXBuildFile; fileRef = E1F80B8C183172B5007885C3 /* JSCryptoKeyPair.h */; }; 5719 E1FE13641834351100892F13 /* CryptoDigestMac.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E1FE13621834351100892F13 /* CryptoDigestMac.cpp */; }; 5720 E1FE136718343A1000892F13 /* CryptoDigest.h in Headers */ = {isa = PBXBuildFile; fileRef = E1FE136618343A1000892F13 /* CryptoDigest.h */; }; 5724 5721 E1FF57A30F01255B00891EBB /* ThreadGlobalData.h in Headers */ = {isa = PBXBuildFile; fileRef = E1FF57A20F01255B00891EBB /* ThreadGlobalData.h */; settings = {ATTRIBUTES = (Private, ); }; }; 5725 5722 E1FF57A60F01256B00891EBB /* ThreadGlobalData.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E1FF57A50F01256B00891EBB /* ThreadGlobalData.cpp */; }; … … 12623 12620 E125F8291822CFEC00D84CD9 /* CryptoAlgorithmSHA1.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CryptoAlgorithmSHA1.cpp; sourceTree = "<group>"; }; 12624 12621 E125F82A1822CFEC00D84CD9 /* CryptoAlgorithmSHA1.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CryptoAlgorithmSHA1.h; sourceTree = "<group>"; }; 12625 E125F82D1822CFFF00D84CD9 /* CryptoAlgorithmSHA1Mac.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = CryptoAlgorithmSHA1Mac.cpp; path = mac/CryptoAlgorithmSHA1Mac.cpp; sourceTree = "<group>"; };12626 12622 E125F82F1822F11B00D84CD9 /* CryptoAlgorithmHMAC.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CryptoAlgorithmHMAC.cpp; sourceTree = "<group>"; }; 12627 12623 E125F8301822F11B00D84CD9 /* CryptoAlgorithmHMAC.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CryptoAlgorithmHMAC.h; sourceTree = "<group>"; }; … … 12723 12719 E18772F0126E2629003DD586 /* Language.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Language.cpp; sourceTree = "<group>"; }; 12724 12720 E19727151820549E00592D51 /* CryptoKeyType.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CryptoKeyType.h; sourceTree = "<group>"; }; 12725 E19AC3DE1824DC6900349426 /* CryptoAlgorithmSHA224Mac.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = CryptoAlgorithmSHA224Mac.cpp; path = mac/CryptoAlgorithmSHA224Mac.cpp; sourceTree = "<group>"; };12726 E19AC3DF1824DC6900349426 /* CryptoAlgorithmSHA256Mac.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = CryptoAlgorithmSHA256Mac.cpp; path = mac/CryptoAlgorithmSHA256Mac.cpp; sourceTree = "<group>"; };12727 E19AC3E01824DC6900349426 /* CryptoAlgorithmSHA384Mac.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = CryptoAlgorithmSHA384Mac.cpp; path = mac/CryptoAlgorithmSHA384Mac.cpp; sourceTree = "<group>"; };12728 E19AC3E11824DC6900349426 /* CryptoAlgorithmSHA512Mac.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = CryptoAlgorithmSHA512Mac.cpp; path = mac/CryptoAlgorithmSHA512Mac.cpp; sourceTree = "<group>"; };12729 12721 E19AC3E61824DC7900349426 /* CryptoAlgorithmSHA224.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CryptoAlgorithmSHA224.cpp; sourceTree = "<group>"; }; 12730 12722 E19AC3E71824DC7900349426 /* CryptoAlgorithmSHA224.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CryptoAlgorithmSHA224.h; sourceTree = "<group>"; }; … … 12827 12819 E1F80B8B183172B5007885C3 /* JSCryptoKeyPair.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSCryptoKeyPair.cpp; sourceTree = "<group>"; }; 12828 12820 E1F80B8C183172B5007885C3 /* JSCryptoKeyPair.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSCryptoKeyPair.h; sourceTree = "<group>"; }; 12821 E1FE13621834351100892F13 /* CryptoDigestMac.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = CryptoDigestMac.cpp; path = mac/CryptoDigestMac.cpp; sourceTree = "<group>"; }; 12822 E1FE136618343A1000892F13 /* CryptoDigest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CryptoDigest.h; sourceTree = "<group>"; }; 12829 12823 E1FF57A20F01255B00891EBB /* ThreadGlobalData.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ThreadGlobalData.h; sourceTree = "<group>"; }; 12830 12824 E1FF57A50F01256B00891EBB /* ThreadGlobalData.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ThreadGlobalData.cpp; sourceTree = "<group>"; }; … … 20355 20349 E125F8371822F1EB00D84CD9 /* CryptoAlgorithmHMACMac.cpp */, 20356 20350 E1BB84AC1822CA7400525043 /* CryptoAlgorithmRegistryMac.cpp */, 20357 E125F82D1822CFFF00D84CD9 /* CryptoAlgorithmSHA1Mac.cpp */,20358 20351 E1C266D618317AB4003F8B33 /* CryptoAlgorithmRSASSA_PKCS1_v1_5Mac.cpp */, 20359 E19AC3DE1824DC6900349426 /* CryptoAlgorithmSHA224Mac.cpp */,20360 E19AC3DF1824DC6900349426 /* CryptoAlgorithmSHA256Mac.cpp */,20361 E19AC3E01824DC6900349426 /* CryptoAlgorithmSHA384Mac.cpp */,20362 E19AC3E11824DC6900349426 /* CryptoAlgorithmSHA512Mac.cpp */,20363 20352 E19AC3F8182566F700349426 /* CryptoKeyMac.cpp */, 20364 20353 E164FAA418315E1A00DB4E61 /* CryptoKeyRSAMac.cpp */, 20354 E1FE13621834351100892F13 /* CryptoDigestMac.cpp */, 20365 20355 ); 20366 20356 name = mac; … … 20546 20536 E1FF8F6A180DB5BE00132674 /* CryptoAlgorithmRegistry.cpp */, 20547 20537 E1FF8F6B180DB5BE00132674 /* CryptoAlgorithmRegistry.h */, 20538 E1FE136618343A1000892F13 /* CryptoDigest.h */, 20548 20539 E157A8DC18172C2C009F821D /* CryptoKey.idl */, 20549 20540 E157A8E218173A3A009F821D /* CryptoKey.cpp */, … … 22880 22871 0F099D0917B968A100FF84B9 /* WebCoreTypedArrayController.h in Headers */, 22881 22872 1A88A90517553CD7000C74F9 /* FileIconLoader.h in Headers */, 22873 E1FE136718343A1000892F13 /* CryptoDigest.h in Headers */, 22882 22874 F55B3DBE1251F12D003EF269 /* FileInputType.h in Headers */, 22883 22875 976D6C86122B8A3D001FD1F7 /* FileList.h in Headers */, … … 25696 25688 37C238221098C84200EF9F72 /* ComplexTextControllerCoreText.mm in Sources */, 25697 25689 316FE1150E6E1DA700BF6088 /* CompositeAnimation.cpp in Sources */, 25698 E19AC3E31824DC6900349426 /* CryptoAlgorithmSHA256Mac.cpp in Sources */,25699 25690 93309DDC099E64920056E581 /* CompositeEditCommand.cpp in Sources */, 25700 25691 79F2F5A11091939A000D87CB /* CompositionEvent.cpp in Sources */, … … 26391 26382 A81369D7097374F600D74463 /* HTMLTextAreaElement.cpp in Sources */, 26392 26383 9BC6C21C13CCC97B008E0337 /* HTMLTextFormControlElement.cpp in Sources */, 26393 E125F82E1822CFFF00D84CD9 /* CryptoAlgorithmSHA1Mac.cpp in Sources */,26394 26384 A871DC290A15205700B12A68 /* HTMLTitleElement.cpp in Sources */, 26395 26385 977B3877122883E900B81FF8 /* HTMLTokenizer.cpp in Sources */, … … 27270 27260 85031B490A44EFC700F992E0 /* MutationEvent.cpp in Sources */, 27271 27261 C6F0900E14327B6100685849 /* MutationObserver.cpp in Sources */, 27272 E19AC3E51824DC6900349426 /* CryptoAlgorithmSHA512Mac.cpp in Sources */,27273 27262 D6E528A3149A926D00EFE1F3 /* MutationObserverInterestGroup.cpp in Sources */, 27274 27263 E19AC3F9182566F700349426 /* CryptoKeyMac.cpp in Sources */, … … 27641 27630 BCD0E0FA0E972C3500265DEA /* SecurityOrigin.cpp in Sources */, 27642 27631 974D2DA4146A535D00D51F8B /* SecurityPolicy.cpp in Sources */, 27643 E19AC3E21824DC6900349426 /* CryptoAlgorithmSHA224Mac.cpp in Sources */,27644 27632 371F4FFD0D25E7F300ECE0D5 /* SegmentedFontData.cpp in Sources */, 27645 27633 B2C3DA2E0D006C1D00EF6F26 /* SegmentedString.cpp in Sources */, … … 28151 28139 FB719C4017238CAE0022DE34 /* WebKitCSSMatFunctionValue.cpp in Sources */, 28152 28140 078E091117D14CEE00420AA1 /* RTCVoidRequestImpl.cpp in Sources */, 28141 E1FE13641834351100892F13 /* CryptoDigestMac.cpp in Sources */, 28153 28142 498391580F1E776900C23782 /* WebKitCSSMatrix.cpp in Sources */, 28154 28143 A24BF77C15CC3BAF003191F2 /* WebKitCSSMixFunctionValue.cpp in Sources */, … … 28221 28210 BC772C460C4EB2C60083285F /* XMLHttpRequest.cpp in Sources */, 28222 28211 978D07CE145A10370096908D /* XMLHttpRequestException.cpp in Sources */, 28223 E19AC3E41824DC6900349426 /* CryptoAlgorithmSHA384Mac.cpp in Sources */,28224 28212 A136A00C1134DBD200CC8D50 /* XMLHttpRequestProgressEventThrottle.cpp in Sources */, 28225 28213 BCDFD48F0E305290009D10AD /* XMLHttpRequestUpload.cpp in Sources */, -
trunk/Source/WebCore/crypto/CryptoAlgorithmRSASSA_PKCS1_v1_5Mac.cpp
r159180 r159292 29 29 #if ENABLE(SUBTLE_CRYPTO) 30 30 31 #include "CryptoAlgorithmRsaSsaParams.h" 32 #include "CryptoDigest.h" 33 #include "CryptoKeyRSA.h" 31 34 #include "ExceptionCode.h" 35 #include "JSDOMPromise.h" 36 37 #if defined(__has_include) 38 #if __has_include(<CommonCrypto/CommonRSACryptor.h>) 39 #include <CommonCrypto/CommonRSACryptor.h> 40 #endif 41 #endif 42 43 #ifndef _CC_RSACRYPTOR_H_ 44 enum { 45 ccPKCS1Padding = 1001 46 }; 47 typedef uint32_t CCAsymmetricPadding; 48 49 enum { 50 kCCDigestSHA1 = 8, 51 kCCDigestSHA224 = 9, 52 kCCDigestSHA256 = 10, 53 kCCDigestSHA384 = 11, 54 kCCDigestSHA512 = 12, 55 }; 56 typedef uint32_t CCDigestAlgorithm; 57 58 enum { 59 kCCNotVerified = -4306 60 }; 61 #endif 62 63 extern "C" CCCryptorStatus CCRSACryptorSign(CCRSACryptorRef privateKey, CCAsymmetricPadding padding, const void *hashToSign, size_t hashSignLen, CCDigestAlgorithm digestType, size_t saltLen, void *signedData, size_t *signedDataLen); 64 extern "C" CCCryptorStatus CCRSACryptorVerify(CCRSACryptorRef publicKey, CCAsymmetricPadding padding, const void *hash, size_t hashLen, CCDigestAlgorithm digestType, size_t saltLen, const void *signedData, size_t signedDataLen); 32 65 33 66 namespace WebCore { 34 67 35 void CryptoAlgorithmRSASSA_PKCS1_v1_5::sign(const CryptoAlgorithmParameters&, const CryptoKey&, const Vector<CryptoOperationData>&, std::unique_ptr<PromiseWrapper>, ExceptionCode& ec)68 static bool getCommonCryptoDigestAlgorithm(CryptoAlgorithmIdentifier hashFunction, CCDigestAlgorithm& algorithm) 36 69 { 37 ec = NOT_SUPPORTED_ERR; 70 switch (hashFunction) { 71 case CryptoAlgorithmIdentifier::SHA_1: 72 algorithm = kCCDigestSHA1; 73 return true; 74 case CryptoAlgorithmIdentifier::SHA_224: 75 algorithm = kCCDigestSHA224; 76 return true; 77 case CryptoAlgorithmIdentifier::SHA_256: 78 algorithm = kCCDigestSHA256; 79 return true; 80 case CryptoAlgorithmIdentifier::SHA_384: 81 algorithm = kCCDigestSHA384; 82 return true; 83 case CryptoAlgorithmIdentifier::SHA_512: 84 algorithm = kCCDigestSHA512; 85 return true; 86 default: 87 return false; 88 } 38 89 } 39 90 40 void CryptoAlgorithmRSASSA_PKCS1_v1_5:: verify(const CryptoAlgorithmParameters&, const CryptoKey&, const CryptoOperationData& /*signature*/, const Vector<CryptoOperationData>& /*data*/, std::unique_ptr<PromiseWrapper>, ExceptionCode& ec)91 void CryptoAlgorithmRSASSA_PKCS1_v1_5::sign(const CryptoAlgorithmParameters& parameters, const CryptoKey& key, const Vector<CryptoOperationData>& data, std::unique_ptr<PromiseWrapper> promise, ExceptionCode& ec) 41 92 { 42 ec = NOT_SUPPORTED_ERR; 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 CCDigestAlgorithm digestAlgorithm; 102 if (!getCommonCryptoDigestAlgorithm(rsaSSAParameters.hash, digestAlgorithm)) { 103 ec = NOT_SUPPORTED_ERR; 104 return; 105 } 106 107 std::unique_ptr<CryptoDigest> digest = CryptoDigest::create(rsaSSAParameters.hash); 108 if (!digest) { 109 ec = NOT_SUPPORTED_ERR; 110 return; 111 } 112 113 for (size_t i = 0; i != data.size(); ++i) 114 digest->addBytes(data[i].first, data[i].second); 115 116 Vector<unsigned char> digestData = digest->computeHash(); 117 118 Vector<unsigned char> signature(512); 119 size_t signatureSize = signature.size(); 120 121 CCCryptorStatus status = CCRSACryptorSign(rsaKey.platformKey(), ccPKCS1Padding, digestData.data(), digestData.size(), digestAlgorithm, 0, signature.data(), &signatureSize); 122 if (status) { 123 promise->reject(nullptr); 124 return; 125 } 126 127 signature.resize(signatureSize); 128 promise->fulfill(signature); 129 } 130 131 void CryptoAlgorithmRSASSA_PKCS1_v1_5::verify(const CryptoAlgorithmParameters& parameters, const CryptoKey& key, const CryptoOperationData& signature, const Vector<CryptoOperationData>& data, std::unique_ptr<PromiseWrapper> promise, ExceptionCode& ec) 132 { 133 const CryptoAlgorithmRsaSsaParams& rsaSSAParameters = toCryptoAlgorithmRsaSsaParams(parameters); 134 135 if (!isCryptoKeyRSA(key)) { 136 ec = NOT_SUPPORTED_ERR; 137 return; 138 } 139 const CryptoKeyRSA& rsaKey = toCryptoKeyRSA(key); 140 141 CCDigestAlgorithm digestAlgorithm; 142 if (!getCommonCryptoDigestAlgorithm(rsaSSAParameters.hash, digestAlgorithm)) { 143 ec = NOT_SUPPORTED_ERR; 144 return; 145 } 146 147 std::unique_ptr<CryptoDigest> digest = CryptoDigest::create(rsaSSAParameters.hash); 148 if (!digest) { 149 ec = NOT_SUPPORTED_ERR; 150 return; 151 } 152 153 for (size_t i = 0; i != data.size(); ++i) 154 digest->addBytes(data[i].first, data[i].second); 155 156 Vector<unsigned char> digestData = digest->computeHash(); 157 158 CCCryptorStatus status = CCRSACryptorVerify(rsaKey.platformKey(), ccPKCS1Padding, digestData.data(), digestData.size(), digestAlgorithm, 0, signature.first, signature.second); 159 if (!status) 160 promise->fulfill(true); 161 else if (status == kCCNotVerified || kCCDecodeError) // <rdar://problem/15464982> CCRSACryptorVerify returns kCCDecodeError instead of kCCNotVerified sometimes 162 promise->fulfill(false); 163 else 164 promise->reject(nullptr); 43 165 } 44 166 -
trunk/Source/WebCore/crypto/CryptoDigest.h
r159291 r159292 24 24 */ 25 25 26 #include "config.h" 27 #include "CryptoAlgorithmSHA512.h" 26 #ifndef CryptoDigest_h 27 #define CryptoDigest_h 28 29 #include "CryptoAlgorithmIdentifier.h" 30 #include <wtf/Noncopyable.h> 31 #include <wtf/Vector.h> 28 32 29 33 #if ENABLE(SUBTLE_CRYPTO) … … 31 35 namespace WebCore { 32 36 33 const char* const CryptoAlgorithmSHA512::s_name = "sha-512";37 struct CryptoDigestContext; 34 38 35 CryptoAlgorithmSHA512::CryptoAlgorithmSHA512() 36 { 37 } 39 class CryptoDigest { 40 WTF_MAKE_NONCOPYABLE(CryptoDigest); 41 public: 42 static std::unique_ptr<CryptoDigest> create(CryptoAlgorithmIdentifier); 43 ~CryptoDigest(); 38 44 39 CryptoAlgorithmSHA512::~CryptoAlgorithmSHA512() 40 { 41 } 45 void addBytes(const void* input, size_t length); 46 Vector<unsigned char> computeHash(); 42 47 43 std::unique_ptr<CryptoAlgorithm> CryptoAlgorithmSHA512::create() 44 { 45 return std::unique_ptr<CryptoAlgorithm>(new CryptoAlgorithmSHA512); 46 } 48 private: 49 CryptoDigest(); 47 50 48 CryptoAlgorithmIdentifier CryptoAlgorithmSHA512::identifier() const 49 { 50 return s_identifier; 51 } 51 std::unique_ptr<CryptoDigestContext> m_context; 52 }; 52 53 53 } 54 } // namespace WebCore 54 55 55 56 #endif // ENABLE(SUBTLE_CRYPTO) 57 #endif // CryptoDigest_h -
trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmSHA1.cpp
r158396 r159292 29 29 #if ENABLE(SUBTLE_CRYPTO) 30 30 31 #include "CryptoDigest.h" 32 #include "JSDOMPromise.h" 33 31 34 namespace WebCore { 32 35 … … 51 54 } 52 55 56 void CryptoAlgorithmSHA1::digest(const CryptoAlgorithmParameters&, const Vector<CryptoOperationData>& data, std::unique_ptr<PromiseWrapper> promise, ExceptionCode&) 57 { 58 std::unique_ptr<CryptoDigest> digest = CryptoDigest::create(CryptoAlgorithmIdentifier::SHA_1); 59 if (!digest) { 60 promise->reject(nullptr); 61 return; 62 } 63 64 for (size_t i = 0, size = data.size(); i < size; ++i) 65 digest->addBytes(data[i].first, data[i].second); 66 67 promise->fulfill(digest->computeHash()); 68 } 69 53 70 } 54 71 -
trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmSHA224.cpp
r158494 r159292 29 29 #if ENABLE(SUBTLE_CRYPTO) 30 30 31 #include "CryptoDigest.h" 32 #include "JSDOMPromise.h" 33 31 34 namespace WebCore { 32 35 … … 51 54 } 52 55 56 void CryptoAlgorithmSHA224::digest(const CryptoAlgorithmParameters&, const Vector<CryptoOperationData>& data, std::unique_ptr<PromiseWrapper> promise, ExceptionCode&) 57 { 58 std::unique_ptr<CryptoDigest> digest = CryptoDigest::create(CryptoAlgorithmIdentifier::SHA_224); 59 if (!digest) { 60 promise->reject(nullptr); 61 return; 62 } 63 64 for (size_t i = 0, size = data.size(); i < size; ++i) 65 digest->addBytes(data[i].first, data[i].second); 66 67 promise->fulfill(digest->computeHash()); 68 } 69 53 70 } 54 71 -
trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmSHA256.cpp
r158494 r159292 29 29 #if ENABLE(SUBTLE_CRYPTO) 30 30 31 #include "CryptoDigest.h" 32 #include "JSDOMPromise.h" 33 31 34 namespace WebCore { 32 35 … … 51 54 } 52 55 56 void CryptoAlgorithmSHA256::digest(const CryptoAlgorithmParameters&, const Vector<CryptoOperationData>& data, std::unique_ptr<PromiseWrapper> promise, ExceptionCode&) 57 { 58 std::unique_ptr<CryptoDigest> digest = CryptoDigest::create(CryptoAlgorithmIdentifier::SHA_256); 59 if (!digest) { 60 promise->reject(nullptr); 61 return; 62 } 63 64 for (size_t i = 0, size = data.size(); i < size; ++i) 65 digest->addBytes(data[i].first, data[i].second); 66 67 promise->fulfill(digest->computeHash()); 68 } 69 53 70 } 54 71 -
trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmSHA384.cpp
r158494 r159292 29 29 #if ENABLE(SUBTLE_CRYPTO) 30 30 31 #include "CryptoDigest.h" 32 #include "JSDOMPromise.h" 33 31 34 namespace WebCore { 32 35 … … 51 54 } 52 55 56 void CryptoAlgorithmSHA384::digest(const CryptoAlgorithmParameters&, const Vector<CryptoOperationData>& data, std::unique_ptr<PromiseWrapper> promise, ExceptionCode&) 57 { 58 std::unique_ptr<CryptoDigest> digest = CryptoDigest::create(CryptoAlgorithmIdentifier::SHA_384); 59 if (!digest) { 60 promise->reject(nullptr); 61 return; 62 } 63 64 for (size_t i = 0, size = data.size(); i < size; ++i) 65 digest->addBytes(data[i].first, data[i].second); 66 67 promise->fulfill(digest->computeHash()); 68 } 69 53 70 } 54 71 -
trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmSHA512.cpp
r158494 r159292 29 29 #if ENABLE(SUBTLE_CRYPTO) 30 30 31 #include "CryptoDigest.h" 32 #include "JSDOMPromise.h" 33 31 34 namespace WebCore { 32 35 … … 51 54 } 52 55 56 void CryptoAlgorithmSHA512::digest(const CryptoAlgorithmParameters&, const Vector<CryptoOperationData>& data, std::unique_ptr<PromiseWrapper> promise, ExceptionCode&) 57 { 58 std::unique_ptr<CryptoDigest> digest = CryptoDigest::create(CryptoAlgorithmIdentifier::SHA_512); 59 if (!digest) { 60 promise->reject(nullptr); 61 return; 62 } 63 64 for (size_t i = 0, size = data.size(); i < size; ++i) 65 digest->addBytes(data[i].first, data[i].second); 66 67 promise->fulfill(digest->computeHash()); 68 } 69 53 70 } 54 71
Note: See TracChangeset
for help on using the changeset viewer.