Changeset 208918 in webkit


Ignore:
Timestamp:
Nov 18, 2016 8:38:59 PM (7 years ago)
Author:
jiewen_tan@apple.com
Message:

Update SubtleCrypto::decrypt to match the latest spec
https://bugs.webkit.org/show_bug.cgi?id=164739
<rdar://problem/29257848>

Reviewed by Brent Fulgham.

LayoutTests/imported/w3c:

  • WebCryptoAPI/encrypt_decrypt/test_aes_cbc-expected.txt:
  • WebCryptoAPI/idlharness-expected.txt:

Source/WebCore:

This patch does following few things:

  1. It updates the SubtleCrypto::decrypt method to match the latest spec: https://www.w3.org/TR/WebCryptoAPI/#SubtleCrypto-method-decrypt. It also refers to the latest Editor's Draft to a certain degree: https://w3c.github.io/webcrypto/Overview.html#SubtleCrypto-method-decrypt.
  2. It implements decrypt operations of the following algorithms: AES-CBC, RSAES-PKCS1-V1_5, and RSA-OAEP.

Tests: crypto/subtle/aes-cbc-decrypt-malformed-parameters.html

crypto/subtle/aes-cbc-generate-key-encrypt-decrypt.html
crypto/subtle/aes-cbc-import-key-decrypt.html
crypto/subtle/decrypt-malformed-parameters.html
crypto/subtle/rsa-oaep-decrypt-malformed-parameters.html
crypto/subtle/rsa-oaep-generate-key-encrypt-decrypt-label.html
crypto/subtle/rsa-oaep-generate-key-encrypt-decrypt.html
crypto/subtle/rsa-oaep-import-key-decrypt-label.html
crypto/subtle/rsa-oaep-import-key-decrypt.html
crypto/subtle/rsaes-pkcs1-v1_5-generate-key-encrypt-decrypt.html
crypto/subtle/rsaes-pkcs1-v1_5-import-key-decrypt.html
crypto/workers/subtle/aes-cbc-import-key-decrypt.html
crypto/workers/subtle/rsa-oaep-import-key-decrypt.html
crypto/workers/subtle/rsaes-pkcs1-v1_5-import-key-decrypt.html

  • bindings/js/JSSubtleCryptoCustom.cpp:

(WebCore::normalizeCryptoAlgorithmParameters):
(WebCore::toCryptoKey):
(WebCore::toVector):
(WebCore::jsSubtleCryptoFunctionEncryptPromise):
(WebCore::jsSubtleCryptoFunctionDecryptPromise):
(WebCore::jsSubtleCryptoFunctionExportKeyPromise):
(WebCore::JSSubtleCrypto::decrypt):

  • crypto/CryptoAlgorithm.cpp:

(WebCore::CryptoAlgorithm::decrypt):

  • crypto/CryptoAlgorithm.h:
  • crypto/SubtleCrypto.idl:
  • crypto/algorithms/CryptoAlgorithmAES_CBC.cpp:

(WebCore::CryptoAlgorithmAES_CBC::decrypt):

  • crypto/algorithms/CryptoAlgorithmAES_CBC.h:
  • crypto/algorithms/CryptoAlgorithmRSAES_PKCS1_v1_5.cpp:

(WebCore::CryptoAlgorithmRSAES_PKCS1_v1_5::decrypt):

  • crypto/algorithms/CryptoAlgorithmRSAES_PKCS1_v1_5.h:
  • crypto/algorithms/CryptoAlgorithmRSA_OAEP.cpp:

(WebCore::CryptoAlgorithmRSA_OAEP::decrypt):

  • crypto/algorithms/CryptoAlgorithmRSA_OAEP.h:
  • crypto/gnutls/CryptoAlgorithmAES_CBCGnuTLS.cpp:

(WebCore::CryptoAlgorithmAES_CBC::platformDecrypt):

  • crypto/gnutls/CryptoAlgorithmRSAES_PKCS1_v1_5GnuTLS.cpp:

(WebCore::CryptoAlgorithmRSAES_PKCS1_v1_5::platformDecrypt):

  • crypto/gnutls/CryptoAlgorithmRSA_OAEPGnuTLS.cpp:

(WebCore::CryptoAlgorithmRSA_OAEP::platformDecrypt):

  • crypto/mac/CryptoAlgorithmAES_CBCMac.cpp:

(WebCore::CryptoAlgorithmAES_CBC::platformDecrypt):

  • crypto/mac/CryptoAlgorithmRSAES_PKCS1_v1_5Mac.cpp:

(WebCore::decryptRSAES_PKCS1_v1_5):
(WebCore::CryptoAlgorithmRSAES_PKCS1_v1_5::platformDecrypt):

  • crypto/mac/CryptoAlgorithmRSA_OAEPMac.cpp:

(WebCore::decryptRSA_OAEP):
(WebCore::CryptoAlgorithmRSA_OAEP::platformDecrypt):

LayoutTests:

  • crypto/subtle/aes-cbc-decrypt-malformed-parameters-expected.txt: Added.
  • crypto/subtle/aes-cbc-decrypt-malformed-parameters.html: Added.
  • crypto/subtle/aes-cbc-generate-key-encrypt-decrypt-expected.txt: Added.
  • crypto/subtle/aes-cbc-generate-key-encrypt-decrypt.html: Added.
  • crypto/subtle/aes-cbc-import-key-decrypt-expected.txt: Added.
  • crypto/subtle/aes-cbc-import-key-decrypt.html: Added.
  • crypto/subtle/decrypt-malformed-parameters-expected.txt: Added.
  • crypto/subtle/decrypt-malformed-parameters.html: Added.
  • crypto/subtle/rsa-oaep-decrypt-malformed-parameters-expected.txt: Added.
  • crypto/subtle/rsa-oaep-decrypt-malformed-parameters.html: Added.
  • crypto/subtle/rsa-oaep-generate-key-encrypt-decrypt-expected.txt: Added.
  • crypto/subtle/rsa-oaep-generate-key-encrypt-decrypt-label-expected.txt: Added.
  • crypto/subtle/rsa-oaep-generate-key-encrypt-decrypt-label.html: Added.
  • crypto/subtle/rsa-oaep-generate-key-encrypt-decrypt.html: Added.
  • crypto/subtle/rsa-oaep-import-key-decrypt-expected.txt: Added.
  • crypto/subtle/rsa-oaep-import-key-decrypt-label-expected.txt: Added.
  • crypto/subtle/rsa-oaep-import-key-decrypt-label.html: Added.
  • crypto/subtle/rsa-oaep-import-key-decrypt.html: Added.
  • crypto/subtle/rsaes-pkcs1-v1_5-generate-key-encrypt-decrypt-expected.txt: Added.
  • crypto/subtle/rsaes-pkcs1-v1_5-generate-key-encrypt-decrypt.html: Added.
  • crypto/subtle/rsaes-pkcs1-v1_5-import-key-decrypt-expected.txt: Added.
  • crypto/subtle/rsaes-pkcs1-v1_5-import-key-decrypt.html: Added.
  • crypto/workers/subtle/aes-cbc-import-key-decrypt-expected.txt: Added.
  • crypto/workers/subtle/aes-cbc-import-key-decrypt.html: Added.
  • crypto/workers/subtle/resources/aes-cbc-import-key-decrypt.js: Added.
  • crypto/workers/subtle/resources/rsa-oaep-import-key-decrypt.js: Added.
  • crypto/workers/subtle/resources/rsaes-pkcs1-v1_5-import-key-decrypt.js: Added.
  • crypto/workers/subtle/rsa-oaep-import-key-decrypt-expected.txt: Added.
  • crypto/workers/subtle/rsa-oaep-import-key-decrypt.html: Added.
  • crypto/workers/subtle/rsaes-pkcs1-v1_5-import-key-decrypt-expected.txt: Added.
  • crypto/workers/subtle/rsaes-pkcs1-v1_5-import-key-decrypt.html: Added.
Location:
trunk
Files:
31 added
21 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r208917 r208918  
     12016-11-18  Jiewen Tan  <jiewen_tan@apple.com>
     2
     3        Update SubtleCrypto::decrypt to match the latest spec
     4        https://bugs.webkit.org/show_bug.cgi?id=164739
     5        <rdar://problem/29257848>
     6
     7        Reviewed by Brent Fulgham.
     8
     9        * crypto/subtle/aes-cbc-decrypt-malformed-parameters-expected.txt: Added.
     10        * crypto/subtle/aes-cbc-decrypt-malformed-parameters.html: Added.
     11        * crypto/subtle/aes-cbc-generate-key-encrypt-decrypt-expected.txt: Added.
     12        * crypto/subtle/aes-cbc-generate-key-encrypt-decrypt.html: Added.
     13        * crypto/subtle/aes-cbc-import-key-decrypt-expected.txt: Added.
     14        * crypto/subtle/aes-cbc-import-key-decrypt.html: Added.
     15        * crypto/subtle/decrypt-malformed-parameters-expected.txt: Added.
     16        * crypto/subtle/decrypt-malformed-parameters.html: Added.
     17        * crypto/subtle/rsa-oaep-decrypt-malformed-parameters-expected.txt: Added.
     18        * crypto/subtle/rsa-oaep-decrypt-malformed-parameters.html: Added.
     19        * crypto/subtle/rsa-oaep-generate-key-encrypt-decrypt-expected.txt: Added.
     20        * crypto/subtle/rsa-oaep-generate-key-encrypt-decrypt-label-expected.txt: Added.
     21        * crypto/subtle/rsa-oaep-generate-key-encrypt-decrypt-label.html: Added.
     22        * crypto/subtle/rsa-oaep-generate-key-encrypt-decrypt.html: Added.
     23        * crypto/subtle/rsa-oaep-import-key-decrypt-expected.txt: Added.
     24        * crypto/subtle/rsa-oaep-import-key-decrypt-label-expected.txt: Added.
     25        * crypto/subtle/rsa-oaep-import-key-decrypt-label.html: Added.
     26        * crypto/subtle/rsa-oaep-import-key-decrypt.html: Added.
     27        * crypto/subtle/rsaes-pkcs1-v1_5-generate-key-encrypt-decrypt-expected.txt: Added.
     28        * crypto/subtle/rsaes-pkcs1-v1_5-generate-key-encrypt-decrypt.html: Added.
     29        * crypto/subtle/rsaes-pkcs1-v1_5-import-key-decrypt-expected.txt: Added.
     30        * crypto/subtle/rsaes-pkcs1-v1_5-import-key-decrypt.html: Added.
     31        * crypto/workers/subtle/aes-cbc-import-key-decrypt-expected.txt: Added.
     32        * crypto/workers/subtle/aes-cbc-import-key-decrypt.html: Added.
     33        * crypto/workers/subtle/resources/aes-cbc-import-key-decrypt.js: Added.
     34        * crypto/workers/subtle/resources/rsa-oaep-import-key-decrypt.js: Added.
     35        * crypto/workers/subtle/resources/rsaes-pkcs1-v1_5-import-key-decrypt.js: Added.
     36        * crypto/workers/subtle/rsa-oaep-import-key-decrypt-expected.txt: Added.
     37        * crypto/workers/subtle/rsa-oaep-import-key-decrypt.html: Added.
     38        * crypto/workers/subtle/rsaes-pkcs1-v1_5-import-key-decrypt-expected.txt: Added.
     39        * crypto/workers/subtle/rsaes-pkcs1-v1_5-import-key-decrypt.html: Added.
     40
    1412016-11-18  Chris Dumez  <cdumez@apple.com>
    242
  • trunk/LayoutTests/imported/w3c/ChangeLog

    r208909 r208918  
     12016-11-18  Jiewen Tan  <jiewen_tan@apple.com>
     2
     3        Update SubtleCrypto::decrypt to match the latest spec
     4        https://bugs.webkit.org/show_bug.cgi?id=164739
     5        <rdar://problem/29257848>
     6
     7        Reviewed by Brent Fulgham.
     8
     9        * WebCryptoAPI/encrypt_decrypt/test_aes_cbc-expected.txt:
     10        * WebCryptoAPI/idlharness-expected.txt:
     11
    1122016-11-18  Alex Christensen  <achristensen@webkit.org>
    213
  • trunk/LayoutTests/imported/w3c/WebCryptoAPI/encrypt_decrypt/test_aes_cbc-expected.txt

    r208891 r208918  
    88PASS AES-CBC 192-bit key with altered plaintext
    99PASS AES-CBC 256-bit key with altered plaintext
    10 FAIL AES-CBC 128-bit key decryption subtle.decrypt is not a function. (In 'subtle.decrypt(vector.algorithm, vector.key, vector.result)', 'subtle.decrypt' is undefined)
    11 FAIL AES-CBC 192-bit key decryption subtle.decrypt is not a function. (In 'subtle.decrypt(vector.algorithm, vector.key, vector.result)', 'subtle.decrypt' is undefined)
    12 FAIL AES-CBC 256-bit key decryption subtle.decrypt is not a function. (In 'subtle.decrypt(vector.algorithm, vector.key, vector.result)', 'subtle.decrypt' is undefined)
    13 FAIL AES-CBC 128-bit key decryption with altered ciphertext subtle.decrypt is not a function. (In 'subtle.decrypt(vector.algorithm, vector.key, ciphertext)', 'subtle.decrypt' is undefined)
    14 FAIL AES-CBC 192-bit key decryption with altered ciphertext subtle.decrypt is not a function. (In 'subtle.decrypt(vector.algorithm, vector.key, ciphertext)', 'subtle.decrypt' is undefined)
    15 FAIL AES-CBC 256-bit key decryption with altered ciphertext subtle.decrypt is not a function. (In 'subtle.decrypt(vector.algorithm, vector.key, ciphertext)', 'subtle.decrypt' is undefined)
     10PASS AES-CBC 128-bit key decryption
     11PASS AES-CBC 192-bit key decryption
     12PASS AES-CBC 256-bit key decryption
     13PASS AES-CBC 128-bit key decryption with altered ciphertext
     14PASS AES-CBC 192-bit key decryption with altered ciphertext
     15PASS AES-CBC 256-bit key decryption with altered ciphertext
    1616PASS AES-CBC 128-bit key without encrypt usage
    1717PASS AES-CBC 192-bit key without encrypt usage
     
    2020FAIL AES-CBC 192-bit key with mismatched key and algorithm assert_equals: Mismatch should cause InvalidAccessError instead of The operation is not supported. expected "InvalidAccessError" but got "NotSupportedError"
    2121FAIL AES-CBC 256-bit key with mismatched key and algorithm assert_equals: Mismatch should cause InvalidAccessError instead of The operation is not supported. expected "InvalidAccessError" but got "NotSupportedError"
    22 FAIL AES-CBC 128-bit key without decrypt usage subtle.decrypt is not a function. (In 'subtle.decrypt(vector.algorithm, vector.key, vector.result)', 'subtle.decrypt' is undefined)
    23 FAIL AES-CBC 192-bit key without decrypt usage subtle.decrypt is not a function. (In 'subtle.decrypt(vector.algorithm, vector.key, vector.result)', 'subtle.decrypt' is undefined)
    24 FAIL AES-CBC 256-bit key without decrypt usage subtle.decrypt is not a function. (In 'subtle.decrypt(vector.algorithm, vector.key, vector.result)', 'subtle.decrypt' is undefined)
     22PASS AES-CBC 128-bit key without decrypt usage
     23PASS AES-CBC 192-bit key without decrypt usage
     24PASS AES-CBC 256-bit key without decrypt usage
    2525PASS AES-CBC 128-bit key, 64-bit IV
    2626PASS AES-CBC 128-bit key, 192-bit IV
     
    2929PASS AES-CBC 256-bit key, 64-bit IV
    3030PASS AES-CBC 256-bit key, 192-bit IV
    31 FAIL AES-CBC 128-bit key, 64-bit IV decryption subtle.decrypt is not a function. (In 'subtle.decrypt(vector.algorithm, vector.key, vector.result)', 'subtle.decrypt' is undefined)
    32 FAIL AES-CBC 128-bit key, 192-bit IV decryption subtle.decrypt is not a function. (In 'subtle.decrypt(vector.algorithm, vector.key, vector.result)', 'subtle.decrypt' is undefined)
    33 FAIL AES-CBC 192-bit key, 64-bit IV decryption subtle.decrypt is not a function. (In 'subtle.decrypt(vector.algorithm, vector.key, vector.result)', 'subtle.decrypt' is undefined)
    34 FAIL AES-CBC 192-bit key, 192-bit IV decryption subtle.decrypt is not a function. (In 'subtle.decrypt(vector.algorithm, vector.key, vector.result)', 'subtle.decrypt' is undefined)
    35 FAIL AES-CBC 256-bit key, 64-bit IV decryption subtle.decrypt is not a function. (In 'subtle.decrypt(vector.algorithm, vector.key, vector.result)', 'subtle.decrypt' is undefined)
    36 FAIL AES-CBC 256-bit key, 192-bit IV decryption subtle.decrypt is not a function. (In 'subtle.decrypt(vector.algorithm, vector.key, vector.result)', 'subtle.decrypt' is undefined)
    37 FAIL AES-CBC 128-bit key, zeroPadChar subtle.decrypt is not a function. (In 'subtle.decrypt(vector.algorithm, vector.key, vector.result)', 'subtle.decrypt' is undefined)
    38 FAIL AES-CBC 128-bit key, bigPadChar subtle.decrypt is not a function. (In 'subtle.decrypt(vector.algorithm, vector.key, vector.result)', 'subtle.decrypt' is undefined)
    39 FAIL AES-CBC 128-bit key, inconsistentPadChars subtle.decrypt is not a function. (In 'subtle.decrypt(vector.algorithm, vector.key, vector.result)', 'subtle.decrypt' is undefined)
    40 FAIL AES-CBC 192-bit key, zeroPadChar subtle.decrypt is not a function. (In 'subtle.decrypt(vector.algorithm, vector.key, vector.result)', 'subtle.decrypt' is undefined)
    41 FAIL AES-CBC 192-bit key, bigPadChar subtle.decrypt is not a function. (In 'subtle.decrypt(vector.algorithm, vector.key, vector.result)', 'subtle.decrypt' is undefined)
    42 FAIL AES-CBC 192-bit key, inconsistentPadChars subtle.decrypt is not a function. (In 'subtle.decrypt(vector.algorithm, vector.key, vector.result)', 'subtle.decrypt' is undefined)
    43 FAIL AES-CBC 256-bit key, zeroPadChar subtle.decrypt is not a function. (In 'subtle.decrypt(vector.algorithm, vector.key, vector.result)', 'subtle.decrypt' is undefined)
    44 FAIL AES-CBC 256-bit key, bigPadChar subtle.decrypt is not a function. (In 'subtle.decrypt(vector.algorithm, vector.key, vector.result)', 'subtle.decrypt' is undefined)
    45 FAIL AES-CBC 256-bit key, inconsistentPadChars subtle.decrypt is not a function. (In 'subtle.decrypt(vector.algorithm, vector.key, vector.result)', 'subtle.decrypt' is undefined)
     31PASS AES-CBC 128-bit key, 64-bit IV decryption
     32PASS AES-CBC 128-bit key, 192-bit IV decryption
     33PASS AES-CBC 192-bit key, 64-bit IV decryption
     34PASS AES-CBC 192-bit key, 192-bit IV decryption
     35PASS AES-CBC 256-bit key, 64-bit IV decryption
     36PASS AES-CBC 256-bit key, 192-bit IV decryption
     37FAIL AES-CBC 128-bit key, zeroPadChar assert_unreached: should have thrown exception for test AES-CBC 128-bit key, zeroPadChar Reached unreachable code
     38FAIL AES-CBC 128-bit key, bigPadChar assert_unreached: should have thrown exception for test AES-CBC 128-bit key, bigPadChar Reached unreachable code
     39FAIL AES-CBC 128-bit key, inconsistentPadChars assert_unreached: should have thrown exception for test AES-CBC 128-bit key, inconsistentPadChars Reached unreachable code
     40FAIL AES-CBC 192-bit key, zeroPadChar assert_unreached: should have thrown exception for test AES-CBC 192-bit key, zeroPadChar Reached unreachable code
     41FAIL AES-CBC 192-bit key, bigPadChar assert_unreached: should have thrown exception for test AES-CBC 192-bit key, bigPadChar Reached unreachable code
     42FAIL AES-CBC 192-bit key, inconsistentPadChars assert_unreached: should have thrown exception for test AES-CBC 192-bit key, inconsistentPadChars Reached unreachable code
     43FAIL AES-CBC 256-bit key, zeroPadChar assert_unreached: should have thrown exception for test AES-CBC 256-bit key, zeroPadChar Reached unreachable code
     44FAIL AES-CBC 256-bit key, bigPadChar assert_unreached: should have thrown exception for test AES-CBC 256-bit key, bigPadChar Reached unreachable code
     45FAIL AES-CBC 256-bit key, inconsistentPadChars assert_unreached: should have thrown exception for test AES-CBC 256-bit key, inconsistentPadChars Reached unreachable code
    4646
  • trunk/LayoutTests/imported/w3c/WebCryptoAPI/idlharness-expected.txt

    r208891 r208918  
    4646PASS SubtleCrypto interface: crypto.subtle must inherit property "encrypt" with the proper type (0)
    4747PASS SubtleCrypto interface: calling encrypt(AlgorithmIdentifier,CryptoKey,BufferSource) on crypto.subtle with too few arguments must throw TypeError
    48 FAIL SubtleCrypto interface: crypto.subtle must inherit property "decrypt" with the proper type (1) assert_inherits: property "decrypt" not found in prototype chain
    49 FAIL SubtleCrypto interface: calling decrypt(AlgorithmIdentifier,CryptoKey,BufferSource) on crypto.subtle with too few arguments must throw TypeError assert_inherits: property "decrypt" not found in prototype chain
     48PASS SubtleCrypto interface: crypto.subtle must inherit property "decrypt" with the proper type (1)
     49PASS SubtleCrypto interface: calling decrypt(AlgorithmIdentifier,CryptoKey,BufferSource) on crypto.subtle with too few arguments must throw TypeError
    5050FAIL SubtleCrypto interface: crypto.subtle must inherit property "sign" with the proper type (2) assert_inherits: property "sign" not found in prototype chain
    5151FAIL SubtleCrypto interface: calling sign(AlgorithmIdentifier,CryptoKey,BufferSource) on crypto.subtle with too few arguments must throw TypeError assert_inherits: property "sign" not found in prototype chain
  • trunk/Source/WebCore/ChangeLog

    r208917 r208918  
     12016-11-18  Jiewen Tan  <jiewen_tan@apple.com>
     2
     3        Update SubtleCrypto::decrypt to match the latest spec
     4        https://bugs.webkit.org/show_bug.cgi?id=164739
     5        <rdar://problem/29257848>
     6
     7        Reviewed by Brent Fulgham.
     8
     9        This patch does following few things:
     10        1. It updates the SubtleCrypto::decrypt method to match the latest spec:
     11           https://www.w3.org/TR/WebCryptoAPI/#SubtleCrypto-method-decrypt.
     12           It also refers to the latest Editor's Draft to a certain degree:
     13           https://w3c.github.io/webcrypto/Overview.html#SubtleCrypto-method-decrypt.
     14        2. It implements decrypt operations of the following algorithms: AES-CBC,
     15           RSAES-PKCS1-V1_5, and RSA-OAEP.
     16
     17        Tests: crypto/subtle/aes-cbc-decrypt-malformed-parameters.html
     18               crypto/subtle/aes-cbc-generate-key-encrypt-decrypt.html
     19               crypto/subtle/aes-cbc-import-key-decrypt.html
     20               crypto/subtle/decrypt-malformed-parameters.html
     21               crypto/subtle/rsa-oaep-decrypt-malformed-parameters.html
     22               crypto/subtle/rsa-oaep-generate-key-encrypt-decrypt-label.html
     23               crypto/subtle/rsa-oaep-generate-key-encrypt-decrypt.html
     24               crypto/subtle/rsa-oaep-import-key-decrypt-label.html
     25               crypto/subtle/rsa-oaep-import-key-decrypt.html
     26               crypto/subtle/rsaes-pkcs1-v1_5-generate-key-encrypt-decrypt.html
     27               crypto/subtle/rsaes-pkcs1-v1_5-import-key-decrypt.html
     28               crypto/workers/subtle/aes-cbc-import-key-decrypt.html
     29               crypto/workers/subtle/rsa-oaep-import-key-decrypt.html
     30               crypto/workers/subtle/rsaes-pkcs1-v1_5-import-key-decrypt.html
     31
     32        * bindings/js/JSSubtleCryptoCustom.cpp:
     33        (WebCore::normalizeCryptoAlgorithmParameters):
     34        (WebCore::toCryptoKey):
     35        (WebCore::toVector):
     36        (WebCore::jsSubtleCryptoFunctionEncryptPromise):
     37        (WebCore::jsSubtleCryptoFunctionDecryptPromise):
     38        (WebCore::jsSubtleCryptoFunctionExportKeyPromise):
     39        (WebCore::JSSubtleCrypto::decrypt):
     40        * crypto/CryptoAlgorithm.cpp:
     41        (WebCore::CryptoAlgorithm::decrypt):
     42        * crypto/CryptoAlgorithm.h:
     43        * crypto/SubtleCrypto.idl:
     44        * crypto/algorithms/CryptoAlgorithmAES_CBC.cpp:
     45        (WebCore::CryptoAlgorithmAES_CBC::decrypt):
     46        * crypto/algorithms/CryptoAlgorithmAES_CBC.h:
     47        * crypto/algorithms/CryptoAlgorithmRSAES_PKCS1_v1_5.cpp:
     48        (WebCore::CryptoAlgorithmRSAES_PKCS1_v1_5::decrypt):
     49        * crypto/algorithms/CryptoAlgorithmRSAES_PKCS1_v1_5.h:
     50        * crypto/algorithms/CryptoAlgorithmRSA_OAEP.cpp:
     51        (WebCore::CryptoAlgorithmRSA_OAEP::decrypt):
     52        * crypto/algorithms/CryptoAlgorithmRSA_OAEP.h:
     53        * crypto/gnutls/CryptoAlgorithmAES_CBCGnuTLS.cpp:
     54        (WebCore::CryptoAlgorithmAES_CBC::platformDecrypt):
     55        * crypto/gnutls/CryptoAlgorithmRSAES_PKCS1_v1_5GnuTLS.cpp:
     56        (WebCore::CryptoAlgorithmRSAES_PKCS1_v1_5::platformDecrypt):
     57        * crypto/gnutls/CryptoAlgorithmRSA_OAEPGnuTLS.cpp:
     58        (WebCore::CryptoAlgorithmRSA_OAEP::platformDecrypt):
     59        * crypto/mac/CryptoAlgorithmAES_CBCMac.cpp:
     60        (WebCore::CryptoAlgorithmAES_CBC::platformDecrypt):
     61        * crypto/mac/CryptoAlgorithmRSAES_PKCS1_v1_5Mac.cpp:
     62        (WebCore::decryptRSAES_PKCS1_v1_5):
     63        (WebCore::CryptoAlgorithmRSAES_PKCS1_v1_5::platformDecrypt):
     64        * crypto/mac/CryptoAlgorithmRSA_OAEPMac.cpp:
     65        (WebCore::decryptRSA_OAEP):
     66        (WebCore::CryptoAlgorithmRSA_OAEP::platformDecrypt):
     67
    1682016-11-18  Chris Dumez  <cdumez@apple.com>
    269
  • trunk/Source/WebCore/bindings/js/JSSubtleCryptoCustom.cpp

    r208891 r208918  
    5454enum class Operations {
    5555    Encrypt,
     56    Decrypt,
    5657    Digest,
    5758    GenerateKey,
     
    9596        switch (operation) {
    9697        case Operations::Encrypt:
     98        case Operations::Decrypt:
    9799            switch (*identifier) {
    98100            case CryptoAlgorithmIdentifier::RSAES_PKCS1_v1_5:
     
    389391}
    390392
     393static RefPtr<CryptoKey> toCryptoKey(ExecState& state, JSValue value)
     394{
     395    VM& vm = state.vm();
     396    auto scope = DECLARE_THROW_SCOPE(vm);
     397
     398    RefPtr<CryptoKey> result = JSCryptoKey::toWrapped(value);
     399    if (!result) {
     400        throwTypeError(&state, scope, ASCIILiteral("Invalid CryptoKey"));
     401        return nullptr;
     402    }
     403    return result;
     404}
     405
     406static Vector<uint8_t> toVector(ExecState& state, JSValue value)
     407{
     408    VM& vm = state.vm();
     409    auto scope = DECLARE_THROW_SCOPE(vm);
     410
     411    BufferSource data = convert<IDLBufferSource>(state, value);
     412    RETURN_IF_EXCEPTION(scope, { });
     413    Vector<uint8_t> dataVector;
     414    dataVector.append(data.data(), data.length());
     415
     416    return dataVector;
     417}
     418
    391419static void jsSubtleCryptoFunctionEncryptPromise(ExecState& state, Ref<DeferredPromise>&& promise)
    392420{
     
    402430    RETURN_IF_EXCEPTION(scope, void());
    403431
    404     RefPtr<CryptoKey> key = JSCryptoKey::toWrapped(state.uncheckedArgument(1));
    405     if (!key) {
    406         promise->reject(TypeError, ASCIILiteral("Invalid CryptoKey"));
    407         return;
    408     }
    409 
    410     BufferSource data = convert<IDLBufferSource>(state, state.uncheckedArgument(2));
    411     RETURN_IF_EXCEPTION(scope, void());
    412     Vector<uint8_t> dataVector;
    413     dataVector.append(data.data(), data.length());
     432    auto key = toCryptoKey(state, state.uncheckedArgument(1));
     433    RETURN_IF_EXCEPTION(scope, void());
     434
     435    auto data = toVector(state, state.uncheckedArgument(2));
     436    RETURN_IF_EXCEPTION(scope, void());
    414437
    415438    if (params->identifier != key->algorithmIdentifier()) {
     
    436459    JSSubtleCrypto* subtle = jsDynamicDowncast<JSSubtleCrypto*>(state.thisValue());
    437460    ASSERT(subtle);
    438     algorithm->encrypt(WTFMove(params), key.releaseNonNull(), WTFMove(dataVector), WTFMove(callback), WTFMove(exceptionCallback), *scriptExecutionContextFromExecState(&state), subtle->wrapped().workQueue());
     461    algorithm->encrypt(WTFMove(params), key.releaseNonNull(), WTFMove(data), WTFMove(callback), WTFMove(exceptionCallback), *scriptExecutionContextFromExecState(&state), subtle->wrapped().workQueue());
     462}
     463
     464static void jsSubtleCryptoFunctionDecryptPromise(ExecState& state, Ref<DeferredPromise>&& promise)
     465{
     466    VM& vm = state.vm();
     467    auto scope = DECLARE_THROW_SCOPE(vm);
     468
     469    if (UNLIKELY(state.argumentCount() < 3)) {
     470        promise->reject<JSValue>(createNotEnoughArgumentsError(&state));
     471        return;
     472    }
     473
     474    auto params = normalizeCryptoAlgorithmParameters(state, state.uncheckedArgument(0), Operations::Decrypt);
     475    RETURN_IF_EXCEPTION(scope, void());
     476
     477    auto key = toCryptoKey(state, state.uncheckedArgument(1));
     478    RETURN_IF_EXCEPTION(scope, void());
     479
     480    auto data = toVector(state, state.uncheckedArgument(2));
     481    RETURN_IF_EXCEPTION(scope, void());
     482
     483    if (params->identifier != key->algorithmIdentifier()) {
     484        promise->reject(INVALID_ACCESS_ERR, ASCIILiteral("CryptoKey doesn't match AlgorithmIdentifier"));
     485        return;
     486    }
     487
     488    if (!key->allows(CryptoKeyUsageDecrypt)) {
     489        promise->reject(INVALID_ACCESS_ERR, ASCIILiteral("CryptoKey doesn't support decryption"));
     490        return;
     491    }
     492
     493    auto algorithm = createAlgorithm(state, key->algorithmIdentifier());
     494    RETURN_IF_EXCEPTION(scope, void());
     495
     496    auto callback = [capturedPromise = promise.copyRef()](const Vector<uint8_t>& cipherText) mutable {
     497        fulfillPromiseWithArrayBuffer(WTFMove(capturedPromise), cipherText.data(), cipherText.size());
     498        return;
     499    };
     500    auto exceptionCallback = [capturedPromise = promise.copyRef()](ExceptionCode ec) mutable {
     501        rejectWithException(WTFMove(capturedPromise), ec);
     502    };
     503
     504    JSSubtleCrypto* subtle = jsDynamicDowncast<JSSubtleCrypto*>(state.thisValue());
     505    ASSERT(subtle);
     506    algorithm->decrypt(WTFMove(params), key.releaseNonNull(), WTFMove(data), WTFMove(callback), WTFMove(exceptionCallback), *scriptExecutionContextFromExecState(&state), subtle->wrapped().workQueue());
    439507}
    440508
     
    546614    RETURN_IF_EXCEPTION(scope, void());
    547615
    548     RefPtr<CryptoKey> key = JSCryptoKey::toWrapped(state.uncheckedArgument(1));
    549     if (!key) {
    550         promise->reject(TypeError, ASCIILiteral("Invalid CryptoKey"));
    551         return;
    552     }
     616    auto key = toCryptoKey(state, state.uncheckedArgument(1));
     617    RETURN_IF_EXCEPTION(scope, void());
    553618
    554619    switch (key->algorithmIdentifier()) {
     
    608673}
    609674
     675JSValue JSSubtleCrypto::decrypt(ExecState& state)
     676{
     677    return callPromiseFunction<jsSubtleCryptoFunctionDecryptPromise, PromiseExecutionScope::WindowOrWorker>(state);
     678}
     679
    610680JSValue JSSubtleCrypto::generateKey(ExecState& state)
    611681{
  • trunk/Source/WebCore/crypto/CryptoAlgorithm.cpp

    r208891 r208918  
    3434
    3535void CryptoAlgorithm::encrypt(std::unique_ptr<CryptoAlgorithmParameters>&&, Ref<CryptoKey>&&, Vector<uint8_t>&&, VectorCallback&&, ExceptionCallback&& exceptionCallback, ScriptExecutionContext&, WorkQueue&)
     36{
     37    exceptionCallback(NOT_SUPPORTED_ERR);
     38}
     39
     40void CryptoAlgorithm::decrypt(std::unique_ptr<CryptoAlgorithmParameters>&&, Ref<CryptoKey>&&, Vector<uint8_t>&&, VectorCallback&&, ExceptionCallback&& exceptionCallback, ScriptExecutionContext&, WorkQueue&)
    3641{
    3742    exceptionCallback(NOT_SUPPORTED_ERR);
  • trunk/Source/WebCore/crypto/CryptoAlgorithm.h

    r208891 r208918  
    6666
    6767    virtual void encrypt(std::unique_ptr<CryptoAlgorithmParameters>&&, Ref<CryptoKey>&&, Vector<uint8_t>&&, VectorCallback&&, ExceptionCallback&&, ScriptExecutionContext&, WorkQueue&);
     68    virtual void decrypt(std::unique_ptr<CryptoAlgorithmParameters>&&, Ref<CryptoKey>&&, Vector<uint8_t>&&, VectorCallback&&, ExceptionCallback&&, ScriptExecutionContext&, WorkQueue&);
    6869    virtual void generateKey(const std::unique_ptr<CryptoAlgorithmParameters>&&, bool extractable, CryptoKeyUsageBitmap, KeyOrKeyPairCallback&&, ExceptionCallback&&, ScriptExecutionContext&);
    6970    virtual void importKey(SubtleCrypto::KeyFormat, KeyData&&, const std::unique_ptr<CryptoAlgorithmParameters>&&, bool extractable, CryptoKeyUsageBitmap, KeyCallback&&, ExceptionCallback&&);
  • trunk/Source/WebCore/crypto/SubtleCrypto.idl

    r208891 r208918  
    3333] interface SubtleCrypto {
    3434    [Custom] Promise<any> encrypt(AlgorithmIdentifier algorithm, CryptoKey key, BufferSource data);
     35    [Custom] Promise<any> decrypt(AlgorithmIdentifier algorithm, CryptoKey key, BufferSource data);
    3536    // FIXME: Should this return a Promise<(CryptoKey or CryptoKeyPair)>?
    3637    [Custom] Promise<any> generateKey(AlgorithmIdentifier algorithm, boolean extractable, sequence<CryptoKeyUsage> keyUsages);
  • trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmAES_CBC.cpp

    r208891 r208918  
    7878}
    7979
     80void CryptoAlgorithmAES_CBC::decrypt(std::unique_ptr<CryptoAlgorithmParameters>&& parameters, Ref<CryptoKey>&& key, Vector<uint8_t>&& cipherText, VectorCallback&& callback, ExceptionCallback&& exceptionCallback, ScriptExecutionContext& context, WorkQueue& workQueue)
     81{
     82    ASSERT(parameters);
     83    auto& aesParameters = downcast<CryptoAlgorithmAesCbcParams>(*parameters);
     84    if (aesParameters.ivVector().size() != IVSIZE) {
     85        exceptionCallback(OperationError);
     86        return;
     87    }
     88    platformDecrypt(WTFMove(parameters), WTFMove(key), WTFMove(cipherText), WTFMove(callback), WTFMove(exceptionCallback), context, workQueue);
     89}
     90
    8091void CryptoAlgorithmAES_CBC::generateKey(const std::unique_ptr<CryptoAlgorithmParameters>&& parameters, bool extractable, CryptoKeyUsageBitmap usages, KeyOrKeyPairCallback&& callback, ExceptionCallback&& exceptionCallback, ScriptExecutionContext&)
    8192{
  • trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmAES_CBC.h

    r208891 r208918  
    4646
    4747    void encrypt(std::unique_ptr<CryptoAlgorithmParameters>&&, Ref<CryptoKey>&&, Vector<uint8_t>&&, VectorCallback&&, ExceptionCallback&&, ScriptExecutionContext&, WorkQueue&) final;
     48    void decrypt(std::unique_ptr<CryptoAlgorithmParameters>&&, Ref<CryptoKey>&&, Vector<uint8_t>&&, VectorCallback&&, ExceptionCallback&&, ScriptExecutionContext&, WorkQueue&) final;
    4849    void generateKey(const std::unique_ptr<CryptoAlgorithmParameters>&&, bool extractable, CryptoKeyUsageBitmap, KeyOrKeyPairCallback&&, ExceptionCallback&&, ScriptExecutionContext&) final;
    4950    void importKey(SubtleCrypto::KeyFormat, KeyData&&, const std::unique_ptr<CryptoAlgorithmParameters>&&, bool extractable, CryptoKeyUsageBitmap, KeyCallback&&, ExceptionCallback&&) final;
     
    5758    bool keyAlgorithmMatches(const CryptoAlgorithmAesCbcParamsDeprecated& algorithmParameters, const CryptoKey&) const;
    5859    void platformEncrypt(std::unique_ptr<CryptoAlgorithmParameters>&&, Ref<CryptoKey>&&, Vector<uint8_t>&&, VectorCallback&&, ExceptionCallback&&, ScriptExecutionContext&, WorkQueue&);
     60    void platformDecrypt(std::unique_ptr<CryptoAlgorithmParameters>&&, Ref<CryptoKey>&&, Vector<uint8_t>&&, VectorCallback&&, ExceptionCallback&&, ScriptExecutionContext&, WorkQueue&);
    5961    ExceptionOr<void> platformEncrypt(const CryptoAlgorithmAesCbcParamsDeprecated&, const CryptoKeyAES&, const CryptoOperationData&, VectorCallback&&, VoidCallback&& failureCallback);
    6062    ExceptionOr<void> platformDecrypt(const CryptoAlgorithmAesCbcParamsDeprecated&, const CryptoKeyAES&, const CryptoOperationData&, VectorCallback&&, VoidCallback&& failureCallback);
  • trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmRSAES_PKCS1_v1_5.cpp

    r208891 r208918  
    6969}
    7070
     71void CryptoAlgorithmRSAES_PKCS1_v1_5::decrypt(std::unique_ptr<CryptoAlgorithmParameters>&&, Ref<CryptoKey>&& key, Vector<uint8_t>&& cipherText, VectorCallback&& callback, ExceptionCallback&& exceptionCallback, ScriptExecutionContext& context, WorkQueue& workQueue)
     72{
     73    if (key->type() != CryptoKeyType::Private) {
     74        exceptionCallback(INVALID_ACCESS_ERR);
     75        return;
     76    }
     77    platformDecrypt(WTFMove(key), WTFMove(cipherText), WTFMove(callback), WTFMove(exceptionCallback), context, workQueue);
     78}
     79
    7180void CryptoAlgorithmRSAES_PKCS1_v1_5::generateKey(const std::unique_ptr<CryptoAlgorithmParameters>&& parameters, bool extractable, CryptoKeyUsageBitmap usages, KeyOrKeyPairCallback&& callback, ExceptionCallback&& exceptionCallback, ScriptExecutionContext& context)
    7281{
  • trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmRSAES_PKCS1_v1_5.h

    r208891 r208918  
    4646
    4747    void encrypt(std::unique_ptr<CryptoAlgorithmParameters>&&, Ref<CryptoKey>&&, Vector<uint8_t>&&, VectorCallback&&, ExceptionCallback&&, ScriptExecutionContext&, WorkQueue&) final;
     48    void decrypt(std::unique_ptr<CryptoAlgorithmParameters>&&, Ref<CryptoKey>&&, Vector<uint8_t>&&, VectorCallback&&, ExceptionCallback&&, ScriptExecutionContext&, WorkQueue&) final;
    4849    void generateKey(const std::unique_ptr<CryptoAlgorithmParameters>&&, bool extractable, CryptoKeyUsageBitmap, KeyOrKeyPairCallback&&, ExceptionCallback&&, ScriptExecutionContext&) final;
    4950    void importKey(SubtleCrypto::KeyFormat, KeyData&&, const std::unique_ptr<CryptoAlgorithmParameters>&&, bool extractable, CryptoKeyUsageBitmap, KeyCallback&&, ExceptionCallback&&) final;
     
    5758    bool keyAlgorithmMatches(const CryptoKey&) const;
    5859    void platformEncrypt(Ref<CryptoKey>&&, Vector<uint8_t>&&, VectorCallback&&, ExceptionCallback&&, ScriptExecutionContext&, WorkQueue&);
     60    void platformDecrypt(Ref<CryptoKey>&&, Vector<uint8_t>&&, VectorCallback&&, ExceptionCallback&&, ScriptExecutionContext&, WorkQueue&);
    5961    ExceptionOr<void> platformEncrypt(const CryptoKeyRSA&, const CryptoOperationData&, VectorCallback&&, VoidCallback&& failureCallback);
    6062    ExceptionOr<void> platformDecrypt(const CryptoKeyRSA&, const CryptoOperationData&, VectorCallback&&, VoidCallback&& failureCallback);
  • trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmRSA_OAEP.cpp

    r208891 r208918  
    7979}
    8080
     81void CryptoAlgorithmRSA_OAEP::decrypt(std::unique_ptr<CryptoAlgorithmParameters>&& parameters, Ref<CryptoKey>&& key, Vector<uint8_t>&& cipherText, VectorCallback&& callback, ExceptionCallback&& exceptionCallback, ScriptExecutionContext& context, WorkQueue& workQueue)
     82{
     83    ASSERT(parameters);
     84    if (key->type() != CryptoKeyType::Private) {
     85        exceptionCallback(INVALID_ACCESS_ERR);
     86        return;
     87    }
     88    platformDecrypt(WTFMove(parameters), WTFMove(key), WTFMove(cipherText), WTFMove(callback), WTFMove(exceptionCallback), context, workQueue);
     89}
    8190
    8291void CryptoAlgorithmRSA_OAEP::generateKey(const std::unique_ptr<CryptoAlgorithmParameters>&& parameters, bool extractable, CryptoKeyUsageBitmap usages, KeyOrKeyPairCallback&& callback, ExceptionCallback&& exceptionCallback, ScriptExecutionContext& context)
  • trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmRSA_OAEP.h

    r208891 r208918  
    4646
    4747    void encrypt(std::unique_ptr<CryptoAlgorithmParameters>&&, Ref<CryptoKey>&&, Vector<uint8_t>&&, VectorCallback&&, ExceptionCallback&&, ScriptExecutionContext&, WorkQueue&) final;
     48    void decrypt(std::unique_ptr<CryptoAlgorithmParameters>&&, Ref<CryptoKey>&&, Vector<uint8_t>&&, VectorCallback&&, ExceptionCallback&&, ScriptExecutionContext&, WorkQueue&) final;
    4849    void generateKey(const std::unique_ptr<CryptoAlgorithmParameters>&&, bool extractable, CryptoKeyUsageBitmap, KeyOrKeyPairCallback&&, ExceptionCallback&&, ScriptExecutionContext&) final;
    4950    void importKey(SubtleCrypto::KeyFormat, KeyData&&, const std::unique_ptr<CryptoAlgorithmParameters>&&, bool extractable, CryptoKeyUsageBitmap, KeyCallback&&, ExceptionCallback&&) final;
     
    5758    bool keyAlgorithmMatches(const CryptoAlgorithmRsaOaepParamsDeprecated& algorithmParameters, const CryptoKey&) const;
    5859    void platformEncrypt(std::unique_ptr<CryptoAlgorithmParameters>&&, Ref<CryptoKey>&&, Vector<uint8_t>&&, VectorCallback&&, ExceptionCallback&&, ScriptExecutionContext&, WorkQueue&);
     60    void platformDecrypt(std::unique_ptr<CryptoAlgorithmParameters>&&, Ref<CryptoKey>&&, Vector<uint8_t>&&, VectorCallback&&, ExceptionCallback&&, ScriptExecutionContext&, WorkQueue&);
    5961    ExceptionOr<void> platformEncrypt(const CryptoAlgorithmRsaOaepParamsDeprecated&, const CryptoKeyRSA&, const CryptoOperationData&, VectorCallback&&, VoidCallback&& failureCallback);
    6062    ExceptionOr<void> platformDecrypt(const CryptoAlgorithmRsaOaepParamsDeprecated&, const CryptoKeyRSA&, const CryptoOperationData&, VectorCallback&&, VoidCallback&& failureCallback);
  • trunk/Source/WebCore/crypto/gnutls/CryptoAlgorithmAES_CBCGnuTLS.cpp

    r208891 r208918  
    3939}
    4040
     41void CryptoAlgorithmAES_CBC::platformDecrypt(std::unique_ptr<CryptoAlgorithmParameters>&&, Ref<CryptoKey>&&, Vector<uint8_t>&&, VectorCallback&&, ExceptionCallback&&, ScriptExecutionContext&, WorkQueue&)
     42{
     43    notImplemented();
     44}
     45
    4146ExceptionOr<void> CryptoAlgorithmAES_CBC::platformEncrypt(const CryptoAlgorithmAesCbcParamsDeprecated&, const CryptoKeyAES&, const CryptoOperationData&, VectorCallback&&, VoidCallback&&)
    4247{
  • trunk/Source/WebCore/crypto/gnutls/CryptoAlgorithmRSAES_PKCS1_v1_5GnuTLS.cpp

    r208891 r208918  
    4040}
    4141
     42void CryptoAlgorithmRSAES_PKCS1_v1_5::platformDecrypt(Ref<CryptoKey>&&, Vector<uint8_t>&&, VectorCallback&&, ExceptionCallback&&, ScriptExecutionContext&, WorkQueue&)
     43{
     44    notImplemented();
     45}
     46
    4247ExceptionOr<void> CryptoAlgorithmRSAES_PKCS1_v1_5::platformEncrypt(const CryptoKeyRSA&, const CryptoOperationData&, VectorCallback&&, VoidCallback&&)
    4348{
  • trunk/Source/WebCore/crypto/gnutls/CryptoAlgorithmRSA_OAEPGnuTLS.cpp

    r208891 r208918  
    3939}
    4040
     41void CryptoAlgorithmRSA_OAEP::platformDecrypt(std::unique_ptr<CryptoAlgorithmParameters>&&, Ref<CryptoKey>&&, Vector<uint8_t>&&, VectorCallback&&, ExceptionCallback&&, ScriptExecutionContext&, WorkQueue&)
     42{
     43    notImplemented();
     44}
     45
    4146ExceptionOr<void> CryptoAlgorithmRSA_OAEP::platformEncrypt(const CryptoAlgorithmRsaOaepParamsDeprecated&, const CryptoKeyRSA&, const CryptoOperationData&, VectorCallback&&, VoidCallback&&)
    4247{
  • trunk/Source/WebCore/crypto/mac/CryptoAlgorithmAES_CBCMac.cpp

    r208891 r208918  
    9696}
    9797
     98void CryptoAlgorithmAES_CBC::platformDecrypt(std::unique_ptr<CryptoAlgorithmParameters>&& parameters, Ref<CryptoKey>&& key, Vector<uint8_t>&& cipherText, VectorCallback&& callback, ExceptionCallback&& exceptionCallback, ScriptExecutionContext& context, WorkQueue& workQueue)
     99{
     100    context.ref();
     101    workQueue.dispatch([parameters = WTFMove(parameters), key = WTFMove(key), cipherText = WTFMove(cipherText), callback = WTFMove(callback), exceptionCallback = WTFMove(exceptionCallback), &context]() mutable {
     102        auto& aesParameters = downcast<CryptoAlgorithmAesCbcParams>(*parameters);
     103        auto& aesKey = downcast<CryptoKeyAES>(key.get());
     104        assert(aesParameters.ivVector().size() == kCCBlockSizeAES128);
     105        auto result = transformAES_CBC(kCCDecrypt, aesParameters.ivVector().data(), aesKey.key(), cipherText.data(), cipherText.size());
     106        if (result.hasException()) {
     107            context.postTask([exceptionCallback = WTFMove(exceptionCallback), ec = result.releaseException().code()](ScriptExecutionContext& context) {
     108                exceptionCallback(ec);
     109                context.deref();
     110            });
     111            return;
     112        }
     113        context.postTask([callback = WTFMove(callback), result = result.releaseReturnValue()](ScriptExecutionContext& context) {
     114            callback(result);
     115            context.deref();
     116        });
     117    });
     118}
     119
    98120ExceptionOr<void> CryptoAlgorithmAES_CBC::platformEncrypt(const CryptoAlgorithmAesCbcParamsDeprecated& parameters, const CryptoKeyAES& key, const CryptoOperationData& data, VectorCallback&& callback, VoidCallback&& failureCallback)
    99121{
  • trunk/Source/WebCore/crypto/mac/CryptoAlgorithmRSAES_PKCS1_v1_5Mac.cpp

    r208891 r208918  
    4848}
    4949
     50// FIXME: We should change data to Vector<uint8_t> type once WebKitSubtleCrypto is deprecated.
     51// https://bugs.webkit.org/show_bug.cgi?id=164939
     52static ExceptionOr<Vector<uint8_t>> decryptRSAES_PKCS1_v1_5(const PlatformRSAKey key, size_t keyLength, const uint8_t* data, size_t dataLength)
     53{
     54    Vector<uint8_t> plainText(keyLength / 8); // Per Step 1 of https://tools.ietf.org/html/rfc3447#section-7.2.1
     55    size_t plainTextLength = plainText.size();
     56    if (CCRSACryptorDecrypt(key, ccPKCS1Padding, data, dataLength, plainText.data(), &plainTextLength, 0, 0, kCCDigestNone))
     57        return Exception { OperationError };
     58
     59    plainText.resize(plainTextLength);
     60    return WTFMove(plainText);
     61}
     62
    5063void CryptoAlgorithmRSAES_PKCS1_v1_5::platformEncrypt(Ref<CryptoKey>&& key, Vector<uint8_t>&& plainText, VectorCallback&& callback, ExceptionCallback&& exceptionCallback, ScriptExecutionContext& context, WorkQueue& workQueue)
    5164{
     
    5467        auto& rsaKey = downcast<CryptoKeyRSA>(key.get());
    5568        auto result = encryptRSAES_PKCS1_v1_5(rsaKey.platformKey(), rsaKey.keySizeInBits(), plainText.data(), plainText.size());
     69        if (result.hasException()) {
     70            context.postTask([exceptionCallback = WTFMove(exceptionCallback), ec = result.releaseException().code()](ScriptExecutionContext& context) {
     71                exceptionCallback(ec);
     72                context.deref();
     73            });
     74            return;
     75        }
     76        context.postTask([callback = WTFMove(callback), result = result.releaseReturnValue()](ScriptExecutionContext& context) {
     77            callback(result);
     78            context.deref();
     79        });
     80    });
     81}
     82
     83void CryptoAlgorithmRSAES_PKCS1_v1_5::platformDecrypt(Ref<CryptoKey>&& key, Vector<uint8_t>&& cipherText, VectorCallback&& callback, ExceptionCallback&& exceptionCallback, ScriptExecutionContext& context, WorkQueue& workQueue)
     84{
     85    context.ref();
     86    workQueue.dispatch([key = WTFMove(key), cipherText = WTFMove(cipherText), callback = WTFMove(callback), exceptionCallback = WTFMove(exceptionCallback), &context]() mutable {
     87        auto& rsaKey = downcast<CryptoKeyRSA>(key.get());
     88        auto result = decryptRSAES_PKCS1_v1_5(rsaKey.platformKey(), rsaKey.keySizeInBits(), cipherText.data(), cipherText.size());
    5689        if (result.hasException()) {
    5790            context.postTask([exceptionCallback = WTFMove(exceptionCallback), ec = result.releaseException().code()](ScriptExecutionContext& context) {
     
    79112}
    80113
    81 // FIXME: We should get rid of the magic number 1024. It only makes sense when key length < 8192 bits
    82114ExceptionOr<void> CryptoAlgorithmRSAES_PKCS1_v1_5::platformDecrypt(const CryptoKeyRSA& key, const CryptoOperationData& data, VectorCallback&& callback, VoidCallback&& failureCallback)
    83115{
    84     Vector<uint8_t> plainText(1024);
    85     size_t plainTextLength = plainText.size();
    86     CCCryptorStatus status = CCRSACryptorDecrypt(key.platformKey(), ccPKCS1Padding, data.first, data.second, plainText.data(), &plainTextLength, 0, 0, kCCDigestNone);
    87     if (status) {
     116    auto result = decryptRSAES_PKCS1_v1_5(key.platformKey(), key.keySizeInBits(), data.first, data.second);
     117    if (result.hasException()) {
    88118        failureCallback();
    89119        return { };
    90120    }
    91 
    92     plainText.resize(plainTextLength);
    93     callback(plainText);
     121    callback(result.releaseReturnValue());
    94122    return { };
    95123}
  • trunk/Source/WebCore/crypto/mac/CryptoAlgorithmRSA_OAEPMac.cpp

    r208891 r208918  
    5454}
    5555
     56// FIXME: We should change data to Vector<uint8_t> type once WebKitSubtleCrypto is deprecated.
     57// https://bugs.webkit.org/show_bug.cgi?id=164939
     58static ExceptionOr<Vector<uint8_t>> decryptRSA_OAEP(CryptoAlgorithmIdentifier hash, const Vector<uint8_t>& label, const PlatformRSAKey key, size_t keyLength, const uint8_t* data, size_t dataLength)
     59{
     60    CCDigestAlgorithm digestAlgorithm;
     61    if (!getCommonCryptoDigestAlgorithm(hash, digestAlgorithm))
     62        return Exception { OperationError };
     63
     64    Vector<uint8_t> plainText(keyLength / 8); // Per Step 1.b of https://tools.ietf.org/html/rfc3447#section-7.1.1
     65    size_t plainTextLength = plainText.size();
     66    if (CCRSACryptorDecrypt(key, ccOAEPPadding, data, dataLength, plainText.data(), &plainTextLength, label.data(), label.size(), digestAlgorithm))
     67        return Exception { OperationError };
     68
     69    plainText.resize(plainTextLength);
     70    return WTFMove(plainText);
     71}
     72
    5673void CryptoAlgorithmRSA_OAEP::platformEncrypt(std::unique_ptr<CryptoAlgorithmParameters>&& parameters, Ref<CryptoKey>&& key, Vector<uint8_t>&& plainText, VectorCallback&& callback, ExceptionCallback&& exceptionCallback, ScriptExecutionContext& context, WorkQueue& workQueue)
    5774{
     
    6178        auto& rsaKey = downcast<CryptoKeyRSA>(key.get());
    6279        auto result = encryptRSA_OAEP(rsaKey.hashAlgorithmIdentifier(), rsaParameters.labelVector(), rsaKey.platformKey(), rsaKey.keySizeInBits(), plainText.data(), plainText.size());
     80        if (result.hasException()) {
     81            context.postTask([exceptionCallback = WTFMove(exceptionCallback), ec = result.releaseException().code()](ScriptExecutionContext& context) {
     82                exceptionCallback(ec);
     83                context.deref();
     84            });
     85            return;
     86        }
     87        context.postTask([callback = WTFMove(callback), result = result.releaseReturnValue()](ScriptExecutionContext& context) {
     88            callback(result);
     89            context.deref();
     90        });
     91    });
     92}
     93
     94void CryptoAlgorithmRSA_OAEP::platformDecrypt(std::unique_ptr<CryptoAlgorithmParameters>&& parameters, Ref<CryptoKey>&& key, Vector<uint8_t>&& cipherText, VectorCallback&& callback, ExceptionCallback&& exceptionCallback, ScriptExecutionContext& context, WorkQueue& workQueue)
     95{
     96    context.ref();
     97    workQueue.dispatch([parameters = WTFMove(parameters), key = WTFMove(key), cipherText = WTFMove(cipherText), callback = WTFMove(callback), exceptionCallback = WTFMove(exceptionCallback), &context]() mutable {
     98        auto& rsaParameters = downcast<CryptoAlgorithmRsaOaepParams>(*parameters);
     99        auto& rsaKey = downcast<CryptoKeyRSA>(key.get());
     100        auto result = decryptRSA_OAEP(rsaKey.hashAlgorithmIdentifier(), rsaParameters.labelVector(), rsaKey.platformKey(), rsaKey.keySizeInBits(), cipherText.data(), cipherText.size());
    63101        if (result.hasException()) {
    64102            context.postTask([exceptionCallback = WTFMove(exceptionCallback), ec = result.releaseException().code()](ScriptExecutionContext& context) {
     
    87125}
    88126
    89 // FIXME: We should get rid of the magic number 1024. It only makes sense when key length < 8192 bits
    90127ExceptionOr<void> CryptoAlgorithmRSA_OAEP::platformDecrypt(const CryptoAlgorithmRsaOaepParamsDeprecated& parameters, const CryptoKeyRSA& key, const CryptoOperationData& data, VectorCallback&& callback, VoidCallback&& failureCallback)
    91128{
    92     CCDigestAlgorithm digestAlgorithm;
    93     if (!getCommonCryptoDigestAlgorithm(parameters.hash, digestAlgorithm))
    94         return Exception { NOT_SUPPORTED_ERR };
    95 
    96     Vector<uint8_t> plainText(1024);
    97     size_t plainTextLength = plainText.size();
    98     CCCryptorStatus status = CCRSACryptorDecrypt(key.platformKey(), ccOAEPPadding, data.first, data.second, plainText.data(), &plainTextLength, parameters.label.data(), parameters.label.size(), digestAlgorithm);
    99     if (status) {
     129    ASSERT(parameters.hasLabel || parameters.label.isEmpty());
     130    auto result = decryptRSA_OAEP(parameters.hash, parameters.label, key.platformKey(), key.keySizeInBits(), data.first, data.second);
     131    if (result.hasException()) {
    100132        failureCallback();
    101133        return { };
    102134    }
    103 
    104     plainText.resize(plainTextLength);
    105     callback(plainText);
     135    callback(result.releaseReturnValue());
    106136    return { };
    107137}
Note: See TracChangeset for help on using the changeset viewer.