Changeset 275535 in webkit


Ignore:
Timestamp:
Apr 6, 2021 11:10:31 AM (3 years ago)
Author:
jiewen_tan@apple.com
Message:

WebCrypto in Safari will not AES-GCM encrypt 0 bytes
https://bugs.webkit.org/show_bug.cgi?id=224083
<rdar://75093377>

Reviewed by Youenn Fablet.

Source/WebCore:

CommonCrypto will bail out both the encryption and decryption process if the dataOut is a null pointer.
To workaround the issue, this patch forces the dataOut to be a non-null pointer.

Test: crypto/subtle/aes-gcm-generate-key-encrypt-decrypt-null-plain-text.html

  • crypto/mac/CryptoAlgorithmAES_GCMMac.cpp:

(WebCore::encryptAES_GCM):
(WebCore::decyptAES_GCM):

LayoutTests:

  • crypto/subtle/aes-gcm-generate-key-encrypt-decrypt-null-plain-text-expected.txt: Added.
  • crypto/subtle/aes-gcm-generate-key-encrypt-decrypt-null-plain-text.html: Added.
Location:
trunk
Files:
2 added
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r275533 r275535  
     12021-04-06  Jiewen Tan  <jiewen_tan@apple.com>
     2
     3        WebCrypto in Safari will not AES-GCM encrypt 0 bytes
     4        https://bugs.webkit.org/show_bug.cgi?id=224083
     5        <rdar://75093377>
     6
     7        Reviewed by Youenn Fablet.
     8
     9        * crypto/subtle/aes-gcm-generate-key-encrypt-decrypt-null-plain-text-expected.txt: Added.
     10        * crypto/subtle/aes-gcm-generate-key-encrypt-decrypt-null-plain-text.html: Added.
     11
    1122021-04-06  Chris Gambrell  <cgambrell@apple.com>
    213
  • trunk/Source/WebCore/ChangeLog

    r275529 r275535  
     12021-04-06  Jiewen Tan  <jiewen_tan@apple.com>
     2
     3        WebCrypto in Safari will not AES-GCM encrypt 0 bytes
     4        https://bugs.webkit.org/show_bug.cgi?id=224083
     5        <rdar://75093377>
     6
     7        Reviewed by Youenn Fablet.
     8
     9        CommonCrypto will bail out both the encryption and decryption process if the dataOut is a null pointer.
     10        To workaround the issue, this patch forces the dataOut to be a non-null pointer.
     11
     12        Test: crypto/subtle/aes-gcm-generate-key-encrypt-decrypt-null-plain-text.html
     13
     14        * crypto/mac/CryptoAlgorithmAES_GCMMac.cpp:
     15        (WebCore::encryptAES_GCM):
     16        (WebCore::decyptAES_GCM):
     17
    1182021-04-06  Patrick Angle  <pangle@apple.com>
    219
  • trunk/Source/WebCore/crypto/mac/CryptoAlgorithmAES_GCMMac.cpp

    r239461 r275535  
    3838static ExceptionOr<Vector<uint8_t>> encryptAES_GCM(const Vector<uint8_t>& iv, const Vector<uint8_t>& key, const Vector<uint8_t>& plainText, const Vector<uint8_t>& additionalData, size_t desiredTagLengthInBytes)
    3939{
    40     Vector<uint8_t> cipherText(plainText.size()); // Per section 5.2.1.2: http://nvlpubs.nist.gov/nistpubs/Legacy/SP/nistspecialpublication800-38d.pdf
     40    // This is a wordaround for rdar://75093377. Force the buffer to be a non null pointer.
     41    Vector<uint8_t> cipherText(plainText.size() + desiredTagLengthInBytes); // Per section 5.2.1.2: http://nvlpubs.nist.gov/nistpubs/Legacy/SP/nistspecialpublication800-38d.pdf
    4142    Vector<uint8_t> tag(desiredTagLengthInBytes);
    4243    // tagLength is actual an input <rdar://problem/30660074>
     
    4748        return Exception { OperationError };
    4849
    49     cipherText.append(tag.data(), desiredTagLengthInBytes);
     50    memcpy(cipherText.data() + plainText.size(), tag.data(), desiredTagLengthInBytes);
    5051
    5152    return WTFMove(cipherText);
     
    5455static ExceptionOr<Vector<uint8_t>> decyptAES_GCM(const Vector<uint8_t>& iv, const Vector<uint8_t>& key, const Vector<uint8_t>& cipherText, const Vector<uint8_t>& additionalData, size_t desiredTagLengthInBytes)
    5556{
    56     Vector<uint8_t> plainText(cipherText.size() - desiredTagLengthInBytes); // Per section 5.2.1.2: http://nvlpubs.nist.gov/nistpubs/Legacy/SP/nistspecialpublication800-38d.pdf
     57    // This is a wordaround for rdar://75093377. Force the buffer to be a non null pointer.
     58    Vector<uint8_t> plainText(cipherText.size()); // Per section 5.2.1.2: http://nvlpubs.nist.gov/nistpubs/Legacy/SP/nistspecialpublication800-38d.pdf
    5759    Vector<uint8_t> tag(desiredTagLengthInBytes);
    5860    size_t offset = cipherText.size() - desiredTagLengthInBytes;
     
    6870        return Exception { OperationError };
    6971
     72    // This is a wordaround for rdar://75093377. Force the buffer to be a non null pointer.
     73    plainText.shrink(offset);
    7074    return WTFMove(plainText);
    7175}
Note: See TracChangeset for help on using the changeset viewer.