Add receive support for encrypted TOC byte

This commit is contained in:
Rashad Sookram 2024-03-26 10:37:56 -04:00 committed by GitHub
parent 84db3b7d55
commit f93cee1ebf
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 9 additions and 7 deletions

View file

@ -63,8 +63,8 @@ class FrameDecryptorInterface : public rtc::RefCountInterface {
rtc::ArrayView<const uint8_t> additional_data,
rtc::ArrayView<const uint8_t> encrypted_frame,
rtc::ArrayView<uint8_t> frame,
// RingRTC change to detect received dependency descriptor
bool has_dependency_descriptor) = 0;
// RingRTC change to encrypt media header
bool has_encrypted_media_header) = 0;
// Returns the total required length in bytes for the output of the
// decryption. This can be larger than the actual number of bytes you need but

View file

@ -713,14 +713,16 @@ void ChannelReceive::ReceivePacket(const uint8_t* packet,
const std::vector<uint32_t> csrcs(header.arrOfCSRCs,
header.arrOfCSRCs + header.numCSRCs);
// RingRTC change to determine if TOC is encrypted
bool has_encrypted_toc = header.extension.hasAudioLevel && ((header.extension.audioLevel & 0x1) != 0);
const FrameDecryptorInterface::Result decrypt_result =
frame_decryptor_->Decrypt(
cricket::MEDIA_TYPE_AUDIO, csrcs,
/*additional_data=*/nullptr,
rtc::ArrayView<const uint8_t>(payload, payload_data_length),
decrypted_audio_payload,
// RingRTC change to detect received dependency descriptor
/*has_dependency_descriptor=*/false);
// RingRTC change to determine if TOC is encrypted
has_encrypted_toc);
if (decrypt_result.IsOk()) {
decrypted_audio_payload.SetSize(decrypt_result.bytes_written);

View file

@ -57,7 +57,7 @@ typedef struct {
size_t (*getMediaCiphertextBufferSize)(void* observer_borrowed, bool, size_t);
bool (*encryptMedia)(void* observer_borrowed, bool, const uint8_t* plaintext_borrowed, size_t, uint8_t* ciphertext_out, size_t, size_t* ciphertext_size_out);
size_t (*getMediaPlaintextBufferSize)(void* observer_borrowed, uint32_t, bool, size_t);
bool (*decryptMedia)(void* observer_borrowed, uint32_t, bool, const uint8_t* ciphertext_borrowed, size_t, uint8_t* plaintext_out, size_t, size_t* plaintext_size_out, bool has_dependency_descriptor);
bool (*decryptMedia)(void* observer_borrowed, uint32_t, bool, const uint8_t* ciphertext_borrowed, size_t, uint8_t* plaintext_out, size_t, size_t* plaintext_size_out, bool has_encrypted_media_header);
} PeerConnectionObserverCallbacks;
// Passed-in observer must live at least as long as the PeerConnectionObserverRffi,

View file

@ -316,7 +316,7 @@ class Decryptor : public webrtc::FrameDecryptorInterface {
rtc::ArrayView<const uint8_t> _generic_video_header,
rtc::ArrayView<const uint8_t> ciphertext,
rtc::ArrayView<uint8_t> plaintext_buffer,
bool has_dependency_descriptor) override {
bool has_encrypted_media_header) override {
bool is_audio = (media_type == cricket::MEDIA_TYPE_AUDIO);
bool is_video = (media_type == cricket::MEDIA_TYPE_VIDEO);
if (!is_audio && !is_video) {
@ -324,7 +324,7 @@ class Decryptor : public webrtc::FrameDecryptorInterface {
return FrameDecryptorInterface::Result(FrameDecryptorInterface::Status::kUnknown, 0);
}
size_t plaintext_size = 0;
if (!callbacks_->decryptMedia(observer_, track_id_, is_audio, ciphertext.data(), ciphertext.size(), plaintext_buffer.data(), plaintext_buffer.size(), &plaintext_size, has_dependency_descriptor)) {
if (!callbacks_->decryptMedia(observer_, track_id_, is_audio, ciphertext.data(), ciphertext.size(), plaintext_buffer.data(), plaintext_buffer.size(), &plaintext_size, has_encrypted_media_header)) {
return FrameDecryptorInterface::Result(FrameDecryptorInterface::Status::kFailedToDecrypt, 0);
}
return FrameDecryptorInterface::Result(FrameDecryptorInterface::Status::kOk, plaintext_size);