Changeset 159160 in webkit


Ignore:
Timestamp:
Nov 12, 2013 4:32:37 PM (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:
14 added
21 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r159157 r159160  
     12013-11-12  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  Roger Fong  <roger_fong@apple.com>
    220
  • trunk/LayoutTests/crypto/subtle/resources/common.js

    r158485 r159160  
    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

    r159159 r159160  
     12013-11-12  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  Bem Jones-Bey  <bjonesbe@adobe.com>
    2110
  • trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj

    r159159 r159160  
    55955595                E15A36D71104572000B7B639 /* XMLNSNames.h in Headers */ = {isa = PBXBuildFile; fileRef = E15A36D61104572000B7B639 /* XMLNSNames.h */; };
    55965596                E15A36D91104572700B7B639 /* XMLNSNames.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E15A36D81104572700B7B639 /* XMLNSNames.cpp */; };
     5597                E164FAA318315BF400DB4E61 /* CryptoKeyRSA.h in Headers */ = {isa = PBXBuildFile; fileRef = E164FAA218315BF400DB4E61 /* CryptoKeyRSA.h */; };
     5598                E164FAA518315E1A00DB4E61 /* CryptoKeyRSAMac.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E164FAA418315E1A00DB4E61 /* CryptoKeyRSAMac.cpp */; };
    55975599                E169803D1133542D00894115 /* CRuntimeObject.h in Headers */ = {isa = PBXBuildFile; fileRef = E169803C1133542D00894115 /* CRuntimeObject.h */; };
    55985600                E16980491133644700894115 /* CRuntimeObject.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E16980481133644700894115 /* CRuntimeObject.cpp */; };
     
    56695671                E1BA671A1742BEF400C20251 /* WebCoreTestShimLibrary.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E1BA67191742BEF400C20251 /* WebCoreTestShimLibrary.cpp */; };
    56705672                E1BB84AD1822CA7400525043 /* CryptoAlgorithmRegistryMac.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E1BB84AC1822CA7400525043 /* CryptoAlgorithmRegistryMac.cpp */; };
     5673                E1BD3319182D8DDD00C05D9F /* CryptoAlgorithmRSASSA_PKCS1_v1_5.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E1BD3317182D8DDD00C05D9F /* CryptoAlgorithmRSASSA_PKCS1_v1_5.cpp */; };
     5674                E1BD331A182D8DDD00C05D9F /* CryptoAlgorithmRSASSA_PKCS1_v1_5.h in Headers */ = {isa = PBXBuildFile; fileRef = E1BD3318182D8DDD00C05D9F /* CryptoAlgorithmRSASSA_PKCS1_v1_5.h */; };
     5675                E1BD331C182D8EE900C05D9F /* CryptoAlgorithmRsaSsaParams.h in Headers */ = {isa = PBXBuildFile; fileRef = E1BD331B182D8EE900C05D9F /* CryptoAlgorithmRsaSsaParams.h */; };
     5676                E1BD331E182D8F4200C05D9F /* CryptoAlgorithmRsaKeyGenParams.h in Headers */ = {isa = PBXBuildFile; fileRef = E1BD331D182D8F4200C05D9F /* CryptoAlgorithmRsaKeyGenParams.h */; };
    56715677                E1BE512D0CF6C512002EA959 /* XSLTUnicodeSort.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E1BE512B0CF6C512002EA959 /* XSLTUnicodeSort.cpp */; };
    56725678                E1BE512E0CF6C512002EA959 /* XSLTUnicodeSort.h in Headers */ = {isa = PBXBuildFile; fileRef = E1BE512C0CF6C512002EA959 /* XSLTUnicodeSort.h */; };
     5679                E1C266D818317AB4003F8B33 /* CryptoAlgorithmRSASSA_PKCS1_v1_5Mac.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E1C266D618317AB4003F8B33 /* CryptoAlgorithmRSASSA_PKCS1_v1_5Mac.cpp */; };
     5680                E1C266DB18319935003F8B33 /* CryptoAlgorithmRsaSsaKeyParams.h in Headers */ = {isa = PBXBuildFile; fileRef = E1C266DA18319935003F8B33 /* CryptoAlgorithmRsaSsaKeyParams.h */; };
     5681                E1C266DE18319F31003F8B33 /* CryptoKeyDataRSAComponents.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E1C266DC18319F31003F8B33 /* CryptoKeyDataRSAComponents.cpp */; };
     5682                E1C266DF18319F31003F8B33 /* CryptoKeyDataRSAComponents.h in Headers */ = {isa = PBXBuildFile; fileRef = E1C266DD18319F31003F8B33 /* CryptoKeyDataRSAComponents.h */; };
    56735683                E1C2F24A1533A2120083F974 /* SettingsMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = E1C2F2481533A2120083F974 /* SettingsMac.mm */; };
    56745684                E1C362EF0EAF2AA9007410BC /* JSWorkerLocation.h in Headers */ = {isa = PBXBuildFile; fileRef = E1C362ED0EAF2AA9007410BC /* JSWorkerLocation.h */; };
     
    1267612686                E15A36D61104572000B7B639 /* XMLNSNames.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = XMLNSNames.h; sourceTree = "<group>"; };
    1267712687                E15A36D81104572700B7B639 /* XMLNSNames.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = XMLNSNames.cpp; sourceTree = "<group>"; };
     12688                E164FAA218315BF400DB4E61 /* CryptoKeyRSA.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CryptoKeyRSA.h; path = keys/CryptoKeyRSA.h; sourceTree = "<group>"; };
     12689                E164FAA418315E1A00DB4E61 /* CryptoKeyRSAMac.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = CryptoKeyRSAMac.cpp; path = mac/CryptoKeyRSAMac.cpp; sourceTree = "<group>"; };
    1267812690                E169803C1133542D00894115 /* CRuntimeObject.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CRuntimeObject.h; sourceTree = "<group>"; };
    1267912691                E16980481133644700894115 /* CRuntimeObject.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CRuntimeObject.cpp; sourceTree = "<group>"; };
     
    1275912771                E1BA67191742BEF400C20251 /* WebCoreTestShimLibrary.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WebCoreTestShimLibrary.cpp; sourceTree = "<group>"; };
    1276012772                E1BB84AC1822CA7400525043 /* CryptoAlgorithmRegistryMac.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = CryptoAlgorithmRegistryMac.cpp; path = mac/CryptoAlgorithmRegistryMac.cpp; sourceTree = "<group>"; };
     12773                E1BD3317182D8DDD00C05D9F /* CryptoAlgorithmRSASSA_PKCS1_v1_5.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CryptoAlgorithmRSASSA_PKCS1_v1_5.cpp; sourceTree = "<group>"; };
     12774                E1BD3318182D8DDD00C05D9F /* CryptoAlgorithmRSASSA_PKCS1_v1_5.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CryptoAlgorithmRSASSA_PKCS1_v1_5.h; sourceTree = "<group>"; };
     12775                E1BD331B182D8EE900C05D9F /* CryptoAlgorithmRsaSsaParams.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CryptoAlgorithmRsaSsaParams.h; path = parameters/CryptoAlgorithmRsaSsaParams.h; sourceTree = "<group>"; };
     12776                E1BD331D182D8F4200C05D9F /* CryptoAlgorithmRsaKeyGenParams.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CryptoAlgorithmRsaKeyGenParams.h; path = parameters/CryptoAlgorithmRsaKeyGenParams.h; sourceTree = "<group>"; };
    1276112777                E1BE512B0CF6C512002EA959 /* XSLTUnicodeSort.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = XSLTUnicodeSort.cpp; sourceTree = "<group>"; };
    1276212778                E1BE512C0CF6C512002EA959 /* XSLTUnicodeSort.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = XSLTUnicodeSort.h; sourceTree = "<group>"; };
     12779                E1C266D618317AB4003F8B33 /* CryptoAlgorithmRSASSA_PKCS1_v1_5Mac.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CryptoAlgorithmRSASSA_PKCS1_v1_5Mac.cpp; sourceTree = "<group>"; };
     12780                E1C266DA18319935003F8B33 /* CryptoAlgorithmRsaSsaKeyParams.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CryptoAlgorithmRsaSsaKeyParams.h; path = parameters/CryptoAlgorithmRsaSsaKeyParams.h; sourceTree = "<group>"; };
     12781                E1C266DC18319F31003F8B33 /* CryptoKeyDataRSAComponents.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = CryptoKeyDataRSAComponents.cpp; path = keys/CryptoKeyDataRSAComponents.cpp; sourceTree = "<group>"; };
     12782                E1C266DD18319F31003F8B33 /* CryptoKeyDataRSAComponents.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CryptoKeyDataRSAComponents.h; path = keys/CryptoKeyDataRSAComponents.h; sourceTree = "<group>"; };
    1276312783                E1C2F2481533A2120083F974 /* SettingsMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = SettingsMac.mm; sourceTree = "<group>"; };
    1276412784                E1C362ED0EAF2AA9007410BC /* JSWorkerLocation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSWorkerLocation.h; sourceTree = "<group>"; };
     
    2032620346                                E1BB84AC1822CA7400525043 /* CryptoAlgorithmRegistryMac.cpp */,
    2032720347                                E125F82D1822CFFF00D84CD9 /* CryptoAlgorithmSHA1Mac.cpp */,
     20348                                E1C266D618317AB4003F8B33 /* CryptoAlgorithmRSASSA_PKCS1_v1_5Mac.cpp */,
    2032820349                                E19AC3DE1824DC6900349426 /* CryptoAlgorithmSHA224Mac.cpp */,
    2032920350                                E19AC3DF1824DC6900349426 /* CryptoAlgorithmSHA256Mac.cpp */,
     
    2033120352                                E19AC3E11824DC6900349426 /* CryptoAlgorithmSHA512Mac.cpp */,
    2033220353                                E19AC3F8182566F700349426 /* CryptoKeyMac.cpp */,
     20354                                E164FAA418315E1A00DB4E61 /* CryptoKeyRSAMac.cpp */,
    2033320355                        );
    2033420356                        name = mac;
     
    2034220364                                E125F82F1822F11B00D84CD9 /* CryptoAlgorithmHMAC.cpp */,
    2034320365                                E125F8301822F11B00D84CD9 /* CryptoAlgorithmHMAC.h */,
     20366                                E1BD3317182D8DDD00C05D9F /* CryptoAlgorithmRSASSA_PKCS1_v1_5.cpp */,
     20367                                E1BD3318182D8DDD00C05D9F /* CryptoAlgorithmRSASSA_PKCS1_v1_5.h */,
    2034420368                                E125F8291822CFEC00D84CD9 /* CryptoAlgorithmSHA1.cpp */,
    2034520369                                E125F82A1822CFEC00D84CD9 /* CryptoAlgorithmSHA1.h */,
     
    2036320387                                E125F861182C303A00D84CD9 /* CryptoKeyDataOctetSequence.cpp */,
    2036420388                                E125F862182C303A00D84CD9 /* CryptoKeyDataOctetSequence.h */,
     20389                                E1C266DC18319F31003F8B33 /* CryptoKeyDataRSAComponents.cpp */,
     20390                                E1C266DD18319F31003F8B33 /* CryptoKeyDataRSAComponents.h */,
    2036520391                                E125F8331822F18A00D84CD9 /* CryptoKeyHMAC.cpp */,
    2036620392                                E125F8341822F18A00D84CD9 /* CryptoKeyHMAC.h */,
     20393                                E164FAA218315BF400DB4E61 /* CryptoKeyRSA.h */,
    2036720394                                E125F857182C1AA600D84CD9 /* CryptoKeySerializationRaw.cpp */,
    2036820395                                E125F858182C1AA600D84CD9 /* CryptoKeySerializationRaw.h */,
     
    2037820405                                E19DA29B18189ADD00088BC8 /* CryptoAlgorithmHmacKeyParams.h */,
    2037920406                                E1C6571E1816E50300256CDD /* CryptoAlgorithmHmacParams.h */,
     20407                                E1BD331D182D8F4200C05D9F /* CryptoAlgorithmRsaKeyGenParams.h */,
     20408                                E1C266DA18319935003F8B33 /* CryptoAlgorithmRsaSsaKeyParams.h */,
     20409                                E1BD331B182D8EE900C05D9F /* CryptoAlgorithmRsaSsaParams.h */,
    2038020410                        );
    2038120411                        name = parameters;
     
    2210722137                                6550B6A0099DF0270090D781 /* CharacterData.h in Headers */,
    2210822138                                97B8FFD116AE7F960038388D /* CharacterReferenceParserInlines.h in Headers */,
     22139                                E164FAA318315BF400DB4E61 /* CryptoKeyRSA.h in Headers */,
    2210922140                                B2C3DA2A0D006C1D00EF6F26 /* CharsetData.h in Headers */,
    2211022141                                F55B3DB21251F12D003EF269 /* CheckboxInputType.h in Headers */,
     
    2230822339                                453EB637159C570400001BB7 /* DateTimeFormat.h in Headers */,
    2230922340                                0705850317FA10D0005F2BCB /* JSAllVideoCapabilities.h in Headers */,
     22341                                E1BD331A182D8DDD00C05D9F /* CryptoAlgorithmRSASSA_PKCS1_v1_5.h in Headers */,
    2231022342                                F55B3DB81251F12D003EF269 /* DateTimeInputType.h in Headers */,
    2231122343                                F55B3DBA1251F12D003EF269 /* DateTimeLocalInputType.h in Headers */,
     
    2286722899                                B275356D0B053814002CE64F /* FloatSize.h in Headers */,
    2286822900                                D72F6D7A153159A3001EE44E /* FlowThreadController.h in Headers */,
     22901                                E1BD331E182D8F4200C05D9F /* CryptoAlgorithmRsaKeyGenParams.h in Headers */,
    2286922902                                14993BE60B2F2B1C0050497F /* FocusController.h in Headers */,
    2287022903                                062287840B4DB322000C34DF /* FocusDirection.h in Headers */,
     
    2344223475                                070756D414239A4F00414161 /* JSHTMLTrackElement.h in Headers */,
    2344323476                                1A85B2110A1B258700D8C87C /* JSHTMLUListElement.h in Headers */,
     23477                                E1C266DF18319F31003F8B33 /* CryptoKeyDataRSAComponents.h in Headers */,
    2344423478                                6E4ABCD5138EA0B70071D291 /* JSHTMLUnknownElement.h in Headers */,
    2344523479                                078E092717D14D1C00420AA1 /* RTCSessionDescriptionCallback.h in Headers */,
     
    2367023704                                B2FA3DDF0AB75A6F000E5AC4 /* JSSVGPathSegMovetoRel.h in Headers */,
    2367123705                                0705852117FDC140005F2BCB /* MediaTrackConstraint.h in Headers */,
     23706                                E1C266DB18319935003F8B33 /* CryptoAlgorithmRsaSsaKeyParams.h in Headers */,
    2367223707                                CD8B5A46180DFF4E008B8E65 /* VideoTrackMediaSource.h in Headers */,
    2367323708                                B2FA3DE10AB75A6F000E5AC4 /* JSSVGPatternElement.h in Headers */,
     
    2398224017                                BC5EB5DD0E81B8DD00B25965 /* OutlineValue.h in Headers */,
    2398324018                                1A0D57370A5C77FE007EDD4C /* OverflowEvent.h in Headers */,
     24019                                E1BD331C182D8EE900C05D9F /* CryptoAlgorithmRsaSsaParams.h in Headers */,
    2398424020                                3774ABA50FA21EB400AD7DE9 /* OverlapTestRequestClient.h in Headers */,
    2398524021                                65A21468097A329100B9050A /* Page.h in Headers */,
     
    2575125787                                50987C26157D676D00BDA835 /* CustomFilterGlobalContext.cpp in Sources */,
    2575225788                                50D405F9147D31F300D30BB5 /* CustomFilterMesh.cpp in Sources */,
     25789                                E1C266DE18319F31003F8B33 /* CryptoKeyDataRSAComponents.cpp in Sources */,
    2575325790                                7E12E91015FA5D3A005E4126 /* CustomFilterMeshGenerator.cpp in Sources */,
    2575425791                                50CC0A3914C6F5B10017AB51 /* CustomFilterOperation.cpp in Sources */,
     
    2635226389                                BCCD74E50A4C8DDF005FDA6D /* HTMLViewSourceDocument.cpp in Sources */,
    2635326390                                977B3879122883E900B81FF8 /* HTMLViewSourceParser.cpp in Sources */,
     26391                                E1C266D818317AB4003F8B33 /* CryptoAlgorithmRSASSA_PKCS1_v1_5Mac.cpp in Sources */,
    2635426392                                0B8C56D40F28627F000502E1 /* HTTPHeaderMap.cpp in Sources */,
    2635526393                                514C76720CE923A1007EF3CD /* HTTPParsers.cpp in Sources */,
     
    2676726805                                65DF31FB09D1CC60000BE325 /* JSMutationEvent.cpp in Sources */,
    2676826806                                C6F0902C14327D4F00685849 /* JSMutationObserver.cpp in Sources */,
     26807                                E164FAA518315E1A00DB4E61 /* CryptoKeyRSAMac.cpp in Sources */,
    2676926808                                C6F0917F143A2BB900685849 /* JSMutationObserverCustom.cpp in Sources */,
    2677026809                                C6F08FC91431000D00685849 /* JSMutationRecord.cpp in Sources */,
     
    2705727096                                49C7B99B1042D2D30009D447 /* JSWebGLProgram.cpp in Sources */,
    2705827097                                49C7B99D1042D2D30009D447 /* JSWebGLRenderbuffer.cpp in Sources */,
     27098                                E1BD3319182D8DDD00C05D9F /* CryptoAlgorithmRSASSA_PKCS1_v1_5.cpp in Sources */,
    2705927099                                49EED1461051969400099FAB /* JSWebGLRenderingContext.cpp in Sources */,
    2706027100                                49EED14F1051971A00099FAB /* JSWebGLRenderingContextCustom.cpp in Sources */,
  • trunk/Source/WebCore/bindings/js/JSCryptoAlgorithmBuilder.cpp

    r158396 r159160  
    3131#include <runtime/ObjectConstructor.h>
    3232#include <runtime/Operations.h>
     33#include <runtime/TypedArrays.h>
    3334
    3435using namespace JSC;
     
    6566}
    6667
     68void JSCryptoAlgorithmBuilder::add(const char* key, const Vector<uint8_t>& buffer)
     69{
     70    VM& vm = m_exec->vm();
     71    Identifier identifier(&vm, key);
     72    RefPtr<Uint8Array> arrayView = Uint8Array::create(buffer.data(), buffer.size());
     73    m_dictionary->putDirect(vm, identifier, arrayView->wrap(m_exec, vm.dynamicGlobalObject));
     74}
     75
    6776void JSCryptoAlgorithmBuilder::add(const char* key, const CryptoAlgorithmDescriptionBuilder& nestedBuilder)
    6877{
  • trunk/Source/WebCore/bindings/js/JSCryptoAlgorithmBuilder.h

    r158361 r159160  
    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

    r158582 r159160  
    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

    r158943 r159160  
    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

    r158943 r159160  
    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

    r158361 r159160  
    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/CryptoKey.h

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

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

    r158943 r159160  
    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

    r158943 r159160  
    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/keys/CryptoKeyAES.h

    r158945 r159160  
    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

    r158943 r159160  
    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/CryptoKeyHMAC.h

    r158582 r159160  
    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/mac/CryptoAlgorithmAES_CBCMac.cpp

    r158582 r159160  
    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

    r158582 r159160  
    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

    r158494 r159160  
    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

    r158366 r159160  
    3636class CryptoAlgorithmHmacKeyParams FINAL : public CryptoAlgorithmParameters {
    3737public:
     38    CryptoAlgorithmHmacKeyParams()
     39        : hasLength(false)
     40    {
     41    }
     42
    3843    // The inner hash function to use.
    3944    CryptoAlgorithmIdentifier hash;
Note: See TracChangeset for help on using the changeset viewer.