Changeset 269830 in webkit


Ignore:
Timestamp:
Nov 15, 2020 9:59:54 AM (3 years ago)
Author:
youenn@apple.com
Message:

Add a WebRTC SFrame transform
https://bugs.webkit.org/show_bug.cgi?id=218752

Reviewed by Eric Carlson.

Source/WebCore:

Introduce a RTCRtpSFrameTransform that implements the SFrame format.
RTCRtpSFrameTransform is a RTCRtpTransform that can be set to RTCRtp sender and receiver objects.
API supports setting encryption key.
Minor refactoring to reuse WebCrypto routines for encryption/decryption.

Test: webrtc/audio-sframe.html

  • DerivedSources-input.xcfilelist:
  • DerivedSources-output.xcfilelist:
  • DerivedSources.make:
  • Modules/mediastream/RTCRtpSFrameTransform.cpp: Added.

(WebCore::RTCRtpSFrameTransform::RTCRtpSFrameTransform):
(WebCore::RTCRtpSFrameTransform::~RTCRtpSFrameTransform):
(WebCore::RTCRtpSFrameTransform::setEncryptionKey):
(WebCore::RTCRtpSFrameTransform::initializeTransformer):
(WebCore::RTCRtpSFrameTransform::initializeBackendForReceiver):
(WebCore::RTCRtpSFrameTransform::initializeBackendForSender):
(WebCore::RTCRtpSFrameTransform::willClearBackend):

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

(WebCore::writeUInt64):
(WebCore::lengthOfUInt64):
(WebCore::computeFirstHeaderByte):
(WebCore::computeIV):
(WebCore::parseSFrameHeader):
(WebCore::RTCRtpSFrameTransformer::create):
(WebCore::RTCRtpSFrameTransformer::RTCRtpSFrameTransformer):
(WebCore::RTCRtpSFrameTransformer::~RTCRtpSFrameTransformer):
(WebCore::RTCRtpSFrameTransformer::setEncryptionKey):
(WebCore::RTCRtpSFrameTransformer::decryptFrame):
(WebCore::RTCRtpSFrameTransformer::encryptFrame):
(WebCore::RTCRtpSFrameTransformer::transform):
(WebCore::RTCRtpSFrameTransformer::computeSaltKey):
(WebCore::RTCRtpSFrameTransformer::computeAuthenticationKey):
(WebCore::RTCRtpSFrameTransformer::computeEncryptionKey):
(WebCore::RTCRtpSFrameTransformer::decryptData):
(WebCore::RTCRtpSFrameTransformer::encryptData):
(WebCore::RTCRtpSFrameTransformer::computeEncryptedDataSignature):

  • Modules/mediastream/RTCRtpSFrameTransformer.h: Added.

(WebCore::RTCRtpSFrameTransformer::setIsSending):
(WebCore::RTCRtpSFrameTransformer::setIsProcessingAudio):

  • Modules/mediastream/RTCRtpSFrameTransformerCocoa.cpp: Added.

(WebCore::deriveHDKFSHA256Bits):
(WebCore::transformAES_CTR):
(WebCore::RTCRtpSFrameTransformer::computeSaltKey):
(WebCore::RTCRtpSFrameTransformer::computeAuthenticationKey):
(WebCore::RTCRtpSFrameTransformer::computeEncryptionKey):
(WebCore::RTCRtpSFrameTransformer::decryptData):
(WebCore::RTCRtpSFrameTransformer::encryptData):
(WebCore::RTCRtpSFrameTransformer::computeEncryptedDataSignature):

  • Sources.txt:
  • SourcesCocoa.txt:
  • WebCore.xcodeproj/project.pbxproj:
  • WebCore.xcodeproj/project.pbxproj:
  • crypto/mac/CryptoAlgorithmAES_CTRMac.cpp:

(WebCore::CryptoAlgorithmAES_CTR::platformEncrypt):
(WebCore::CryptoAlgorithmAES_CTR::platformDecrypt):
(WebCore::transformAES_CTR): Deleted.

  • crypto/mac/CryptoAlgorithmHKDFMac.cpp:

(WebCore::CryptoAlgorithmHKDF::platformDeriveBits):

  • crypto/mac/CryptoUtilitiesCocoa.cpp: Added.

(WebCore::transformAES_CTR):
(WebCore::deriveHDKFSHA256Bits):

  • crypto/mac/CryptoUtilitiesCocoa.h: Added.
  • bindings/js/WebCoreBuiltinNames.h:

Tools:

Add unit tests that validate SFrame generation and parsing.

  • TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
  • TestWebKitAPI/Tests/WebCore/RTCRtpSFrameTransformerTests.cpp: Added.

(TestWebKitAPI::getRawKey):
(TestWebKitAPI::createVideoTransformer):
(TestWebKitAPI::checkVectorsAreEqual):
(TestWebKitAPI::TEST):

LayoutTests:

  • webrtc/audio-sframe-expected.txt: Added.
  • webrtc/audio-sframe.html: Added.
Location:
trunk
Files:
7 added
18 edited
4 copied

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r269827 r269830  
     12020-11-15  Youenn Fablet  <youenn@apple.com>
     2
     3        Add a WebRTC SFrame transform
     4        https://bugs.webkit.org/show_bug.cgi?id=218752
     5
     6        Reviewed by Eric Carlson.
     7
     8        * webrtc/audio-sframe-expected.txt: Added.
     9        * webrtc/audio-sframe.html: Added.
     10
    1112020-11-15  Philippe Normand  <pnormand@igalia.com>
    212
  • trunk/Source/WebCore/CMakeLists.txt

    r269764 r269830  
    403403    Modules/mediastream/RTCRtpReceiver.idl
    404404    Modules/mediastream/RTCRtpRtxParameters.idl
     405    Modules/mediastream/RTCRtpSFrameTransform.idl
    405406    Modules/mediastream/RTCRtpSendParameters.idl
    406407    Modules/mediastream/RTCRtpSender+Transform.idl
  • trunk/Source/WebCore/ChangeLog

    r269829 r269830  
     12020-11-15  Youenn Fablet  <youenn@apple.com>
     2
     3        Add a WebRTC SFrame transform
     4        https://bugs.webkit.org/show_bug.cgi?id=218752
     5
     6        Reviewed by Eric Carlson.
     7
     8        Introduce a RTCRtpSFrameTransform that implements the SFrame format.
     9        RTCRtpSFrameTransform is a RTCRtpTransform that can be set to RTCRtp sender and receiver objects.
     10        API supports setting encryption key.
     11        Minor refactoring to reuse WebCrypto routines for encryption/decryption.
     12
     13        Test: webrtc/audio-sframe.html
     14
     15        * DerivedSources-input.xcfilelist:
     16        * DerivedSources-output.xcfilelist:
     17        * DerivedSources.make:
     18        * Modules/mediastream/RTCRtpSFrameTransform.cpp: Added.
     19        (WebCore::RTCRtpSFrameTransform::RTCRtpSFrameTransform):
     20        (WebCore::RTCRtpSFrameTransform::~RTCRtpSFrameTransform):
     21        (WebCore::RTCRtpSFrameTransform::setEncryptionKey):
     22        (WebCore::RTCRtpSFrameTransform::initializeTransformer):
     23        (WebCore::RTCRtpSFrameTransform::initializeBackendForReceiver):
     24        (WebCore::RTCRtpSFrameTransform::initializeBackendForSender):
     25        (WebCore::RTCRtpSFrameTransform::willClearBackend):
     26        * Modules/mediastream/RTCRtpSFrameTransform.h: Added.
     27        * Modules/mediastream/RTCRtpSFrameTransform.idl: Added.
     28        * Modules/mediastream/RTCRtpSFrameTransformer.cpp: Added.
     29        (WebCore::writeUInt64):
     30        (WebCore::lengthOfUInt64):
     31        (WebCore::computeFirstHeaderByte):
     32        (WebCore::computeIV):
     33        (WebCore::parseSFrameHeader):
     34        (WebCore::RTCRtpSFrameTransformer::create):
     35        (WebCore::RTCRtpSFrameTransformer::RTCRtpSFrameTransformer):
     36        (WebCore::RTCRtpSFrameTransformer::~RTCRtpSFrameTransformer):
     37        (WebCore::RTCRtpSFrameTransformer::setEncryptionKey):
     38        (WebCore::RTCRtpSFrameTransformer::decryptFrame):
     39        (WebCore::RTCRtpSFrameTransformer::encryptFrame):
     40        (WebCore::RTCRtpSFrameTransformer::transform):
     41        (WebCore::RTCRtpSFrameTransformer::computeSaltKey):
     42        (WebCore::RTCRtpSFrameTransformer::computeAuthenticationKey):
     43        (WebCore::RTCRtpSFrameTransformer::computeEncryptionKey):
     44        (WebCore::RTCRtpSFrameTransformer::decryptData):
     45        (WebCore::RTCRtpSFrameTransformer::encryptData):
     46        (WebCore::RTCRtpSFrameTransformer::computeEncryptedDataSignature):
     47        * Modules/mediastream/RTCRtpSFrameTransformer.h: Added.
     48        (WebCore::RTCRtpSFrameTransformer::setIsSending):
     49        (WebCore::RTCRtpSFrameTransformer::setIsProcessingAudio):
     50        * Modules/mediastream/RTCRtpSFrameTransformerCocoa.cpp: Added.
     51        (WebCore::deriveHDKFSHA256Bits):
     52        (WebCore::transformAES_CTR):
     53        (WebCore::RTCRtpSFrameTransformer::computeSaltKey):
     54        (WebCore::RTCRtpSFrameTransformer::computeAuthenticationKey):
     55        (WebCore::RTCRtpSFrameTransformer::computeEncryptionKey):
     56        (WebCore::RTCRtpSFrameTransformer::decryptData):
     57        (WebCore::RTCRtpSFrameTransformer::encryptData):
     58        (WebCore::RTCRtpSFrameTransformer::computeEncryptedDataSignature):
     59        * Sources.txt:
     60        * SourcesCocoa.txt:
     61        * WebCore.xcodeproj/project.pbxproj:
     62        * WebCore.xcodeproj/project.pbxproj:
     63        * crypto/mac/CryptoAlgorithmAES_CTRMac.cpp:
     64        (WebCore::CryptoAlgorithmAES_CTR::platformEncrypt):
     65        (WebCore::CryptoAlgorithmAES_CTR::platformDecrypt):
     66        (WebCore::transformAES_CTR): Deleted.
     67        * crypto/mac/CryptoAlgorithmHKDFMac.cpp:
     68        (WebCore::CryptoAlgorithmHKDF::platformDeriveBits):
     69        * crypto/mac/CryptoUtilitiesCocoa.cpp: Added.
     70        (WebCore::transformAES_CTR):
     71        (WebCore::deriveHDKFSHA256Bits):
     72        * crypto/mac/CryptoUtilitiesCocoa.h: Added.
     73        * bindings/js/WebCoreBuiltinNames.h:
     74
    1752020-11-15  Youenn Fablet  <youenn@apple.com>
    276
  • trunk/Source/WebCore/DerivedSources-input.xcfilelist

    r269775 r269830  
    237237$(PROJECT_DIR)/Modules/mediastream/RTCRtpReceiver.idl
    238238$(PROJECT_DIR)/Modules/mediastream/RTCRtpRtxParameters.idl
     239$(PROJECT_DIR)/Modules/mediastream/RTCRtpSFrameTransform.idl
    239240$(PROJECT_DIR)/Modules/mediastream/RTCRtpSendParameters.idl
    240241$(PROJECT_DIR)/Modules/mediastream/RTCRtpSender+Transform.idl
  • trunk/Source/WebCore/DerivedSources-output.xcfilelist

    r269764 r269830  
    17061706$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSRTCRtpRtxParameters.cpp
    17071707$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSRTCRtpRtxParameters.h
     1708$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSRTCRtpSFrameTransform.cpp
     1709$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSRTCRtpSFrameTransform.h
    17081710$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSRTCRtpSendParameters.cpp
    17091711$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSRTCRtpSendParameters.h
  • trunk/Source/WebCore/DerivedSources.make

    r269775 r269830  
    264264    $(WebCore)/Modules/mediastream/RTCRtpSender.idl \
    265265    $(WebCore)/Modules/mediastream/RTCRtpSender+Transform.idl \
     266    $(WebCore)/Modules/mediastream/RTCRtpSFrameTransform.idl \
    266267    $(WebCore)/Modules/mediastream/RTCRtpSynchronizationSource.idl \
    267268    $(WebCore)/Modules/mediastream/RTCRtpTransceiver.idl \
  • trunk/Source/WebCore/Modules/mediastream/RTCRtpSFrameTransform.h

    r269829 r269830  
    2424 */
    2525
    26 [
    27     Conditional=WEB_RTC,
    28     JSGenerateToJSObject,
    29     LegacyNoInterfaceObject,
    30 ] interface MockRTCRtpTransform : RTCRtpTransform {
    31     readonly attribute boolean isProcessing;
     26#pragma once
     27
     28#if ENABLE(WEB_RTC)
     29
     30#include "JSDOMPromiseDeferred.h"
     31#include "RTCRtpTransform.h"
     32
     33namespace WebCore {
     34
     35class CryptoKey;
     36class RTCRtpSFrameTransformer;
     37
     38class RTCRtpSFrameTransform final : public RTCRtpTransform {
     39public:
     40    static Ref<RTCRtpSFrameTransform> create() { return adoptRef(*new RTCRtpSFrameTransform); }
     41    ~RTCRtpSFrameTransform();
     42
     43    void setEncryptionKey(CryptoKey&, Optional<uint64_t>, DOMPromiseDeferred<void>&&);
     44
     45    WEBCORE_EXPORT uint64_t counterForTesting() const;
     46
     47private:
     48    RTCRtpSFrameTransform();
     49
     50    void initializeBackendForReceiver(RTCRtpTransformBackend&) final;
     51    void initializeBackendForSender(RTCRtpTransformBackend&) final;
     52    void willClearBackend(RTCRtpTransformBackend&) final;
     53
     54    enum class Side { Sender, Receiver };
     55    void initializeTransformer(RTCRtpTransformBackend&, Side);
     56
     57    Ref<RTCRtpSFrameTransformer> m_transformer;
    3258};
     59
     60} // namespace WebCore
     61
     62#endif // ENABLE(WEB_RTC)
  • trunk/Source/WebCore/Modules/mediastream/RTCRtpSFrameTransform.idl

    r269829 r269830  
    2626[
    2727    Conditional=WEB_RTC,
    28     JSGenerateToJSObject,
    29     LegacyNoInterfaceObject,
    30 ] interface MockRTCRtpTransform : RTCRtpTransform {
    31     readonly attribute boolean isProcessing;
     28    EnabledBySetting=WebRTCInsertableStreams,
     29    ExportMacro=WEBCORE_EXPORT,
     30    Exposed=Window,
     31    JSGenerateToNativeObject,
     32] interface RTCRtpSFrameTransform : RTCRtpTransform {
     33    constructor();
     34
     35    Promise<undefined> setEncryptionKey(CryptoKey key, optional unsigned long long keyID);
     36    // FIXME: Add support for missing methods.
     37    // Promise<undefined> ratchetEncryptionKey();
     38    // Promise<undefined> setSigningKey(CryptoKey key);
    3239};
  • trunk/Source/WebCore/Sources.txt

    r269812 r269830  
    164164Modules/mediastream/RTCPeerConnectionIceEvent.cpp
    165165Modules/mediastream/RTCRtpReceiver.cpp
     166Modules/mediastream/RTCRtpSFrameTransform.cpp
     167Modules/mediastream/RTCRtpSFrameTransformer.cpp
    166168Modules/mediastream/RTCRtpSender.cpp
    167169Modules/mediastream/RTCRtpTransform.cpp
     
    33213323JSRTCRtpReceiver.cpp
    33223324JSRTCRtpRtxParameters.cpp
     3325JSRTCRtpSFrameTransform.cpp
    33233326JSRTCRtpSendParameters.cpp
    33243327JSRTCRtpSender.cpp
  • trunk/Source/WebCore/SourcesCocoa.txt

    r269678 r269830  
    9090Modules/async-clipboard/ios/ClipboardImageReaderIOS.mm
    9191Modules/async-clipboard/mac/ClipboardImageReaderMac.mm
     92Modules/mediastream/RTCRtpSFrameTransformerCocoa.cpp
    9293Modules/plugins/QuickTimePluginReplacement.mm
    9394Modules/plugins/YouTubePluginReplacement.cpp
     
    129130crypto/mac/CryptoKeyMac.cpp
    130131crypto/mac/CryptoKeyRSAMac.cpp
     132crypto/mac/CryptoUtilitiesCocoa.cpp
    131133crypto/mac/SerializedCryptoKeyWrapMac.mm
    132134dom/DataTransferMac.mm
  • trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj

    r269824 r269830  
    11091109                4181C5D72555C49A00AEB0FF /* MockRTCRtpTransform.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4181C5D32555C1B100AEB0FF /* MockRTCRtpTransform.cpp */; };
    11101110                4181C639255AE90F00AEB0FF /* JSMockRTCRtpTransform.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2D6F3E921C1F85550061DBE4 /* JSMockRTCRtpTransform.cpp */; };
     1111                4181C648255B4C2800AEB0FF /* RTCRtpSFrameTransformer.h in Headers */ = {isa = PBXBuildFile; fileRef = 4181C642255B4C2600AEB0FF /* RTCRtpSFrameTransformer.h */; settings = {ATTRIBUTES = (Private, ); }; };
     1112                4181C64A255B4C2800AEB0FF /* RTCRtpSFrameTransform.h in Headers */ = {isa = PBXBuildFile; fileRef = 4181C644255B4C2700AEB0FF /* RTCRtpSFrameTransform.h */; };
    11111113                418205471E53E98C00D62207 /* RTCController.h in Headers */ = {isa = PBXBuildFile; fileRef = 418205451E53C8CD00D62207 /* RTCController.h */; settings = {ATTRIBUTES = (Private, ); }; };
    11121114                41826BF223FB597700B922B1 /* DocumentIdentifier.h in Headers */ = {isa = PBXBuildFile; fileRef = 41826BF123FB597000B922B1 /* DocumentIdentifier.h */; settings = {ATTRIBUTES = (Private, ); }; };
     
    76997701                4181C5D52555C1B900AEB0FF /* MockRTCRtpTransform.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MockRTCRtpTransform.h; sourceTree = "<group>"; };
    77007702                4181C636255AE26100AEB0FF /* MockRTCRtpTransform.idl */ = {isa = PBXFileReference; lastKnownFileType = text; path = MockRTCRtpTransform.idl; sourceTree = "<group>"; };
     7703                4181C63F255B4C2500AEB0FF /* RTCRtpSFrameTransformerCocoa.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RTCRtpSFrameTransformerCocoa.cpp; sourceTree = "<group>"; };
     7704                4181C641255B4C2600AEB0FF /* RTCRtpSFrameTransformer.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RTCRtpSFrameTransformer.cpp; sourceTree = "<group>"; };
     7705                4181C642255B4C2600AEB0FF /* RTCRtpSFrameTransformer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RTCRtpSFrameTransformer.h; sourceTree = "<group>"; };
     7706                4181C643255B4C2700AEB0FF /* RTCRtpSFrameTransform.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = RTCRtpSFrameTransform.idl; sourceTree = "<group>"; };
     7707                4181C644255B4C2700AEB0FF /* RTCRtpSFrameTransform.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RTCRtpSFrameTransform.h; sourceTree = "<group>"; };
     7708                4181C645255B4C2800AEB0FF /* RTCRtpSFrameTransform.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RTCRtpSFrameTransform.cpp; sourceTree = "<group>"; };
    77017709                418205451E53C8CD00D62207 /* RTCController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RTCController.h; sourceTree = "<group>"; };
    77027710                418205481E53EAAD00D62207 /* RTCController.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RTCController.cpp; sourceTree = "<group>"; };
     
    77327740                419BC2DD1685329900D64D6D /* VisitedLinkState.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = VisitedLinkState.h; sourceTree = "<group>"; };
    77337741                419BE7521BC7F3DB00E1C85B /* WebCoreBuiltinNames.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebCoreBuiltinNames.h; sourceTree = "<group>"; };
     7742                419D9305255E842700DA1984 /* CryptoUtilitiesCocoa.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CryptoUtilitiesCocoa.h; sourceTree = "<group>"; };
     7743                419D9307255E842800DA1984 /* CryptoUtilitiesCocoa.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = CryptoUtilitiesCocoa.cpp; sourceTree = "<group>"; };
    77347744                419FAFAD1ABABCD5005B3572 /* ReadableStreamBYOBReader.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = ReadableStreamBYOBReader.idl; sourceTree = "<group>"; };
    77357745                419FAFAD1ABABCD5005B828B /* ReadableStreamDefaultReader.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = ReadableStreamDefaultReader.idl; sourceTree = "<group>"; };
     
    1708917099                                414AD3FC2149842000521676 /* RTCRtpSendParameters.h */,
    1709017100                                414AD3FE2149842000521676 /* RTCRtpSendParameters.idl */,
     17101                                4181C645255B4C2800AEB0FF /* RTCRtpSFrameTransform.cpp */,
     17102                                4181C644255B4C2700AEB0FF /* RTCRtpSFrameTransform.h */,
     17103                                4181C643255B4C2700AEB0FF /* RTCRtpSFrameTransform.idl */,
     17104                                4181C641255B4C2600AEB0FF /* RTCRtpSFrameTransformer.cpp */,
     17105                                4181C642255B4C2600AEB0FF /* RTCRtpSFrameTransformer.h */,
     17106                                4181C63F255B4C2500AEB0FF /* RTCRtpSFrameTransformerCocoa.cpp */,
    1709117107                                415E1BB62150152A0022DA96 /* RTCRtpSynchronizationSource.h */,
    1709217108                                415E1BB7215015300022DA96 /* RTCRtpSynchronizationSource.idl */,
     
    2825628272                                E19AC3F8182566F700349426 /* CryptoKeyMac.cpp */,
    2825728273                                E164FAA418315E1A00DB4E61 /* CryptoKeyRSAMac.cpp */,
     28274                                419D9307255E842800DA1984 /* CryptoUtilitiesCocoa.cpp */,
     28275                                419D9305255E842700DA1984 /* CryptoUtilitiesCocoa.h */,
    2825828276                                E18DF33618AAF14D00773E59 /* SerializedCryptoKeyWrapMac.mm */,
    2825928277                        );
     
    3409434112                                5E2C43611BCEE3230001E2BC /* RTCRtpSender.h in Headers */,
    3409534113                                413C8B332552F27D00E65055 /* RTCRtpSenderWithTransform.h in Headers */,
     34114                                4181C64A255B4C2800AEB0FF /* RTCRtpSFrameTransform.h in Headers */,
     34115                                4181C648255B4C2800AEB0FF /* RTCRtpSFrameTransformer.h in Headers */,
    3409634116                                5E5E2B141CFC3E75000C0D85 /* RTCRtpTransceiver.h in Headers */,
    3409734117                                31EB54DF1E7DC74400C1623B /* RTCRtpTransceiverDirection.h in Headers */,
  • trunk/Source/WebCore/bindings/js/WebCoreBuiltinNames.h

    r269764 r269830  
    220220    macro(RTCPeerConnectionIceEvent) \
    221221    macro(RTCRtpReceiver) \
     222    macro(RTCRtpSFrameTransform) \
    222223    macro(RTCRtpSender) \
    223224    macro(RTCRtpTransceiver) \
  • trunk/Source/WebCore/crypto/mac/CryptoAlgorithmAES_CTRMac.cpp

    r260238 r269830  
    3232#include "CryptoAlgorithmAesCtrParams.h"
    3333#include "CryptoKeyAES.h"
    34 #include <CommonCrypto/CommonCrypto.h>
     34#include "CryptoUtilitiesCocoa.h"
    3535
    3636namespace WebCore {
    37 
    38 static ExceptionOr<Vector<uint8_t>> transformAES_CTR(CCOperation operation, const Vector<uint8_t>& counter, size_t counterLength, const Vector<uint8_t>& key, const Vector<uint8_t>& data)
    39 {
    40     // FIXME: We should remove the following hack once <rdar://problem/31361050> is fixed.
    41     // counter = nonce + counter
    42     // CommonCrypto currently can neither reset the counter nor detect overflow once the counter reaches its max value restricted
    43     // by the counterLength. It then increments the nonce which should stay same for the whole operation. To remedy this issue,
    44     // we detect the overflow ahead and divide the operation into two parts.
    45     size_t numberOfBlocks = data.size() % kCCBlockSizeAES128 ? data.size() / kCCBlockSizeAES128 + 1 : data.size() / kCCBlockSizeAES128;
    46 
    47     // Detect loop
    48     if (counterLength < sizeof(size_t) * 8 && numberOfBlocks > (static_cast<size_t>(1) << counterLength))
    49         return Exception { OperationError };
    50 
    51     // Calculate capacity before overflow
    52     CryptoAlgorithmAES_CTR::CounterBlockHelper counterBlockHelper(counter, counterLength);
    53     size_t capacity = counterBlockHelper.countToOverflowSaturating();
    54 
    55     // Divide data into two parts if necessary.
    56     size_t headSize = data.size();
    57     if (capacity < numberOfBlocks)
    58         headSize = capacity * kCCBlockSizeAES128;
    59 
    60     // first part: compute the first n=capacity blocks of data if capacity is insufficient. Otherwise, return the result.
    61     CCCryptorRef cryptor;
    62     CCCryptorStatus status = CCCryptorCreateWithMode(operation, kCCModeCTR, kCCAlgorithmAES128, ccNoPadding, counter.data(), key.data(), key.size(), 0, 0, 0, kCCModeOptionCTR_BE, &cryptor);
    63     if (status)
    64         return Exception { OperationError };
    65 
    66     Vector<uint8_t> head(CCCryptorGetOutputLength(cryptor, headSize, true));
    67 
    68     size_t bytesWritten;
    69     status = CCCryptorUpdate(cryptor, data.data(), headSize, head.data(), head.size(), &bytesWritten);
    70     if (status)
    71         return Exception { OperationError };
    72 
    73     uint8_t* p = head.data() + bytesWritten;
    74     status = CCCryptorFinal(cryptor, p, head.end() - p, &bytesWritten);
    75     p += bytesWritten;
    76     if (status)
    77         return Exception { OperationError };
    78 
    79     ASSERT_WITH_SECURITY_IMPLICATION(p <= head.end());
    80     head.shrink(p - head.begin());
    81 
    82     CCCryptorRelease(cryptor);
    83 
    84     if (capacity >= numberOfBlocks)
    85         return WTFMove(head);
    86 
    87     // second part: compute the remaining data and append them to the head.
    88     // reset counter
    89     Vector<uint8_t> remainingCounter = counterBlockHelper.counterVectorAfterOverflow();
    90     status = CCCryptorCreateWithMode(operation, kCCModeCTR, kCCAlgorithmAES128, ccNoPadding, remainingCounter.data(), key.data(), key.size(), 0, 0, 0, kCCModeOptionCTR_BE, &cryptor);
    91     if (status)
    92         return Exception { OperationError };
    93 
    94     size_t tailSize = data.size() - headSize;
    95     Vector<uint8_t> tail(CCCryptorGetOutputLength(cryptor, tailSize, true));
    96 
    97     status = CCCryptorUpdate(cryptor, data.data() + headSize, tailSize, tail.data(), tail.size(), &bytesWritten);
    98     if (status)
    99         return Exception { OperationError };
    100 
    101     p = tail.data() + bytesWritten;
    102     status = CCCryptorFinal(cryptor, p, tail.end() - p, &bytesWritten);
    103     p += bytesWritten;
    104     if (status)
    105         return Exception { OperationError };
    106 
    107     ASSERT_WITH_SECURITY_IMPLICATION(p <= tail.end());
    108     tail.shrink(p - tail.begin());
    109 
    110     CCCryptorRelease(cryptor);
    111 
    112     head.appendVector(tail);
    113     return WTFMove(head);
    114 }
    11537
    11638ExceptionOr<Vector<uint8_t>> CryptoAlgorithmAES_CTR::platformEncrypt(const CryptoAlgorithmAesCtrParams& parameters, const CryptoKeyAES& key, const Vector<uint8_t>& plainText)
    11739{
    11840    ASSERT(parameters.counterVector().size() == kCCBlockSizeAES128);
    119     return transformAES_CTR(kCCEncrypt, parameters.counterVector(), parameters.length, key.key(), plainText);
     41    return transformAES_CTR(kCCEncrypt, parameters.counterVector(), parameters.length, key.key(), plainText.data(), plainText.size());
    12042}
    12143
    12244ExceptionOr<Vector<uint8_t>> CryptoAlgorithmAES_CTR::platformDecrypt(const CryptoAlgorithmAesCtrParams& parameters, const CryptoKeyAES& key, const Vector<uint8_t>& cipherText)
    12345{
    124       ASSERT(parameters.counterVector().size() == kCCBlockSizeAES128);
    125     return transformAES_CTR(kCCDecrypt, parameters.counterVector(), parameters.length, key.key(), cipherText);
     46    ASSERT(parameters.counterVector().size() == kCCBlockSizeAES128);
     47    return transformAES_CTR(kCCDecrypt, parameters.counterVector(), parameters.length, key.key(), cipherText.data(), cipherText.size());
    12648}
     49
    12750
    12851} // namespace WebCore
  • trunk/Source/WebCore/crypto/mac/CryptoAlgorithmHKDFMac.cpp

    r242988 r269830  
    2929#if ENABLE(WEB_CRYPTO)
    3030
    31 #include "CommonCryptoUtilities.h"
    3231#include "CryptoAlgorithmHkdfParams.h"
    3332#include "CryptoKeyRaw.h"
     33#include "CryptoUtilitiesCocoa.h"
    3434
    3535namespace WebCore {
     
    3737ExceptionOr<Vector<uint8_t>> CryptoAlgorithmHKDF::platformDeriveBits(const CryptoAlgorithmHkdfParams& parameters, const CryptoKeyRaw& key, size_t length)
    3838{
    39     Vector<uint8_t> result(length / 8);
    4039    CCDigestAlgorithm digestAlgorithm;
    4140    getCommonCryptoDigestAlgorithm(parameters.hashIdentifier, digestAlgorithm);
    4241
    43     ALLOW_DEPRECATED_DECLARATIONS_BEGIN
    44     // <rdar://problem/32439455> Currently, when key data is empty, CCKeyDerivationHMac will bail out.
    45     // <rdar://problem/48896021> Reminder: Switch to CCDeriveKey now that CCKeyDerivationHMac is deprecated.
    46     if (CCKeyDerivationHMac(kCCKDFAlgorithmHKDF, digestAlgorithm, 0, key.key().data(), key.key().size(), 0, 0, parameters.infoVector().data(), parameters.infoVector().size(), 0, 0, parameters.saltVector().data(), parameters.saltVector().size(), result.data(), result.size()))
    47         return Exception { OperationError };
    48     ALLOW_DEPRECATED_DECLARATIONS_END
    49     return WTFMove(result);
     42    return deriveHDKFBits(digestAlgorithm, key.key().data(), key.key().size(), parameters.saltVector().data(), parameters.saltVector().size(), parameters.infoVector().data(), parameters.infoVector().size(), length);
    5043}
    5144
  • trunk/Source/WebCore/crypto/mac/CryptoUtilitiesCocoa.cpp

    r269829 r269830  
    11/*
    2  * Copyright (C) 2017 Apple Inc. All rights reserved.
    3  * Copyright (C) 2020 Sony Interactive Entertainment Inc.
     2 * Copyright (C) 2020 Apple Inc. All rights reserved.
    43 *
    54 * Redistribution and use in source and binary forms, with or without
     
    2625
    2726#include "config.h"
     27#include "CryptoUtilitiesCocoa.h"
     28
     29#if ENABLE(WEB_CRYPTO) || ENABLE(WEB_RTC)
     30
    2831#include "CryptoAlgorithmAES_CTR.h"
    29 
    30 #if ENABLE(WEB_CRYPTO)
    31 
    32 #include "CryptoAlgorithmAesCtrParams.h"
    33 #include "CryptoKeyAES.h"
    3432#include <CommonCrypto/CommonCrypto.h>
    3533
    3634namespace WebCore {
    3735
    38 static ExceptionOr<Vector<uint8_t>> transformAES_CTR(CCOperation operation, const Vector<uint8_t>& counter, size_t counterLength, const Vector<uint8_t>& key, const Vector<uint8_t>& data)
     36ExceptionOr<Vector<uint8_t>> transformAES_CTR(CCOperation operation, const Vector<uint8_t>& counter, size_t counterLength, const Vector<uint8_t>& key, const uint8_t* data, size_t dataSize)
    3937{
    4038    // FIXME: We should remove the following hack once <rdar://problem/31361050> is fixed.
     
    4341    // by the counterLength. It then increments the nonce which should stay same for the whole operation. To remedy this issue,
    4442    // we detect the overflow ahead and divide the operation into two parts.
    45     size_t numberOfBlocks = data.size() % kCCBlockSizeAES128 ? data.size() / kCCBlockSizeAES128 + 1 : data.size() / kCCBlockSizeAES128;
     43    size_t numberOfBlocks = dataSize % kCCBlockSizeAES128 ? dataSize / kCCBlockSizeAES128 + 1 : dataSize / kCCBlockSizeAES128;
    4644
    4745    // Detect loop
     
    5452
    5553    // Divide data into two parts if necessary.
    56     size_t headSize = data.size();
     54    size_t headSize = dataSize;
    5755    if (capacity < numberOfBlocks)
    5856        headSize = capacity * kCCBlockSizeAES128;
     
    6765
    6866    size_t bytesWritten;
    69     status = CCCryptorUpdate(cryptor, data.data(), headSize, head.data(), head.size(), &bytesWritten);
     67    status = CCCryptorUpdate(cryptor, data, headSize, head.data(), head.size(), &bytesWritten);
    7068    if (status)
    7169        return Exception { OperationError };
     
    9290        return Exception { OperationError };
    9391
    94     size_t tailSize = data.size() - headSize;
     92    size_t tailSize = dataSize - headSize;
    9593    Vector<uint8_t> tail(CCCryptorGetOutputLength(cryptor, tailSize, true));
    9694
    97     status = CCCryptorUpdate(cryptor, data.data() + headSize, tailSize, tail.data(), tail.size(), &bytesWritten);
     95    status = CCCryptorUpdate(cryptor, data + headSize, tailSize, tail.data(), tail.size(), &bytesWritten);
    9896    if (status)
    9997        return Exception { OperationError };
     
    114112}
    115113
    116 ExceptionOr<Vector<uint8_t>> CryptoAlgorithmAES_CTR::platformEncrypt(const CryptoAlgorithmAesCtrParams& parameters, const CryptoKeyAES& key, const Vector<uint8_t>& plainText)
     114ExceptionOr<Vector<uint8_t>> deriveHDKFBits(CCDigestAlgorithm digestAlgorithm, const uint8_t* key, size_t keySize, const uint8_t* salt, size_t saltSize, const uint8_t* info, size_t infoSize, size_t length)
    117115{
    118     ASSERT(parameters.counterVector().size() == kCCBlockSizeAES128);
    119     return transformAES_CTR(kCCEncrypt, parameters.counterVector(), parameters.length, key.key(), plainText);
     116    Vector<uint8_t> result(length / 8);
     117    Vector<uint8_t> infoVector;
     118
     119    ALLOW_DEPRECATED_DECLARATIONS_BEGIN
     120    // <rdar://problem/32439455> Currently, when key data is empty, CCKeyDerivationHMac will bail out.
     121    // <rdar://problem/48896021> Reminder: Switch to CCDeriveKey now that CCKeyDerivationHMac is deprecated.
     122    if (CCKeyDerivationHMac(kCCKDFAlgorithmHKDF, digestAlgorithm, 0, key, keySize, 0, 0, info, infoSize, 0, 0, salt, saltSize, result.data(), result.size()))
     123        return Exception { OperationError };
     124    ALLOW_DEPRECATED_DECLARATIONS_END
     125    return WTFMove(result);
    120126}
    121127
    122 ExceptionOr<Vector<uint8_t>> CryptoAlgorithmAES_CTR::platformDecrypt(const CryptoAlgorithmAesCtrParams& parameters, const CryptoKeyAES& key, const Vector<uint8_t>& cipherText)
     128ExceptionOr<Vector<uint8_t>> deriveHDKFSHA256Bits(const uint8_t* key, size_t keySize, const uint8_t* salt, size_t saltSize, const uint8_t* info, size_t infoSize, size_t length)
    123129{
    124       ASSERT(parameters.counterVector().size() == kCCBlockSizeAES128);
    125     return transformAES_CTR(kCCDecrypt, parameters.counterVector(), parameters.length, key.key(), cipherText);
     130    return deriveHDKFBits(kCCDigestSHA256, key, keySize, salt, saltSize, info, infoSize, length);
    126131}
    127132
  • trunk/Source/WebCore/crypto/mac/CryptoUtilitiesCocoa.h

    r269829 r269830  
    11/*
    2  * Copyright (C) 2017 Apple Inc. All rights reserved.
     2 * Copyright (C) 2020 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    2424 */
    2525
    26 #include "config.h"
    27 #include "CryptoAlgorithmHKDF.h"
     26#pragma once
    2827
    29 #if ENABLE(WEB_CRYPTO)
     28#if ENABLE(WEB_CRYPTO) || ENABLE(WEB_RTC)
    3029
    31 #include "CommonCryptoUtilities.h"
    32 #include "CryptoAlgorithmHkdfParams.h"
    33 #include "CryptoKeyRaw.h"
     30#include "ExceptionOr.h"
     31#include <wtf/Vector.h>
     32
     33typedef uint32_t CCDigestAlgorithm;
     34typedef uint32_t CCOperation;
    3435
    3536namespace WebCore {
    3637
    37 ExceptionOr<Vector<uint8_t>> CryptoAlgorithmHKDF::platformDeriveBits(const CryptoAlgorithmHkdfParams& parameters, const CryptoKeyRaw& key, size_t length)
    38 {
    39     Vector<uint8_t> result(length / 8);
    40     CCDigestAlgorithm digestAlgorithm;
    41     getCommonCryptoDigestAlgorithm(parameters.hashIdentifier, digestAlgorithm);
     38ExceptionOr<Vector<uint8_t>> transformAES_CTR(CCOperation, const Vector<uint8_t>& counter, size_t counterLength, const Vector<uint8_t>& key, const uint8_t* data, size_t dataSize);
     39ExceptionOr<Vector<uint8_t>> deriveHDKFBits(CCDigestAlgorithm, const uint8_t* key, size_t keySize, const uint8_t* salt, size_t saltSize, const uint8_t* info, size_t infoSize, size_t length);
     40ExceptionOr<Vector<uint8_t>> deriveHDKFSHA256Bits(const uint8_t* key, size_t keySize, const uint8_t* salt, size_t saltSize, const uint8_t* info, size_t infoSize, size_t length);
    4241
    43     ALLOW_DEPRECATED_DECLARATIONS_BEGIN
    44     // <rdar://problem/32439455> Currently, when key data is empty, CCKeyDerivationHMac will bail out.
    45     // <rdar://problem/48896021> Reminder: Switch to CCDeriveKey now that CCKeyDerivationHMac is deprecated.
    46     if (CCKeyDerivationHMac(kCCKDFAlgorithmHKDF, digestAlgorithm, 0, key.key().data(), key.key().size(), 0, 0, parameters.infoVector().data(), parameters.infoVector().size(), 0, 0, parameters.saltVector().data(), parameters.saltVector().size(), result.data(), result.size()))
    47         return Exception { OperationError };
    48     ALLOW_DEPRECATED_DECLARATIONS_END
    49     return WTFMove(result);
    50 }
     42} // namespace WebCore
    5143
    52 }
    53 
    54 #endif // ENABLE(WEB_CRYPTO)
     44#endif // ENABLE(WEB_CRYPTO) || ENABLE(WEB_RTC)
  • trunk/Source/WebCore/testing/Internals.cpp

    r269785 r269830  
    154154#include "PrintContext.h"
    155155#include "PseudoElement.h"
     156#include "RTCRtpSFrameTransform.h"
    156157#include "Range.h"
    157158#include "ReadableStream.h"
     
    15821583}
    15831584
     1585uint64_t Internals::sframeCounter(const RTCRtpSFrameTransform& transform)
     1586{
     1587    return transform.counterForTesting();
     1588}
     1589
    15841590void Internals::setEnableWebRTCEncryption(bool value)
    15851591{
  • trunk/Source/WebCore/testing/Internals.h

    r269784 r269830  
    125125#endif
    126126
     127#if ENABLE(WEB_RTC)
     128class RTCRtpSFrameTransform;
     129#endif
     130
    127131#if ENABLE(WEBXR)
    128132class WebXRTest;
     
    608612    void setWebRTCVP9VTBSupport(bool);
    609613    Ref<MockRTCRtpTransform> createMockRTCRtpTransform();
     614    uint64_t sframeCounter(const RTCRtpSFrameTransform&);
    610615    void setEnableWebRTCEncryption(bool);
    611616    void setUseDTLS10(bool);
  • trunk/Source/WebCore/testing/Internals.idl

    r269764 r269830  
    804804    [Conditional=WEB_RTC] undefined setWebRTCVP9VTBSupport(boolean allowed);
    805805    [Conditional=WEB_RTC] MockRTCRtpTransform createMockRTCRtpTransform();
     806    [Conditional=WEB_RTC] unsigned long long sframeCounter(RTCRtpSFrameTransform transform);
    806807
    807808    [Conditional=MEDIA_STREAM] undefined setMockAudioTrackChannelNumber(MediaStreamTrack track, unsigned short count);
  • trunk/Source/WebCore/testing/MockRTCRtpTransform.idl

    r269764 r269830  
    2727    Conditional=WEB_RTC,
    2828    JSGenerateToJSObject,
     29    JSGenerateToNativeObject,
    2930    LegacyNoInterfaceObject,
    3031] interface MockRTCRtpTransform : RTCRtpTransform {
  • trunk/Tools/ChangeLog

    r269810 r269830  
     12020-11-15  Youenn Fablet  <youenn@apple.com>
     2
     3        Add a WebRTC SFrame transform
     4        https://bugs.webkit.org/show_bug.cgi?id=218752
     5
     6        Reviewed by Eric Carlson.
     7
     8        Add unit tests that validate SFrame generation and parsing.
     9
     10        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
     11        * TestWebKitAPI/Tests/WebCore/RTCRtpSFrameTransformerTests.cpp: Added.
     12        (TestWebKitAPI::getRawKey):
     13        (TestWebKitAPI::createVideoTransformer):
     14        (TestWebKitAPI::checkVectorsAreEqual):
     15        (TestWebKitAPI::TEST):
     16
    1172020-11-13  Sihui Liu  <sihui_liu@apple.com>
    218
  • trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj

    r269810 r269830  
    237237                414AD6862285D1C000777F2D /* StorageQuota.mm in Sources */ = {isa = PBXBuildFile; fileRef = 414AD6852285D1B000777F2D /* StorageQuota.mm */; };
    238238                41661C662355E85E00D33C27 /* getUserMedia-webaudio.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 41661C652355D98B00D33C27 /* getUserMedia-webaudio.html */; };
     239                4181C62D255A891100AEB0FF /* RTCRtpSFrameTransformerTests.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4181C62C255A891100AEB0FF /* RTCRtpSFrameTransformerTests.cpp */; };
    239240                41848F4424891879000E2588 /* open-window-with-file-url-with-host.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 41848F4324891815000E2588 /* open-window-with-file-url-with-host.html */; };
    240241                41882F0321010C0D002FF288 /* ProcessPreWarming.mm in Sources */ = {isa = PBXBuildFile; fileRef = 41882F0221010A70002FF288 /* ProcessPreWarming.mm */; };
     
    19631964                414AD6852285D1B000777F2D /* StorageQuota.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = StorageQuota.mm; sourceTree = "<group>"; };
    19641965                41661C652355D98B00D33C27 /* getUserMedia-webaudio.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "getUserMedia-webaudio.html"; sourceTree = "<group>"; };
     1966                4181C62C255A891100AEB0FF /* RTCRtpSFrameTransformerTests.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RTCRtpSFrameTransformerTests.cpp; sourceTree = "<group>"; };
    19651967                41848F4324891815000E2588 /* open-window-with-file-url-with-host.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "open-window-with-file-url-with-host.html"; sourceTree = "<group>"; };
    19661968                41882F0221010A70002FF288 /* ProcessPreWarming.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = ProcessPreWarming.mm; sourceTree = "<group>"; };
     
    35353537                                6B4E861B2220A5520022F389 /* RegistrableDomain.cpp */,
    35363538                                F418BE141F71B7DC001970E6 /* RoundedRectTests.cpp */,
     3539                                4181C62C255A891100AEB0FF /* RTCRtpSFrameTransformerTests.cpp */,
    35373540                                CDCFA7A91E45122F00C2433D /* SampleMap.cpp */,
    35383541                                CE06DF9A1E1851F200E570C9 /* SecurityOrigin.cpp */,
     
    54235426                                46E816F81E79E29C00375ADC /* RestoreStateAfterTermination.mm in Sources */,
    54245427                                F418BE151F71B7DC001970E6 /* RoundedRectTests.cpp in Sources */,
     5428                                4181C62D255A891100AEB0FF /* RTCRtpSFrameTransformerTests.cpp in Sources */,
    54255429                                A180C0FA1EE67DF000468F47 /* RunOpenPanel.mm in Sources */,
    54265430                                F4D2986E20FEE7370092D636 /* RunScriptAfterDocumentLoad.mm in Sources */,
Note: See TracChangeset for help on using the changeset viewer.