From 066e37a253f844beb3ab9df37611068fc38ead04 Mon Sep 17 00:00:00 2001 From: Dooley_labs Date: Wed, 18 Sep 2024 03:47:49 -0400 Subject: [PATCH] Deprecate `pynacl` voice dependency - disco.util.crypto: removed `pynacl` - disco.voice.udp: cleanup --- disco/util/crypto.py | 14 +++++--------- disco/voice/udp.py | 6 ++---- 2 files changed, 7 insertions(+), 13 deletions(-) diff --git a/disco/util/crypto.py b/disco/util/crypto.py index bd29328..45cd50a 100644 --- a/disco/util/crypto.py +++ b/disco/util/crypto.py @@ -1,10 +1,5 @@ from warnings import warn as warnings_warn -try: - from nacl.utils import EncryptedMessage -except ImportError: - warnings_warn('nacl is not installed, voice support is disabled') - try: from libnacl import crypto_aead_xchacha20poly1305_ietf_encrypt, crypto_aead_xchacha20poly1305_ietf_decrypt, crypto_aead_aes256gcm_encrypt, crypto_aead_aes256gcm_decrypt except ImportError: @@ -13,7 +8,9 @@ class AEScrypt: """ - BECAUSE PYNACL REFUSES TO DO IT WITH THEIR TERRIBLE SELF-RIGHTEOUS PRACTICES + BECAUSE PYNACL REFUSED TO DO IT WITH THEIR TERRIBLE SELF-RIGHTEOUS PRACTICES, + BUT IN THIS MODERN AGE, WE NEEDED A GRACEFUL WRAPPER FOR LIBNACL AS PYNACL IS DEAD. + LONG LIVE LIBNACL, THE INFINITELY SUPERIOR SUCCESSOR TO PYNACL. """ def __init__(self, key: bytes, ciper: str): self._key = key @@ -25,10 +22,9 @@ def __bytes__(self) -> bytes: def encrypt(self, plaintext: bytes, nonce: bytes, aad: bytes) -> bytes: if self.cipher == 'aead_xchacha20_poly1305_rtpsize': - payload = crypto_aead_xchacha20poly1305_ietf_encrypt(message=plaintext, aad=aad, nonce=nonce, key=self._key) + return crypto_aead_xchacha20poly1305_ietf_encrypt(message=plaintext, aad=aad, nonce=nonce, key=self._key) else: - payload = crypto_aead_aes256gcm_encrypt(message=plaintext, aad=aad, nonce=nonce, key=self._key) - return EncryptedMessage._from_parts(nonce, payload, nonce + payload) + return crypto_aead_aes256gcm_encrypt(message=plaintext, aad=aad, nonce=nonce, key=self._key) def decrypt(self, ciphertext: bytes, nonce: bytes, aad: bytes) -> bytes: if self.cipher == 'aead_xchacha20_poly1305_rtpsize': diff --git a/disco/voice/udp.py b/disco/voice/udp.py index af3b779..d39fcea 100644 --- a/disco/voice/udp.py +++ b/disco/voice/udp.py @@ -157,11 +157,9 @@ def send_frame(self, frame, sequence=None, timestamp=None, incr_timestamp=None): # Encrypt the payload with the nonce payload = self._secret_box.encrypt(plaintext=frame, nonce=bytes(nonce), aad=bytes(self._rtp_audio_header)) - payload = payload.ciphertext - # Pad the payload with the nonce, if applicable - if nonce_padding: - payload += nonce_padding + # Pad the payload with the nonce + payload += nonce_padding # Send the header (sans nonce padding) plus the payload self.send(self._rtp_audio_header + payload)