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

feat(voice)!: add new encryption methods, remove old methods #10451

Open
wants to merge 15 commits into
base: main
Choose a base branch
from

Conversation

nyapat
Copy link
Contributor

@nyapat nyapat commented Aug 19, 2024

Please describe the changes this PR makes and why it should be merged:

  • aes256gcm encryption
  • xchacha20 encryption
  • aes256gcm decryption
  • xchacha20 decryption
  • test if alternative sodiums work for above
  • alternative for tweetnacl
  • remove old encryption, decryption methods
  • tests (waiting on test: replace jest with vitest #10472)

Added the new encryption methods that Discord will enforce for all voice users in November. Since the older methods are being deprecated entirely, I am removing them as well. Because tweetnacl does not support the cipher methods necessary for xchacha, I have removed it and replaced it with @stablelib/xchacha20poly1305 (aes256gcm does not require anything other than node:crypto, so that could theoretically be the only one needed if the vc always requested that)

Testing has been added for the encryption methods aswell, and I have changed some older tests to properly remove the RTP header based on the original encrypted data.

Status and versioning classification:

  • Code changes have been tested against the Discord API, or there are no code changes
  • I know how to update typings and have done so, or typings don't need updating
  • This PR includes breaking changes (methods removed or renamed, parameters moved or removed)

Copy link

vercel bot commented Aug 19, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

2 Skipped Deployments
Name Status Preview Comments Updated (UTC)
discord-js ⬜️ Ignored (Inspect) Visit Preview Oct 18, 2024 11:46pm
discord-js-guide ⬜️ Ignored (Inspect) Visit Preview Oct 18, 2024 11:46pm

packages/ws/src/ws/WebSocketShard.ts Outdated Show resolved Hide resolved
@nyapat nyapat force-pushed the feat/voice-encryption branch 2 times, most recently from 47606c3 to 4879a69 Compare August 19, 2024 13:53
@vladfrangu vladfrangu added this to the voice 0.18.0 milestone Aug 20, 2024
packages/voice/src/networking/Networking.ts Outdated Show resolved Hide resolved
packages/voice/src/receive/VoiceReceiver.ts Outdated Show resolved Hide resolved
packages/voice/src/util/Secretbox.ts Outdated Show resolved Hide resolved
@nyapat
Copy link
Contributor Author

nyapat commented Sep 2, 2024

when #10472 is ready i will update tests for this (tweetnacl is being swapped out for stablelib & jest utterly hates it)

Copy link

codecov bot commented Oct 7, 2024

Codecov Report

Attention: Patch coverage is 34.78261% with 90 lines in your changes missing coverage. Please review.

Project coverage is 37.81%. Comparing base (24128a3) to head (914676b).
Report is 11 commits behind head on main.

Files with missing lines Patch % Lines
packages/voice/src/util/Secretbox.ts 14.75% 52 Missing ⚠️
packages/voice/src/networking/Networking.ts 8.10% 34 Missing ⚠️
packages/voice/src/receive/VoiceReceiver.ts 92.30% 3 Missing ⚠️
...ackages/voice/src/util/generateDependencyReport.ts 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #10451      +/-   ##
==========================================
- Coverage   38.00%   37.81%   -0.20%     
==========================================
  Files         239      239              
  Lines       15488    15472      -16     
  Branches     1367     1351      -16     
==========================================
- Hits         5886     5850      -36     
- Misses       9587     9607      +20     
  Partials       15       15              
Flag Coverage Δ
guide 0.54% <ø> (ø)
voice 70.93% <34.78%> (-1.30%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@nyapat nyapat marked this pull request as ready for review October 7, 2024 10:07
@nyapat nyapat requested review from a team and iCrawl as code owners October 7, 2024 10:07
@nyapat nyapat requested a review from vladfrangu October 7, 2024 10:07
@nyapat nyapat changed the title feat(voice): aes-256-gcm, xchacha20-poly1305 encryption feat(voice)!: add new encryption methods, remove old methods Oct 7, 2024
};

void (async () => {
for (const libName of Object.keys(libs) as (keyof typeof libs)[]) {
try {
// eslint-disable-next-line @typescript-eslint/no-require-imports, @typescript-eslint/no-var-requires
const lib = require(libName);
const lib = await import(libName);
Copy link
Member

Choose a reason for hiding this comment

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

Any particular reason for this change? Do we have any way to not require this to become async (as it can come with its own can of worms)... Maybe we should make this secretbox module a lazy loaded thing thats awaitable (export the two functions that handle imports themselves the first time)

Copy link
Member

Choose a reason for hiding this comment

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

I'm not even sure how the require worked before? What was tsup compiling it to in ESM builds? There's no sync equivalent, which makes me think this just like, straight up didn't work for pure ESM users.

Copy link
Member

Choose a reason for hiding this comment

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

You can create the require function [in ESM] by using createRequire() from node:module

Copy link
Member

Choose a reason for hiding this comment

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

Realistically its still something we ought to change, this random void Promise thing is hella janky imo (and prone to race conditions or worse)

Copy link
Member

Choose a reason for hiding this comment

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

I'm for a lazy top level.

Copy link
Contributor Author

@nyapat nyapat Nov 7, 2024

Choose a reason for hiding this comment

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

i did find an alternative that is fine with cjs require, should i just swap over to that and revert this change to import?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sorry to be annoying with notifs ^_^ but ^if i swap the dependency to a cjs one (and thus go back to require) does this solve the issue? will do if so!

Copy link
Member

Choose a reason for hiding this comment

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

I mean you didn't show what the alternative is 😅, so 🤷‍♂️

Copy link
Contributor Author

Choose a reason for hiding this comment

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

okok, it's @noble/ciphers unless you have any other suggestions

Copy link
Member

Choose a reason for hiding this comment

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

Sure! But would love the thoughts of @didinele and/or @discordjs/core about this too (if we should just leave it as is or not)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Review in Progress
Development

Successfully merging this pull request may close these issues.

6 participants