Driver: Replace xsalsa20poly1305 with crypto_secretbox (#198)
As of v0.9.1, `xsalsa20poly1305` has been deprecated. This is a mostly seamless replacement, as it appears to be the same crate authors / code / etc. Co-authored-by: Kyle Simpson <kyleandrew.simpson@gmail.com>
This commit is contained in:
@@ -18,6 +18,7 @@ async-trait = { optional = true, version = "0.1" }
|
|||||||
audiopus = { optional = true, version = "0.3.0-rc.0" }
|
audiopus = { optional = true, version = "0.3.0-rc.0" }
|
||||||
byteorder = { optional = true, version = "1" }
|
byteorder = { optional = true, version = "1" }
|
||||||
bytes = { optional = true, version = "1" }
|
bytes = { optional = true, version = "1" }
|
||||||
|
crypto_secretbox = { optional = true, features = ["std"], version = "0.1" }
|
||||||
dashmap = { optional = true, version = "5" }
|
dashmap = { optional = true, version = "5" }
|
||||||
derivative = "2"
|
derivative = "2"
|
||||||
discortp = { default-features = false, features = ["discord", "pnet", "rtp"], optional = true, version = "0.5" }
|
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" }
|
typemap_rev = { optional = true, version = "0.3" }
|
||||||
url = { optional = true, version = "2" }
|
url = { optional = true, version = "2" }
|
||||||
uuid = { features = ["v4"], optional = true, version = "1" }
|
uuid = { features = ["v4"], optional = true, version = "1" }
|
||||||
xsalsa20poly1305 = { features = ["std"], optional = true, version = "0.9" }
|
|
||||||
|
|
||||||
[dependencies.serenity]
|
[dependencies.serenity]
|
||||||
version = "0.11"
|
version = "0.11"
|
||||||
@@ -91,6 +91,7 @@ driver = [
|
|||||||
"dep:async-trait",
|
"dep:async-trait",
|
||||||
"dep:audiopus",
|
"dep:audiopus",
|
||||||
"dep:byteorder",
|
"dep:byteorder",
|
||||||
|
"dep:crypto_secretbox",
|
||||||
"dep:discortp",
|
"dep:discortp",
|
||||||
"dep:reqwest",
|
"dep:reqwest",
|
||||||
"dep:flume",
|
"dep:flume",
|
||||||
@@ -113,7 +114,6 @@ driver = [
|
|||||||
"dep:typemap_rev",
|
"dep:typemap_rev",
|
||||||
"dep:url",
|
"dep:url",
|
||||||
"dep:uuid",
|
"dep:uuid",
|
||||||
"dep:xsalsa20poly1305",
|
|
||||||
"tokio?/fs",
|
"tokio?/fs",
|
||||||
"tokio?/io-util",
|
"tokio?/io-util",
|
||||||
"tokio?/macros",
|
"tokio?/macros",
|
||||||
|
|||||||
@@ -4,11 +4,11 @@ use crate::{
|
|||||||
driver::tasks::{error::Recipient, message::*},
|
driver::tasks::{error::Recipient, message::*},
|
||||||
ws::Error as WsError,
|
ws::Error as WsError,
|
||||||
};
|
};
|
||||||
|
use crypto_secretbox::Error as CryptoError;
|
||||||
use flume::SendError;
|
use flume::SendError;
|
||||||
use serde_json::Error as JsonError;
|
use serde_json::Error as JsonError;
|
||||||
use std::{error::Error as StdError, fmt, io::Error as IoError};
|
use std::{error::Error as StdError, fmt, io::Error as IoError};
|
||||||
use tokio::time::error::Elapsed;
|
use tokio::time::error::Elapsed;
|
||||||
use xsalsa20poly1305::aead::Error as CryptoError;
|
|
||||||
|
|
||||||
/// Errors encountered while connecting to a Discord voice server over the driver.
|
/// Errors encountered while connecting to a Discord voice server over the driver.
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ use crate::{
|
|||||||
ws::WsStream,
|
ws::WsStream,
|
||||||
ConnectionInfo,
|
ConnectionInfo,
|
||||||
};
|
};
|
||||||
|
use crypto_secretbox::{KeyInit, XSalsa20Poly1305 as Cipher};
|
||||||
use discortp::discord::{IpDiscoveryPacket, IpDiscoveryType, MutableIpDiscoveryPacket};
|
use discortp::discord::{IpDiscoveryPacket, IpDiscoveryType, MutableIpDiscoveryPacket};
|
||||||
use error::{Error, Result};
|
use error::{Error, Result};
|
||||||
use flume::Sender;
|
use flume::Sender;
|
||||||
@@ -30,7 +31,6 @@ use std::{net::IpAddr, str::FromStr};
|
|||||||
use tokio::{net::UdpSocket, spawn, time::timeout};
|
use tokio::{net::UdpSocket, spawn, time::timeout};
|
||||||
use tracing::{debug, info, instrument};
|
use tracing::{debug, info, instrument};
|
||||||
use url::Url;
|
use url::Url;
|
||||||
use xsalsa20poly1305::{KeyInit, XSalsa20Poly1305 as Cipher};
|
|
||||||
|
|
||||||
pub(crate) struct Connection {
|
pub(crate) struct Connection {
|
||||||
pub(crate) info: ConnectionInfo,
|
pub(crate) info: ConnectionInfo,
|
||||||
|
|||||||
@@ -1,17 +1,21 @@
|
|||||||
//! Encryption schemes supported by Discord's secure RTP negotiation.
|
//! Encryption schemes supported by Discord's secure RTP negotiation.
|
||||||
use byteorder::{NetworkEndian, WriteBytesExt};
|
use byteorder::{NetworkEndian, WriteBytesExt};
|
||||||
|
#[cfg(any(feature = "receive", test))]
|
||||||
|
use crypto_secretbox::Tag;
|
||||||
|
use crypto_secretbox::{
|
||||||
|
aead::{AeadInPlace, Error as CryptoError},
|
||||||
|
Nonce,
|
||||||
|
SecretBox,
|
||||||
|
XSalsa20Poly1305 as Cipher,
|
||||||
|
};
|
||||||
use discortp::{rtp::RtpPacket, MutablePacket};
|
use discortp::{rtp::RtpPacket, MutablePacket};
|
||||||
use rand::Rng;
|
use rand::Rng;
|
||||||
use std::num::Wrapping;
|
use std::num::Wrapping;
|
||||||
#[cfg(any(feature = "receive", test))]
|
|
||||||
use xsalsa20poly1305::Tag;
|
#[cfg(test)]
|
||||||
use xsalsa20poly1305::{
|
pub const KEY_SIZE: usize = SecretBox::<()>::KEY_SIZE;
|
||||||
aead::{AeadInPlace, Error as CryptoError},
|
pub const NONCE_SIZE: usize = SecretBox::<()>::NONCE_SIZE;
|
||||||
Nonce,
|
pub const TAG_SIZE: usize = SecretBox::<()>::TAG_SIZE;
|
||||||
XSalsa20Poly1305 as Cipher,
|
|
||||||
NONCE_SIZE,
|
|
||||||
TAG_SIZE,
|
|
||||||
};
|
|
||||||
|
|
||||||
/// Variants of the `XSalsa20Poly1305` encryption scheme.
|
/// Variants of the `XSalsa20Poly1305` encryption scheme.
|
||||||
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
|
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
|
||||||
@@ -253,8 +257,8 @@ impl CryptoState {
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
use crypto_secretbox::KeyInit;
|
||||||
use discortp::rtp::MutableRtpPacket;
|
use discortp::rtp::MutableRtpPacket;
|
||||||
use xsalsa20poly1305::{KeyInit, KEY_SIZE, TAG_SIZE};
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn small_packet_decrypts_error() {
|
fn small_packet_decrypts_error() {
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
use super::message::*;
|
use super::message::*;
|
||||||
use crate::ws::Error as WsError;
|
use crate::ws::Error as WsError;
|
||||||
use audiopus::Error as OpusError;
|
use audiopus::Error as OpusError;
|
||||||
|
use crypto_secretbox::aead::Error as CryptoError;
|
||||||
use flume::SendError;
|
use flume::SendError;
|
||||||
use std::io::{Error as IoError, ErrorKind as IoErrorKind};
|
use std::io::{Error as IoError, ErrorKind as IoErrorKind};
|
||||||
use xsalsa20poly1305::aead::Error as CryptoError;
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum Recipient {
|
pub enum Recipient {
|
||||||
|
|||||||
@@ -8,10 +8,10 @@ use crate::{
|
|||||||
driver::{Bitrate, Config, CryptoState},
|
driver::{Bitrate, Config, CryptoState},
|
||||||
input::{AudioStreamError, Compose, Parsed},
|
input::{AudioStreamError, Compose, Parsed},
|
||||||
};
|
};
|
||||||
|
use crypto_secretbox::XSalsa20Poly1305 as Cipher;
|
||||||
use flume::Sender;
|
use flume::Sender;
|
||||||
use std::{net::UdpSocket, sync::Arc};
|
use std::{net::UdpSocket, sync::Arc};
|
||||||
use symphonia_core::{errors::Error as SymphoniaError, formats::SeekedTo};
|
use symphonia_core::{errors::Error as SymphoniaError, formats::SeekedTo};
|
||||||
use xsalsa20poly1305::XSalsa20Poly1305 as Cipher;
|
|
||||||
|
|
||||||
pub struct MixerConnection {
|
pub struct MixerConnection {
|
||||||
pub cipher: Cipher,
|
pub cipher: Cipher,
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ use super::{
|
|||||||
error::{Error, Result},
|
error::{Error, Result},
|
||||||
message::*,
|
message::*,
|
||||||
};
|
};
|
||||||
|
use crate::driver::crypto::TAG_SIZE;
|
||||||
use crate::{
|
use crate::{
|
||||||
constants::*,
|
constants::*,
|
||||||
driver::MixMode,
|
driver::MixMode,
|
||||||
@@ -53,7 +54,6 @@ use symphonia_core::{
|
|||||||
};
|
};
|
||||||
use tokio::runtime::Handle;
|
use tokio::runtime::Handle;
|
||||||
use tracing::error;
|
use tracing::error;
|
||||||
use xsalsa20poly1305::TAG_SIZE;
|
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
use crate::driver::test_config::{OutputMessage, OutputMode};
|
use crate::driver::test_config::{OutputMessage, OutputMode};
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ use crate::{
|
|||||||
Config,
|
Config,
|
||||||
};
|
};
|
||||||
use bytes::BytesMut;
|
use bytes::BytesMut;
|
||||||
|
use crypto_secretbox::XSalsa20Poly1305 as Cipher;
|
||||||
use discortp::{
|
use discortp::{
|
||||||
demux::{self, DemuxedMut},
|
demux::{self, DemuxedMut},
|
||||||
rtp::RtpPacket,
|
rtp::RtpPacket,
|
||||||
@@ -25,7 +26,6 @@ use std::{
|
|||||||
};
|
};
|
||||||
use tokio::{net::UdpSocket, select, time::Instant};
|
use tokio::{net::UdpSocket, select, time::Instant};
|
||||||
use tracing::{error, instrument, trace, warn};
|
use tracing::{error, instrument, trace, warn};
|
||||||
use xsalsa20poly1305::XSalsa20Poly1305 as Cipher;
|
|
||||||
|
|
||||||
type RtpSequence = Wrapping<u16>;
|
type RtpSequence = Wrapping<u16>;
|
||||||
type RtpTimestamp = Wrapping<u32>;
|
type RtpTimestamp = Wrapping<u32>;
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
constants::*,
|
constants::*,
|
||||||
|
driver::crypto::KEY_SIZE,
|
||||||
input::{
|
input::{
|
||||||
cached::Compressed,
|
cached::Compressed,
|
||||||
codecs::{CODEC_REGISTRY, PROBE},
|
codecs::{CODEC_REGISTRY, PROBE},
|
||||||
@@ -10,10 +11,10 @@ use crate::{
|
|||||||
test_utils,
|
test_utils,
|
||||||
tracks::LoopState,
|
tracks::LoopState,
|
||||||
};
|
};
|
||||||
|
use crypto_secretbox::{KeyInit, XSalsa20Poly1305 as Cipher};
|
||||||
use flume::{Receiver, Sender};
|
use flume::{Receiver, Sender};
|
||||||
use std::{io::Cursor, net::UdpSocket, sync::Arc};
|
use std::{io::Cursor, net::UdpSocket, sync::Arc};
|
||||||
use tokio::runtime::Handle;
|
use tokio::runtime::Handle;
|
||||||
use xsalsa20poly1305::{KeyInit, XSalsa20Poly1305 as Cipher, KEY_SIZE};
|
|
||||||
|
|
||||||
use super::{
|
use super::{
|
||||||
scheduler::*,
|
scheduler::*,
|
||||||
|
|||||||
Reference in New Issue
Block a user