Changeset 159180 in webkit


Ignore:
Timestamp:
Nov 13, 2013 1:31:51 AM (10 years ago)
Author:
ap@apple.com
Message:

Implement key generation and JWK import for RSASSA-PKCS1-v1_5
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.
Location:
trunk
Files:
7 added
21 edited
7 copied

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r159179 r159180  
     12013-11-13  Alexey Proskuryakov  <ap@apple.com>
     2
     3        Implement key generation and JWK import for RSASSA-PKCS1-v1_5
     4        https://bugs.webkit.org/show_bug.cgi?id=124236
     5
     6        Reviewed by Sam Weinig.
     7
     8        * crypto/subtle/resources/common.js:
     9        (hexToArrayBuffer): Fixed a typo
     10        (Base64URL.stringify):
     11        (Base64URL.parse):
     12        Added helpers to deal with Base64URL, as needed for JWK.
     13
     14        * crypto/subtle/rsassa-pkcs1-v1_5-generate-key-expected.txt: Added.
     15        * crypto/subtle/rsassa-pkcs1-v1_5-generate-key.html: Added.
     16        * crypto/subtle/rsassa-pkcs1-v1_5-import-jwk-expected.txt: Added.
     17        * crypto/subtle/rsassa-pkcs1-v1_5-import-jwk.html: Added.
     18
    1192013-11-12  Alexey Proskuryakov  <ap@apple.com>
    220
  • trunk/LayoutTests/crypto/subtle/resources/common.js

    r159167 r159180  
    4949{
    5050    if (str.length % 2)
    51         throw "Hex string lenght must be even";
     51        throw "Hex string length must be even";
    5252    var chars = [];
    5353    for (var i = 0; i < str.length; i += 2)
     
    5555    return new Uint8Array(chars);
    5656}
     57
     58var Base64URL = {
     59    stringify: function (a) {
     60        var base64string = btoa(String.fromCharCode.apply(0, a));
     61        return base64string.replace(/=/g, "").replace(/\+/g, "-").replace(/\//g, "_");
     62    },
     63    parse: function (s) {
     64        s = s.replace(/-/g, "+").replace(/_/g, "/").replace(/\s/g, '');
     65        return new Uint8Array(Array.prototype.map.call(atob(s), function (c) { return c.charCodeAt(0) }));
     66    }
     67};
    5768
    5869function printRejectedResult(value)
  • trunk/Source/WebCore/ChangeLog

    r159179 r159180  
     12013-11-13  Alexey Proskuryakov  <ap@apple.com>
     2
     3        Implement key generation and JWK import for RSASSA-PKCS1-v1_5
     4        https://bugs.webkit.org/show_bug.cgi?id=124236
     5
     6        Reviewed by Sam Weinig.
     7
     8        Tests: crypto/subtle/rsassa-pkcs1-v1_5-generate-key.html
     9               crypto/subtle/rsassa-pkcs1-v1_5-import-jwk.html
     10
     11        * WebCore.xcodeproj/project.pbxproj: Added new files.
     12
     13        * bindings/js/JSCryptoAlgorithmBuilder.cpp:
     14        (WebCore::JSCryptoAlgorithmBuilder::add):
     15        * bindings/js/JSCryptoAlgorithmBuilder.h:
     16        * crypto/CryptoAlgorithmDescriptionBuilder.h:
     17        Added a way to add an Uint8Array, as needed for RSA key.algorithm.publicExponent.
     18
     19        * bindings/js/JSCryptoAlgorithmDictionary.cpp:
     20        (WebCore::createAesCbcParams): Removed unneeded JSC prefixes.
     21        (WebCore::createAesKeyGenParams): Ditto.
     22        (WebCore::createHmacParams): Ditto.
     23        (WebCore::createHmacKeyParams): Ditto.
     24        (WebCore::createRsaKeyGenParams): Added.
     25        (WebCore::createRsaSsaKeyParams): Added. WebCrypto currently doesn't specify any
     26        parameters for importKey, so the structure remains blank (unlike with JWK).
     27        (WebCore::createRsaSsaParams): Added (currently unused, will be sued for sign/verify soon).
     28        (WebCore::JSCryptoAlgorithmDictionary::createParametersForEncrypt): Removed unneeded JSC prefixes.
     29        (WebCore::JSCryptoAlgorithmDictionary::createParametersForDecrypt): Ditto.
     30        (WebCore::JSCryptoAlgorithmDictionary::createParametersForSign): Added support for RSAES_PKCS1_v1_5.
     31        (WebCore::JSCryptoAlgorithmDictionary::createParametersForVerify): Ditto.
     32        (WebCore::JSCryptoAlgorithmDictionary::createParametersForDigest): Removed unneeded JSC prefixes.
     33        (WebCore::JSCryptoAlgorithmDictionary::createParametersForGenerateKey): Ditto.
     34        (WebCore::JSCryptoAlgorithmDictionary::createParametersForDeriveKey): Ditto.
     35        (WebCore::JSCryptoAlgorithmDictionary::createParametersForDeriveBits): Ditto.
     36        (WebCore::JSCryptoAlgorithmDictionary::createParametersForImportKey): Added support for RSAES_PKCS1_v1_5.
     37        (WebCore::JSCryptoAlgorithmDictionary::createParametersForExportKey): Removed unneeded JSC prefixes.
     38        (WebCore::JSCryptoAlgorithmDictionary::createParametersForWrapKey): Ditto.
     39        (WebCore::JSCryptoAlgorithmDictionary::createParametersForUnwrapKey): Ditto.
     40
     41        * bindings/js/JSCryptoKeySerializationJWK.h:
     42        * bindings/js/JSCryptoKeySerializationJWK.cpp:
     43        (WebCore::getJSArrayFromJSON): Added.
     44        (WebCore::getBigIntegerVectorFromJSON): Added.
     45        (WebCore::createRSASSAKeyParameters): Create parameters for key import. The key
     46        will remember which algorithm it's allowed to be used with.
     47        (WebCore::JSCryptoKeySerializationJWK::reconcileAlgorithm): Added support for
     48        RS256...RS512 (tha is, RSAES_PKCS1_v1_5 with SHA-256...SHA-512).
     49        (WebCore::JSCryptoKeySerializationJWK::keyDataOctetSequence): Split out of keyData().
     50        (WebCore::JSCryptoKeySerializationJWK::keyDataRSAComponents): Added code to read
     51        RSA key components from JWK.
     52        (WebCore::JSCryptoKeySerializationJWK::keyData): Call one of the above functions.
     53
     54        * crypto/CryptoAlgorithmRSASSA_PKCS1_v1_5Mac.cpp: Added.
     55        (WebCore::CryptoAlgorithmRSASSA_PKCS1_v1_5::sign):
     56        (WebCore::CryptoAlgorithmRSASSA_PKCS1_v1_5::verify):
     57        Placeholders.
     58
     59        * crypto/CryptoKey.h: (WebCore::CryptoKeyClass): Added RSA key class for poor man's RTTI.
     60
     61        * crypto/CryptoKeyData.h: (WebCore::CryptoKeyData::FormatRSAComponents): Added RSAComponents
     62        for poor man's RTTI.
     63
     64        * crypto/algorithms/CryptoAlgorithmAES_CBC.cpp: (WebCore::CryptoAlgorithmAES_CBC::importKey):
     65        * crypto/algorithms/CryptoAlgorithmHMAC.cpp: (WebCore::CryptoAlgorithmHMAC::importKey):
     66        * crypto/keys/CryptoKeyAES.h:
     67        (WebCore::isCryptoKeyAES):
     68        (WebCore::toCryptoKeyAES):
     69        * crypto/keys/CryptoKeyDataOctetSequence.h:
     70        (WebCore::toCryptoKeyDataOctetSequence):
     71        * crypto/keys/CryptoKeyHMAC.h:
     72        (WebCore::isCryptoKeyHMAC):
     73        (WebCore::toCryptoKeyHMAC):
     74        * crypto/mac/CryptoAlgorithmAES_CBCMac.cpp:
     75        (WebCore::CryptoAlgorithmAES_CBC::encrypt):
     76        (WebCore::CryptoAlgorithmAES_CBC::decrypt):
     77        * crypto/mac/CryptoAlgorithmHMACMac.cpp:
     78        (WebCore::CryptoAlgorithmHMAC::sign):
     79        (WebCore::CryptoAlgorithmHMAC::verify):
     80        Switched from "as" functions to "is" and "to" ones, as that's more idiomatic.
     81
     82        * crypto/algorithms/CryptoAlgorithmRSASSA_PKCS1_v1_5.cpp: Added.
     83        * crypto/algorithms/CryptoAlgorithmRSASSA_PKCS1_v1_5.h: Added.
     84        Glue code for importKey/generateKey for now.
     85
     86        * crypto/keys/CryptoKeyDataRSAComponents.cpp: Added.
     87        (WebCore::CryptoKeyDataRSAComponents::CryptoKeyDataRSAComponents):
     88        (WebCore::CryptoKeyDataRSAComponents::~CryptoKeyDataRSAComponents):
     89        * crypto/keys/CryptoKeyDataRSAComponents.h: Added.
     90        (WebCore::toCryptoKeyDataRSAComponents):
     91        Added a structure to hold RSA key components, extracted from JWK or another format.
     92
     93        * crypto/keys/CryptoKeyRSA.h: Added.
     94        * crypto/mac/CryptoKeyRSAMac.cpp: Added.
     95
     96        * crypto/mac/CryptoAlgorithmRegistryMac.cpp:
     97        (WebCore::CryptoAlgorithmRegistry::platformRegisterAlgorithms):
     98        Register RSASSA_PKCS1_v1_5.
     99
     100        * crypto/parameters/CryptoAlgorithmHmacKeyParams.h: Added a constructor to make
     101        sure that hasLength is never left uninitialized, even when reading formats that
     102        don't contain a length.
     103
     104        * crypto/parameters/CryptoAlgorithmRsaKeyGenParams.h: Added.
     105        * crypto/parameters/CryptoAlgorithmRsaSsaKeyParams.h: Added.
     106        * crypto/parameters/CryptoAlgorithmRsaSsaParams.h: Added.
     107        Added parameter structures that are needed for RSASSA_PKCS1_v1_5.
     108
    11092013-11-12  Alexey Proskuryakov  <ap@apple.com>
    2110
  • trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj

    r159167 r159180  
    55965596                E15A36D71104572000B7B639 /* XMLNSNames.h in Headers */ = {isa = PBXBuildFile; fileRef = E15A36D61104572000B7B639 /* XMLNSNames.h */; };
    55975597                E15A36D91104572700B7B639 /* XMLNSNames.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E15A36D81104572700B7B639 /* XMLNSNames.cpp */; };
     5598                E164FAA318315BF400DB4E61 /* CryptoKeyRSA.h in Headers */ = {isa = PBXBuildFile; fileRef = E164FAA218315BF400DB4E61 /* CryptoKeyRSA.h */; };
     5599                E164FAA518315E1A00DB4E61 /* CryptoKeyRSAMac.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E164FAA418315E1A00DB4E61 /* CryptoKeyRSAMac.cpp */; };
    55985600                E169803D1133542D00894115 /* CRuntimeObject.h in Headers */ = {isa = PBXBuildFile; fileRef = E169803C1133542D00894115 /* CRuntimeObject.h */; };
    55995601                E16980491133644700894115 /* CRuntimeObject.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E16980481133644700894115 /* CRuntimeObject.cpp */; };
     
    56705672                E1BA671A1742BEF400C20251 /* WebCoreTestShimLibrary.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E1BA67191742BEF400C20251 /* WebCoreTestShimLibrary.cpp */; };
    56715673                E1BB84AD1822CA7400525043 /* CryptoAlgorithmRegistryMac.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E1BB84AC1822CA7400525043 /* CryptoAlgorithmRegistryMac.cpp */; };
     5674                E1BD3319182D8DDD00C05D9F /* CryptoAlgorithmRSASSA_PKCS1_v1_5.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E1BD3317182D8DDD00C05D9F /* CryptoAlgorithmRSASSA_PKCS1_v1_5.cpp */; };
     5675                E1BD331A182D8DDD00C05D9F /* CryptoAlgorithmRSASSA_PKCS1_v1_5.h in Headers */ = {isa = PBXBuildFile; fileRef = E1BD3318182D8DDD00C05D9F /* CryptoAlgorithmRSASSA_PKCS1_v1_5.h */; };
     5676                E1BD331C182D8EE900C05D9F /* CryptoAlgorithmRsaSsaParams.h in Headers */ = {isa = PBXBuildFile; fileRef = E1BD331B182D8EE900C05D9F /* CryptoAlgorithmRsaSsaParams.h */; };
     5677                E1BD331E182D8F4200C05D9F /* CryptoAlgorithmRsaKeyGenParams.h in Headers */ = {isa = PBXBuildFile; fileRef = E1BD331D182D8F4200C05D9F /* CryptoAlgorithmRsaKeyGenParams.h */; };
    56725678                E1BE512D0CF6C512002EA959 /* XSLTUnicodeSort.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E1BE512B0CF6C512002EA959 /* XSLTUnicodeSort.cpp */; };
    56735679                E1BE512E0CF6C512002EA959 /* XSLTUnicodeSort.h in Headers */ = {isa = PBXBuildFile; fileRef = E1BE512C0CF6C512002EA959 /* XSLTUnicodeSort.h */; };
     5680                E1C266D818317AB4003F8B33 /* CryptoAlgorithmRSASSA_PKCS1_v1_5Mac.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E1C266D618317AB4003F8B33 /* CryptoAlgorithmRSASSA_PKCS1_v1_5Mac.cpp */; };
     5681                E1C266DB18319935003F8B33 /* CryptoAlgorithmRsaSsaKeyParams.h in Headers */ = {isa = PBXBuildFile; fileRef = E1C266DA18319935003F8B33 /* CryptoAlgorithmRsaSsaKeyParams.h */; };
     5682                E1C266DE18319F31003F8B33 /* CryptoKeyDataRSAComponents.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E1C266DC18319F31003F8B33 /* CryptoKeyDataRSAComponents.cpp */; };
     5683                E1C266DF18319F31003F8B33 /* CryptoKeyDataRSAComponents.h in Headers */ = {isa = PBXBuildFile; fileRef = E1C266DD18319F31003F8B33 /* CryptoKeyDataRSAComponents.h */; };
    56745684                E1C2F24A1533A2120083F974 /* SettingsMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = E1C2F2481533A2120083F974 /* SettingsMac.mm */; };
    56755685                E1C362EF0EAF2AA9007410BC /* JSWorkerLocation.h in Headers */ = {isa = PBXBuildFile; fileRef = E1C362ED0EAF2AA9007410BC /* JSWorkerLocation.h */; };
     
    1267812688                E15A36D61104572000B7B639 /* XMLNSNames.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = XMLNSNames.h; sourceTree = "<group>"; };
    1267912689                E15A36D81104572700B7B639 /* XMLNSNames.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = XMLNSNames.cpp; sourceTree = "<group>"; };
     12690                E164FAA218315BF400DB4E61 /* CryptoKeyRSA.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CryptoKeyRSA.h; path = keys/CryptoKeyRSA.h; sourceTree = "<group>"; };
     12691                E164FAA418315E1A00DB4E61 /* CryptoKeyRSAMac.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = CryptoKeyRSAMac.cpp; path = mac/CryptoKeyRSAMac.cpp; sourceTree = "<group>"; };
    1268012692                E169803C1133542D00894115 /* CRuntimeObject.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CRuntimeObject.h; sourceTree = "<group>"; };
    1268112693                E16980481133644700894115 /* CRuntimeObject.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CRuntimeObject.cpp; sourceTree = "<group>"; };
     
    1276112773                E1BA67191742BEF400C20251 /* WebCoreTestShimLibrary.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WebCoreTestShimLibrary.cpp; sourceTree = "<group>"; };
    1276212774                E1BB84AC1822CA7400525043 /* CryptoAlgorithmRegistryMac.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = CryptoAlgorithmRegistryMac.cpp; path = mac/CryptoAlgorithmRegistryMac.cpp; sourceTree = "<group>"; };
     12775                E1BD3317182D8DDD00C05D9F /* CryptoAlgorithmRSASSA_PKCS1_v1_5.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CryptoAlgorithmRSASSA_PKCS1_v1_5.cpp; sourceTree = "<group>"; };
     12776                E1BD3318182D8DDD00C05D9F /* CryptoAlgorithmRSASSA_PKCS1_v1_5.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CryptoAlgorithmRSASSA_PKCS1_v1_5.h; sourceTree = "<group>"; };
     12777                E1BD331B182D8EE900C05D9F /* CryptoAlgorithmRsaSsaParams.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CryptoAlgorithmRsaSsaParams.h; path = parameters/CryptoAlgorithmRsaSsaParams.h; sourceTree = "<group>"; };
     12778                E1BD331D182D8F4200C05D9F /* CryptoAlgorithmRsaKeyGenParams.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CryptoAlgorithmRsaKeyGenParams.h; path = parameters/CryptoAlgorithmRsaKeyGenParams.h; sourceTree = "<group>"; };
    1276312779                E1BE512B0CF6C512002EA959 /* XSLTUnicodeSort.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = XSLTUnicodeSort.cpp; sourceTree = "<group>"; };
    1276412780                E1BE512C0CF6C512002EA959 /* XSLTUnicodeSort.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = XSLTUnicodeSort.h; sourceTree = "<group>"; };
     12781                E1C266D618317AB4003F8B33 /* CryptoAlgorithmRSASSA_PKCS1_v1_5Mac.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CryptoAlgorithmRSASSA_PKCS1_v1_5Mac.cpp; sourceTree = "<group>"; };
     12782                E1C266DA18319935003F8B33 /* CryptoAlgorithmRsaSsaKeyParams.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CryptoAlgorithmRsaSsaKeyParams.h; path = parameters/CryptoAlgorithmRsaSsaKeyParams.h; sourceTree = "<group>"; };
     12783                E1C266DC18319F31003F8B33 /* CryptoKeyDataRSAComponents.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = CryptoKeyDataRSAComponents.cpp; path = keys/CryptoKeyDataRSAComponents.cpp; sourceTree = "<group>"; };
     12784                E1C266DD18319F31003F8B33 /* CryptoKeyDataRSAComponents.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CryptoKeyDataRSAComponents.h; path = keys/CryptoKeyDataRSAComponents.h; sourceTree = "<group>"; };
    1276512785                E1C2F2481533A2120083F974 /* SettingsMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = SettingsMac.mm; sourceTree = "<group>"; };
    1276612786                E1C362ED0EAF2AA9007410BC /* JSWorkerLocation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSWorkerLocation.h; sourceTree = "<group>"; };
     
    2032920349                                E1BB84AC1822CA7400525043 /* CryptoAlgorithmRegistryMac.cpp */,
    2033020350                                E125F82D1822CFFF00D84CD9 /* CryptoAlgorithmSHA1Mac.cpp */,
     20351                                E1C266D618317AB4003F8B33 /* CryptoAlgorithmRSASSA_PKCS1_v1_5Mac.cpp */,
    2033120352                                E19AC3DE1824DC6900349426 /* CryptoAlgorithmSHA224Mac.cpp */,
    2033220353                                E19AC3DF1824DC6900349426 /* CryptoAlgorithmSHA256Mac.cpp */,
     
    2033420355                                E19AC3E11824DC6900349426 /* CryptoAlgorithmSHA512Mac.cpp */,
    2033520356                                E19AC3F8182566F700349426 /* CryptoKeyMac.cpp */,
     20357                                E164FAA418315E1A00DB4E61 /* CryptoKeyRSAMac.cpp */,
    2033620358                        );
    2033720359                        name = mac;
     
    2034520367                                E125F82F1822F11B00D84CD9 /* CryptoAlgorithmHMAC.cpp */,
    2034620368                                E125F8301822F11B00D84CD9 /* CryptoAlgorithmHMAC.h */,
     20369                                E1BD3317182D8DDD00C05D9F /* CryptoAlgorithmRSASSA_PKCS1_v1_5.cpp */,
     20370                                E1BD3318182D8DDD00C05D9F /* CryptoAlgorithmRSASSA_PKCS1_v1_5.h */,
    2034720371                                E125F8291822CFEC00D84CD9 /* CryptoAlgorithmSHA1.cpp */,
    2034820372                                E125F82A1822CFEC00D84CD9 /* CryptoAlgorithmSHA1.h */,
     
    2036620390                                E125F861182C303A00D84CD9 /* CryptoKeyDataOctetSequence.cpp */,
    2036720391                                E125F862182C303A00D84CD9 /* CryptoKeyDataOctetSequence.h */,
     20392                                E1C266DC18319F31003F8B33 /* CryptoKeyDataRSAComponents.cpp */,
     20393                                E1C266DD18319F31003F8B33 /* CryptoKeyDataRSAComponents.h */,
    2036820394                                E125F8331822F18A00D84CD9 /* CryptoKeyHMAC.cpp */,
    2036920395                                E125F8341822F18A00D84CD9 /* CryptoKeyHMAC.h */,
     20396                                E164FAA218315BF400DB4E61 /* CryptoKeyRSA.h */,
    2037020397                                E125F857182C1AA600D84CD9 /* CryptoKeySerializationRaw.cpp */,
    2037120398                                E125F858182C1AA600D84CD9 /* CryptoKeySerializationRaw.h */,
     
    2038120408                                E19DA29B18189ADD00088BC8 /* CryptoAlgorithmHmacKeyParams.h */,
    2038220409                                E1C6571E1816E50300256CDD /* CryptoAlgorithmHmacParams.h */,
     20410                                E1BD331D182D8F4200C05D9F /* CryptoAlgorithmRsaKeyGenParams.h */,
     20411                                E1C266DA18319935003F8B33 /* CryptoAlgorithmRsaSsaKeyParams.h */,
     20412                                E1BD331B182D8EE900C05D9F /* CryptoAlgorithmRsaSsaParams.h */,
    2038320413                        );
    2038420414                        name = parameters;
     
    2211122141                                6550B6A0099DF0270090D781 /* CharacterData.h in Headers */,
    2211222142                                97B8FFD116AE7F960038388D /* CharacterReferenceParserInlines.h in Headers */,
     22143                                E164FAA318315BF400DB4E61 /* CryptoKeyRSA.h in Headers */,
    2211322144                                B2C3DA2A0D006C1D00EF6F26 /* CharsetData.h in Headers */,
    2211422145                                F55B3DB21251F12D003EF269 /* CheckboxInputType.h in Headers */,
     
    2231222343                                453EB637159C570400001BB7 /* DateTimeFormat.h in Headers */,
    2231322344                                0705850317FA10D0005F2BCB /* JSAllVideoCapabilities.h in Headers */,
     22345                                E1BD331A182D8DDD00C05D9F /* CryptoAlgorithmRSASSA_PKCS1_v1_5.h in Headers */,
    2231422346                                F55B3DB81251F12D003EF269 /* DateTimeInputType.h in Headers */,
    2231522347                                F55B3DBA1251F12D003EF269 /* DateTimeLocalInputType.h in Headers */,
     
    2287122903                                B275356D0B053814002CE64F /* FloatSize.h in Headers */,
    2287222904                                D72F6D7A153159A3001EE44E /* FlowThreadController.h in Headers */,
     22905                                E1BD331E182D8F4200C05D9F /* CryptoAlgorithmRsaKeyGenParams.h in Headers */,
    2287322906                                14993BE60B2F2B1C0050497F /* FocusController.h in Headers */,
    2287422907                                062287840B4DB322000C34DF /* FocusDirection.h in Headers */,
     
    2344623479                                070756D414239A4F00414161 /* JSHTMLTrackElement.h in Headers */,
    2344723480                                1A85B2110A1B258700D8C87C /* JSHTMLUListElement.h in Headers */,
     23481                                E1C266DF18319F31003F8B33 /* CryptoKeyDataRSAComponents.h in Headers */,
    2344823482                                6E4ABCD5138EA0B70071D291 /* JSHTMLUnknownElement.h in Headers */,
    2344923483                                078E092717D14D1C00420AA1 /* RTCSessionDescriptionCallback.h in Headers */,
     
    2367423708                                B2FA3DDF0AB75A6F000E5AC4 /* JSSVGPathSegMovetoRel.h in Headers */,
    2367523709                                0705852117FDC140005F2BCB /* MediaTrackConstraint.h in Headers */,
     23710                                E1C266DB18319935003F8B33 /* CryptoAlgorithmRsaSsaKeyParams.h in Headers */,
    2367623711                                CD8B5A46180DFF4E008B8E65 /* VideoTrackMediaSource.h in Headers */,
    2367723712                                B2FA3DE10AB75A6F000E5AC4 /* JSSVGPatternElement.h in Headers */,
     
    2398624021                                BC5EB5DD0E81B8DD00B25965 /* OutlineValue.h in Headers */,
    2398724022                                1A0D57370A5C77FE007EDD4C /* OverflowEvent.h in Headers */,
     24023                                E1BD331C182D8EE900C05D9F /* CryptoAlgorithmRsaSsaParams.h in Headers */,
    2398824024                                3774ABA50FA21EB400AD7DE9 /* OverlapTestRequestClient.h in Headers */,
    2398924025                                65A21468097A329100B9050A /* Page.h in Headers */,
     
    2575525791                                50987C26157D676D00BDA835 /* CustomFilterGlobalContext.cpp in Sources */,
    2575625792                                50D405F9147D31F300D30BB5 /* CustomFilterMesh.cpp in Sources */,
     25793                                E1C266DE18319F31003F8B33 /* CryptoKeyDataRSAComponents.cpp in Sources */,
    2575725794                                7E12E91015FA5D3A005E4126 /* CustomFilterMeshGenerator.cpp in Sources */,
    2575825795                                50CC0A3914C6F5B10017AB51 /* CustomFilterOperation.cpp in Sources */,
     
    2635626393                                BCCD74E50A4C8DDF005FDA6D /* HTMLViewSourceDocument.cpp in Sources */,
    2635726394                                977B3879122883E900B81FF8 /* HTMLViewSourceParser.cpp in Sources */,
     26395                                E1C266D818317AB4003F8B33 /* CryptoAlgorithmRSASSA_PKCS1_v1_5Mac.cpp in Sources */,
    2635826396                                0B8C56D40F28627F000502E1 /* HTTPHeaderMap.cpp in Sources */,
    2635926397                                514C76720CE923A1007EF3CD /* HTTPParsers.cpp in Sources */,
     
    2677026808                                65DF31FB09D1CC60000BE325 /* JSMutationEvent.cpp in Sources */,
    2677126809                                C6F0902C14327D4F00685849 /* JSMutationObserver.cpp in Sources */,
     26810                                E164FAA518315E1A00DB4E61 /* CryptoKeyRSAMac.cpp in Sources */,
    2677226811                                C6F0917F143A2BB900685849 /* JSMutationObserverCustom.cpp in Sources */,
    2677326812                                C6F08FC91431000D00685849 /* JSMutationRecord.cpp in Sources */,
     
    2706027099                                49C7B99B1042D2D30009D447 /* JSWebGLProgram.cpp in Sources */,
    2706127100                                49C7B99D1042D2D30009D447 /* JSWebGLRenderbuffer.cpp in Sources */,
     27101                                E1BD3319182D8DDD00C05D9F /* CryptoAlgorithmRSASSA_PKCS1_v1_5.cpp in Sources */,
    2706227102                                49EED1461051969400099FAB /* JSWebGLRenderingContext.cpp in Sources */,
    2706327103                                49EED14F1051971A00099FAB /* JSWebGLRenderingContextCustom.cpp in Sources */,
  • trunk/Source/WebCore/bindings/js/JSCryptoAlgorithmBuilder.cpp

    r159167 r159180  
    3131#include <runtime/ObjectConstructor.h>
    3232#include <runtime/Operations.h>
     33#include <runtime/TypedArrays.h>
     34#include <runtime/TypedArrayInlines.h>
    3335
    3436using namespace JSC;
     
    6567}
    6668
     69void JSCryptoAlgorithmBuilder::add(const char* key, const Vector<uint8_t>& buffer)
     70{
     71    VM& vm = m_exec->vm();
     72    Identifier identifier(&vm, key);
     73    RefPtr<Uint8Array> arrayView = Uint8Array::create(buffer.data(), buffer.size());
     74    m_dictionary->putDirect(vm, identifier, arrayView->wrap(m_exec, vm.dynamicGlobalObject));
     75}
     76
    6777void JSCryptoAlgorithmBuilder::add(const char* key, const CryptoAlgorithmDescriptionBuilder& nestedBuilder)
    6878{
  • trunk/Source/WebCore/bindings/js/JSCryptoAlgorithmBuilder.h

    r159167 r159180  
    4949    virtual void add(const char*, unsigned) OVERRIDE;
    5050    virtual void add(const char*, const String&) OVERRIDE;
     51    virtual void add(const char*, const Vector<uint8_t>&) OVERRIDE;
    5152    virtual void add(const char*, const CryptoAlgorithmDescriptionBuilder&) OVERRIDE;
    5253
  • trunk/Source/WebCore/bindings/js/JSCryptoAlgorithmDictionary.cpp

    r159167 r159180  
    3434#include "CryptoAlgorithmHmacParams.h"
    3535#include "CryptoAlgorithmRegistry.h"
     36#include "CryptoAlgorithmRsaKeyGenParams.h"
     37#include "CryptoAlgorithmRsaSsaKeyParams.h"
     38#include "CryptoAlgorithmRsaSsaParams.h"
    3639#include "ExceptionCode.h"
    3740#include "JSCryptoOperationData.h"
     
    117120}
    118121
    119 static std::unique_ptr<CryptoAlgorithmParameters> createAesCbcParams(JSC::ExecState* exec, JSC::JSValue value)
     122static std::unique_ptr<CryptoAlgorithmParameters> createAesCbcParams(ExecState* exec, JSValue value)
    120123{
    121124    if (!value.isObject()) {
     
    146149}
    147150
    148 static std::unique_ptr<CryptoAlgorithmParameters> createAesKeyGenParams(JSC::ExecState* exec, JSC::JSValue value)
     151static std::unique_ptr<CryptoAlgorithmParameters> createAesKeyGenParams(ExecState* exec, JSValue value)
    149152{
    150153    if (!value.isObject()) {
     
    164167}
    165168
    166 static std::unique_ptr<CryptoAlgorithmParameters> createHmacParams(JSC::ExecState* exec, JSC::JSValue value)
     169static std::unique_ptr<CryptoAlgorithmParameters> createHmacParams(ExecState* exec, JSValue value)
    167170{
    168171    if (!value.isObject()) {
     
    182185}
    183186
    184 static std::unique_ptr<CryptoAlgorithmParameters> createHmacKeyParams(JSC::ExecState* exec, JSC::JSValue value)
     187static std::unique_ptr<CryptoAlgorithmParameters> createHmacKeyParams(ExecState* exec, JSValue value)
    185188{
    186189    if (!value.isObject()) {
     
    204207}
    205208
    206 std::unique_ptr<CryptoAlgorithmParameters> JSCryptoAlgorithmDictionary::createParametersForEncrypt(JSC::ExecState* exec, CryptoAlgorithmIdentifier algorithm, JSC::JSValue value)
     209static std::unique_ptr<CryptoAlgorithmParameters> createRsaKeyGenParams(ExecState* exec, JSValue value)
     210{
     211    if (!value.isObject()) {
     212        throwTypeError(exec);
     213        return nullptr;
     214    }
     215
     216    auto result = std::make_unique<CryptoAlgorithmRsaKeyGenParams>();
     217
     218    JSValue modulusLengthValue = getProperty(exec, value.getObject(), "modulusLength");
     219    if (exec->hadException())
     220        return nullptr;
     221
     222    // FIXME: Why no EnforceRange? Filed as <https://www.w3.org/Bugs/Public/show_bug.cgi?id=23779>.
     223    result->modulusLength = toUInt32(exec, modulusLengthValue, NormalConversion);
     224    if (exec->hadException())
     225        return nullptr;
     226
     227    JSValue publicExponentValue = getProperty(exec, value.getObject(), "publicExponent");
     228    if (exec->hadException())
     229        return nullptr;
     230
     231    RefPtr<Uint8Array> publicExponentArray = toUint8Array(publicExponentValue);
     232    if (!publicExponentArray) {
     233        throwTypeError(exec, "Expected a Uint8Array in publicExponent");
     234        return nullptr;
     235    }
     236    result->publicExponent.append(publicExponentArray->data(), publicExponentArray->byteLength());
     237
     238    return std::move(result);
     239}
     240
     241static std::unique_ptr<CryptoAlgorithmParameters> createRsaSsaKeyParams(ExecState*, JSValue)
     242{
     243    // WebCrypto RSASSA-PKCS1-v1_5 algorithm currently does not take any parameters to importKey.
     244    return std::make_unique<CryptoAlgorithmRsaSsaKeyParams>();
     245}
     246
     247static std::unique_ptr<CryptoAlgorithmParameters> createRsaSsaParams(ExecState* exec, JSValue value)
     248{
     249    if (!value.isObject()) {
     250        throwTypeError(exec);
     251        return nullptr;
     252    }
     253
     254    JSDictionary jsDictionary(exec, value.getObject());
     255    auto result = std::make_unique<CryptoAlgorithmRsaSsaParams>();
     256
     257    if (!getHashAlgorithm(jsDictionary, result->hash)) {
     258        ASSERT(exec->hadException());
     259        return nullptr;
     260    }
     261
     262    return std::move(result);
     263}
     264
     265std::unique_ptr<CryptoAlgorithmParameters> JSCryptoAlgorithmDictionary::createParametersForEncrypt(ExecState* exec, CryptoAlgorithmIdentifier algorithm, JSValue value)
    207266{
    208267    switch (algorithm) {
     
    236295}
    237296
    238 std::unique_ptr<CryptoAlgorithmParameters> JSCryptoAlgorithmDictionary::createParametersForDecrypt(JSC::ExecState* exec, CryptoAlgorithmIdentifier algorithm, JSC::JSValue value)
     297std::unique_ptr<CryptoAlgorithmParameters> JSCryptoAlgorithmDictionary::createParametersForDecrypt(ExecState* exec, CryptoAlgorithmIdentifier algorithm, JSValue value)
    239298{
    240299    switch (algorithm) {
     
    268327}
    269328
    270 std::unique_ptr<CryptoAlgorithmParameters> JSCryptoAlgorithmDictionary::createParametersForSign(JSC::ExecState* exec, CryptoAlgorithmIdentifier algorithm, JSC::JSValue value)
    271 {
    272     switch (algorithm) {
    273     case CryptoAlgorithmIdentifier::RSAES_PKCS1_v1_5:
    274     case CryptoAlgorithmIdentifier::RSASSA_PKCS1_v1_5:
     329std::unique_ptr<CryptoAlgorithmParameters> JSCryptoAlgorithmDictionary::createParametersForSign(ExecState* exec, CryptoAlgorithmIdentifier algorithm, JSValue value)
     330{
     331    switch (algorithm) {
     332    case CryptoAlgorithmIdentifier::RSAES_PKCS1_v1_5:
     333        setDOMException(exec, NOT_SUPPORTED_ERR);
     334        return nullptr;
     335    case CryptoAlgorithmIdentifier::RSASSA_PKCS1_v1_5:
     336        return createRsaSsaParams(exec, value);
    275337    case CryptoAlgorithmIdentifier::RSA_PSS:
    276338    case CryptoAlgorithmIdentifier::RSA_OAEP:
     
    300362}
    301363
    302 std::unique_ptr<CryptoAlgorithmParameters> JSCryptoAlgorithmDictionary::createParametersForVerify(JSC::ExecState* exec, CryptoAlgorithmIdentifier algorithm, JSC::JSValue value)
    303 {
    304     switch (algorithm) {
    305     case CryptoAlgorithmIdentifier::RSAES_PKCS1_v1_5:
    306     case CryptoAlgorithmIdentifier::RSASSA_PKCS1_v1_5:
     364std::unique_ptr<CryptoAlgorithmParameters> JSCryptoAlgorithmDictionary::createParametersForVerify(ExecState* exec, CryptoAlgorithmIdentifier algorithm, JSValue value)
     365{
     366    switch (algorithm) {
     367    case CryptoAlgorithmIdentifier::RSAES_PKCS1_v1_5:
     368        setDOMException(exec, NOT_SUPPORTED_ERR);
     369        return nullptr;
     370    case CryptoAlgorithmIdentifier::RSASSA_PKCS1_v1_5:
     371        return createRsaSsaParams(exec, value);
    307372    case CryptoAlgorithmIdentifier::RSA_PSS:
    308373    case CryptoAlgorithmIdentifier::RSA_OAEP:
     
    332397}
    333398
    334 std::unique_ptr<CryptoAlgorithmParameters> JSCryptoAlgorithmDictionary::createParametersForDigest(JSC::ExecState* exec, CryptoAlgorithmIdentifier algorithm, JSC::JSValue)
     399std::unique_ptr<CryptoAlgorithmParameters> JSCryptoAlgorithmDictionary::createParametersForDigest(ExecState* exec, CryptoAlgorithmIdentifier algorithm, JSValue)
    335400{
    336401    switch (algorithm) {
     
    364429}
    365430
    366 std::unique_ptr<CryptoAlgorithmParameters> JSCryptoAlgorithmDictionary::createParametersForGenerateKey(JSC::ExecState* exec, CryptoAlgorithmIdentifier algorithm, JSC::JSValue value)
    367 {
    368     switch (algorithm) {
    369     case CryptoAlgorithmIdentifier::RSAES_PKCS1_v1_5:
    370     case CryptoAlgorithmIdentifier::RSASSA_PKCS1_v1_5:
    371     case CryptoAlgorithmIdentifier::RSA_PSS:
    372     case CryptoAlgorithmIdentifier::RSA_OAEP:
     431std::unique_ptr<CryptoAlgorithmParameters> JSCryptoAlgorithmDictionary::createParametersForGenerateKey(ExecState* exec, CryptoAlgorithmIdentifier algorithm, JSValue value)
     432{
     433    switch (algorithm) {
     434    case CryptoAlgorithmIdentifier::RSAES_PKCS1_v1_5:
     435    case CryptoAlgorithmIdentifier::RSASSA_PKCS1_v1_5:
     436    case CryptoAlgorithmIdentifier::RSA_PSS:
     437    case CryptoAlgorithmIdentifier::RSA_OAEP:
     438        return createRsaKeyGenParams(exec, value);
    373439    case CryptoAlgorithmIdentifier::ECDSA:
    374440    case CryptoAlgorithmIdentifier::ECDH:
     
    397463}
    398464
    399 std::unique_ptr<CryptoAlgorithmParameters> JSCryptoAlgorithmDictionary::createParametersForDeriveKey(JSC::ExecState* exec, CryptoAlgorithmIdentifier algorithm, JSC::JSValue)
    400 {
    401     switch (algorithm) {
    402     case CryptoAlgorithmIdentifier::RSAES_PKCS1_v1_5:
    403     case CryptoAlgorithmIdentifier::RSASSA_PKCS1_v1_5:
    404     case CryptoAlgorithmIdentifier::RSA_PSS:
    405     case CryptoAlgorithmIdentifier::RSA_OAEP:
    406     case CryptoAlgorithmIdentifier::ECDSA:
    407     case CryptoAlgorithmIdentifier::ECDH:
    408     case CryptoAlgorithmIdentifier::AES_CTR:
    409     case CryptoAlgorithmIdentifier::AES_CBC:
    410     case CryptoAlgorithmIdentifier::AES_CMAC:
    411     case CryptoAlgorithmIdentifier::AES_GCM:
    412     case CryptoAlgorithmIdentifier::AES_CFB:
    413     case CryptoAlgorithmIdentifier::HMAC:
    414     case CryptoAlgorithmIdentifier::DH:
    415     case CryptoAlgorithmIdentifier::SHA_1:
    416     case CryptoAlgorithmIdentifier::SHA_224:
    417     case CryptoAlgorithmIdentifier::SHA_256:
    418     case CryptoAlgorithmIdentifier::SHA_384:
    419     case CryptoAlgorithmIdentifier::SHA_512:
    420     case CryptoAlgorithmIdentifier::CONCAT:
    421     case CryptoAlgorithmIdentifier::HKDF_CTR:
    422     case CryptoAlgorithmIdentifier::PBKDF2:
    423         setDOMException(exec, NOT_SUPPORTED_ERR);
    424         return nullptr;
    425     }
    426 }
    427 
    428 std::unique_ptr<CryptoAlgorithmParameters> JSCryptoAlgorithmDictionary::createParametersForDeriveBits(JSC::ExecState* exec, CryptoAlgorithmIdentifier algorithm, JSC::JSValue)
    429 {
    430     switch (algorithm) {
    431     case CryptoAlgorithmIdentifier::RSAES_PKCS1_v1_5:
    432     case CryptoAlgorithmIdentifier::RSASSA_PKCS1_v1_5:
    433     case CryptoAlgorithmIdentifier::RSA_PSS:
    434     case CryptoAlgorithmIdentifier::RSA_OAEP:
    435     case CryptoAlgorithmIdentifier::ECDSA:
    436     case CryptoAlgorithmIdentifier::ECDH:
    437     case CryptoAlgorithmIdentifier::AES_CTR:
    438     case CryptoAlgorithmIdentifier::AES_CBC:
    439     case CryptoAlgorithmIdentifier::AES_CMAC:
    440     case CryptoAlgorithmIdentifier::AES_GCM:
    441     case CryptoAlgorithmIdentifier::AES_CFB:
    442     case CryptoAlgorithmIdentifier::HMAC:
    443     case CryptoAlgorithmIdentifier::DH:
    444     case CryptoAlgorithmIdentifier::SHA_1:
    445     case CryptoAlgorithmIdentifier::SHA_224:
    446     case CryptoAlgorithmIdentifier::SHA_256:
    447     case CryptoAlgorithmIdentifier::SHA_384:
    448     case CryptoAlgorithmIdentifier::SHA_512:
    449     case CryptoAlgorithmIdentifier::CONCAT:
    450     case CryptoAlgorithmIdentifier::HKDF_CTR:
    451     case CryptoAlgorithmIdentifier::PBKDF2:
    452         setDOMException(exec, NOT_SUPPORTED_ERR);
    453         return nullptr;
    454     }
    455 }
    456 
    457 std::unique_ptr<CryptoAlgorithmParameters> JSCryptoAlgorithmDictionary::createParametersForImportKey(JSC::ExecState* exec, CryptoAlgorithmIdentifier algorithm, JSC::JSValue value)
    458 {
    459     switch (algorithm) {
    460     case CryptoAlgorithmIdentifier::RSAES_PKCS1_v1_5:
    461     case CryptoAlgorithmIdentifier::RSASSA_PKCS1_v1_5:
    462     case CryptoAlgorithmIdentifier::RSA_PSS:
    463     case CryptoAlgorithmIdentifier::RSA_OAEP:
    464     case CryptoAlgorithmIdentifier::ECDSA:
    465     case CryptoAlgorithmIdentifier::ECDH:
    466     case CryptoAlgorithmIdentifier::AES_CTR:
    467     case CryptoAlgorithmIdentifier::AES_CBC:
    468     case CryptoAlgorithmIdentifier::AES_CMAC:
    469     case CryptoAlgorithmIdentifier::AES_GCM:
    470     case CryptoAlgorithmIdentifier::AES_CFB:
     465std::unique_ptr<CryptoAlgorithmParameters> JSCryptoAlgorithmDictionary::createParametersForDeriveKey(ExecState* exec, CryptoAlgorithmIdentifier algorithm, JSValue)
     466{
     467    switch (algorithm) {
     468    case CryptoAlgorithmIdentifier::RSAES_PKCS1_v1_5:
     469    case CryptoAlgorithmIdentifier::RSASSA_PKCS1_v1_5:
     470    case CryptoAlgorithmIdentifier::RSA_PSS:
     471    case CryptoAlgorithmIdentifier::RSA_OAEP:
     472    case CryptoAlgorithmIdentifier::ECDSA:
     473    case CryptoAlgorithmIdentifier::ECDH:
     474    case CryptoAlgorithmIdentifier::AES_CTR:
     475    case CryptoAlgorithmIdentifier::AES_CBC:
     476    case CryptoAlgorithmIdentifier::AES_CMAC:
     477    case CryptoAlgorithmIdentifier::AES_GCM:
     478    case CryptoAlgorithmIdentifier::AES_CFB:
     479    case CryptoAlgorithmIdentifier::HMAC:
     480    case CryptoAlgorithmIdentifier::DH:
     481    case CryptoAlgorithmIdentifier::SHA_1:
     482    case CryptoAlgorithmIdentifier::SHA_224:
     483    case CryptoAlgorithmIdentifier::SHA_256:
     484    case CryptoAlgorithmIdentifier::SHA_384:
     485    case CryptoAlgorithmIdentifier::SHA_512:
     486    case CryptoAlgorithmIdentifier::CONCAT:
     487    case CryptoAlgorithmIdentifier::HKDF_CTR:
     488    case CryptoAlgorithmIdentifier::PBKDF2:
     489        setDOMException(exec, NOT_SUPPORTED_ERR);
     490        return nullptr;
     491    }
     492}
     493
     494std::unique_ptr<CryptoAlgorithmParameters> JSCryptoAlgorithmDictionary::createParametersForDeriveBits(ExecState* exec, CryptoAlgorithmIdentifier algorithm, JSValue)
     495{
     496    switch (algorithm) {
     497    case CryptoAlgorithmIdentifier::RSAES_PKCS1_v1_5:
     498    case CryptoAlgorithmIdentifier::RSASSA_PKCS1_v1_5:
     499    case CryptoAlgorithmIdentifier::RSA_PSS:
     500    case CryptoAlgorithmIdentifier::RSA_OAEP:
     501    case CryptoAlgorithmIdentifier::ECDSA:
     502    case CryptoAlgorithmIdentifier::ECDH:
     503    case CryptoAlgorithmIdentifier::AES_CTR:
     504    case CryptoAlgorithmIdentifier::AES_CBC:
     505    case CryptoAlgorithmIdentifier::AES_CMAC:
     506    case CryptoAlgorithmIdentifier::AES_GCM:
     507    case CryptoAlgorithmIdentifier::AES_CFB:
     508    case CryptoAlgorithmIdentifier::HMAC:
     509    case CryptoAlgorithmIdentifier::DH:
     510    case CryptoAlgorithmIdentifier::SHA_1:
     511    case CryptoAlgorithmIdentifier::SHA_224:
     512    case CryptoAlgorithmIdentifier::SHA_256:
     513    case CryptoAlgorithmIdentifier::SHA_384:
     514    case CryptoAlgorithmIdentifier::SHA_512:
     515    case CryptoAlgorithmIdentifier::CONCAT:
     516    case CryptoAlgorithmIdentifier::HKDF_CTR:
     517    case CryptoAlgorithmIdentifier::PBKDF2:
     518        setDOMException(exec, NOT_SUPPORTED_ERR);
     519        return nullptr;
     520    }
     521}
     522
     523std::unique_ptr<CryptoAlgorithmParameters> JSCryptoAlgorithmDictionary::createParametersForImportKey(ExecState* exec, CryptoAlgorithmIdentifier algorithm, JSValue value)
     524{
     525    switch (algorithm) {
     526    case CryptoAlgorithmIdentifier::RSAES_PKCS1_v1_5:
    471527        return std::make_unique<CryptoAlgorithmParameters>();
     528    case CryptoAlgorithmIdentifier::RSASSA_PKCS1_v1_5:
     529        return createRsaSsaKeyParams(exec, value);
     530    case CryptoAlgorithmIdentifier::RSA_PSS:
     531    case CryptoAlgorithmIdentifier::RSA_OAEP:
     532    case CryptoAlgorithmIdentifier::ECDSA:
     533    case CryptoAlgorithmIdentifier::ECDH:
     534    case CryptoAlgorithmIdentifier::AES_CTR:
     535    case CryptoAlgorithmIdentifier::AES_CBC:
     536    case CryptoAlgorithmIdentifier::AES_CMAC:
     537    case CryptoAlgorithmIdentifier::AES_GCM:
     538    case CryptoAlgorithmIdentifier::AES_CFB:
     539        return std::make_unique<CryptoAlgorithmParameters>();
    472540    case CryptoAlgorithmIdentifier::HMAC:
    473541        return createHmacKeyParams(exec, value);
     
    487555}
    488556
    489 std::unique_ptr<CryptoAlgorithmParameters> JSCryptoAlgorithmDictionary::createParametersForExportKey(JSC::ExecState* exec, CryptoAlgorithmIdentifier algorithm, JSC::JSValue)
     557std::unique_ptr<CryptoAlgorithmParameters> JSCryptoAlgorithmDictionary::createParametersForExportKey(ExecState* exec, CryptoAlgorithmIdentifier algorithm, JSValue)
    490558{
    491559    switch (algorithm) {
     
    517585}
    518586
    519 std::unique_ptr<CryptoAlgorithmParameters> JSCryptoAlgorithmDictionary::createParametersForWrapKey(JSC::ExecState* exec, CryptoAlgorithmIdentifier algorithm, JSC::JSValue)
    520 {
    521     switch (algorithm) {
    522     case CryptoAlgorithmIdentifier::RSAES_PKCS1_v1_5:
    523     case CryptoAlgorithmIdentifier::RSASSA_PKCS1_v1_5:
    524     case CryptoAlgorithmIdentifier::RSA_PSS:
    525     case CryptoAlgorithmIdentifier::RSA_OAEP:
    526     case CryptoAlgorithmIdentifier::ECDSA:
    527     case CryptoAlgorithmIdentifier::ECDH:
    528     case CryptoAlgorithmIdentifier::AES_CTR:
    529     case CryptoAlgorithmIdentifier::AES_CBC:
    530     case CryptoAlgorithmIdentifier::AES_CMAC:
    531     case CryptoAlgorithmIdentifier::AES_GCM:
    532     case CryptoAlgorithmIdentifier::AES_CFB:
    533     case CryptoAlgorithmIdentifier::HMAC:
    534     case CryptoAlgorithmIdentifier::DH:
    535     case CryptoAlgorithmIdentifier::SHA_1:
    536     case CryptoAlgorithmIdentifier::SHA_224:
    537     case CryptoAlgorithmIdentifier::SHA_256:
    538     case CryptoAlgorithmIdentifier::SHA_384:
    539     case CryptoAlgorithmIdentifier::SHA_512:
    540     case CryptoAlgorithmIdentifier::CONCAT:
    541     case CryptoAlgorithmIdentifier::HKDF_CTR:
    542     case CryptoAlgorithmIdentifier::PBKDF2:
    543         setDOMException(exec, NOT_SUPPORTED_ERR);
    544         return nullptr;
    545     }
    546 }
    547 
    548 std::unique_ptr<CryptoAlgorithmParameters> JSCryptoAlgorithmDictionary::createParametersForUnwrapKey(JSC::ExecState* exec, CryptoAlgorithmIdentifier algorithm, JSC::JSValue)
     587std::unique_ptr<CryptoAlgorithmParameters> JSCryptoAlgorithmDictionary::createParametersForWrapKey(ExecState* exec, CryptoAlgorithmIdentifier algorithm, JSValue)
     588{
     589    switch (algorithm) {
     590    case CryptoAlgorithmIdentifier::RSAES_PKCS1_v1_5:
     591    case CryptoAlgorithmIdentifier::RSASSA_PKCS1_v1_5:
     592    case CryptoAlgorithmIdentifier::RSA_PSS:
     593    case CryptoAlgorithmIdentifier::RSA_OAEP:
     594    case CryptoAlgorithmIdentifier::ECDSA:
     595    case CryptoAlgorithmIdentifier::ECDH:
     596    case CryptoAlgorithmIdentifier::AES_CTR:
     597    case CryptoAlgorithmIdentifier::AES_CBC:
     598    case CryptoAlgorithmIdentifier::AES_CMAC:
     599    case CryptoAlgorithmIdentifier::AES_GCM:
     600    case CryptoAlgorithmIdentifier::AES_CFB:
     601    case CryptoAlgorithmIdentifier::HMAC:
     602    case CryptoAlgorithmIdentifier::DH:
     603    case CryptoAlgorithmIdentifier::SHA_1:
     604    case CryptoAlgorithmIdentifier::SHA_224:
     605    case CryptoAlgorithmIdentifier::SHA_256:
     606    case CryptoAlgorithmIdentifier::SHA_384:
     607    case CryptoAlgorithmIdentifier::SHA_512:
     608    case CryptoAlgorithmIdentifier::CONCAT:
     609    case CryptoAlgorithmIdentifier::HKDF_CTR:
     610    case CryptoAlgorithmIdentifier::PBKDF2:
     611        setDOMException(exec, NOT_SUPPORTED_ERR);
     612        return nullptr;
     613    }
     614}
     615
     616std::unique_ptr<CryptoAlgorithmParameters> JSCryptoAlgorithmDictionary::createParametersForUnwrapKey(ExecState* exec, CryptoAlgorithmIdentifier algorithm, JSValue)
    549617{
    550618    switch (algorithm) {
  • trunk/Source/WebCore/bindings/js/JSCryptoKeySerializationJWK.cpp

    r159167 r159180  
    3232#include "CryptoAlgorithmHmacParams.h"
    3333#include "CryptoAlgorithmRegistry.h"
     34#include "CryptoAlgorithmRsaSsaKeyParams.h"
    3435#include "CryptoKeyDataOctetSequence.h"
     36#include "CryptoKeyDataRSAComponents.h"
    3537#include "ExceptionCode.h"
    3638#include "JSDOMBinding.h"
     
    4244
    4345namespace WebCore {
     46
     47static bool getJSArrayFromJSON(ExecState* exec, JSObject* json, const char* key, JSArray*& result)
     48{
     49    Identifier identifier(exec, key);
     50    PropertySlot slot(json);
     51
     52    if (!json->getPropertySlot(exec, identifier, slot))
     53        return false;
     54
     55    JSValue value = slot.getValue(exec, identifier);
     56    ASSERT(!exec->hadException());
     57    if (isJSArray(value)) {
     58        throwTypeError(exec, String::format("Expected an array for \"%s\" JSON key",  key));
     59        return false;
     60    }
     61
     62    result = asArray(value);
     63
     64    return true;
     65}
    4466
    4567static bool getStringFromJSON(ExecState* exec, JSObject* json, const char* key, String& result)
     
    83105}
    84106
     107static bool getBigIntegerVectorFromJSON(ExecState* exec, JSObject* json, const char* key, Vector<char>& result)
     108{
     109    String base64urlEncodedNumber;
     110    if (!getStringFromJSON(exec, json, key, base64urlEncodedNumber))
     111        return false;
     112
     113    if (!base64URLDecode(base64urlEncodedNumber, result)) {
     114        throwTypeError(exec, "Cannot decode base64url key data in JWK");
     115        return false;
     116    }
     117
     118    if (result[0] == 0) {
     119        throwTypeError(exec, "JWK BigInteger must utilize the minimum number of octets to represent the value");
     120        return false;
     121    }
     122
     123    return true;
     124}
     125
    85126JSCryptoKeySerializationJWK::JSCryptoKeySerializationJWK(ExecState* exec, const String& jsonString)
    86127    : m_exec(exec)
     
    108149    return std::move(hmacParameters);
    109150}
     151
     152static std::unique_ptr<CryptoAlgorithmParameters> createRSASSAKeyParameters(CryptoAlgorithmIdentifier hashFunction)
     153{
     154    std::unique_ptr<CryptoAlgorithmRsaSsaKeyParams> rsaSSAParameters = std::make_unique<CryptoAlgorithmRsaSsaKeyParams>();
     155    rsaSSAParameters->hasHash = true;
     156    rsaSSAParameters->hash = hashFunction;
     157    return std::move(rsaSSAParameters);
     158}
     159
    110160
    111161bool JSCryptoKeySerializationJWK::reconcileAlgorithm(std::unique_ptr<CryptoAlgorithm>& suggestedAlgorithm, std::unique_ptr<CryptoAlgorithmParameters>& suggestedParameters) const
     
    127177        algorithm = CryptoAlgorithmRegistry::shared().create(CryptoAlgorithmIdentifier::HMAC);
    128178        parameters = createHMACParameters(CryptoAlgorithmIdentifier::SHA_512);
     179    } else if (m_jwkAlgorithmName == "RS256") {
     180        algorithm = CryptoAlgorithmRegistry::shared().create(CryptoAlgorithmIdentifier::RSASSA_PKCS1_v1_5);
     181        parameters = createRSASSAKeyParameters(CryptoAlgorithmIdentifier::SHA_256);
     182    } else if (m_jwkAlgorithmName == "RS384") {
     183        algorithm = CryptoAlgorithmRegistry::shared().create(CryptoAlgorithmIdentifier::RSASSA_PKCS1_v1_5);
     184        parameters = createRSASSAKeyParameters(CryptoAlgorithmIdentifier::SHA_384);
     185    } else if (m_jwkAlgorithmName == "RS512") {
     186        algorithm = CryptoAlgorithmRegistry::shared().create(CryptoAlgorithmIdentifier::RSASSA_PKCS1_v1_5);
     187        parameters = createRSASSAKeyParameters(CryptoAlgorithmIdentifier::SHA_512);
    129188    } else if (m_jwkAlgorithmName == "A128CBC") {
    130189        algorithm = CryptoAlgorithmRegistry::shared().create(CryptoAlgorithmIdentifier::AES_CBC);
     
    153212        return false;
    154213
    155     // HMAC is the only algorithm that has parameters in importKey.
    156     if (algorithm->identifier() != CryptoAlgorithmIdentifier::HMAC)
    157         return true;
    158 
    159     return static_cast<CryptoAlgorithmHmacParams&>(*parameters).hash == static_cast<CryptoAlgorithmHmacParams&>(*suggestedParameters).hash;
     214    if (algorithm->identifier() == CryptoAlgorithmIdentifier::HMAC)
     215        return static_cast<CryptoAlgorithmHmacParams&>(*parameters).hash == static_cast<CryptoAlgorithmHmacParams&>(*suggestedParameters).hash;
     216    if (algorithm->identifier() == CryptoAlgorithmIdentifier::RSASSA_PKCS1_v1_5) {
     217        CryptoAlgorithmRsaSsaKeyParams& rsaSSAParameters = static_cast<CryptoAlgorithmRsaSsaKeyParams&>(*parameters);
     218        CryptoAlgorithmRsaSsaKeyParams& suggestedRSASSAParameters = static_cast<CryptoAlgorithmRsaSsaKeyParams&>(*suggestedParameters);
     219        ASSERT(rsaSSAParameters.hasHash);
     220        if (suggestedRSASSAParameters.hasHash)
     221            return suggestedRSASSAParameters.hash == rsaSSAParameters.hash;
     222        suggestedRSASSAParameters.hasHash = true;
     223        suggestedRSASSAParameters.hash = rsaSSAParameters.hash;
     224    }
     225
     226    // Other algorithms don't have parameters.
     227    return true;
    160228}
    161229
     
    208276}
    209277
     278std::unique_ptr<CryptoKeyData> JSCryptoKeySerializationJWK::keyDataOctetSequence() const
     279{
     280    String keyBase64URL;
     281    if (!getStringFromJSON(m_exec, m_json.get(), "k", keyBase64URL)) {
     282        if (!m_exec->hadException())
     283            throwTypeError(m_exec, "Secret key data is not present is JWK");
     284        return nullptr;
     285    }
     286
     287    Vector<char> octetSequence;
     288    if (!base64URLDecode(keyBase64URL, octetSequence)) {
     289        throwTypeError(m_exec, "Cannot decode base64url key data in JWK");
     290        return nullptr;
     291    }
     292
     293    if (!keySizeIsValid(octetSequence.size() * 8)) {
     294        throwTypeError(m_exec, "Key size is not valid for " + m_jwkAlgorithmName);
     295        return nullptr;
     296    }
     297
     298    return CryptoKeyDataOctetSequence::create(octetSequence);
     299}
     300
     301std::unique_ptr<CryptoKeyData> JSCryptoKeySerializationJWK::keyDataRSAComponents() const
     302{
     303    Vector<char> modulus;
     304    Vector<char> exponent;
     305    Vector<char> privateExponent;
     306
     307    if (!getBigIntegerVectorFromJSON(m_exec, m_json.get(), "n", modulus)) {
     308        if (!m_exec->hadException())
     309            throwTypeError(m_exec, "Required JWK \"n\" member is missing");
     310        return nullptr;
     311    }
     312
     313    if (!getBigIntegerVectorFromJSON(m_exec, m_json.get(), "e", exponent)) {
     314        if (!m_exec->hadException())
     315            throwTypeError(m_exec, "Required JWK \"e\" member is missing");
     316        return nullptr;
     317    }
     318
     319    if (!getBigIntegerVectorFromJSON(m_exec, m_json.get(), "d", modulus)) {
     320        if (m_exec->hadException())
     321            return nullptr;
     322        return CryptoKeyDataRSAComponents::createPublic(modulus, exponent);
     323    }
     324
     325    CryptoKeyDataRSAComponents::PrimeInfo firstPrimeInfo;
     326    CryptoKeyDataRSAComponents::PrimeInfo secondPrimeInfo;
     327    Vector<CryptoKeyDataRSAComponents::PrimeInfo> otherPrimeInfos;
     328    if (!getBigIntegerVectorFromJSON(m_exec, m_json.get(), "p", firstPrimeInfo.primeFactor)) {
     329        if (m_exec->hadException())
     330            return nullptr;
     331        return CryptoKeyDataRSAComponents::createPrivate(modulus, exponent, privateExponent);
     332    }
     333
     334    if (!getBigIntegerVectorFromJSON(m_exec, m_json.get(), "dp", firstPrimeInfo.factorCRTExponent)) {
     335        if (m_exec->hadException())
     336            return nullptr;
     337        return CryptoKeyDataRSAComponents::createPrivate(modulus, exponent, privateExponent);
     338    }
     339
     340    if (!getBigIntegerVectorFromJSON(m_exec, m_json.get(), "q", secondPrimeInfo.primeFactor)) {
     341        if (m_exec->hadException())
     342            return nullptr;
     343        return CryptoKeyDataRSAComponents::createPrivate(modulus, exponent, privateExponent);
     344    }
     345
     346    if (!getBigIntegerVectorFromJSON(m_exec, m_json.get(), "dq", secondPrimeInfo.factorCRTExponent)) {
     347        if (m_exec->hadException())
     348            return nullptr;
     349        return CryptoKeyDataRSAComponents::createPrivate(modulus, exponent, privateExponent);
     350    }
     351
     352    if (!getBigIntegerVectorFromJSON(m_exec, m_json.get(), "qi", secondPrimeInfo.factorCRTCoefficient)) {
     353        if (m_exec->hadException())
     354            return nullptr;
     355        return CryptoKeyDataRSAComponents::createPrivate(modulus, exponent, privateExponent);
     356    }
     357
     358    JSArray* otherPrimeInfoJSArray;
     359    if (!getJSArrayFromJSON(m_exec, m_json.get(), "oth", otherPrimeInfoJSArray)) {
     360        if (m_exec->hadException())
     361            return nullptr;
     362        return CryptoKeyDataRSAComponents::createPrivateWithAdditionalData(modulus, exponent, privateExponent, firstPrimeInfo, secondPrimeInfo, otherPrimeInfos);
     363    }
     364
     365    for (size_t i = 0; i < otherPrimeInfoJSArray->length(); ++i) {
     366        CryptoKeyDataRSAComponents::PrimeInfo info;
     367        JSValue element = otherPrimeInfoJSArray->getIndex(m_exec, i);
     368        if (m_exec->hadException())
     369            return nullptr;
     370        if (!element.isObject()) {
     371            throwTypeError(m_exec, "JWK \"oth\" array member is not an object");
     372            return nullptr;
     373        }
     374        if (!getBigIntegerVectorFromJSON(m_exec, asObject(element), "r", info.primeFactor)) {
     375            if (!m_exec->hadException())
     376                throwTypeError(m_exec, "Cannot get prime factor for a prime in \"oth\" dictionary");
     377            return nullptr;
     378        }
     379        if (!getBigIntegerVectorFromJSON(m_exec, asObject(element), "d", info.factorCRTExponent)) {
     380            if (!m_exec->hadException())
     381                throwTypeError(m_exec, "Cannot get factor CRT exponent for a prime in \"oth\" dictionary");
     382            return nullptr;
     383        }
     384        if (!getBigIntegerVectorFromJSON(m_exec, asObject(element), "t", info.factorCRTCoefficient)) {
     385            if (!m_exec->hadException())
     386                throwTypeError(m_exec, "Cannot get factor CRT coefficient for a prime in \"oth\" dictionary");
     387            return nullptr;
     388        }
     389        otherPrimeInfos.append(info);
     390    }
     391
     392    return CryptoKeyDataRSAComponents::createPrivateWithAdditionalData(modulus, exponent, privateExponent, firstPrimeInfo, secondPrimeInfo, otherPrimeInfos);
     393}
     394
    210395std::unique_ptr<CryptoKeyData> JSCryptoKeySerializationJWK::keyData() const
    211396{
     
    217402    }
    218403
    219     if (jwkKeyType != "oct") {
    220         throwTypeError(m_exec, "Unsupported JWK key type " + jwkKeyType);
    221         return nullptr;
    222     }
    223 
    224     String keyBase64URL;
    225     if (!getStringFromJSON(m_exec, m_json.get(), "k", keyBase64URL)) {
    226         if (!m_exec->hadException())
    227             throwTypeError(m_exec, "Secret key data is not present is JWK");
    228         return nullptr;
    229     }
    230 
    231     Vector<char> octetSequence;
    232     if (!base64URLDecode(keyBase64URL, octetSequence)) {
    233         throwTypeError(m_exec, "Cannot decode base64url key data in JWK");
    234         return nullptr;
    235     }
    236 
    237     if (!keySizeIsValid(octetSequence.size() * 8)) {
    238         throwTypeError(m_exec, "Key size is not valid for " + m_jwkAlgorithmName);
    239         return nullptr;
    240     }
    241 
    242     return CryptoKeyDataOctetSequence::create(octetSequence);
     404    if (jwkKeyType == "oct")
     405        return keyDataOctetSequence();
     406
     407    if (jwkKeyType == "RSA")
     408        return keyDataRSAComponents();
     409
     410    throwTypeError(m_exec, "Unsupported JWK key type " + jwkKeyType);
     411    return nullptr;
    243412}
    244413
  • trunk/Source/WebCore/bindings/js/JSCryptoKeySerializationJWK.h

    r159167 r159180  
    6464
    6565    bool keySizeIsValid(size_t sizeInBits) const;
     66    std::unique_ptr<CryptoKeyData> keyDataOctetSequence() const;
     67    std::unique_ptr<CryptoKeyData> keyDataRSAComponents() const;
    6668
    6769    JSC::ExecState* m_exec;
  • trunk/Source/WebCore/crypto/CryptoAlgorithmDescriptionBuilder.h

    r159167 r159180  
    2929#include <wtf/Forward.h>
    3030#include <wtf/Noncopyable.h>
     31#include <wtf/Vector.h>
    3132
    3233#if ENABLE(SUBTLE_CRYPTO)
     
    4445    virtual void add(const char*, unsigned) = 0;
    4546    virtual void add(const char*, const String&) = 0;
     47    virtual void add(const char*, const Vector<uint8_t>&) = 0;
    4648    virtual void add(const char*, const CryptoAlgorithmDescriptionBuilder&) = 0;
    4749};
  • trunk/Source/WebCore/crypto/CryptoAlgorithmRSASSA_PKCS1_v1_5Mac.cpp

    r159179 r159180  
    2424 */
    2525
    26 #ifndef CryptoKeyData_h
    27 #define CryptoKeyData_h
    28 
    29 #include <wtf/Noncopyable.h>
     26#include "config.h"
     27#include "CryptoAlgorithmRSASSA_PKCS1_v1_5.h"
    3028
    3129#if ENABLE(SUBTLE_CRYPTO)
    3230
     31#include "ExceptionCode.h"
     32
    3333namespace WebCore {
    3434
    35 class CryptoKeyData {
    36 WTF_MAKE_NONCOPYABLE(CryptoKeyData);
    37 public:
    38     ENUM_CLASS(Format) {
    39         OctetSequence
    40     };
     35void CryptoAlgorithmRSASSA_PKCS1_v1_5::sign(const CryptoAlgorithmParameters&, const CryptoKey&, const Vector<CryptoOperationData>&, std::unique_ptr<PromiseWrapper>, ExceptionCode& ec)
     36{
     37    ec = NOT_SUPPORTED_ERR;
     38}
    4139
    42     CryptoKeyData(Format format)
    43         : m_format(format)
    44     {
    45     }
    46     virtual ~CryptoKeyData() { }
    47 
    48     Format format() const { return m_format; }
    49 
    50 private:
    51     Format m_format;
    52 };
     40void CryptoAlgorithmRSASSA_PKCS1_v1_5::verify(const CryptoAlgorithmParameters&, const CryptoKey&, const CryptoOperationData& /*signature*/, const Vector<CryptoOperationData>& /*data*/, std::unique_ptr<PromiseWrapper>, ExceptionCode& ec)
     41{
     42    ec = NOT_SUPPORTED_ERR;
     43}
    5344
    5445} // namespace WebCore
    5546
    5647#endif // ENABLE(SUBTLE_CRYPTO)
    57 #endif // CryptoKeyData_h
  • trunk/Source/WebCore/crypto/CryptoKey.h

    r159167 r159180  
    4242ENUM_CLASS(CryptoKeyClass) {
    4343    HMAC,
    44     AES
     44    AES,
     45    RSA
    4546};
    4647
  • trunk/Source/WebCore/crypto/CryptoKeyData.h

    r159167 r159180  
    3737public:
    3838    ENUM_CLASS(Format) {
    39         OctetSequence
     39        OctetSequence,
     40        RSAComponents
    4041    };
    4142
  • trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmAES_CBC.cpp

    r159167 r159180  
    7676        return;
    7777    }
    78     const CryptoKeyDataOctetSequence& keyDataOctetSequence = asCryptoKeyDataOctetSequence(keyData);
     78    const CryptoKeyDataOctetSequence& keyDataOctetSequence = toCryptoKeyDataOctetSequence(keyData);
    7979    RefPtr<CryptoKeyAES> result = CryptoKeyAES::create(CryptoAlgorithmIdentifier::AES_CBC, keyDataOctetSequence.octetSequence(), extractable, usage);
    8080    promise->fulfill(result.release());
  • trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmHMAC.cpp

    r159167 r159180  
    7777        return;
    7878    }
    79     const CryptoKeyDataOctetSequence& keyDataOctetSequence = asCryptoKeyDataOctetSequence(keyData);
     79    const CryptoKeyDataOctetSequence& keyDataOctetSequence = toCryptoKeyDataOctetSequence(keyData);
    8080
    8181    const CryptoAlgorithmHmacParams& hmacParameters = static_cast<const CryptoAlgorithmHmacParams&>(parameters);
  • trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmRSASSA_PKCS1_v1_5.h

    r159179 r159180  
    2424 */
    2525
    26 #ifndef JSCryptoAlgorithmBuilder_h
    27 #define JSCryptoAlgorithmBuilder_h
     26#ifndef CryptoAlgorithmRSASSA_PKCS1_v1_5_h
     27#define CryptoAlgorithmRSASSA_PKCS1_v1_5_h
    2828
    29 #include "CryptoAlgorithmDescriptionBuilder.h"
     29#include "CryptoAlgorithm.h"
    3030
    3131#if ENABLE(SUBTLE_CRYPTO)
    3232
    33 namespace JSC {
    34 class ExecState;
    35 class JSObject;
     33namespace WebCore {
     34
     35class CryptoAlgorithmRSASSA_PKCS1_v1_5 FINAL : public CryptoAlgorithm {
     36public:
     37    static const char* const s_name;
     38    static const CryptoAlgorithmIdentifier s_identifier = CryptoAlgorithmIdentifier::RSASSA_PKCS1_v1_5;
     39
     40    static std::unique_ptr<CryptoAlgorithm> create();
     41
     42    virtual CryptoAlgorithmIdentifier identifier() const OVERRIDE;
     43
     44    virtual void sign(const CryptoAlgorithmParameters&, const CryptoKey&, const Vector<CryptoOperationData>&, std::unique_ptr<PromiseWrapper>, ExceptionCode&) OVERRIDE;
     45    virtual void verify(const CryptoAlgorithmParameters&, const CryptoKey&, const CryptoOperationData& signature, const Vector<CryptoOperationData>& data, std::unique_ptr<PromiseWrapper>, ExceptionCode&) OVERRIDE;
     46    virtual void generateKey(const CryptoAlgorithmParameters&, bool extractable, CryptoKeyUsage, std::unique_ptr<PromiseWrapper>, ExceptionCode&) OVERRIDE;
     47    virtual void importKey(const CryptoAlgorithmParameters&, const CryptoKeyData&, bool extractable, CryptoKeyUsage, std::unique_ptr<PromiseWrapper>, ExceptionCode&) OVERRIDE;
     48
     49private:
     50    CryptoAlgorithmRSASSA_PKCS1_v1_5();
     51    virtual ~CryptoAlgorithmRSASSA_PKCS1_v1_5();
     52};
     53
    3654}
    3755
    38 namespace WebCore {
    39 
    40 class JSCryptoAlgorithmBuilder FINAL : public CryptoAlgorithmDescriptionBuilder {
    41 public:
    42     JSCryptoAlgorithmBuilder(JSC::ExecState*);
    43     virtual ~JSCryptoAlgorithmBuilder();
    44 
    45     JSC::JSObject* result() const { return m_dictionary; }
    46 
    47     virtual std::unique_ptr<CryptoAlgorithmDescriptionBuilder> createEmptyClone() const OVERRIDE;
    48 
    49     virtual void add(const char*, unsigned) OVERRIDE;
    50     virtual void add(const char*, const String&) OVERRIDE;
    51     virtual void add(const char*, const CryptoAlgorithmDescriptionBuilder&) OVERRIDE;
    52 
    53 private:
    54     JSC::ExecState* m_exec;
    55     JSC::JSObject* m_dictionary;
    56 };
    57 
    58 } // namespace WebCore
    59 
    6056#endif // ENABLE(SUBTLE_CRYPTO)
    61 #endif // JSCryptoAlgorithmBuilder_h
     57#endif // CryptoAlgorithmRSASSA_PKCS1_v1_5_h
  • trunk/Source/WebCore/crypto/keys/CryptoKeyAES.h

    r159167 r159180  
    5757};
    5858
    59 inline const CryptoKeyAES* asCryptoKeyAES(const CryptoKey& key)
     59inline bool isCryptoKeyAES(const CryptoKey& key)
    6060{
    61     if (key.keyClass() != CryptoKeyClass::AES)
    62         return nullptr;
    63     return static_cast<const CryptoKeyAES*>(&key);
     61    return key.keyClass() == CryptoKeyClass::AES;
    6462}
    6563
    66 inline CryptoKeyAES* asCryptoKeyAES(CryptoKey& key)
     64inline const CryptoKeyAES& toCryptoKeyAES(const CryptoKey& key)
    6765{
    68     if (key.keyClass() != CryptoKeyClass::AES)
    69         return nullptr;
    70     return static_cast<CryptoKeyAES*>(&key);
     66    ASSERT_WITH_SECURITY_IMPLICATION(isCryptoKeyAES(key));
     67    return static_cast<const CryptoKeyAES&>(key);
     68}
     69
     70inline CryptoKeyAES& toCryptoKeyAES(CryptoKey& key)
     71{
     72    ASSERT_WITH_SECURITY_IMPLICATION(isCryptoKeyAES(key));
     73    return static_cast<CryptoKeyAES&>(key);
    7174}
    7275
  • trunk/Source/WebCore/crypto/keys/CryptoKeyDataOctetSequence.h

    r159167 r159180  
    5050};
    5151
    52 inline const CryptoKeyDataOctetSequence& asCryptoKeyDataOctetSequence(const CryptoKeyData& data)
     52inline const CryptoKeyDataOctetSequence& toCryptoKeyDataOctetSequence(const CryptoKeyData& data)
    5353{
    5454    ASSERT(data.format() == CryptoKeyData::Format::OctetSequence);
  • trunk/Source/WebCore/crypto/keys/CryptoKeyDataRSAComponents.cpp

    r159179 r159180  
    2525
    2626#include "config.h"
    27 #include "JSCryptoAlgorithmBuilder.h"
     27#include "CryptoKeyDataRSAComponents.h"
    2828
    2929#if ENABLE(SUBTLE_CRYPTO)
    3030
    31 #include <runtime/ObjectConstructor.h>
    32 #include <runtime/Operations.h>
    33 
    34 using namespace JSC;
    35 
    3631namespace WebCore {
    3732
    38 JSCryptoAlgorithmBuilder::JSCryptoAlgorithmBuilder(ExecState* exec)
    39     : m_exec(exec)
    40     , m_dictionary(constructEmptyObject(exec))
     33CryptoKeyDataRSAComponents::CryptoKeyDataRSAComponents(const Vector<char>& modulus, const Vector<char>& exponent)
     34    : CryptoKeyData(CryptoKeyData::Format::RSAComponents)
     35    , m_type(Type::Public)
     36    , m_modulus(modulus)
     37    , m_exponent(exponent)
    4138{
    4239}
    4340
    44 JSCryptoAlgorithmBuilder::~JSCryptoAlgorithmBuilder()
     41CryptoKeyDataRSAComponents::CryptoKeyDataRSAComponents(const Vector<char>& modulus, const Vector<char>& exponent, const Vector<char>& privateExponent)
     42    : CryptoKeyData(CryptoKeyData::Format::RSAComponents)
     43    , m_type(Type::Private)
     44    , m_modulus(modulus)
     45    , m_exponent(exponent)
     46    , m_privateExponent(privateExponent)
     47    , m_hasAdditionalPrivateKeyParameters(false)
    4548{
    4649}
    4750
    48 std::unique_ptr<CryptoAlgorithmDescriptionBuilder> JSCryptoAlgorithmBuilder::createEmptyClone() const
     51CryptoKeyDataRSAComponents::CryptoKeyDataRSAComponents(const Vector<char>& modulus, const Vector<char>& exponent, const Vector<char>& privateExponent, const PrimeInfo& firstPrimeInfo, const PrimeInfo& secondPrimeInfo, const Vector<PrimeInfo>& otherPrimeInfos)
     52    : CryptoKeyData(CryptoKeyData::Format::RSAComponents)
     53    , m_type(Type::Private)
     54    , m_modulus(modulus)
     55    , m_exponent(exponent)
     56    , m_privateExponent(privateExponent)
     57    , m_hasAdditionalPrivateKeyParameters(true)
     58    , m_firstPrimeInfo(firstPrimeInfo)
     59    , m_secondPrimeInfo(secondPrimeInfo)
     60    , m_otherPrimeInfos(otherPrimeInfos)
    4961{
    50     return std::make_unique<JSCryptoAlgorithmBuilder>(m_exec);
    5162}
    5263
    53 void JSCryptoAlgorithmBuilder::add(const char* key, unsigned value)
     64CryptoKeyDataRSAComponents::~CryptoKeyDataRSAComponents()
    5465{
    55     VM& vm = m_exec->vm();
    56     Identifier identifier(&vm, key);
    57     m_dictionary->putDirect(vm, identifier, jsNumber(value));
    58 }
    59 
    60 void JSCryptoAlgorithmBuilder::add(const char* key, const String& value)
    61 {
    62     VM& vm = m_exec->vm();
    63     Identifier identifier(&vm, key);
    64     m_dictionary->putDirect(vm, identifier, jsString(m_exec, value));
    65 }
    66 
    67 void JSCryptoAlgorithmBuilder::add(const char* key, const CryptoAlgorithmDescriptionBuilder& nestedBuilder)
    68 {
    69     VM& vm = m_exec->vm();
    70     Identifier identifier(&vm, key);
    71     const JSCryptoAlgorithmBuilder& jsBuilder = static_cast<const JSCryptoAlgorithmBuilder&>(nestedBuilder);
    72     m_dictionary->putDirect(vm, identifier, jsBuilder.result());
    7366}
    7467
  • trunk/Source/WebCore/crypto/keys/CryptoKeyHMAC.h

    r159167 r159180  
    5858};
    5959
    60 inline const CryptoKeyHMAC* asCryptoKeyHMAC(const CryptoKey& key)
     60inline bool isCryptoKeyHMAC(const CryptoKey& key)
    6161{
    62     if (key.keyClass() != CryptoKeyClass::HMAC)
    63         return nullptr;
    64     return static_cast<const CryptoKeyHMAC*>(&key);
     62    return key.keyClass() == CryptoKeyClass::HMAC;
    6563}
    6664
    67 inline CryptoKeyHMAC* asCryptoKeyHMAC(CryptoKey& key)
     65inline const CryptoKeyHMAC& toCryptoKeyHMAC(const CryptoKey& key)
    6866{
    69     if (key.keyClass() != CryptoKeyClass::HMAC)
    70         return nullptr;
    71     return static_cast<CryptoKeyHMAC*>(&key);
     67    ASSERT_WITH_SECURITY_IMPLICATION(isCryptoKeyHMAC(key));
     68    return static_cast<const CryptoKeyHMAC&>(key);
     69}
     70
     71inline CryptoKeyHMAC& toCryptoKeyHMAC(CryptoKey& key)
     72{
     73    ASSERT_WITH_SECURITY_IMPLICATION(isCryptoKeyHMAC(key));
     74    return static_cast<CryptoKeyHMAC&>(key);
    7275}
    7376
  • trunk/Source/WebCore/crypto/keys/CryptoKeyRSA.h

    r159179 r159180  
    2424 */
    2525
    26 #ifndef CryptoKeyHMAC_h
    27 #define CryptoKeyHMAC_h
     26#ifndef CryptoKeyRSA_h
     27#define CryptoKeyRSA_h
    2828
    2929#include "CryptoKey.h"
    30 #include <wtf/Vector.h>
    3130
    3231#if ENABLE(SUBTLE_CRYPTO)
    3332
     33#if PLATFORM(MAC) || PLATFORM(IOS)
     34typedef struct _CCRSACryptor *CCRSACryptorRef;
     35typedef CCRSACryptorRef PlatformRSAKey;
     36#endif
     37
    3438namespace WebCore {
    3539
    36 class CryptoKeyHMAC FINAL : public CryptoKey {
     40class CryptoKeyDataRSAComponents;
     41class CryptoKeyPair;
     42class PromiseWrapper;
     43
     44class CryptoKeyRSA FINAL : public CryptoKey {
    3745public:
    38     static PassRefPtr<CryptoKeyHMAC> create(const Vector<char>& key, CryptoAlgorithmIdentifier hash, bool extractable, CryptoKeyUsage usage)
     46    static PassRefPtr<CryptoKeyRSA> create(CryptoAlgorithmIdentifier identifier, CryptoKeyType type, PlatformRSAKey platformKey, bool extractable, CryptoKeyUsage usage)
    3947    {
    40         return adoptRef(new CryptoKeyHMAC(key, hash, extractable, usage));
     48        return adoptRef(new CryptoKeyRSA(identifier, type, platformKey, extractable, usage));
    4149    }
    42     virtual ~CryptoKeyHMAC();
     50    static PassRefPtr<CryptoKeyRSA> create(CryptoAlgorithmIdentifier, const CryptoKeyDataRSAComponents&, bool extractable, CryptoKeyUsage);
     51    virtual ~CryptoKeyRSA();
    4352
    44     // If lengthBytes is 0, a recommended length is used, which is the size of the associated hash function's block size.
    45     static PassRefPtr<CryptoKeyHMAC> generate(size_t lengthBytes, CryptoAlgorithmIdentifier hash, bool extractable, CryptoKeyUsage);
     53    void restrictToHash(CryptoAlgorithmIdentifier);
    4654
    47     virtual CryptoKeyClass keyClass() const OVERRIDE { return CryptoKeyClass::HMAC; }
     55    static void generatePair(CryptoAlgorithmIdentifier, unsigned modulusLength, const Vector<char>& publicExponent, bool extractable, CryptoKeyUsage, std::unique_ptr<PromiseWrapper>);
    4856
    49     const Vector<char>& key() const { return m_key; }
     57    virtual CryptoKeyClass keyClass() const OVERRIDE { return CryptoKeyClass::RSA; }
     58
     59    PlatformRSAKey platformKey() const { return m_platformKey; }
    5060
    5161    virtual void buildAlgorithmDescription(CryptoAlgorithmDescriptionBuilder&) const OVERRIDE;
    5262
    5363private:
    54     CryptoKeyHMAC(const Vector<char>& key, CryptoAlgorithmIdentifier hash, bool extractable, CryptoKeyUsage);
     64    CryptoKeyRSA(CryptoAlgorithmIdentifier, CryptoKeyType, PlatformRSAKey, bool extractable, CryptoKeyUsage);
    5565
     66    PlatformRSAKey m_platformKey;
     67
     68    bool m_restrictedToSpecificHash;
    5669    CryptoAlgorithmIdentifier m_hash;
    57     Vector<char> m_key;
    5870};
    5971
    60 inline const CryptoKeyHMAC* asCryptoKeyHMAC(const CryptoKey& key)
     72inline bool isCryptoKeyRSA(const CryptoKey& key)
    6173{
    62     if (key.keyClass() != CryptoKeyClass::HMAC)
    63         return nullptr;
    64     return static_cast<const CryptoKeyHMAC*>(&key);
     74    return key.keyClass() == CryptoKeyClass::RSA;
    6575}
    6676
    67 inline CryptoKeyHMAC* asCryptoKeyHMAC(CryptoKey& key)
     77inline const CryptoKeyRSA& toCryptoKeyRSA(const CryptoKey& key)
    6878{
    69     if (key.keyClass() != CryptoKeyClass::HMAC)
    70         return nullptr;
    71     return static_cast<CryptoKeyHMAC*>(&key);
     79    ASSERT_WITH_SECURITY_IMPLICATION(isCryptoKeyRSA(key));
     80    return static_cast<const CryptoKeyRSA&>(key);
     81}
     82
     83inline CryptoKeyRSA& asCryptoKeyRSA(CryptoKey& key)
     84{
     85    ASSERT_WITH_SECURITY_IMPLICATION(isCryptoKeyRSA(key));
     86    return static_cast<CryptoKeyRSA&>(key);
    7287}
    7388
     
    7590
    7691#endif // ENABLE(SUBTLE_CRYPTO)
    77 #endif // CryptoKeyHMAC_h
     92#endif // CryptoKeyRSA_h
  • trunk/Source/WebCore/crypto/mac/CryptoAlgorithmAES_CBCMac.cpp

    r159167 r159180  
    9393{
    9494    const CryptoAlgorithmAesCbcParams& aesCBCParameters = static_cast<const CryptoAlgorithmAesCbcParams&>(parameters);
    95     const CryptoKeyAES* aesKey = asCryptoKeyAES(key);
    9695
    97     if (!aesKey) {
     96    if (!isCryptoKeyAES(key)) {
    9897        ec = NOT_SUPPORTED_ERR;
    9998        return;
    10099    }
     100    const CryptoKeyAES& aesKey = toCryptoKeyAES(key);
    101101
    102     transformAES_CBC(kCCEncrypt, aesCBCParameters, *aesKey, data, std::move(promise));
     102    transformAES_CBC(kCCEncrypt, aesCBCParameters, aesKey, data, std::move(promise));
    103103}
    104104
     
    106106{
    107107    const CryptoAlgorithmAesCbcParams& aesCBCParameters = static_cast<const CryptoAlgorithmAesCbcParams&>(parameters);
    108     const CryptoKeyAES* aesKey = asCryptoKeyAES(key);
    109108
    110     if (!aesKey) {
     109    if (!isCryptoKeyAES(key)) {
    111110        ec = NOT_SUPPORTED_ERR;
    112111        return;
    113112    }
     113    const CryptoKeyAES& aesKey = toCryptoKeyAES(key);
    114114
    115     transformAES_CBC(kCCDecrypt, aesCBCParameters, *aesKey, data, std::move(promise));
     115    transformAES_CBC(kCCDecrypt, aesCBCParameters, aesKey, data, std::move(promise));
    116116}
    117117
  • trunk/Source/WebCore/crypto/mac/CryptoAlgorithmHMACMac.cpp

    r159167 r159180  
    9696{
    9797    const CryptoAlgorithmHmacParams& hmacParameters = static_cast<const CryptoAlgorithmHmacParams&>(parameters);
    98     const CryptoKeyHMAC* hmacKey = asCryptoKeyHMAC(key);
     98
     99    if (!isCryptoKeyHMAC(key)) {
     100        ec = NOT_SUPPORTED_ERR;
     101        return;
     102    }
     103    const CryptoKeyHMAC& hmacKey = toCryptoKeyHMAC(key);
    99104
    100105    CCHmacAlgorithm algorithm;
     
    104109    }
    105110
    106     if (!hmacKey) {
    107         ec = NOT_SUPPORTED_ERR;
    108         return;
    109     }
    110 
    111     Vector<unsigned char> signature = calculateSignature(algorithm, hmacKey->key(), data);
     111    Vector<unsigned char> signature = calculateSignature(algorithm, hmacKey.key(), data);
    112112
    113113    promise->fulfill(signature);
     
    117117{
    118118    const CryptoAlgorithmHmacParams& hmacParameters = static_cast<const CryptoAlgorithmHmacParams&>(parameters);
    119     const CryptoKeyHMAC* hmacKey = asCryptoKeyHMAC(key);
     119
     120    if (!isCryptoKeyHMAC(key)) {
     121        ec = NOT_SUPPORTED_ERR;
     122        return;
     123    }
     124    const CryptoKeyHMAC& hmacKey = toCryptoKeyHMAC(key);
    120125
    121126    CCHmacAlgorithm algorithm;
     
    125130    }
    126131
    127     if (!hmacKey) {
    128         ec = NOT_SUPPORTED_ERR;
    129         return;
    130     }
    131 
    132     Vector<unsigned char> signature = calculateSignature(algorithm, hmacKey->key(), data);
     132    Vector<unsigned char> signature = calculateSignature(algorithm, hmacKey.key(), data);
    133133
    134134    bool result = signature.size() == expectedSignature.second && !memcmp(signature.data(), expectedSignature.first, signature.size());
  • trunk/Source/WebCore/crypto/mac/CryptoAlgorithmRegistryMac.cpp

    r159167 r159180  
    3131#include "CryptoAlgorithmAES_CBC.h"
    3232#include "CryptoAlgorithmHMAC.h"
     33#include "CryptoAlgorithmRSASSA_PKCS1_v1_5.h"
    3334#include "CryptoAlgorithmSHA1.h"
    3435#include "CryptoAlgorithmSHA224.h"
     
    4344    registerAlgorithm(CryptoAlgorithmAES_CBC::s_name, CryptoAlgorithmAES_CBC::s_identifier, CryptoAlgorithmAES_CBC::create);
    4445    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);
    4547    registerAlgorithm(CryptoAlgorithmSHA1::s_name, CryptoAlgorithmSHA1::s_identifier, CryptoAlgorithmSHA1::create);
    4648    registerAlgorithm(CryptoAlgorithmSHA224::s_name, CryptoAlgorithmSHA224::s_identifier, CryptoAlgorithmSHA224::create);
  • trunk/Source/WebCore/crypto/parameters/CryptoAlgorithmHmacKeyParams.h

    r159167 r159180  
    3636class CryptoAlgorithmHmacKeyParams FINAL : public CryptoAlgorithmParameters {
    3737public:
     38    CryptoAlgorithmHmacKeyParams()
     39        : hasLength(false)
     40    {
     41    }
     42
    3843    // The inner hash function to use.
    3944    CryptoAlgorithmIdentifier hash;
  • trunk/Source/WebCore/crypto/parameters/CryptoAlgorithmRsaKeyGenParams.h

    r159179 r159180  
    2424 */
    2525
    26 #ifndef CryptoKeyData_h
    27 #define CryptoKeyData_h
     26#ifndef CryptoAlgorithmRsaKeyGenParams_h
     27#define CryptoAlgorithmRsaKeyGenParams_h
    2828
    29 #include <wtf/Noncopyable.h>
     29#include "CryptoAlgorithmParameters.h"
    3030
    3131#if ENABLE(SUBTLE_CRYPTO)
     
    3333namespace WebCore {
    3434
    35 class CryptoKeyData {
    36 WTF_MAKE_NONCOPYABLE(CryptoKeyData);
     35class CryptoAlgorithmRsaKeyGenParams FINAL : public CryptoAlgorithmParameters {
    3736public:
    38     ENUM_CLASS(Format) {
    39         OctetSequence
    40     };
    41 
    42     CryptoKeyData(Format format)
    43         : m_format(format)
    44     {
    45     }
    46     virtual ~CryptoKeyData() { }
    47 
    48     Format format() const { return m_format; }
    49 
    50 private:
    51     Format m_format;
     37    // The length, in bits, of the RSA modulus.
     38    unsigned modulusLength;
     39    // The RSA public exponent, encoded as BigInteger.
     40    Vector<char> publicExponent;
    5241};
    5342
    54 } // namespace WebCore
     43}
    5544
    5645#endif // ENABLE(SUBTLE_CRYPTO)
    57 #endif // CryptoKeyData_h
     46#endif // CryptoAlgorithmRsaKeyGenParams_h
  • trunk/Source/WebCore/crypto/parameters/CryptoAlgorithmRsaSsaKeyParams.h

    r159179 r159180  
    2424 */
    2525
    26 #ifndef CryptoAlgorithmHmacKeyParams_h
    27 #define CryptoAlgorithmHmacKeyParams_h
     26#ifndef CryptoAlgorithmRsaSsaKeyParams_h
     27#define CryptoAlgorithmRsaSsaKey
    2828
    2929#include "CryptoAlgorithmIdentifier.h"
     
    3434namespace WebCore {
    3535
    36 class CryptoAlgorithmHmacKeyParams FINAL : public CryptoAlgorithmParameters {
     36// This parameters class is currently not specified in WebCrypto.
     37// It is necessary to support import from JWK, which treats hash function as part of algorithm
     38// identifier, so we need to remember it to compare with one passed to sign or verify functions.
     39class CryptoAlgorithmRsaSsaKeyParams FINAL : public CryptoAlgorithmParameters {
    3740public:
    38     // The inner hash function to use.
     41    CryptoAlgorithmRsaSsaKeyParams()
     42        : hasHash(false)
     43    {
     44    }
     45
     46    // The hash algorithm to use.
     47    bool hasHash;
    3948    CryptoAlgorithmIdentifier hash;
    40 
    41     // The length (in bytes) of the key to generate. If unspecified, the recommended length will be used,
    42     // which is the size of the associated hash function's block size.
    43     bool hasLength;
    44     unsigned length;
    4549};
    4650
     
    4852
    4953#endif // ENABLE(SUBTLE_CRYPTO)
    50 #endif // CryptoAlgorithmHmacKeyParams_h
     54#endif // CryptoAlgorithmRsaSsaParams_h
  • trunk/Source/WebCore/crypto/parameters/CryptoAlgorithmRsaSsaParams.h

    r159179 r159180  
    2424 */
    2525
    26 #ifndef CryptoAlgorithmHmacKeyParams_h
    27 #define CryptoAlgorithmHmacKeyParams_h
     26#ifndef CryptoAlgorithmRsaSsaParams_h
     27#define CryptoAlgorithmRsaSsaParams_h
    2828
    2929#include "CryptoAlgorithmIdentifier.h"
     
    3434namespace WebCore {
    3535
    36 class CryptoAlgorithmHmacKeyParams FINAL : public CryptoAlgorithmParameters {
     36class CryptoAlgorithmRsaSsaParams FINAL : public CryptoAlgorithmParameters {
    3737public:
    38     // The inner hash function to use.
     38    // The hash algorithm to use.
    3939    CryptoAlgorithmIdentifier hash;
    40 
    41     // The length (in bytes) of the key to generate. If unspecified, the recommended length will be used,
    42     // which is the size of the associated hash function's block size.
    43     bool hasLength;
    44     unsigned length;
    4540};
    4641
     
    4843
    4944#endif // ENABLE(SUBTLE_CRYPTO)
    50 #endif // CryptoAlgorithmHmacKeyParams_h
     45#endif // CryptoAlgorithmRsaSsaParams_h
Note: See TracChangeset for help on using the changeset viewer.