Changeset 269830 in webkit
- Timestamp:
- Nov 15, 2020 9:59:54 AM (3 years ago)
- Location:
- trunk
- Files:
-
- 7 added
- 18 edited
- 4 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r269827 r269830 1 2020-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 1 11 2020-11-15 Philippe Normand <pnormand@igalia.com> 2 12 -
trunk/Source/WebCore/CMakeLists.txt
r269764 r269830 403 403 Modules/mediastream/RTCRtpReceiver.idl 404 404 Modules/mediastream/RTCRtpRtxParameters.idl 405 Modules/mediastream/RTCRtpSFrameTransform.idl 405 406 Modules/mediastream/RTCRtpSendParameters.idl 406 407 Modules/mediastream/RTCRtpSender+Transform.idl -
trunk/Source/WebCore/ChangeLog
r269829 r269830 1 2020-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 1 75 2020-11-15 Youenn Fablet <youenn@apple.com> 2 76 -
trunk/Source/WebCore/DerivedSources-input.xcfilelist
r269775 r269830 237 237 $(PROJECT_DIR)/Modules/mediastream/RTCRtpReceiver.idl 238 238 $(PROJECT_DIR)/Modules/mediastream/RTCRtpRtxParameters.idl 239 $(PROJECT_DIR)/Modules/mediastream/RTCRtpSFrameTransform.idl 239 240 $(PROJECT_DIR)/Modules/mediastream/RTCRtpSendParameters.idl 240 241 $(PROJECT_DIR)/Modules/mediastream/RTCRtpSender+Transform.idl -
trunk/Source/WebCore/DerivedSources-output.xcfilelist
r269764 r269830 1706 1706 $(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSRTCRtpRtxParameters.cpp 1707 1707 $(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSRTCRtpRtxParameters.h 1708 $(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSRTCRtpSFrameTransform.cpp 1709 $(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSRTCRtpSFrameTransform.h 1708 1710 $(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSRTCRtpSendParameters.cpp 1709 1711 $(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSRTCRtpSendParameters.h -
trunk/Source/WebCore/DerivedSources.make
r269775 r269830 264 264 $(WebCore)/Modules/mediastream/RTCRtpSender.idl \ 265 265 $(WebCore)/Modules/mediastream/RTCRtpSender+Transform.idl \ 266 $(WebCore)/Modules/mediastream/RTCRtpSFrameTransform.idl \ 266 267 $(WebCore)/Modules/mediastream/RTCRtpSynchronizationSource.idl \ 267 268 $(WebCore)/Modules/mediastream/RTCRtpTransceiver.idl \ -
trunk/Source/WebCore/Modules/mediastream/RTCRtpSFrameTransform.h
r269829 r269830 24 24 */ 25 25 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 33 namespace WebCore { 34 35 class CryptoKey; 36 class RTCRtpSFrameTransformer; 37 38 class RTCRtpSFrameTransform final : public RTCRtpTransform { 39 public: 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 47 private: 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; 32 58 }; 59 60 } // namespace WebCore 61 62 #endif // ENABLE(WEB_RTC) -
trunk/Source/WebCore/Modules/mediastream/RTCRtpSFrameTransform.idl
r269829 r269830 26 26 [ 27 27 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); 32 39 }; -
trunk/Source/WebCore/Sources.txt
r269812 r269830 164 164 Modules/mediastream/RTCPeerConnectionIceEvent.cpp 165 165 Modules/mediastream/RTCRtpReceiver.cpp 166 Modules/mediastream/RTCRtpSFrameTransform.cpp 167 Modules/mediastream/RTCRtpSFrameTransformer.cpp 166 168 Modules/mediastream/RTCRtpSender.cpp 167 169 Modules/mediastream/RTCRtpTransform.cpp … … 3321 3323 JSRTCRtpReceiver.cpp 3322 3324 JSRTCRtpRtxParameters.cpp 3325 JSRTCRtpSFrameTransform.cpp 3323 3326 JSRTCRtpSendParameters.cpp 3324 3327 JSRTCRtpSender.cpp -
trunk/Source/WebCore/SourcesCocoa.txt
r269678 r269830 90 90 Modules/async-clipboard/ios/ClipboardImageReaderIOS.mm 91 91 Modules/async-clipboard/mac/ClipboardImageReaderMac.mm 92 Modules/mediastream/RTCRtpSFrameTransformerCocoa.cpp 92 93 Modules/plugins/QuickTimePluginReplacement.mm 93 94 Modules/plugins/YouTubePluginReplacement.cpp … … 129 130 crypto/mac/CryptoKeyMac.cpp 130 131 crypto/mac/CryptoKeyRSAMac.cpp 132 crypto/mac/CryptoUtilitiesCocoa.cpp 131 133 crypto/mac/SerializedCryptoKeyWrapMac.mm 132 134 dom/DataTransferMac.mm -
trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj
r269824 r269830 1109 1109 4181C5D72555C49A00AEB0FF /* MockRTCRtpTransform.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4181C5D32555C1B100AEB0FF /* MockRTCRtpTransform.cpp */; }; 1110 1110 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 */; }; 1111 1113 418205471E53E98C00D62207 /* RTCController.h in Headers */ = {isa = PBXBuildFile; fileRef = 418205451E53C8CD00D62207 /* RTCController.h */; settings = {ATTRIBUTES = (Private, ); }; }; 1112 1114 41826BF223FB597700B922B1 /* DocumentIdentifier.h in Headers */ = {isa = PBXBuildFile; fileRef = 41826BF123FB597000B922B1 /* DocumentIdentifier.h */; settings = {ATTRIBUTES = (Private, ); }; }; … … 7699 7701 4181C5D52555C1B900AEB0FF /* MockRTCRtpTransform.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MockRTCRtpTransform.h; sourceTree = "<group>"; }; 7700 7702 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>"; }; 7701 7709 418205451E53C8CD00D62207 /* RTCController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RTCController.h; sourceTree = "<group>"; }; 7702 7710 418205481E53EAAD00D62207 /* RTCController.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RTCController.cpp; sourceTree = "<group>"; }; … … 7732 7740 419BC2DD1685329900D64D6D /* VisitedLinkState.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = VisitedLinkState.h; sourceTree = "<group>"; }; 7733 7741 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>"; }; 7734 7744 419FAFAD1ABABCD5005B3572 /* ReadableStreamBYOBReader.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = ReadableStreamBYOBReader.idl; sourceTree = "<group>"; }; 7735 7745 419FAFAD1ABABCD5005B828B /* ReadableStreamDefaultReader.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = ReadableStreamDefaultReader.idl; sourceTree = "<group>"; }; … … 17089 17099 414AD3FC2149842000521676 /* RTCRtpSendParameters.h */, 17090 17100 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 */, 17091 17107 415E1BB62150152A0022DA96 /* RTCRtpSynchronizationSource.h */, 17092 17108 415E1BB7215015300022DA96 /* RTCRtpSynchronizationSource.idl */, … … 28256 28272 E19AC3F8182566F700349426 /* CryptoKeyMac.cpp */, 28257 28273 E164FAA418315E1A00DB4E61 /* CryptoKeyRSAMac.cpp */, 28274 419D9307255E842800DA1984 /* CryptoUtilitiesCocoa.cpp */, 28275 419D9305255E842700DA1984 /* CryptoUtilitiesCocoa.h */, 28258 28276 E18DF33618AAF14D00773E59 /* SerializedCryptoKeyWrapMac.mm */, 28259 28277 ); … … 34094 34112 5E2C43611BCEE3230001E2BC /* RTCRtpSender.h in Headers */, 34095 34113 413C8B332552F27D00E65055 /* RTCRtpSenderWithTransform.h in Headers */, 34114 4181C64A255B4C2800AEB0FF /* RTCRtpSFrameTransform.h in Headers */, 34115 4181C648255B4C2800AEB0FF /* RTCRtpSFrameTransformer.h in Headers */, 34096 34116 5E5E2B141CFC3E75000C0D85 /* RTCRtpTransceiver.h in Headers */, 34097 34117 31EB54DF1E7DC74400C1623B /* RTCRtpTransceiverDirection.h in Headers */, -
trunk/Source/WebCore/bindings/js/WebCoreBuiltinNames.h
r269764 r269830 220 220 macro(RTCPeerConnectionIceEvent) \ 221 221 macro(RTCRtpReceiver) \ 222 macro(RTCRtpSFrameTransform) \ 222 223 macro(RTCRtpSender) \ 223 224 macro(RTCRtpTransceiver) \ -
trunk/Source/WebCore/crypto/mac/CryptoAlgorithmAES_CTRMac.cpp
r260238 r269830 32 32 #include "CryptoAlgorithmAesCtrParams.h" 33 33 #include "CryptoKeyAES.h" 34 #include <CommonCrypto/CommonCrypto.h>34 #include "CryptoUtilitiesCocoa.h" 35 35 36 36 namespace 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 + counter42 // CommonCrypto currently can neither reset the counter nor detect overflow once the counter reaches its max value restricted43 // 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 loop48 if (counterLength < sizeof(size_t) * 8 && numberOfBlocks > (static_cast<size_t>(1) << counterLength))49 return Exception { OperationError };50 51 // Calculate capacity before overflow52 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 counter89 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 }115 37 116 38 ExceptionOr<Vector<uint8_t>> CryptoAlgorithmAES_CTR::platformEncrypt(const CryptoAlgorithmAesCtrParams& parameters, const CryptoKeyAES& key, const Vector<uint8_t>& plainText) 117 39 { 118 40 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()); 120 42 } 121 43 122 44 ExceptionOr<Vector<uint8_t>> CryptoAlgorithmAES_CTR::platformDecrypt(const CryptoAlgorithmAesCtrParams& parameters, const CryptoKeyAES& key, const Vector<uint8_t>& cipherText) 123 45 { 124 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()); 126 48 } 49 127 50 128 51 } // namespace WebCore -
trunk/Source/WebCore/crypto/mac/CryptoAlgorithmHKDFMac.cpp
r242988 r269830 29 29 #if ENABLE(WEB_CRYPTO) 30 30 31 #include "CommonCryptoUtilities.h"32 31 #include "CryptoAlgorithmHkdfParams.h" 33 32 #include "CryptoKeyRaw.h" 33 #include "CryptoUtilitiesCocoa.h" 34 34 35 35 namespace WebCore { … … 37 37 ExceptionOr<Vector<uint8_t>> CryptoAlgorithmHKDF::platformDeriveBits(const CryptoAlgorithmHkdfParams& parameters, const CryptoKeyRaw& key, size_t length) 38 38 { 39 Vector<uint8_t> result(length / 8);40 39 CCDigestAlgorithm digestAlgorithm; 41 40 getCommonCryptoDigestAlgorithm(parameters.hashIdentifier, digestAlgorithm); 42 41 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); 50 43 } 51 44 -
trunk/Source/WebCore/crypto/mac/CryptoUtilitiesCocoa.cpp
r269829 r269830 1 1 /* 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. 4 3 * 5 4 * Redistribution and use in source and binary forms, with or without … … 26 25 27 26 #include "config.h" 27 #include "CryptoUtilitiesCocoa.h" 28 29 #if ENABLE(WEB_CRYPTO) || ENABLE(WEB_RTC) 30 28 31 #include "CryptoAlgorithmAES_CTR.h" 29 30 #if ENABLE(WEB_CRYPTO)31 32 #include "CryptoAlgorithmAesCtrParams.h"33 #include "CryptoKeyAES.h"34 32 #include <CommonCrypto/CommonCrypto.h> 35 33 36 34 namespace WebCore { 37 35 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)36 ExceptionOr<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) 39 37 { 40 38 // FIXME: We should remove the following hack once <rdar://problem/31361050> is fixed. … … 43 41 // by the counterLength. It then increments the nonce which should stay same for the whole operation. To remedy this issue, 44 42 // 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; 46 44 47 45 // Detect loop … … 54 52 55 53 // Divide data into two parts if necessary. 56 size_t headSize = data .size();54 size_t headSize = dataSize; 57 55 if (capacity < numberOfBlocks) 58 56 headSize = capacity * kCCBlockSizeAES128; … … 67 65 68 66 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); 70 68 if (status) 71 69 return Exception { OperationError }; … … 92 90 return Exception { OperationError }; 93 91 94 size_t tailSize = data .size()- headSize;92 size_t tailSize = dataSize - headSize; 95 93 Vector<uint8_t> tail(CCCryptorGetOutputLength(cryptor, tailSize, true)); 96 94 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); 98 96 if (status) 99 97 return Exception { OperationError }; … … 114 112 } 115 113 116 ExceptionOr<Vector<uint8_t>> CryptoAlgorithmAES_CTR::platformEncrypt(const CryptoAlgorithmAesCtrParams& parameters, const CryptoKeyAES& key, const Vector<uint8_t>& plainText)114 ExceptionOr<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) 117 115 { 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); 120 126 } 121 127 122 ExceptionOr<Vector<uint8_t>> CryptoAlgorithmAES_CTR::platformDecrypt(const CryptoAlgorithmAesCtrParams& parameters, const CryptoKeyAES& key, const Vector<uint8_t>& cipherText)128 ExceptionOr<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) 123 129 { 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); 126 131 } 127 132 -
trunk/Source/WebCore/crypto/mac/CryptoUtilitiesCocoa.h
r269829 r269830 1 1 /* 2 * Copyright (C) 20 17Apple Inc. All rights reserved.2 * Copyright (C) 2020 Apple Inc. All rights reserved. 3 3 * 4 4 * Redistribution and use in source and binary forms, with or without … … 24 24 */ 25 25 26 #include "config.h" 27 #include "CryptoAlgorithmHKDF.h" 26 #pragma once 28 27 29 #if ENABLE(WEB_CRYPTO) 28 #if ENABLE(WEB_CRYPTO) || ENABLE(WEB_RTC) 30 29 31 #include "CommonCryptoUtilities.h" 32 #include "CryptoAlgorithmHkdfParams.h" 33 #include "CryptoKeyRaw.h" 30 #include "ExceptionOr.h" 31 #include <wtf/Vector.h> 32 33 typedef uint32_t CCDigestAlgorithm; 34 typedef uint32_t CCOperation; 34 35 35 36 namespace WebCore { 36 37 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); 38 ExceptionOr<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); 39 ExceptionOr<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); 40 ExceptionOr<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); 42 41 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 51 43 52 } 53 54 #endif // ENABLE(WEB_CRYPTO) 44 #endif // ENABLE(WEB_CRYPTO) || ENABLE(WEB_RTC) -
trunk/Source/WebCore/testing/Internals.cpp
r269785 r269830 154 154 #include "PrintContext.h" 155 155 #include "PseudoElement.h" 156 #include "RTCRtpSFrameTransform.h" 156 157 #include "Range.h" 157 158 #include "ReadableStream.h" … … 1582 1583 } 1583 1584 1585 uint64_t Internals::sframeCounter(const RTCRtpSFrameTransform& transform) 1586 { 1587 return transform.counterForTesting(); 1588 } 1589 1584 1590 void Internals::setEnableWebRTCEncryption(bool value) 1585 1591 { -
trunk/Source/WebCore/testing/Internals.h
r269784 r269830 125 125 #endif 126 126 127 #if ENABLE(WEB_RTC) 128 class RTCRtpSFrameTransform; 129 #endif 130 127 131 #if ENABLE(WEBXR) 128 132 class WebXRTest; … … 608 612 void setWebRTCVP9VTBSupport(bool); 609 613 Ref<MockRTCRtpTransform> createMockRTCRtpTransform(); 614 uint64_t sframeCounter(const RTCRtpSFrameTransform&); 610 615 void setEnableWebRTCEncryption(bool); 611 616 void setUseDTLS10(bool); -
trunk/Source/WebCore/testing/Internals.idl
r269764 r269830 804 804 [Conditional=WEB_RTC] undefined setWebRTCVP9VTBSupport(boolean allowed); 805 805 [Conditional=WEB_RTC] MockRTCRtpTransform createMockRTCRtpTransform(); 806 [Conditional=WEB_RTC] unsigned long long sframeCounter(RTCRtpSFrameTransform transform); 806 807 807 808 [Conditional=MEDIA_STREAM] undefined setMockAudioTrackChannelNumber(MediaStreamTrack track, unsigned short count); -
trunk/Source/WebCore/testing/MockRTCRtpTransform.idl
r269764 r269830 27 27 Conditional=WEB_RTC, 28 28 JSGenerateToJSObject, 29 JSGenerateToNativeObject, 29 30 LegacyNoInterfaceObject, 30 31 ] interface MockRTCRtpTransform : RTCRtpTransform { -
trunk/Tools/ChangeLog
r269810 r269830 1 2020-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 1 17 2020-11-13 Sihui Liu <sihui_liu@apple.com> 2 18 -
trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj
r269810 r269830 237 237 414AD6862285D1C000777F2D /* StorageQuota.mm in Sources */ = {isa = PBXBuildFile; fileRef = 414AD6852285D1B000777F2D /* StorageQuota.mm */; }; 238 238 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 */; }; 239 240 41848F4424891879000E2588 /* open-window-with-file-url-with-host.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 41848F4324891815000E2588 /* open-window-with-file-url-with-host.html */; }; 240 241 41882F0321010C0D002FF288 /* ProcessPreWarming.mm in Sources */ = {isa = PBXBuildFile; fileRef = 41882F0221010A70002FF288 /* ProcessPreWarming.mm */; }; … … 1963 1964 414AD6852285D1B000777F2D /* StorageQuota.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = StorageQuota.mm; sourceTree = "<group>"; }; 1964 1965 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>"; }; 1965 1967 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>"; }; 1966 1968 41882F0221010A70002FF288 /* ProcessPreWarming.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = ProcessPreWarming.mm; sourceTree = "<group>"; }; … … 3535 3537 6B4E861B2220A5520022F389 /* RegistrableDomain.cpp */, 3536 3538 F418BE141F71B7DC001970E6 /* RoundedRectTests.cpp */, 3539 4181C62C255A891100AEB0FF /* RTCRtpSFrameTransformerTests.cpp */, 3537 3540 CDCFA7A91E45122F00C2433D /* SampleMap.cpp */, 3538 3541 CE06DF9A1E1851F200E570C9 /* SecurityOrigin.cpp */, … … 5423 5426 46E816F81E79E29C00375ADC /* RestoreStateAfterTermination.mm in Sources */, 5424 5427 F418BE151F71B7DC001970E6 /* RoundedRectTests.cpp in Sources */, 5428 4181C62D255A891100AEB0FF /* RTCRtpSFrameTransformerTests.cpp in Sources */, 5425 5429 A180C0FA1EE67DF000468F47 /* RunOpenPanel.mm in Sources */, 5426 5430 F4D2986E20FEE7370092D636 /* RunScriptAfterDocumentLoad.mm in Sources */,
Note: See TracChangeset
for help on using the changeset viewer.