diff --git a/Cargo.toml b/Cargo.toml index be9ef89af..e355216f4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,6 +18,7 @@ async-trait = { optional = true, version = "0.1" } audiopus = { optional = true, version = "0.3.0-rc.0" } byteorder = { optional = true, version = "1" } bytes = { optional = true, version = "1" } +crypto_secretbox = { optional = true, features = ["std"], version = "0.1" } dashmap = { optional = true, version = "5" } derivative = "2" discortp = { default-features = false, features = ["discord", "pnet", "rtp"], optional = true, version = "0.5" } @@ -50,7 +51,6 @@ twilight-model = { default-features = false, optional = true, version = "0.15.0" typemap_rev = { optional = true, version = "0.3" } url = { optional = true, version = "2" } uuid = { features = ["v4"], optional = true, version = "1" } -xsalsa20poly1305 = { features = ["std"], optional = true, version = "0.9" } [dependencies.serenity] version = "0.11" @@ -91,6 +91,7 @@ driver = [ "dep:async-trait", "dep:audiopus", "dep:byteorder", + "dep:crypto_secretbox", "dep:discortp", "dep:reqwest", "dep:flume", @@ -113,7 +114,6 @@ driver = [ "dep:typemap_rev", "dep:url", "dep:uuid", - "dep:xsalsa20poly1305", "tokio?/fs", "tokio?/io-util", "tokio?/macros", diff --git a/src/driver/connection/error.rs b/src/driver/connection/error.rs index 70686ba30..81a346408 100644 --- a/src/driver/connection/error.rs +++ b/src/driver/connection/error.rs @@ -4,11 +4,11 @@ use crate::{ driver::tasks::{error::Recipient, message::*}, ws::Error as WsError, }; +use crypto_secretbox::Error as CryptoError; use flume::SendError; use serde_json::Error as JsonError; use std::{error::Error as StdError, fmt, io::Error as IoError}; use tokio::time::error::Elapsed; -use xsalsa20poly1305::aead::Error as CryptoError; /// Errors encountered while connecting to a Discord voice server over the driver. #[derive(Debug)] diff --git a/src/driver/connection/mod.rs b/src/driver/connection/mod.rs index a8d13ab34..9545881e2 100644 --- a/src/driver/connection/mod.rs +++ b/src/driver/connection/mod.rs @@ -20,6 +20,7 @@ use crate::{ ws::WsStream, ConnectionInfo, }; +use crypto_secretbox::{KeyInit, XSalsa20Poly1305 as Cipher}; use discortp::discord::{IpDiscoveryPacket, IpDiscoveryType, MutableIpDiscoveryPacket}; use error::{Error, Result}; use flume::Sender; @@ -30,7 +31,6 @@ use std::{net::IpAddr, str::FromStr}; use tokio::{net::UdpSocket, spawn, time::timeout}; use tracing::{debug, info, instrument}; use url::Url; -use xsalsa20poly1305::{KeyInit, XSalsa20Poly1305 as Cipher}; pub(crate) struct Connection { pub(crate) info: ConnectionInfo, diff --git a/src/driver/crypto.rs b/src/driver/crypto.rs index 3fc8a0208..b2b1108c9 100644 --- a/src/driver/crypto.rs +++ b/src/driver/crypto.rs @@ -1,17 +1,21 @@ //! Encryption schemes supported by Discord's secure RTP negotiation. use byteorder::{NetworkEndian, WriteBytesExt}; -use discortp::{rtp::RtpPacket, MutablePacket}; -use rand::Rng; -use std::num::Wrapping; #[cfg(any(feature = "receive", test))] -use xsalsa20poly1305::Tag; -use xsalsa20poly1305::{ +use crypto_secretbox::Tag; +use crypto_secretbox::{ aead::{AeadInPlace, Error as CryptoError}, Nonce, + SecretBox, XSalsa20Poly1305 as Cipher, - NONCE_SIZE, - TAG_SIZE, }; +use discortp::{rtp::RtpPacket, MutablePacket}; +use rand::Rng; +use std::num::Wrapping; + +#[cfg(test)] +pub const KEY_SIZE: usize = SecretBox::<()>::KEY_SIZE; +pub const NONCE_SIZE: usize = SecretBox::<()>::NONCE_SIZE; +pub const TAG_SIZE: usize = SecretBox::<()>::TAG_SIZE; /// Variants of the `XSalsa20Poly1305` encryption scheme. #[derive(Clone, Copy, Debug, Eq, PartialEq)] @@ -253,8 +257,8 @@ impl CryptoState { #[cfg(test)] mod test { use super::*; + use crypto_secretbox::KeyInit; use discortp::rtp::MutableRtpPacket; - use xsalsa20poly1305::{KeyInit, KEY_SIZE, TAG_SIZE}; #[test] fn small_packet_decrypts_error() { diff --git a/src/driver/tasks/error.rs b/src/driver/tasks/error.rs index 339f14ff3..3f4ba1ea3 100644 --- a/src/driver/tasks/error.rs +++ b/src/driver/tasks/error.rs @@ -1,9 +1,9 @@ use super::message::*; use crate::ws::Error as WsError; use audiopus::Error as OpusError; +use crypto_secretbox::aead::Error as CryptoError; use flume::SendError; use std::io::{Error as IoError, ErrorKind as IoErrorKind}; -use xsalsa20poly1305::aead::Error as CryptoError; #[derive(Debug)] pub enum Recipient { diff --git a/src/driver/tasks/message/mixer.rs b/src/driver/tasks/message/mixer.rs index 0b1c17bad..f38d4abcd 100644 --- a/src/driver/tasks/message/mixer.rs +++ b/src/driver/tasks/message/mixer.rs @@ -8,10 +8,10 @@ use crate::{ driver::{Bitrate, Config, CryptoState}, input::{AudioStreamError, Compose, Parsed}, }; +use crypto_secretbox::XSalsa20Poly1305 as Cipher; use flume::Sender; use std::{net::UdpSocket, sync::Arc}; use symphonia_core::{errors::Error as SymphoniaError, formats::SeekedTo}; -use xsalsa20poly1305::XSalsa20Poly1305 as Cipher; pub struct MixerConnection { pub cipher: Cipher, diff --git a/src/driver/tasks/mixer/mod.rs b/src/driver/tasks/mixer/mod.rs index f2e725ec0..7a8778580 100644 --- a/src/driver/tasks/mixer/mod.rs +++ b/src/driver/tasks/mixer/mod.rs @@ -15,6 +15,7 @@ use super::{ error::{Error, Result}, message::*, }; +use crate::driver::crypto::TAG_SIZE; use crate::{ constants::*, driver::MixMode, @@ -53,7 +54,6 @@ use symphonia_core::{ }; use tokio::runtime::Handle; use tracing::error; -use xsalsa20poly1305::TAG_SIZE; #[cfg(test)] use crate::driver::test_config::{OutputMessage, OutputMode}; diff --git a/src/driver/tasks/udp_rx/mod.rs b/src/driver/tasks/udp_rx/mod.rs index 593c0b209..6f4a67249 100644 --- a/src/driver/tasks/udp_rx/mod.rs +++ b/src/driver/tasks/udp_rx/mod.rs @@ -12,6 +12,7 @@ use crate::{ Config, }; use bytes::BytesMut; +use crypto_secretbox::XSalsa20Poly1305 as Cipher; use discortp::{ demux::{self, DemuxedMut}, rtp::RtpPacket, @@ -25,7 +26,6 @@ use std::{ }; use tokio::{net::UdpSocket, select, time::Instant}; use tracing::{error, instrument, trace, warn}; -use xsalsa20poly1305::XSalsa20Poly1305 as Cipher; type RtpSequence = Wrapping; type RtpTimestamp = Wrapping; diff --git a/src/driver/test_impls.rs b/src/driver/test_impls.rs index 2dd984925..def30bcf6 100644 --- a/src/driver/test_impls.rs +++ b/src/driver/test_impls.rs @@ -2,6 +2,7 @@ use crate::{ constants::*, + driver::crypto::KEY_SIZE, input::{ cached::Compressed, codecs::{CODEC_REGISTRY, PROBE}, @@ -10,10 +11,10 @@ use crate::{ test_utils, tracks::LoopState, }; +use crypto_secretbox::{KeyInit, XSalsa20Poly1305 as Cipher}; use flume::{Receiver, Sender}; use std::{io::Cursor, net::UdpSocket, sync::Arc}; use tokio::runtime::Handle; -use xsalsa20poly1305::{KeyInit, XSalsa20Poly1305 as Cipher, KEY_SIZE}; use super::{ scheduler::*,