Skip to content

Commit

Permalink
feat: DAVE received audio decryption
Browse files Browse the repository at this point in the history
  • Loading branch information
braindigitalis committed Oct 5, 2024
1 parent 33f420d commit 7a17450
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/dpp/dave/decryptor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ void Decryptor::TransitionToPassthroughMode(bool passthroughMode, Duration trans
}
}

size_t Decryptor::Decrypt(MediaType mediaType,
size_t Decryptor::decrypt(MediaType mediaType,
array_view<const uint8_t> encryptedFrame,
array_view<uint8_t> frame)
{
Expand Down
2 changes: 1 addition & 1 deletion src/dpp/dave/decryptor.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class Decryptor {
void TransitionToPassthroughMode(bool passthroughMode,
Duration transitionExpiry = kDefaultTransitionDuration);

size_t Decrypt(MediaType mediaType,
size_t decrypt(MediaType mediaType,
array_view<const uint8_t> encryptedFrame,
array_view<uint8_t> frame);

Expand Down
21 changes: 20 additions & 1 deletion src/dpp/voice/enabled/read_ready.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#include <dpp/discordvoiceclient.h>

#include <opus/opus.h>
#include "../../dave/encryptor.h"
#include "../../dave/decryptor.h"

#include "enabled.h"

Expand Down Expand Up @@ -143,6 +143,25 @@ void discord_voice_client::read_ready()
opus_packet_len -= ext_len;
}

/**
* If DAVE is enabled, use the user's ratchet to decrypt the OPUS audio data
*/
if (is_end_to_end_encrypted()) {
auto decryptor = mls_state->decryptors.find(vp.vr->user_id);
if (decryptor != mls_state->decryptors.end()) {
std::vector<uint8_t> frame(opus_packet_len * 2);
size_t enc_len = decryptor->second->decrypt(
dave::MediaType::Audio,
dave::make_array_view<const uint8_t>(opus_packet, opus_packet_len),
dave::make_array_view(frame)
);
if (enc_len > 0) {
opus_packet = frame.data();
opus_packet_len = enc_len;
}
}
}

/*
* We're left with the decrypted, opus-encoded data.
* Park the payload and decode on the voice courier thread.
Expand Down

0 comments on commit 7a17450

Please sign in to comment.