Changeset 159310 in webkit
- Timestamp:
- Nov 14, 2013, 1:44:25 PM (12 years ago)
- Location:
- trunk
- Files:
-
- 4 added
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r159307 r159310 1 2013-11-14 Alexey Proskuryakov <ap@apple.com> 2 3 Implement raw format for WebCrypto key export 4 https://bugs.webkit.org/show_bug.cgi?id=124376 5 6 Reviewed by Anders Carlsson. 7 8 * crypto/subtle/aes-export-key-expected.txt: Added. 9 * crypto/subtle/aes-export-key.html: Added. 10 * crypto/subtle/hmac-export-key-expected.txt: Added. 11 * crypto/subtle/hmac-export-key.html: Added. 12 1 13 2013-11-14 Bear Travis <betravis@adobe.com> 2 14 -
trunk/Source/WebCore/ChangeLog
r159308 r159310 1 2013-11-14 Alexey Proskuryakov <ap@apple.com> 2 3 Implement raw format for WebCrypto key export 4 https://bugs.webkit.org/show_bug.cgi?id=124376 5 6 Reviewed by Anders Carlsson. 7 8 Tests: crypto/subtle/aes-export-key.html 9 crypto/subtle/hmac-export-key.html 10 11 A CryptoKey just exports its native CryptoKeyData, which will also work nicely for 12 JWK format soon. For spki and pkcs8, we'll need to figure out the best way to 13 utilize platform library support for ASN.1, but we are not there yet. 14 15 * bindings/js/JSSubtleCryptoCustom.cpp: 16 (WebCore::JSSubtleCrypto::exportKey): 17 * crypto/CryptoKey.h: 18 * crypto/SubtleCrypto.idl: 19 * crypto/keys/CryptoKeyAES.cpp: 20 (WebCore::CryptoKeyAES::exportData): 21 * crypto/keys/CryptoKeyAES.h: 22 * crypto/keys/CryptoKeyHMAC.cpp: 23 (WebCore::CryptoKeyHMAC::exportData): 24 * crypto/keys/CryptoKeyHMAC.h: 25 26 * crypto/keys/CryptoKeyRSA.h: 27 * crypto/mac/CryptoKeyRSAMac.cpp: 28 (WebCore::CryptoKeyRSA::exportData): 29 Added a dummy implementation for RSA. 30 1 31 2013-11-14 Joseph Pecoraro <pecoraro@apple.com> 2 32 -
trunk/Source/WebCore/bindings/js/JSSubtleCryptoCustom.cpp
r158943 r159310 33 33 #include "CryptoAlgorithmRegistry.h" 34 34 #include "CryptoKeyData.h" 35 #include "CryptoKeyDataOctetSequence.h" 36 #include "CryptoKeyDataRSAComponents.h" 35 37 #include "CryptoKeySerializationRaw.h" 36 38 #include "Document.h" … … 507 509 } 508 510 511 JSValue JSSubtleCrypto::exportKey(JSC::ExecState* exec) 512 { 513 if (exec->argumentCount() < 2) 514 return exec->vm().throwException(exec, createNotEnoughArgumentsError(exec)); 515 516 CryptoKeyFormat keyFormat; 517 if (!cryptoKeyFormatFromJSValue(exec, exec->argument(0), keyFormat)) { 518 ASSERT(exec->hadException()); 519 return jsUndefined(); 520 } 521 522 RefPtr<CryptoKey> key = toCryptoKey(exec->uncheckedArgument(1)); 523 if (!key) 524 return throwTypeError(exec); 525 526 JSPromise* promise = JSPromise::createWithResolver(exec->vm(), globalObject()); 527 auto promiseWrapper = PromiseWrapper::create(globalObject(), promise); 528 529 if (!key->extractable()) { 530 m_impl->document()->addConsoleMessage(JSMessageSource, ErrorMessageLevel, "Key is not extractable"); 531 promiseWrapper->reject(nullptr); 532 return promise; 533 } 534 535 std::unique_ptr<CryptoKeyData> keyData = key->exportData(); 536 if (!keyData) { 537 // FIXME: Shouldn't happen once all key types implement exportData(). 538 promiseWrapper->reject(nullptr); 539 return promise; 540 } 541 542 switch (keyFormat) { 543 case CryptoKeyFormat::Raw: 544 if (isCryptoKeyDataOctetSequence(*keyData)) { 545 Vector<unsigned char> result; 546 result.appendVector(toCryptoKeyDataOctetSequence(*keyData).octetSequence()); 547 promiseWrapper->fulfill(result); 548 } else { 549 m_impl->document()->addConsoleMessage(JSMessageSource, ErrorMessageLevel, "Key cannot be exported to raw format"); 550 promiseWrapper->reject(nullptr); 551 } 552 break; 553 default: 554 throwTypeError(exec, "Unsupported key format"); 555 return jsUndefined(); 556 } 557 558 return promise; 559 } 560 509 561 } // namespace WebCore 510 562 -
trunk/Source/WebCore/crypto/CryptoKey.h
r159213 r159310 39 39 40 40 class CryptoAlgorithmDescriptionBuilder; 41 class CryptoKeyData; 41 42 42 43 ENUM_CLASS(CryptoKeyClass) { … … 60 61 bool allows(CryptoKeyUsage usage) const { return usage == (m_usages & usage); } 61 62 63 virtual std::unique_ptr<CryptoKeyData> exportData() const = 0; 64 62 65 static Vector<char> randomData(size_t); 63 66 -
trunk/Source/WebCore/crypto/SubtleCrypto.idl
r159061 r159310 37 37 [Custom] Promise generateKey(AlgorithmIdentifier algorithm, optional boolean extractable, optional KeyUsage[] keyUsages); 38 38 [Custom] Promise importKey(KeyFormat format, CryptoOperationData keyData, AlgorithmIdentifier? algorithm, optional boolean extractable, optional KeyUsage[] keyUsages); 39 [Custom] Promise exportKey(KeyFormat format, Key key); 39 40 }; -
trunk/Source/WebCore/crypto/keys/CryptoKeyAES.cpp
r158945 r159310 31 31 #include "CryptoAlgorithmDescriptionBuilder.h" 32 32 #include "CryptoAlgorithmRegistry.h" 33 #include "CryptoKeyDataOctetSequence.h" 33 34 #include <wtf/text/WTFString.h> 34 35 … … 63 64 } 64 65 66 std::unique_ptr<CryptoKeyData> CryptoKeyAES::exportData() const 67 { 68 ASSERT(extractable()); 69 return CryptoKeyDataOctetSequence::create(m_key); 70 } 71 65 72 } // namespace WebCore 66 73 -
trunk/Source/WebCore/crypto/keys/CryptoKeyAES.h
r159213 r159310 49 49 const Vector<char>& key() const { return m_key; } 50 50 51 virtual void buildAlgorithmDescription(CryptoAlgorithmDescriptionBuilder&) const OVERRIDE;52 53 51 private: 54 52 CryptoKeyAES(CryptoAlgorithmIdentifier, const Vector<char>& key, bool extractable, CryptoKeyUsage); 53 54 virtual void buildAlgorithmDescription(CryptoAlgorithmDescriptionBuilder&) const OVERRIDE; 55 virtual std::unique_ptr<CryptoKeyData> exportData() const OVERRIDE; 55 56 56 57 Vector<char> m_key; -
trunk/Source/WebCore/crypto/keys/CryptoKeyHMAC.cpp
r158582 r159310 31 31 #include "CryptoAlgorithmDescriptionBuilder.h" 32 32 #include "CryptoAlgorithmRegistry.h" 33 #include "CryptoKeyDataOctetSequence.h" 33 34 #include <wtf/text/WTFString.h> 34 35 … … 78 79 } 79 80 81 std::unique_ptr<CryptoKeyData> CryptoKeyHMAC::exportData() const 82 { 83 ASSERT(extractable()); 84 return CryptoKeyDataOctetSequence::create(m_key); 85 } 86 80 87 } // namespace WebCore 81 88 -
trunk/Source/WebCore/crypto/keys/CryptoKeyHMAC.h
r159213 r159310 49 49 const Vector<char>& key() const { return m_key; } 50 50 51 virtual void buildAlgorithmDescription(CryptoAlgorithmDescriptionBuilder&) const OVERRIDE;52 53 51 private: 54 52 CryptoKeyHMAC(const Vector<char>& key, CryptoAlgorithmIdentifier hash, bool extractable, CryptoKeyUsage); 53 54 virtual void buildAlgorithmDescription(CryptoAlgorithmDescriptionBuilder&) const OVERRIDE; 55 virtual std::unique_ptr<CryptoKeyData> exportData() const OVERRIDE; 55 56 56 57 CryptoAlgorithmIdentifier m_hash; -
trunk/Source/WebCore/crypto/keys/CryptoKeyRSA.h
r159213 r159310 59 59 PlatformRSAKey platformKey() const { return m_platformKey; } 60 60 61 virtual void buildAlgorithmDescription(CryptoAlgorithmDescriptionBuilder&) const OVERRIDE;62 63 61 private: 64 62 CryptoKeyRSA(CryptoAlgorithmIdentifier, CryptoKeyType, PlatformRSAKey, bool extractable, CryptoKeyUsage); 63 64 virtual void buildAlgorithmDescription(CryptoAlgorithmDescriptionBuilder&) const OVERRIDE; 65 virtual std::unique_ptr<CryptoKeyData> exportData() const OVERRIDE; 65 66 66 67 PlatformRSAKey m_platformKey; -
trunk/Source/WebCore/crypto/mac/CryptoKeyRSAMac.cpp
r159211 r159310 144 144 } 145 145 146 std::unique_ptr<CryptoKeyData> CryptoKeyRSA::exportData() const 147 { 148 // Not implemented yet. 149 ASSERT(extractable()); 150 return nullptr; 151 } 152 146 153 static bool bigIntegerToUInt32(const Vector<char>& bigInteger, uint32_t& result) 147 154 {
Note:
See TracChangeset
for help on using the changeset viewer.