1. 04 Dec, 2013 1 commit
    • ap@apple.com's avatar
      Update WebCrypto JWK mapping to newer proposal · e6074e79
      ap@apple.com authored
      https://bugs.webkit.org/show_bug.cgi?id=124218
      
      Reviewed by Anders Carlsson.
      
      Source/WebCore: 
      
      Tests: crypto/subtle/jwk-export-use-values.html
             crypto/subtle/jwk-import-use-values.html
      
      1. "extractable" renamed to "ext" in JWK.
      2. New values for "use" mapping, which can now be combined into comma separated lists,
      and cover all possible WebCrypto usages.
      
      * bindings/js/JSCryptoKeySerializationJWK.cpp:
      (WebCore::JSCryptoKeySerializationJWK::reconcileUsages):
      (WebCore::JSCryptoKeySerializationJWK::reconcileExtractable):
      (WebCore::JSCryptoKeySerializationJWK::addJWKAlgorithmToJSON):
      (WebCore::processUseValue):
      (WebCore::JSCryptoKeySerializationJWK::addJWKUseToJSON):
      (WebCore::JSCryptoKeySerializationJWK::serialize):
      
      LayoutTests: 
      
      * crypto/subtle/jwk-export-use-values-expected.txt: Added.
      * crypto/subtle/jwk-export-use-values.html: Added.
      * crypto/subtle/jwk-import-use-values-expected.txt: Added.
      * crypto/subtle/jwk-import-use-values.html: Added.
      New tests for "use" mapping.
      
      * crypto/subtle/aes-cbc-import-jwk.html:
      * crypto/subtle/aes-cbc-unwrap-rsa.html:
      * crypto/subtle/aes-cbc-wrap-rsa-non-extractable.html:
      * crypto/subtle/aes-cbc-wrap-rsa.html:
      * crypto/subtle/aes-export-key-expected.txt:
      * crypto/subtle/aes-export-key.html:
      * crypto/subtle/hmac-export-key-expected.txt:
      * crypto/subtle/hmac-export-key.html:
      * crypto/subtle/hmac-import-jwk.html:
      * crypto/subtle/import-jwk-expected.txt:
      * crypto/subtle/import-jwk.html:
      * crypto/subtle/rsa-export-key-expected.txt:
      * crypto/subtle/rsa-export-key.html:
      * crypto/subtle/rsa-export-private-key-expected.txt:
      * crypto/subtle/rsa-export-private-key.html:
      * crypto/subtle/rsa-oaep-key-manipulation-expected.txt:
      * crypto/subtle/rsa-oaep-key-manipulation.html:
      
      
      
      git-svn-id: http://svn.webkit.org/repository/webkit/trunk@160061 268f45cc-cd09-0410-ab3c-d52691b4dbfc
      e6074e79
  2. 02 Dec, 2013 2 commits
    • ap@apple.com's avatar
      Support WebCrypto AES-KW · 24ef25bb
      ap@apple.com authored
      https://bugs.webkit.org/show_bug.cgi?id=125105
      
      Reviewed by Sam Weinig.
      
      Source/WebCore: 
      
      Tests: crypto/subtle/aes-kw-key-manipulation.html
             crypto/subtle/aes-kw-wrap-unwrap-aes.html
      
      * WebCore.xcodeproj/project.pbxproj: Added new files.
      
      * crypto/CryptoAlgorithmIdentifier.h: (WebCore::CryptoAlgorithmIdentifier): Added AES-KW.
      It's not standardized yet, but there appears to be a consensus that it will be specified.
      
      * bindings/js/JSCryptoAlgorithmDictionary.cpp:
      (WebCore::JSCryptoAlgorithmDictionary::createParametersForEncrypt):
      (WebCore::JSCryptoAlgorithmDictionary::createParametersForDecrypt):
      (WebCore::JSCryptoAlgorithmDictionary::createParametersForSign):
      (WebCore::JSCryptoAlgorithmDictionary::createParametersForVerify):
      (WebCore::JSCryptoAlgorithmDictionary::createParametersForDigest):
      (WebCore::JSCryptoAlgorithmDictionary::createParametersForGenerateKey):
      (WebCore::JSCryptoAlgorithmDictionary::createParametersForDeriveKey):
      (WebCore::JSCryptoAlgorithmDictionary::createParametersForDeriveBits):
      (WebCore::JSCryptoAlgorithmDictionary::createParametersForImportKey):
      (WebCore::JSCryptoAlgorithmDictionary::createParametersForExportKey):
      Added AES-KW cases everywhere.
      
      * bindings/js/JSCryptoKeySerializationJWK.cpp:
      (WebCore::JSCryptoKeySerializationJWK::reconcileAlgorithm):
      (WebCore::JSCryptoKeySerializationJWK::keySizeIsValid):
      (WebCore::JSCryptoKeySerializationJWK::addJWKAlgorithmToJSON):
      Support importing/exporting AES-KW keys in JWK.
      
      * bindings/js/JSSubtleCryptoCustom.cpp:
      (WebCore::JSSubtleCrypto::importKey):
      (WebCore::JSSubtleCrypto::exportKey):
      (WebCore::JSSubtleCrypto::wrapKey):
      (WebCore::JSSubtleCrypto::unwrapKey):
      Added some accidentally forgotten std::moves.
      
      * crypto/algorithms/CryptoAlgorithmAES_KW.cpp: Added.
      * crypto/algorithms/CryptoAlgorithmAES_KW.h: Added.
      * crypto/mac/CryptoAlgorithmAES_KWMac.cpp: Added.
      
      * crypto/keys/CryptoKeyAES.cpp: (WebCore::CryptoKeyAES::CryptoKeyAES): Allow AES-KW
      as valid algorithm for AES keys.
      
      * crypto/mac/CryptoAlgorithmRegistryMac.cpp:
      (WebCore::CryptoAlgorithmRegistry::platformRegisterAlgorithms): Register AES-KW.
      
      LayoutTests: 
      
      * crypto/subtle/aes-kw-key-manipulation-expected.txt: Added.
      * crypto/subtle/aes-kw-key-manipulation.html: Added.
      * crypto/subtle/aes-kw-wrap-unwrap-aes-expected.txt: Added.
      * crypto/subtle/aes-kw-wrap-unwrap-aes.html: Added.
      
      
      
      git-svn-id: http://svn.webkit.org/repository/webkit/trunk@159966 268f45cc-cd09-0410-ab3c-d52691b4dbfc
      24ef25bb
    • ap@apple.com's avatar
      Add support for WebCrypto RSA-OAEP · a3d6e70d
      ap@apple.com authored
      https://bugs.webkit.org/show_bug.cgi?id=125084
      
      Reviewed by Sam Weinig.
      
      Source/WebCore: 
      
      Tests: crypto/subtle/rsa-oaep-key-manipulation.html
             crypto/subtle/rsa-oaep-plaintext-length.html
             crypto/subtle/rsa-oaep-wrap-unwrap-aes.html
      
      * WebCore.xcodeproj/project.pbxproj: Added new files.
      
      * bindings/js/JSCryptoAlgorithmDictionary.cpp:
      (WebCore::createRsaOaepParams):
      (WebCore::JSCryptoAlgorithmDictionary::createParametersForEncrypt):
      (WebCore::JSCryptoAlgorithmDictionary::createParametersForDecrypt):
      (WebCore::JSCryptoAlgorithmDictionary::createParametersForImportKey):
      Added RSA-OAEP parameters.
      
      * bindings/js/JSCryptoKeySerializationJWK.cpp:
      (WebCore::JSCryptoKeySerializationJWK::reconcileAlgorithm):
      (WebCore::JSCryptoKeySerializationJWK::keySizeIsValid):
      (WebCore::JSCryptoKeySerializationJWK::addJWKAlgorithmToJSON):
      Support RSA-OAEP in JWK. It is more limited than general WebCrypto, as JWK only
      allows SHA-1 as hash.
      
      * crypto/CommonCryptoUtilities.cpp: Added. (WebCore::getCommonCryptoDigestAlgorithm):
      * crypto/CommonCryptoUtilities.h: Added.
      Extracted some shared code and forward declarations for CommonCrypto.
      
      * crypto/CryptoAlgorithmParameters.h: (WebCore::CryptoAlgorithmParameters::Class):
      * crypto/parameters/CryptoAlgorithmRsaOaepParams.h: Added.
      Added RsaOaepParams.
      
      * crypto/algorithms/CryptoAlgorithmRSA_OAEP.cpp: Added.
      * crypto/algorithms/CryptoAlgorithmRSA_OAEP.h: Added.
      * crypto/mac/CryptoAlgorithmRSA_OAEPMac.cpp: Added.
      
      * crypto/mac/CryptoAlgorithmHMACMac.cpp:
      (WebCore::getCommonCryptoHMACAlgorithm):
      (WebCore::CryptoAlgorithmHMAC::platformSign):
      (WebCore::CryptoAlgorithmHMAC::platformVerify):
      * crypto/mac/CryptoAlgorithmRSASSA_PKCS1_v1_5Mac.cpp:
      * crypto/mac/CryptoKeyMac.cpp:
      * crypto/mac/CryptoKeyRSAMac.cpp:
      Use CommonCryptoUtilities.
      
      * crypto/mac/CryptoAlgorithmRegistryMac.cpp:
      (WebCore::CryptoAlgorithmRegistry::platformRegisterAlgorithms): Register RSA-OAEP.
      
      LayoutTests: 
      
      * crypto/subtle/rsa-oaep-key-manipulation-expected.txt: Added.
      * crypto/subtle/rsa-oaep-key-manipulation.html: Added.
      * crypto/subtle/rsa-oaep-plaintext-length-expected.txt: Added.
      * crypto/subtle/rsa-oaep-plaintext-length.html: Added.
      * crypto/subtle/rsa-oaep-wrap-unwrap-aes-expected.txt: Added.
      * crypto/subtle/rsa-oaep-wrap-unwrap-aes.html: Added.
      
      
      
      git-svn-id: http://svn.webkit.org/repository/webkit/trunk@159944 268f45cc-cd09-0410-ab3c-d52691b4dbfc
      a3d6e70d
  3. 22 Nov, 2013 1 commit
    • ap@apple.com's avatar
      WebCrypto algorithms should check that key algorithm matches · 9e2346a1
      ap@apple.com authored
      https://bugs.webkit.org/show_bug.cgi?id=123628
      
      Reviewed by Anders Carlsson.
      
      No change in behavior yet, because we have one algorithm per key class.
      Will be tested once more algorithms are added.
      
      * WebCore.xcodeproj/project.pbxproj: Updated for file renames.
      
      * bindings/js/JSCryptoAlgorithmDictionary.cpp:
      (WebCore::createRsaKeyParamsWithHash):
      (WebCore::JSCryptoAlgorithmDictionary::createParametersForImportKey):
      * bindings/js/JSCryptoKeySerializationJWK.cpp:
      (WebCore::createRSAKeyParametersWithHash):
      (WebCore::JSCryptoKeySerializationJWK::reconcileAlgorithm):
      * crypto/CryptoAlgorithmParameters.h:
      (WebCore::CryptoAlgorithmParameters::ENUM_CLASS):
      * crypto/parameters/CryptoAlgorithmRsaKeyParamsWithHash.h: Copied from Source/WebCore/crypto/parameters/CryptoAlgorithmRsaSsaKeyParams.h.
      * crypto/parameters/CryptoAlgorithmRsaSsaKeyParams.h: Removed.
      Renamed RsaSsaKeyParams to RsaKeyParamsWithHash, because other algorithms (like RSA-OAEP)
      are in the same boat. Depending on where the spec goes, we might need to introduce
      algorithm specific RSA parameter classes later, but let's reduce copy/pasted code at
      least for now.
      
      * crypto/CryptoAlgorithmRSASSA_PKCS1_v1_5Mac.cpp: Moved to the correct directory.
      * crypto/mac/CryptoAlgorithmRSASSA_PKCS1_v1_5Mac.cpp: Copied from Source/WebCore/crypto/CryptoAlgorithmRSASSA_PKCS1_v1_5Mac.cpp.
      (WebCore::CryptoAlgorithmRSASSA_PKCS1_v1_5::platformSign): Factored out Mac specific
      code, leaving type casting to cross-platform files.
      (WebCore::CryptoAlgorithmRSASSA_PKCS1_v1_5::platformVerify): Ditto.
      
      * crypto/CryptoAlgorithmRegistry.h:
      (WebCore::CryptoAlgorithmRegistry::registerAlgorithm):
      * crypto/mac/CryptoAlgorithmRegistryMac.cpp:
      (WebCore::CryptoAlgorithmRegistry::platformRegisterAlgorithms):
      Reduce copy/pasting in registration code.
      
      * crypto/algorithms/CryptoAlgorithmAES_CBC.cpp:
      (WebCore::CryptoAlgorithmAES_CBC::keyAlgorithmMatches): Check key type and algorithm.
      (WebCore::CryptoAlgorithmAES_CBC::encrypt): Cross platform type casting code.
      Maybe we'll find a way to autogenerate or eliminate it one day.
      (WebCore::CryptoAlgorithmAES_CBC::decrypt): Ditto.
      
      * crypto/algorithms/CryptoAlgorithmAES_CBC.h:
      * crypto/algorithms/CryptoAlgorithmHMAC.cpp:
      (WebCore::CryptoAlgorithmHMAC::keyAlgorithmMatches):
      (WebCore::CryptoAlgorithmHMAC::sign):
      (WebCore::CryptoAlgorithmHMAC::verify):
      * crypto/algorithms/CryptoAlgorithmHMAC.h:
      * crypto/algorithms/CryptoAlgorithmRSASSA_PKCS1_v1_5.cpp:
      (WebCore::CryptoAlgorithmRSASSA_PKCS1_v1_5::keyAlgorithmMatches):
      (WebCore::CryptoAlgorithmRSASSA_PKCS1_v1_5::sign):
      (WebCore::CryptoAlgorithmRSASSA_PKCS1_v1_5::verify):
      (WebCore::CryptoAlgorithmRSASSA_PKCS1_v1_5::importKey):
      * crypto/algorithms/CryptoAlgorithmRSASSA_PKCS1_v1_5.h:
      * crypto/mac/CryptoAlgorithmAES_CBCMac.cpp:
      (WebCore::CryptoAlgorithmAES_CBC::platformEncrypt):
      (WebCore::CryptoAlgorithmAES_CBC::platformDecrypt):
      * crypto/mac/CryptoAlgorithmHMACMac.cpp:
      (WebCore::CryptoAlgorithmHMAC::platformSign):
      (WebCore::CryptoAlgorithmHMAC::platformVerify):
      Same changes for all algorithms that have keys.
      
      
      
      git-svn-id: http://svn.webkit.org/repository/webkit/trunk@159717 268f45cc-cd09-0410-ab3c-d52691b4dbfc
      9e2346a1
  4. 18 Nov, 2013 2 commits
    • ap@apple.com's avatar
      Support exporting public RSASSA-PKCS1-v1_5 keys · a7a1d44a
      ap@apple.com authored
      https://bugs.webkit.org/show_bug.cgi?id=124475
      
      Reviewed by Sam Weinig.
      
      Source/WebCore: 
      
      Test: crypto/subtle/rsa-export-key.html
      
      * bindings/js/JSCryptoKeySerializationJWK.h:
      * bindings/js/JSCryptoKeySerializationJWK.cpp:
      (WebCore::JSCryptoKeySerializationJWK::buildJSONForRSAComponents):
      (WebCore::JSCryptoKeySerializationJWK::addJWKAlgorithmToJSON):
      (WebCore::JSCryptoKeySerializationJWK::serialize):
      Added said support (this part works with private keys too).
      
      * crypto/keys/CryptoKeyRSA.h:
      * crypto/mac/CryptoKeyRSAMac.cpp:
      (WebCore::CryptoKeyRSA::getPublicKeyComponents): Moved the logic for getting a
      public key from private one here for reuse in keySizeInBits().
      (WebCore::CryptoKeyRSA::isRestrictedToHash):
      (WebCore::CryptoKeyRSA::keySizeInBits):
      (WebCore::CryptoKeyRSA::exportData):
      Exposed information necessary for JWK serialization.
      
      LayoutTests: 
      
      * crypto/subtle/rsa-export-key-expected.txt: Added.
      * crypto/subtle/rsa-export-key.html: Added.
      
      
      
      git-svn-id: http://svn.webkit.org/repository/webkit/trunk@159403 268f45cc-cd09-0410-ab3c-d52691b4dbfc
      a7a1d44a
    • ap@apple.com's avatar
      RSASSA-PKCS1-v1_5 JWK import doesn't check key size · 48c4fbd3
      ap@apple.com authored
      https://bugs.webkit.org/show_bug.cgi?id=124472
      
      Reviewed by Sam Weinig.
      
      Source/WebCore: 
      
      Test: crypto/subtle/rsassa-pkcs1-v1_5-import-jwk-small-key.html
      
      * bindings/js/JSCryptoKeySerializationJWK.cpp:
      (WebCore::JSCryptoKeySerializationJWK::keySizeIsValid): Added the checks.
      (WebCore::JSCryptoKeySerializationJWK::keyDataRSAComponents): Check key size when
      importing.
      (WebCore::JSCryptoKeySerializationJWK::serialize): Updated a comment.
      
      * crypto/keys/CryptoKeySerializationRaw.cpp: (WebCore::CryptoKeySerializationRaw::serialize):
      Updated a comment.
      
      LayoutTests: 
      
      * crypto/subtle/rsassa-pkcs1-v1_5-import-jwk-small-key-expected.txt: Added.
      * crypto/subtle/rsassa-pkcs1-v1_5-import-jwk-small-key.html: Added.
      
      
      
      git-svn-id: http://svn.webkit.org/repository/webkit/trunk@159393 268f45cc-cd09-0410-ab3c-d52691b4dbfc
      48c4fbd3
  5. 17 Nov, 2013 1 commit
    • ap@apple.com's avatar
      Use uint8_t vectors for WebCrypto data · f37f9b40
      ap@apple.com authored
      https://bugs.webkit.org/show_bug.cgi?id=124466
      
      Reviewed by Sam Weinig.
      
      Source/WebCore: 
      
      Using Vector<char> for crypto key data is somewhat non-idiomatic, and it gets simply
      dangerous for bignums, because signed arithmetic is not appropriate for bignum digits.
      
      * Modules/websockets/WebSocketHandshake.cpp:
      (WebCore::generateSecWebSocketKey):
      (WebCore::WebSocketHandshake::getExpectedWebSocketAccept):
      No longer need to cast data to char* here.
      
      * bindings/js/JSCryptoKeySerializationJWK.cpp:
      * bindings/js/JSCryptoKeySerializationJWK.h:
      * crypto/CryptoDigest.h:
      * crypto/CryptoKey.h:
      * crypto/keys/CryptoKeyAES.cpp:
      * crypto/keys/CryptoKeyAES.h:
      * crypto/keys/CryptoKeyDataOctetSequence.h:
      * crypto/keys/CryptoKeyDataRSAComponents.cpp:
      * crypto/keys/CryptoKeyDataRSAComponents.h:
      * crypto/keys/CryptoKeyHMAC.cpp:
      * crypto/keys/CryptoKeyHMAC.h:
      * crypto/keys/CryptoKeyRSA.h:
      * crypto/keys/CryptoKeySerializationRaw.cpp:
      * crypto/keys/CryptoKeySerializationRaw.h:
      * crypto/mac/CryptoAlgorithmAES_CBCMac.cpp:
      * crypto/mac/CryptoAlgorithmHMACMac.cpp:
      * crypto/mac/CryptoDigestMac.cpp:
      * crypto/mac/CryptoKeyMac.cpp:
      * crypto/parameters/CryptoAlgorithmRsaKeyGenParams.h:
      Switched to Vector<uint8_t>.
      
      * crypto/mac/CryptoKeyRSAMac.cpp:
      (WebCore::getPublicKeyComponents): Extracted from buildAlgorithmDescription() and simplified.
      (WebCore::CryptoKeyRSA::create): Switched to Vector<uint8_t>.
      (WebCore::CryptoKeyRSA::buildAlgorithmDescription): No longer need to copy data just
      to change type from Vector<char> to Vector<unsigned char>.
      (WebCore::bigIntegerToUInt32): Ditto. No longer need to cast types when dealing with the bignum.
      (WebCore::CryptoKeyRSA::generatePair): Improved an error message a little.
      
      * fileapi/FileReaderLoader.cpp: (WebCore::FileReaderLoader::convertToDataURL):
      * inspector/DOMPatchSupport.cpp: (WebCore::DOMPatchSupport::createDigest):
      * inspector/InspectorPageAgent.cpp: (WebCore::InspectorPageAgent::archive):
      * platform/graphics/cg/ImageBufferCG.cpp: (WebCore::CGImageToDataURL):
      No longer need to cast data to char* here.
      
      Source/WTF: 
      
      Binary data can be UTF-8, in which case "char*" is idiomatic, or it can be arbitrary
      binary data, in which case "uint8_t*" is more common.
      
      Changed encode functions that took "const char *" to "const void*", and decode
      functions that took "Vector<char>&" now take an adapter class.
      
      The adapter relies on Vector<char> and Vector<uint8_t> classes having an identical layout.
      
      * wtf/text/Base64.cpp:
      (WTF::base64Encode):
      (WTF::base64URLEncode):
      (WTF::base64DecodeInternal):
      (WTF::base64Decode):
      (WTF::base64URLDecode):
      * wtf/text/Base64.h:
      (WTF::SignedOrUnsignedCharVectorAdapter):
      (WTF::ConstSignedOrUnsignedCharVectorAdapter):
      (WTF::base64Encode):
      (WTF::base64URLEncode):
      
      
      
      git-svn-id: http://svn.webkit.org/repository/webkit/trunk@159390 268f45cc-cd09-0410-ab3c-d52691b4dbfc
      f37f9b40
  6. 16 Nov, 2013 1 commit
    • ap@apple.com's avatar
      Support exporting symmetric keys as JWK · ca827605
      ap@apple.com authored
      https://bugs.webkit.org/show_bug.cgi?id=124442
      
      Reviewed by Sam Weinig.
      
      Source/JavaScriptCore: 
      
      * runtime/JSONObject.h: Export JSONStringify.
      
      Source/WebCore: 
      
      Error handling is not consistent yet - some errors cause exceptions, and others
      result in rejected promises. This part of spec is incomplete, so I basically did
      what was most straightforward in each case.
      
      * bindings/js/JSCryptoKeySerializationJWK.h: 
      * bindings/js/JSCryptoKeySerializationJWK.cpp:
      (WebCore::JSCryptoKeySerializationJWK::reconcileUsages): Updated a comment with a better link.
      (WebCore::JSCryptoKeySerializationJWK::buildJSONForOctetSequence): A helper to building JWK.
      (WebCore::JSCryptoKeySerializationJWK::addToJSON): Ditto.
      (WebCore::JSCryptoKeySerializationJWK::addBoolToJSON): Ditto.
      (WebCore::JSCryptoKeySerializationJWK::addJWKAlgorithmToJSON): Ditto. The code for
      mapping is my best guess, this all needs to be specified.
      (WebCore::JSCryptoKeySerializationJWK::addJWKUseToJSON): A helper to building JWK.
      (WebCore::JSCryptoKeySerializationJWK::serialize): Build a JSON string for the key.
      
      * bindings/js/JSSubtleCryptoCustom.cpp:
      (WebCore::JSSubtleCrypto::importKey): Updated a comment.
      (WebCore::JSSubtleCrypto::exportKey): Use CryptoKeySerialization (also for raw keys,
      for consistency).
      
      * crypto/CryptoKey.h:
      (WebCore::CryptoKey::algorithmIdentifier):
      (WebCore::CryptoKey::usagesBitmap):
      Exposed data needed for building JWK (it used to be only exposed in a form suitable
      for DOM accessors).
      
      * crypto/keys/CryptoKeyHMAC.h: Ditto, added an accessor for JWK.
      
      * crypto/keys/CryptoKeySerializationRaw.cpp: (WebCore::CryptoKeySerializationRaw::serialize):
      * crypto/keys/CryptoKeySerializationRaw.h:
      Moved from JSSubtleCryptoCustom.cpp for consistency.
      
      Source/WTF: 
      
      Base64URL encoding doesn't use '=' padding, and doesn't need any other options.
      Added this mode for encode, and removed policy arguments from exposed functions.
      
      * wtf/text/Base64.cpp:
      (WTF::base64EncodeInternal):
      (WTF::base64URLEncode):
      (WTF::base64URLDecode):
      * wtf/text/Base64.h:
      (WTF::base64URLEncode):
      
      LayoutTests: 
      
      * crypto/subtle/aes-export-key-expected.txt:
      * crypto/subtle/aes-export-key.html:
      * crypto/subtle/hmac-export-key-expected.txt:
      * crypto/subtle/hmac-export-key.html:
      
      
      
      git-svn-id: http://svn.webkit.org/repository/webkit/trunk@159377 268f45cc-cd09-0410-ab3c-d52691b4dbfc
      ca827605
  7. 13 Nov, 2013 4 commits
    • ap@apple.com's avatar
      Check WebCrypto parameter types when casting · 2882324e
      ap@apple.com authored
      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: http://svn.webkit.org/repository/webkit/trunk@159213 268f45cc-cd09-0410-ab3c-d52691b4dbfc
      2882324e
    • ap@apple.com's avatar
      Implement key generation and JWK import for RSASSA-PKCS1-v1_5 · a237529b
      ap@apple.com authored
      https://bugs.webkit.org/show_bug.cgi?id=124236
      
      Reviewed by Sam Weinig.
      
      Source/WebCore:
      
      Tests: crypto/subtle/rsassa-pkcs1-v1_5-generate-key.html
             crypto/subtle/rsassa-pkcs1-v1_5-import-jwk.html
      
      * WebCore.xcodeproj/project.pbxproj: Added new files.
      
      * bindings/js/JSCryptoAlgorithmBuilder.cpp:
      (WebCore::JSCryptoAlgorithmBuilder::add):
      * bindings/js/JSCryptoAlgorithmBuilder.h:
      * crypto/CryptoAlgorithmDescriptionBuilder.h:
      Added a way to add an Uint8Array, as needed for RSA key.algorithm.publicExponent.
      
      * bindings/js/JSCryptoAlgorithmDictionary.cpp:
      (WebCore::createAesCbcParams): Removed unneeded JSC prefixes.
      (WebCore::createAesKeyGenParams): Ditto.
      (WebCore::createHmacParams): Ditto.
      (WebCore::createHmacKeyParams): Ditto.
      (WebCore::createRsaKeyGenParams): Added.
      (WebCore::createRsaSsaKeyParams): Added. WebCrypto currently doesn't specify any
      parameters for importKey, so the structure remains blank (unlike with JWK).
      (WebCore::createRsaSsaParams): Added (currently unused, will be sued for sign/verify soon).
      (WebCore::JSCryptoAlgorithmDictionary::createParametersForEncrypt): Removed unneeded JSC prefixes.
      (WebCore::JSCryptoAlgorithmDictionary::createParametersForDecrypt): Ditto.
      (WebCore::JSCryptoAlgorithmDictionary::createParametersForSign): Added support for RSAES_PKCS1_v1_5.
      (WebCore::JSCryptoAlgorithmDictionary::createParametersForVerify): Ditto.
      (WebCore::JSCryptoAlgorithmDictionary::createParametersForDigest): Removed unneeded JSC prefixes.
      (WebCore::JSCryptoAlgorithmDictionary::createParametersForGenerateKey): Ditto.
      (WebCore::JSCryptoAlgorithmDictionary::createParametersForDeriveKey): Ditto.
      (WebCore::JSCryptoAlgorithmDictionary::createParametersForDeriveBits): Ditto.
      (WebCore::JSCryptoAlgorithmDictionary::createParametersForImportKey): Added support for RSAES_PKCS1_v1_5.
      (WebCore::JSCryptoAlgorithmDictionary::createParametersForExportKey): Removed unneeded JSC prefixes.
      (WebCore::JSCryptoAlgorithmDictionary::createParametersForWrapKey): Ditto.
      (WebCore::JSCryptoAlgorithmDictionary::createParametersForUnwrapKey): Ditto.
      
      * bindings/js/JSCryptoKeySerializationJWK.h:
      * bindings/js/JSCryptoKeySerializationJWK.cpp:
      (WebCore::getJSArrayFromJSON): Added.
      (WebCore::getBigIntegerVectorFromJSON): Added.
      (WebCore::createRSASSAKeyParameters): Create parameters for key import. The key
      will remember which algorithm it's allowed to be used with.
      (WebCore::JSCryptoKeySerializationJWK::reconcileAlgorithm): Added support for
      RS256...RS512 (tha is, RSAES_PKCS1_v1_5 with SHA-256...SHA-512).
      (WebCore::JSCryptoKeySerializationJWK::keyDataOctetSequence): Split out of keyData().
      (WebCore::JSCryptoKeySerializationJWK::keyDataRSAComponents): Added code to read
      RSA key components from JWK.
      (WebCore::JSCryptoKeySerializationJWK::keyData): Call one of the above functions.
      
      * crypto/CryptoAlgorithmRSASSA_PKCS1_v1_5Mac.cpp: Added.
      (WebCore::CryptoAlgorithmRSASSA_PKCS1_v1_5::sign):
      (WebCore::CryptoAlgorithmRSASSA_PKCS1_v1_5::verify):
      Placeholders.
      
      * crypto/CryptoKey.h: (WebCore::CryptoKeyClass): Added RSA key class for poor man's RTTI.
      
      * crypto/CryptoKeyData.h: (WebCore::CryptoKeyData::FormatRSAComponents): Added RSAComponents
      for poor man's RTTI.
      
      * crypto/algorithms/CryptoAlgorithmAES_CBC.cpp: (WebCore::CryptoAlgorithmAES_CBC::importKey):
      * crypto/algorithms/CryptoAlgorithmHMAC.cpp: (WebCore::CryptoAlgorithmHMAC::importKey):
      * crypto/keys/CryptoKeyAES.h:
      (WebCore::isCryptoKeyAES):
      (WebCore::toCryptoKeyAES):
      * crypto/keys/CryptoKeyDataOctetSequence.h:
      (WebCore::toCryptoKeyDataOctetSequence):
      * crypto/keys/CryptoKeyHMAC.h:
      (WebCore::isCryptoKeyHMAC):
      (WebCore::toCryptoKeyHMAC):
      * crypto/mac/CryptoAlgorithmAES_CBCMac.cpp:
      (WebCore::CryptoAlgorithmAES_CBC::encrypt):
      (WebCore::CryptoAlgorithmAES_CBC::decrypt):
      * crypto/mac/CryptoAlgorithmHMACMac.cpp:
      (WebCore::CryptoAlgorithmHMAC::sign):
      (WebCore::CryptoAlgorithmHMAC::verify):
      Switched from "as" functions to "is" and "to" ones, as that's more idiomatic.
      
      * crypto/algorithms/CryptoAlgorithmRSASSA_PKCS1_v1_5.cpp: Added.
      * crypto/algorithms/CryptoAlgorithmRSASSA_PKCS1_v1_5.h: Added.
      Glue code for importKey/generateKey for now.
      
      * crypto/keys/CryptoKeyDataRSAComponents.cpp: Added.
      (WebCore::CryptoKeyDataRSAComponents::CryptoKeyDataRSAComponents):
      (WebCore::CryptoKeyDataRSAComponents::~CryptoKeyDataRSAComponents):
      * crypto/keys/CryptoKeyDataRSAComponents.h: Added.
      (WebCore::toCryptoKeyDataRSAComponents):
      Added a structure to hold RSA key components, extracted from JWK or another format.
      
      * crypto/keys/CryptoKeyRSA.h: Added.
      * crypto/mac/CryptoKeyRSAMac.cpp: Added.
      
      * crypto/mac/CryptoAlgorithmRegistryMac.cpp:
      (WebCore::CryptoAlgorithmRegistry::platformRegisterAlgorithms):
      Register RSASSA_PKCS1_v1_5.
      
      * crypto/parameters/CryptoAlgorithmHmacKeyParams.h: Added a constructor to make
      sure that hasLength is never left uninitialized, even when reading formats that
      don't contain a length.
      
      * crypto/parameters/CryptoAlgorithmRsaKeyGenParams.h: Added.
      * crypto/parameters/CryptoAlgorithmRsaSsaKeyParams.h: Added.
      * crypto/parameters/CryptoAlgorithmRsaSsaParams.h: Added.
      Added parameter structures that are needed for RSASSA_PKCS1_v1_5.
      
      LayoutTests:
      
      * crypto/subtle/resources/common.js:
      (hexToArrayBuffer): Fixed a typo
      (Base64URL.stringify):
      (Base64URL.parse):
      Added helpers to deal with Base64URL, as needed for JWK.
      
      * crypto/subtle/rsassa-pkcs1-v1_5-generate-key-expected.txt: Added.
      * crypto/subtle/rsassa-pkcs1-v1_5-generate-key.html: Added.
      * crypto/subtle/rsassa-pkcs1-v1_5-import-jwk-expected.txt: Added.
      * crypto/subtle/rsassa-pkcs1-v1_5-import-jwk.html: Added.
      
      
      git-svn-id: http://svn.webkit.org/repository/webkit/trunk@159180 268f45cc-cd09-0410-ab3c-d52691b4dbfc
      a237529b
    • commit-queue@webkit.org's avatar
      Unreviewed, rolling out r159160, r159161, and r159164. · 388f415d
      commit-queue@webkit.org authored
      http://trac.webkit.org/changeset/159160
      http://trac.webkit.org/changeset/159161
      http://trac.webkit.org/changeset/159164
      https://bugs.webkit.org/show_bug.cgi?id=124253
      
      Too many errors (make fewer) (Requested by ap on #webkit).
      
      Source/WebCore:
      
      * WebCore.xcodeproj/project.pbxproj:
      * bindings/js/JSCryptoAlgorithmBuilder.cpp:
      * bindings/js/JSCryptoAlgorithmBuilder.h:
      * bindings/js/JSCryptoAlgorithmDictionary.cpp:
      (WebCore::createAesCbcParams):
      (WebCore::createAesKeyGenParams):
      (WebCore::createHmacParams):
      (WebCore::createHmacKeyParams):
      (WebCore::JSCryptoAlgorithmDictionary::createParametersForEncrypt):
      (WebCore::JSCryptoAlgorithmDictionary::createParametersForDecrypt):
      (WebCore::JSCryptoAlgorithmDictionary::createParametersForSign):
      (WebCore::JSCryptoAlgorithmDictionary::createParametersForVerify):
      (WebCore::JSCryptoAlgorithmDictionary::createParametersForDigest):
      (WebCore::JSCryptoAlgorithmDictionary::createParametersForGenerateKey):
      (WebCore::JSCryptoAlgorithmDictionary::createParametersForDeriveKey):
      (WebCore::JSCryptoAlgorithmDictionary::createParametersForDeriveBits):
      (WebCore::JSCryptoAlgorithmDictionary::createParametersForImportKey):
      (WebCore::JSCryptoAlgorithmDictionary::createParametersForExportKey):
      (WebCore::JSCryptoAlgorithmDictionary::createParametersForWrapKey):
      (WebCore::JSCryptoAlgorithmDictionary::createParametersForUnwrapKey):
      * bindings/js/JSCryptoKeySerializationJWK.cpp:
      (WebCore::JSCryptoKeySerializationJWK::reconcileAlgorithm):
      (WebCore::JSCryptoKeySerializationJWK::keyData):
      * bindings/js/JSCryptoKeySerializationJWK.h:
      * crypto/CryptoAlgorithmDescriptionBuilder.h:
      * crypto/CryptoAlgorithmRSASSA_PKCS1_v1_5Mac.cpp: Removed.
      * crypto/CryptoKey.h:
      (WebCore::ENUM_CLASS):
      * crypto/CryptoKeyData.h:
      (WebCore::CryptoKeyData::ENUM_CLASS):
      * crypto/algorithms/CryptoAlgorithmAES_CBC.cpp:
      (WebCore::CryptoAlgorithmAES_CBC::importKey):
      * crypto/algorithms/CryptoAlgorithmHMAC.cpp:
      (WebCore::CryptoAlgorithmHMAC::importKey):
      * crypto/algorithms/CryptoAlgorithmRSASSA_PKCS1_v1_5.cpp: Removed.
      * crypto/algorithms/CryptoAlgorithmRSASSA_PKCS1_v1_5.h: Removed.
      * crypto/keys/CryptoKeyAES.h:
      (WebCore::asCryptoKeyAES):
      * crypto/keys/CryptoKeyDataOctetSequence.h:
      (WebCore::asCryptoKeyDataOctetSequence):
      * crypto/keys/CryptoKeyDataRSAComponents.cpp: Removed.
      * crypto/keys/CryptoKeyDataRSAComponents.h: Removed.
      * crypto/keys/CryptoKeyHMAC.h:
      (WebCore::asCryptoKeyHMAC):
      * crypto/keys/CryptoKeyRSA.h: Removed.
      * crypto/mac/CryptoAlgorithmAES_CBCMac.cpp:
      (WebCore::CryptoAlgorithmAES_CBC::encrypt):
      (WebCore::CryptoAlgorithmAES_CBC::decrypt):
      * crypto/mac/CryptoAlgorithmHMACMac.cpp:
      (WebCore::CryptoAlgorithmHMAC::sign):
      (WebCore::CryptoAlgorithmHMAC::verify):
      * crypto/mac/CryptoAlgorithmRegistryMac.cpp:
      (WebCore::CryptoAlgorithmRegistry::platformRegisterAlgorithms):
      * crypto/mac/CryptoKeyRSAMac.cpp: Removed.
      * crypto/parameters/CryptoAlgorithmHmacKeyParams.h:
      * crypto/parameters/CryptoAlgorithmRsaKeyGenParams.h: Removed.
      * crypto/parameters/CryptoAlgorithmRsaSsaKeyParams.h: Removed.
      * crypto/parameters/CryptoAlgorithmRsaSsaParams.h: Removed.
      
      LayoutTests:
      
      * crypto/subtle/resources/common.js:
      (hexToArrayBuffer):
      * crypto/subtle/rsassa-pkcs1-v1_5-generate-key-expected.txt: Removed.
      * crypto/subtle/rsassa-pkcs1-v1_5-generate-key.html: Removed.
      * crypto/subtle/rsassa-pkcs1-v1_5-import-jwk-expected.txt: Removed.
      * crypto/subtle/rsassa-pkcs1-v1_5-import-jwk.html: Removed.
      * platform/mac/TestExpectations:
      
      git-svn-id: http://svn.webkit.org/repository/webkit/trunk@159167 268f45cc-cd09-0410-ab3c-d52691b4dbfc
      388f415d
    • ap@apple.com's avatar
      Implement key generation and JWK import for RSASSA-PKCS1-v1_5 · c0d58adc
      ap@apple.com authored
      https://bugs.webkit.org/show_bug.cgi?id=124236
      
      Reviewed by Sam Weinig.
      
      Source/WebCore: 
      
      Tests: crypto/subtle/rsassa-pkcs1-v1_5-generate-key.html
             crypto/subtle/rsassa-pkcs1-v1_5-import-jwk.html
      
      * WebCore.xcodeproj/project.pbxproj: Added new files.
      
      * bindings/js/JSCryptoAlgorithmBuilder.cpp:
      (WebCore::JSCryptoAlgorithmBuilder::add):
      * bindings/js/JSCryptoAlgorithmBuilder.h:
      * crypto/CryptoAlgorithmDescriptionBuilder.h:
      Added a way to add an Uint8Array, as needed for RSA key.algorithm.publicExponent.
      
      * bindings/js/JSCryptoAlgorithmDictionary.cpp:
      (WebCore::createAesCbcParams): Removed unneeded JSC prefixes.
      (WebCore::createAesKeyGenParams): Ditto.
      (WebCore::createHmacParams): Ditto.
      (WebCore::createHmacKeyParams): Ditto.
      (WebCore::createRsaKeyGenParams): Added. 
      (WebCore::createRsaSsaKeyParams): Added. WebCrypto currently doesn't specify any
      parameters for importKey, so the structure remains blank (unlike with JWK).
      (WebCore::createRsaSsaParams): Added (currently unused, will be sued for sign/verify soon).
      (WebCore::JSCryptoAlgorithmDictionary::createParametersForEncrypt): Removed unneeded JSC prefixes.
      (WebCore::JSCryptoAlgorithmDictionary::createParametersForDecrypt): Ditto.
      (WebCore::JSCryptoAlgorithmDictionary::createParametersForSign): Added support for RSAES_PKCS1_v1_5.
      (WebCore::JSCryptoAlgorithmDictionary::createParametersForVerify): Ditto.
      (WebCore::JSCryptoAlgorithmDictionary::createParametersForDigest): Removed unneeded JSC prefixes.
      (WebCore::JSCryptoAlgorithmDictionary::createParametersForGenerateKey): Ditto.
      (WebCore::JSCryptoAlgorithmDictionary::createParametersForDeriveKey): Ditto.
      (WebCore::JSCryptoAlgorithmDictionary::createParametersForDeriveBits): Ditto.
      (WebCore::JSCryptoAlgorithmDictionary::createParametersForImportKey): Added support for RSAES_PKCS1_v1_5.
      (WebCore::JSCryptoAlgorithmDictionary::createParametersForExportKey): Removed unneeded JSC prefixes.
      (WebCore::JSCryptoAlgorithmDictionary::createParametersForWrapKey): Ditto.
      (WebCore::JSCryptoAlgorithmDictionary::createParametersForUnwrapKey): Ditto.
      
      * bindings/js/JSCryptoKeySerializationJWK.h:
      * bindings/js/JSCryptoKeySerializationJWK.cpp:
      (WebCore::getJSArrayFromJSON): Added.
      (WebCore::getBigIntegerVectorFromJSON): Added.
      (WebCore::createRSASSAKeyParameters): Create parameters for key import. The key
      will remember which algorithm it's allowed to be used with.
      (WebCore::JSCryptoKeySerializationJWK::reconcileAlgorithm): Added support for
      RS256...RS512 (tha is, RSAES_PKCS1_v1_5 with SHA-256...SHA-512).
      (WebCore::JSCryptoKeySerializationJWK::keyDataOctetSequence): Split out of keyData().
      (WebCore::JSCryptoKeySerializationJWK::keyDataRSAComponents): Added code to read
      RSA key components from JWK.
      (WebCore::JSCryptoKeySerializationJWK::keyData): Call one of the above functions.
      
      * crypto/CryptoAlgorithmRSASSA_PKCS1_v1_5Mac.cpp: Added.
      (WebCore::CryptoAlgorithmRSASSA_PKCS1_v1_5::sign):
      (WebCore::CryptoAlgorithmRSASSA_PKCS1_v1_5::verify):
      Placeholders.
      
      * crypto/CryptoKey.h: (WebCore::CryptoKeyClass): Added RSA key class for poor man's RTTI.
      
      * crypto/CryptoKeyData.h: (WebCore::CryptoKeyData::FormatRSAComponents): Added RSAComponents
      for poor man's RTTI.
      
      * crypto/algorithms/CryptoAlgorithmAES_CBC.cpp: (WebCore::CryptoAlgorithmAES_CBC::importKey): 
      * crypto/algorithms/CryptoAlgorithmHMAC.cpp: (WebCore::CryptoAlgorithmHMAC::importKey):
      * crypto/keys/CryptoKeyAES.h:
      (WebCore::isCryptoKeyAES):
      (WebCore::toCryptoKeyAES):
      * crypto/keys/CryptoKeyDataOctetSequence.h:
      (WebCore::toCryptoKeyDataOctetSequence):
      * crypto/keys/CryptoKeyHMAC.h:
      (WebCore::isCryptoKeyHMAC):
      (WebCore::toCryptoKeyHMAC):
      * crypto/mac/CryptoAlgorithmAES_CBCMac.cpp:
      (WebCore::CryptoAlgorithmAES_CBC::encrypt):
      (WebCore::CryptoAlgorithmAES_CBC::decrypt):
      * crypto/mac/CryptoAlgorithmHMACMac.cpp:
      (WebCore::CryptoAlgorithmHMAC::sign):
      (WebCore::CryptoAlgorithmHMAC::verify):
      Switched from "as" functions to "is" and "to" ones, as that's more idiomatic.
      
      * crypto/algorithms/CryptoAlgorithmRSASSA_PKCS1_v1_5.cpp: Added.
      * crypto/algorithms/CryptoAlgorithmRSASSA_PKCS1_v1_5.h: Added.
      Glue code for importKey/generateKey for now.
      
      * crypto/keys/CryptoKeyDataRSAComponents.cpp: Added.
      (WebCore::CryptoKeyDataRSAComponents::CryptoKeyDataRSAComponents):
      (WebCore::CryptoKeyDataRSAComponents::~CryptoKeyDataRSAComponents):
      * crypto/keys/CryptoKeyDataRSAComponents.h: Added.
      (WebCore::toCryptoKeyDataRSAComponents):
      Added a structure to hold RSA key components, extracted from JWK or another format.
      
      * crypto/keys/CryptoKeyRSA.h: Added.
      * crypto/mac/CryptoKeyRSAMac.cpp: Added.
      
      * crypto/mac/CryptoAlgorithmRegistryMac.cpp:
      (WebCore::CryptoAlgorithmRegistry::platformRegisterAlgorithms):
      Register RSASSA_PKCS1_v1_5.
      
      * crypto/parameters/CryptoAlgorithmHmacKeyParams.h: Added a constructor to make
      sure that hasLength is never left uninitialized, even when reading formats that
      don't contain a length.
      
      * crypto/parameters/CryptoAlgorithmRsaKeyGenParams.h: Added.
      * crypto/parameters/CryptoAlgorithmRsaSsaKeyParams.h: Added.
      * crypto/parameters/CryptoAlgorithmRsaSsaParams.h: Added.
      Added parameter structures that are needed for RSASSA_PKCS1_v1_5.
      
      LayoutTests: 
      
      * crypto/subtle/resources/common.js:
      (hexToArrayBuffer): Fixed a typo
      (Base64URL.stringify):
      (Base64URL.parse):
      Added helpers to deal with Base64URL, as needed for JWK.
      
      * crypto/subtle/rsassa-pkcs1-v1_5-generate-key-expected.txt: Added.
      * crypto/subtle/rsassa-pkcs1-v1_5-generate-key.html: Added.
      * crypto/subtle/rsassa-pkcs1-v1_5-import-jwk-expected.txt: Added.
      * crypto/subtle/rsassa-pkcs1-v1_5-import-jwk.html: Added.
      
      
      
      git-svn-id: http://svn.webkit.org/repository/webkit/trunk@159160 268f45cc-cd09-0410-ab3c-d52691b4dbfc
      c0d58adc
  8. 08 Nov, 2013 1 commit
    • ap@apple.com's avatar
      Implement JWK key import for HMAC and AES-CBC · 7f6fd501
      ap@apple.com authored
      https://bugs.webkit.org/show_bug.cgi?id=124059
      
      Reviewed by Anders Carlsson.
      
      Source/WebCore: 
      
      Tests: crypto/subtle/aes-cbc-import-jwk.html
             crypto/subtle/hmac-import-jwk.html
             crypto/subtle/import-jwk.html
      
      WebCrypto supports multiple key formats - raw, pkcs8, spki, jwk. The design is that
      we'll transform these into parsed KeyData subclasses before passing to algorithms.
      
      CryptoKeySerialization is a base class for handling all these formats.
      
      * WebCore.xcodeproj/project.pbxproj: Added new files. Removed CryptoKeyFormat.h.
              
      * bindings/js/JSCryptoKeySerializationJWK.h: Added.
      * bindings/js/JSCryptoKeySerializationJWK.cpp: Added.
      (WebCore::getStringFromJSON): A helper. Note that we can rely on the object being
      a nice freshly parsed JSON, no getters or anything.
      (WebCore::getBooleanFromJSON): Ditto.
      (WebCore::JSCryptoKeySerializationJWK::JSCryptoKeySerializationJWK):
      (WebCore::JSCryptoKeySerializationJWK::~JSCryptoKeySerializationJWK):
      (WebCore::createHMACParameters): A simple helper.
      (WebCore::JSCryptoKeySerializationJWK::reconcileAlgorithm): WebCrypto API is weird,
      you can have algorithm parameters both inside a JWK key and passed as importKey()
      arguments. They need to agree, whatever that means for specific serialization's
      algorithm options (not all necessarily have a 1-1 matching to WebCrypto).
      (WebCore::JSCryptoKeySerializationJWK::reconcileUsages): Take an intersection of usages.
      (WebCore::JSCryptoKeySerializationJWK::reconcileExtractable): Only extractable if
      both JWK and the caller agree.
      (WebCore::JSCryptoKeySerializationJWK::keySizeIsValid): Verify validity of JWK key.
      (WebCore::JSCryptoKeySerializationJWK::keyData): Return an appropriate KeyData
      subclass.
      
      * bindings/js/JSSubtleCryptoCustom.cpp:
      (WebCore::ENUM_CLASS): Moved CryptoKeyFormat here.
      (WebCore::cryptoKeyFormatFromJSValue): Added a human readable string to an exception.
      (WebCore::JSSubtleCrypto::importKey): Support multiple key formats, not just raw.
      
      * crypto/CryptoAlgorithm.cpp: (WebCore::CryptoAlgorithm::importKey):
      * crypto/CryptoAlgorithm.h:
      Updated signature for importKey to one that makes more sense. Decoding formats all
      the way from a binary blob is not something that CryptoAlgorithm subclasses should
      do, we now pass a KeyData subclass instead.
      Removed exportKey/wrapKey/unwrapKey altogether, because I don't yet know what the
      signatures will be.
      
      * crypto/CryptoKeyData.h: Added.
      (WebCore::CryptoKeyData::ENUM_CLASS):
      (WebCore::CryptoKeyData::CryptoKeyData):
      (WebCore::CryptoKeyData::~CryptoKeyData):
      (WebCore::CryptoKeyData::format):
      A base class for passing key material to algorithms. Currently, only one type is
      supported, that being OctetSequence for secret keys. Keys for RSA and EC are more
      complicated, and secret/public ones are different too.
      
      * crypto/CryptoKeyFormat.h: Removed. There are too many key format classes
      confusingly floating around, and this was only needed in one file for parsing.
      
      * crypto/CryptoKeySerialization.h: Added.
      Base class for handling raw/pkcs8/spki/jwk keys.
      
      * crypto/algorithms/CryptoAlgorithmAES_CBC.cpp:
      (WebCore::CryptoAlgorithmAES_CBC::importKey):
      * crypto/algorithms/CryptoAlgorithmAES_CBC.h:
      Updated to use CryptoKeyData.
      
      * crypto/algorithms/CryptoAlgorithmHMAC.cpp:
      (WebCore::CryptoAlgorithmHMAC::importKey):
      * crypto/algorithms/CryptoAlgorithmHMAC.h:
      Updated to use CryptoKeyData.
      
      * crypto/keys/CryptoKeyDataOctetSequence.cpp: Added.
      (WebCore::CryptoKeyDataOctetSequence::CryptoKeyDataOctetSequence):
      (WebCore::CryptoKeyDataOctetSequence::~CryptoKeyDataOctetSequence):
      * crypto/keys/CryptoKeyDataOctetSequence.h: Added.
      (WebCore::asCryptoKeyDataOctetSequence):
      * crypto/keys/CryptoKeySerializationRaw.cpp: Added.
      (WebCore::CryptoKeySerializationRaw::CryptoKeySerializationRaw):
      (WebCore::CryptoKeySerializationRaw::~CryptoKeySerializationRaw):
      (WebCore::CryptoKeySerializationRaw::reconcileAlgorithm):
      (WebCore::CryptoKeySerializationRaw::reconcileUsages):
      (WebCore::CryptoKeySerializationRaw::reconcileExtractable):
      (WebCore::CryptoKeySerializationRaw::keyData):
      * crypto/keys/CryptoKeySerializationRaw.h: Added.
      Much code to pass around a Vector<char>.
      
      LayoutTests: 
      
      * crypto/subtle/aes-cbc-import-jwk-expected.txt: Added.
      * crypto/subtle/aes-cbc-import-jwk.html: Added.
      * crypto/subtle/hmac-import-jwk-expected.txt: Added.
      * crypto/subtle/hmac-import-jwk.html: Added.
      * crypto/subtle/import-jwk-expected.txt: Added.
      * crypto/subtle/import-jwk.html: Added.
      
      
      
      git-svn-id: http://svn.webkit.org/repository/webkit/trunk@158943 268f45cc-cd09-0410-ab3c-d52691b4dbfc
      7f6fd501