Changeset 279723 in webkit


Ignore:
Timestamp:
Jul 8, 2021 9:29:15 AM (13 months ago)
Author:
Chris Dumez
Message:

[WebCrypto] deriveBits() fails if length is not a multiple of 8 for ECDH algorithm
https://bugs.webkit.org/show_bug.cgi?id=227796

Reviewed by Alex Christensen.

LayoutTests/imported/w3c:

Rebaseline WPT tests now that more checks are passing.

  • web-platform-tests/WebCryptoAPI/derive_bits_keys/ecdh_bits.https.any-expected.txt:
  • web-platform-tests/WebCryptoAPI/derive_bits_keys/ecdh_bits.https.any.worker-expected.txt:

Source/WebCore:

deriveBits() fails if length is not a multiple of 8 for ECDH algorithm. This doesn't match
the specification or the behavior of Chrome.

No new tests, rebaselined existing tests.

  • crypto/algorithms/CryptoAlgorithmECDH.cpp:

(WebCore::CryptoAlgorithmECDH::deriveBits):

LayoutTests:

Update existing layout test due to behavior change.

  • crypto/subtle/ecdh-derive-bits-malformed-parametrs-expected.txt:
  • crypto/subtle/ecdh-derive-bits-malformed-parametrs.html:
Location:
trunk
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r279722 r279723  
     12021-07-08  Chris Dumez  <cdumez@apple.com>
     2
     3        [WebCrypto] deriveBits() fails if length is not a multiple of 8 for ECDH algorithm
     4        https://bugs.webkit.org/show_bug.cgi?id=227796
     5
     6        Reviewed by Alex Christensen.
     7
     8        Update existing layout test due to behavior change.
     9
     10        * crypto/subtle/ecdh-derive-bits-malformed-parametrs-expected.txt:
     11        * crypto/subtle/ecdh-derive-bits-malformed-parametrs.html:
     12
    1132021-07-08  Myles C. Maxfield  <mmaxfield@apple.com>
    214
  • trunk/LayoutTests/crypto/subtle/ecdh-derive-bits-malformed-parametrs-expected.txt

    r219663 r279723  
    1212PASS crypto.subtle.deriveBits({name: "ecdh", public: { }}, privateKey, null) rejected promise  with TypeError: Type error.
    1313PASS crypto.subtle.deriveBits({name: "ecdh", public: 1}, privateKey, null) rejected promise  with TypeError: Type error.
    14 PASS crypto.subtle.deriveBits({ name:"ECDH", public:publicKey }, privateKey, 1) rejected promise  with OperationError: The operation failed for an operation-specific reason.
    1514PASS crypto.subtle.deriveBits({ name:"ECDH", public:publicKey }, publicKey, null) rejected promise  with InvalidAccessError: CryptoKey doesn't support bits derivation.
    1615PASS crypto.subtle.deriveBits({ name:"ECDH", public:privateKey }, privateKey, null) rejected promise  with InvalidAccessError: The requested operation is not valid for the provided key.
  • trunk/LayoutTests/crypto/subtle/ecdh-derive-bits-malformed-parametrs.html

    r213624 r279723  
    5656    shouldReject('crypto.subtle.deriveBits({name: "ecdh", public: { }}, privateKey, null)');
    5757    shouldReject('crypto.subtle.deriveBits({name: "ecdh", public: 1}, privateKey, null)');
    58     // Wrong length
    59     shouldReject('crypto.subtle.deriveBits({ name:"ECDH", public:publicKey }, privateKey, 1)');
    6058    // base key is public
    6159    shouldReject('crypto.subtle.deriveBits({ name:"ECDH", public:publicKey }, publicKey, null)');
  • trunk/LayoutTests/imported/w3c/ChangeLog

    r279722 r279723  
     12021-07-08  Chris Dumez  <cdumez@apple.com>
     2
     3        [WebCrypto] deriveBits() fails if length is not a multiple of 8 for ECDH algorithm
     4        https://bugs.webkit.org/show_bug.cgi?id=227796
     5
     6        Reviewed by Alex Christensen.
     7
     8        Rebaseline WPT tests now that more checks are passing.
     9
     10        * web-platform-tests/WebCryptoAPI/derive_bits_keys/ecdh_bits.https.any-expected.txt:
     11        * web-platform-tests/WebCryptoAPI/derive_bits_keys/ecdh_bits.https.any.worker-expected.txt:
     12
    1132021-07-08  Myles C. Maxfield  <mmaxfield@apple.com>
    214
  • trunk/LayoutTests/imported/w3c/web-platform-tests/WebCryptoAPI/derive_bits_keys/ecdh_bits.https.any-expected.txt

    r279688 r279723  
    55PASS P-521 with null length
    66PASS P-521 short result
    7 FAIL P-521 non-multiple of 8 bits assert_unreached: deriveBits failed with error OperationError: The operation failed for an operation-specific reason Reached unreachable code
     7PASS P-521 non-multiple of 8 bits
    88PASS P-521 missing public curve
    99PASS P-521 public property of algorithm is not a CryptoKey
     
    1919PASS P-256 with null length
    2020PASS P-256 short result
    21 FAIL P-256 non-multiple of 8 bits assert_unreached: deriveBits failed with error OperationError: The operation failed for an operation-specific reason Reached unreachable code
     21PASS P-256 non-multiple of 8 bits
    2222PASS P-256 missing public curve
    2323PASS P-256 public property of algorithm is not a CryptoKey
     
    3333PASS P-384 with null length
    3434PASS P-384 short result
    35 FAIL P-384 non-multiple of 8 bits assert_unreached: deriveBits failed with error OperationError: The operation failed for an operation-specific reason Reached unreachable code
     35PASS P-384 non-multiple of 8 bits
    3636PASS P-384 missing public curve
    3737PASS P-384 public property of algorithm is not a CryptoKey
  • trunk/LayoutTests/imported/w3c/web-platform-tests/WebCryptoAPI/derive_bits_keys/ecdh_bits.https.any.worker-expected.txt

    r279688 r279723  
    55PASS P-521 with null length
    66PASS P-521 short result
    7 FAIL P-521 non-multiple of 8 bits assert_unreached: deriveBits failed with error OperationError: The operation failed for an operation-specific reason Reached unreachable code
     7PASS P-521 non-multiple of 8 bits
    88PASS P-521 missing public curve
    99PASS P-521 public property of algorithm is not a CryptoKey
     
    1919PASS P-256 with null length
    2020PASS P-256 short result
    21 FAIL P-256 non-multiple of 8 bits assert_unreached: deriveBits failed with error OperationError: The operation failed for an operation-specific reason Reached unreachable code
     21PASS P-256 non-multiple of 8 bits
    2222PASS P-256 missing public curve
    2323PASS P-256 public property of algorithm is not a CryptoKey
     
    3333PASS P-384 with null length
    3434PASS P-384 short result
    35 FAIL P-384 non-multiple of 8 bits assert_unreached: deriveBits failed with error OperationError: The operation failed for an operation-specific reason Reached unreachable code
     35PASS P-384 non-multiple of 8 bits
    3636PASS P-384 missing public curve
    3737PASS P-384 public property of algorithm is not a CryptoKey
  • trunk/Source/WebCore/ChangeLog

    r279722 r279723  
     12021-07-08  Chris Dumez  <cdumez@apple.com>
     2
     3        [WebCrypto] deriveBits() fails if length is not a multiple of 8 for ECDH algorithm
     4        https://bugs.webkit.org/show_bug.cgi?id=227796
     5
     6        Reviewed by Alex Christensen.
     7
     8        deriveBits() fails if length is not a multiple of 8 for ECDH algorithm. This doesn't match
     9        the specification or the behavior of Chrome.
     10
     11        No new tests, rebaselined existing tests.
     12
     13        * crypto/algorithms/CryptoAlgorithmECDH.cpp:
     14        (WebCore::CryptoAlgorithmECDH::deriveBits):
     15
    1162021-07-08  Myles C. Maxfield  <mmaxfield@apple.com>
    217
  • trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmECDH.cpp

    r278253 r279723  
    6969void CryptoAlgorithmECDH::deriveBits(const CryptoAlgorithmParameters& parameters, Ref<CryptoKey>&& baseKey, size_t length, VectorCallback&& callback, ExceptionCallback&& exceptionCallback, ScriptExecutionContext& context, WorkQueue& workQueue)
    7070{
    71     // We only accept length that is a multiple of 8.
    72     if (length % 8) {
    73         exceptionCallback(OperationError);
    74         return;
    75     }
    76 
    7771    auto& ecParameters = downcast<CryptoAlgorithmEcdhKeyDeriveParams>(parameters);
    7872
     
    106100            return;
    107101        }
    108         if (length / 8 > (*derivedKey).size()) {
     102        auto lengthInBytes = std::ceil(length / 8.);
     103        if (lengthInBytes > (*derivedKey).size()) {
    109104            exceptionCallback(OperationError);
    110105            return;
    111106        }
    112         (*derivedKey).shrink(length / 8);
     107        (*derivedKey).shrink(lengthInBytes);
    113108        callback(WTFMove(*derivedKey));
    114109    };
Note: See TracChangeset for help on using the changeset viewer.