Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support all voice encryption modes #599

Merged
merged 8 commits into from
May 20, 2024
Merged

Conversation

BrandtHill
Copy link
Contributor

No description provided.

@jchristgit jchristgit self-requested a review May 18, 2024 07:01
@jchristgit jchristgit self-assigned this May 18, 2024
Copy link
Collaborator

@jchristgit jchristgit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is really solid work. I needed quite some time to read into the papers and understand it, but this code is really easy to digest (probably in large part thanks to binary matching).

I have a bunch of smaller questions that I posted as part of the review. I also have two other questions:

  • Do you think it is worth it to add some basic unit tests for the custom crypto?
  • Do you think we should contribute this to OTP?

lib/nostrum/voice/crypto.ex Outdated Show resolved Hide resolved
lib/nostrum/voice/crypto/salsa.ex Show resolved Hide resolved
lib/nostrum/voice/crypto/salsa.ex Show resolved Hide resolved
lib/nostrum/voice/crypto/salsa.ex Show resolved Hide resolved
lib/nostrum/voice/crypto/salsa.ex Outdated Show resolved Hide resolved

@type cipher :: cipher_non_rtpsize() | cipher_alias() | cipher_rtpsize()

defp mode, do: Application.get_env(:nostrum, :voice_encryption_mode, :aes256_gcm)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you reckon there is a need to switch this at runtime? Or should we make this a compile-time setting?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I originally had this a compile time config but changed it to runtime for my encryption mode test suite so I didn’t have to recompile each time. I can change it back

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test suite in question

def voice_encryption_test_suite do
  [
    :xsalsa20_poly1305,
    :xsalsa20_poly1305_suffix,
    :xsalsa20_poly1305_lite,
    :xsalsa20_poly1305_lite_rtpsize,
    :xchacha20_poly1305,
    :aead_xchacha20_poly1305_rtpsize,
    :aes256_gcm,
    :aead_aes256_gcm,
    :aead_aes256_gcm_rtpsize
  ]
  |> Enum.each(&voice_encryption_test/1)
end

def voice_encryption_test(mode) do
  IO.puts("Starting test with #{mode}")
  Application.put_env(:nostrum, :voice_encryption_mode, mode)
  Dummy.join_voice()
  Dummy.sleep_until_ready()
  Dummy.play_file()
  Process.sleep(3_000)
  Dummy.stop()
  IO.puts("Speak now!")
  Dummy.playback_raw(80)
  Process.sleep(1_500)
  Dummy.leave_voice()
  IO.puts("Test complete")
  Process.sleep(1_500)
end

lib/nostrum/voice/crypto.ex Show resolved Hide resolved
lib/nostrum/voice/crypto.ex Show resolved Hide resolved
guides/intro/intro.md Outdated Show resolved Hide resolved
guides/functionality/voice.md Outdated Show resolved Hide resolved
Copy link
Collaborator

@jchristgit jchristgit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Super solid man. I have one more tiny idea but other than that this is rock solid.

Comment on lines 26 to 37
defp mode, do: Application.get_env(:nostrum, :voice_encryption_mode, :aes256_gcm)
@mode Application.compile_env(:nostrum, :voice_encryption_mode, :aes256_gcm)

def encryption_mode do
mode = mode()

Map.get(
%{
xchacha20_poly1305: "aead_xchacha20_poly1305_rtpsize",
aes256_gcm: "aead_aes256_gcm_rtpsize"
},
mode,
"#{mode}"
@mode,
"#{@mode}"
)
end
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yak shaving here but since this is compile time config now we might be able to remove the dynamic apply and Map.get to figure out the proper name and just resolve the function to encrypt and decrypt at compile time - what do you think?

@BrandtHill
Copy link
Contributor Author

I've added some unit tests and internal docs

Copy link
Collaborator

@jchristgit jchristgit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Amazing work!!

@jchristgit jchristgit merged commit f956bb3 into Kraigie:master May 20, 2024
9 checks passed
@jchristgit
Copy link
Collaborator

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants