Changeset 273158 in webkit


Ignore:
Timestamp:
Feb 19, 2021 12:39:40 PM (3 years ago)
Author:
youenn@apple.com
Message:

Allow to use BigInt as key identifier
https://bugs.webkit.org/show_bug.cgi?id=222165

Reviewed by Darin Adler.

Source/WebCore:

Allow to pass a BigInt as key id so as to use all of SFrame key ID 8 bytes.
A RangeError is thrown if BigInt is more than 64 bits.

Update the implementation to use a Vector instead of a map to keep the keys.
This allows to also use 0 and 264-1 values that HashMap reserves for its personal use.

Covered by updated test.

  • Modules/mediastream/RTCRtpSFrameTransform.idl:
  • Modules/mediastream/RTCRtpSFrameTransformer.cpp:

(WebCore::RTCRtpSFrameTransformer::setEncryptionKey):
(WebCore::RTCRtpSFrameTransformer::updateEncryptionKey):
(WebCore::RTCRtpSFrameTransformer::decryptFrame):

  • Modules/mediastream/RTCRtpSFrameTransformer.h:
  • Sources.txt:
  • WebCore.xcodeproj/project.pbxproj:
  • bindings/js/JSRTCRtpSFrameTransformCustom.cpp: Added.

(WebCore::JSRTCRtpSFrameTransform::setEncryptionKey):

LayoutTests:

  • webrtc/sframe-keys-expected.txt:
  • webrtc/sframe-keys.html:
Location:
trunk
Files:
1 added
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r273156 r273158  
     12021-02-19  Youenn Fablet  <youenn@apple.com>
     2
     3        Allow to use BigInt as key identifier
     4        https://bugs.webkit.org/show_bug.cgi?id=222165
     5
     6        Reviewed by Darin Adler.
     7
     8        * webrtc/sframe-keys-expected.txt:
     9        * webrtc/sframe-keys.html:
     10
    1112021-02-19  Fujii Hironori  <Hironori.Fujii@sony.com>
    212
  • trunk/LayoutTests/webrtc/sframe-keys-expected.txt

    r270532 r273158  
    11
    22
     3PASS Passing various key IDs
    34PASS Audio exchange with SFrame setup
    45PASS Add a new encryption key
    56PASS Add a new encryption key with key id
     7PASS Add a new encryption key with BigInt key id
    68
  • trunk/LayoutTests/webrtc/sframe-keys.html

    r270620 r273158  
    1111        <script>
    1212let sender, receiver;
    13 let key1, key2, key3;
     13let key1, key2, key3, key4;
     14
     15promise_test(async (test) => {
     16    const key = await crypto.subtle.importKey("raw", new Uint8Array([143, 77, 43, 10, 72, 19, 37, 67, 236, 219, 24, 93, 26, 165, 91, 178]), "HKDF", false, ["deriveBits", "deriveKey"]);
     17    const transform = new SFrameTransform;
     18
     19    await transform.setEncryptionKey(key);
     20    await transform.setEncryptionKey(key, 1);
     21
     22    await transform.setEncryptionKey(key, BigInt('18446744073709551613'));
     23    await transform.setEncryptionKey(key, BigInt('18446744073709551614'));
     24    await transform.setEncryptionKey(key, BigInt('18446744073709551615'));
     25    await transform.setEncryptionKey(key, BigInt('18446744073709551616')).then(assert_unreached, (e) => {
     26        assert_true(e instanceof RangeError);
     27        assert_equals(e.message, "Not a 64 bits integer");
     28    });
     29}, "Passing various key IDs");
    1430
    1531promise_test(async (test) => {
     
    1733    key2 = await crypto.subtle.importKey("raw", new Uint8Array([144, 77, 43, 10, 72, 19, 37, 67, 236, 219, 24, 93, 26, 165, 91, 178]), "HKDF", false, ["deriveBits", "deriveKey"]);
    1834    key3 = await crypto.subtle.importKey("raw", new Uint8Array([145, 77, 43, 10, 72, 19, 37, 67, 236, 219, 24, 93, 26, 165, 91, 178]), "HKDF", false, ["deriveBits", "deriveKey"]);
     35    key4 = await crypto.subtle.importKey("raw", new Uint8Array([146, 77, 43, 10, 72, 19, 37, 67, 236, 219, 24, 93, 26, 165, 91, 178]), "HKDF", false, ["deriveBits", "deriveKey"]);
    1936
    2037    const localStream = await navigator.mediaDevices.getUserMedia({audio: true});
     
    3148                transform.setEncryptionKey(key2);
    3249                transform.setEncryptionKey(key3, 1000);
     50                transform.setEncryptionKey(key4, BigInt('18446744073709551615'));
    3351                receiver = trackEvent.receiver;
    3452                receiver.transform = transform;
     
    7997   assert_true(await waitForCounterIncrease(receiver), "counter increase 2");
    8098}, "Add a new encryption key with key id");
     99
     100promise_test(async (test) => {
     101   sender.transform.setEncryptionKey(key4, BigInt('18446744073709551613'));
     102
     103   if (!window.internals)
     104       return;
     105
     106   assert_true(await waitForReceiverKeyId(receiver, 1000), "key id 3");
     107   assert_true(await waitForCounterIncrease(receiver), "counter increase 3");
     108}, "Add a new encryption key with BigInt key id");
    81109        </script>
    82110    </body>
  • trunk/Source/WebCore/ChangeLog

    r273156 r273158  
     12021-02-19  Youenn Fablet  <youenn@apple.com>
     2
     3        Allow to use BigInt as key identifier
     4        https://bugs.webkit.org/show_bug.cgi?id=222165
     5
     6        Reviewed by Darin Adler.
     7
     8        Allow to pass a BigInt as key id so as to use all of SFrame key ID 8 bytes.
     9        A RangeError is thrown if BigInt is more than 64 bits.
     10
     11        Update the implementation to use a Vector instead of a map to keep the keys.
     12        This allows to also use 0 and 2^64-1 values that HashMap reserves for its personal use.
     13
     14        Covered by updated test.
     15
     16        * Modules/mediastream/RTCRtpSFrameTransform.idl:
     17        * Modules/mediastream/RTCRtpSFrameTransformer.cpp:
     18        (WebCore::RTCRtpSFrameTransformer::setEncryptionKey):
     19        (WebCore::RTCRtpSFrameTransformer::updateEncryptionKey):
     20        (WebCore::RTCRtpSFrameTransformer::decryptFrame):
     21        * Modules/mediastream/RTCRtpSFrameTransformer.h:
     22        * Sources.txt:
     23        * WebCore.xcodeproj/project.pbxproj:
     24        * bindings/js/JSRTCRtpSFrameTransformCustom.cpp: Added.
     25        (WebCore::JSRTCRtpSFrameTransform::setEncryptionKey):
     26
    1272021-02-19  Fujii Hironori  <Hironori.Fujii@sony.com>
    228
  • trunk/Source/WebCore/Modules/mediastream/RTCRtpSFrameTransform.idl

    r270883 r273158  
    5151    [CallWith=ScriptExecutionContext] constructor(optional RTCRtpSFrameTransformOptions options);
    5252
    53     Promise<undefined> setEncryptionKey(CryptoKey key, optional unsigned long long keyID);
     53    [Custom] Promise<undefined> setEncryptionKey(CryptoKey key, optional any keyID);
    5454    // FIXME: Add support for missing methods.
    5555    // Promise<undefined> ratchetEncryptionKey();
  • trunk/Source/WebCore/Modules/mediastream/RTCRtpSFrameTransformer.cpp

    r270641 r273158  
    150150ExceptionOr<void> RTCRtpSFrameTransformer::setEncryptionKey(const Vector<uint8_t>& rawKey, Optional<uint64_t> keyId)
    151151{
    152     if (keyId && *keyId == std::numeric_limits<uint64_t>::max())
    153         return Exception { TypeError, "Key ID is too big" };
    154 
    155152    auto locker = holdLock(m_keyLock);
    156153    return updateEncryptionKey(rawKey, keyId, ShouldUpdateKeys::Yes);
     
    159156ExceptionOr<void> RTCRtpSFrameTransformer::updateEncryptionKey(const Vector<uint8_t>& rawKey, Optional<uint64_t> keyId, ShouldUpdateKeys shouldUpdateKeys)
    160157{
    161     ASSERT(!keyId || *keyId != std::numeric_limits<uint64_t>::max());
    162 
    163158    ASSERT(m_keyLock.isLocked());
    164159
     
    177172        return encryptionKeyResult.releaseException();
    178173
    179     if (!keyId)
    180         keyId = m_keys.size();
    181 
    182     m_keyId = *keyId;
    183     if (shouldUpdateKeys == ShouldUpdateKeys::Yes)
    184         m_keys.set(*keyId + 1, rawKey);
     174    if (shouldUpdateKeys == ShouldUpdateKeys::No)
     175        m_keyId = *keyId;
     176    else {
     177        // FIXME: In case keyId is not set, it might be best to use the first non used ID.
     178        if (!keyId)
     179            keyId = m_keys.size();
     180
     181        m_keyId = *keyId;
     182        m_keys.append({ m_keyId, rawKey });
     183    }
    185184
    186185    m_saltKey = saltKeyResult.releaseReturnValue();
     
    231230
    232231    if (header->keyId != m_keyId) {
    233         if (header->keyId == std::numeric_limits<uint64_t>::max())
     232        auto position = m_keys.findMatching([keyId = header->keyId](auto& item) { return item.keyId == keyId; });
     233        if (position == notFound)
    234234            return Exception { DataError, "Key ID is unknown" };
    235 
    236         auto iterator = m_keys.find(header->keyId + 1);
    237         if (iterator == m_keys.end())
    238             return Exception { DataError, "Key ID is unknown" };
    239         auto result = updateEncryptionKey(iterator->value, header->keyId, ShouldUpdateKeys::No);
     235        auto result = updateEncryptionKey(m_keys[position].keyData, header->keyId, ShouldUpdateKeys::No);
    240236        if (result.hasException())
    241237            return result.releaseException();
  • trunk/Source/WebCore/Modules/mediastream/RTCRtpSFrameTransformer.h

    r270641 r273158  
    8181    Vector<uint8_t> m_encryptionKey;
    8282    Vector<uint8_t> m_saltKey;
    83     HashMap<uint64_t, Vector<uint8_t>> m_keys;
     83
     84    struct IdentifiedKey {
     85        uint64_t keyId { 0 };
     86        Vector<uint8_t> keyData;
     87    };
     88    Vector<IdentifiedKey> m_keys;
    8489
    8590    bool m_isEncrypting { false };
  • trunk/Source/WebCore/Sources.txt

    r272925 r273158  
    595595bindings/js/JSPopStateEventCustom.cpp
    596596bindings/js/JSPromiseRejectionEventCustom.cpp
     597bindings/js/JSRTCRtpSFrameTransformCustom.cpp
    597598bindings/js/JSReadableStreamSourceCustom.cpp
    598599bindings/js/JSRemoteDOMWindowBase.cpp
  • trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj

    r273143 r273158  
    77867786                417253A81354BBBC00360F2A /* MediaControlTextTrackContainerElement.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MediaControlTextTrackContainerElement.cpp; sourceTree = "<group>"; };
    77877787                417253A91354BBBC00360F2A /* MediaControlTextTrackContainerElement.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MediaControlTextTrackContainerElement.h; sourceTree = "<group>"; };
     7788                41733D7D25DFBFC500A136E5 /* JSRTCRtpSFrameTransformCustom.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = JSRTCRtpSFrameTransformCustom.cpp; sourceTree = "<group>"; };
    77887789                4174E91E2535DCD600FE4202 /* MediaStreamTrackAudioSourceProviderCocoa.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MediaStreamTrackAudioSourceProviderCocoa.h; sourceTree = "<group>"; };
    77897790                4174E9202535DCDD00FE4202 /* MediaStreamTrackAudioSourceProviderCocoa.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = MediaStreamTrackAudioSourceProviderCocoa.cpp; sourceTree = "<group>"; };
     
    2717127172                                BCE1C43F0D9830F4003B02F2 /* JSLocationCustom.cpp */,
    2717227173                                4B6B5CBE216434FB00603817 /* JSPaintWorkletGlobalScopeCustom.cpp */,
     27174                                41733D7D25DFBFC500A136E5 /* JSRTCRtpSFrameTransformCustom.cpp */,
    2717327175                                418C395D1C8F0AAB0051C8A3 /* JSReadableStreamSourceCustom.cpp */,
    2717427176                                46BCBBBE2085005B00710638 /* JSRemoteDOMWindowCustom.cpp */,
Note: See TracChangeset for help on using the changeset viewer.