From 36bc0bec2740f75fbee8bb0ff867240156562f74 Mon Sep 17 00:00:00 2001 From: zonyitoo Date: Tue, 6 Aug 2019 21:19:10 +0800 Subject: [PATCH] Supports camellia-*-cfb --- Cargo.toml | 3 +- src/crypto/cipher.rs | 212 ++++++++++++++++++++++++++++++++ src/crypto/openssl.rs | 106 +++++++++++----- src/crypto/rc4_md5.rs | 5 +- src/crypto/ring.rs | 15 +-- src/crypto/siv.rs | 5 +- src/crypto/table.rs | 4 +- src/relay/tcprelay/client.rs | 9 +- src/relay/tcprelay/crypto_io.rs | 4 +- src/relay/tcprelay/utils.rs | 4 +- src/relay/udprelay/dns.rs | 4 +- src/relay/udprelay/local.rs | 4 +- src/relay/udprelay/mod.rs | 3 +- src/relay/udprelay/server.rs | 4 +- tests/dns.rs | 3 +- tests/socks5.rs | 3 +- tests/udp.rs | 3 +- 17 files changed, 306 insertions(+), 85 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 16bf48a8..6ee7628a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -32,11 +32,12 @@ path = "src/bin/ssdns.rs" lto = true [features] -default = ["sodium", "rc4", "aes-cfb", "aes-ctr"] +default = ["sodium", "rc4", "aes-cfb", "aes-ctr", "camellia-cfb"] sodium = ["libsodium-ffi"] rc4 = ["openssl"] aes-cfb = ["openssl"] aes-ctr = ["openssl"] +camellia-cfb = ["openssl"] single-threaded = [] [dependencies] diff --git a/src/crypto/cipher.rs b/src/crypto/cipher.rs index c5315eb4..f9ff3d24 100644 --- a/src/crypto/cipher.rs +++ b/src/crypto/cipher.rs @@ -10,6 +10,8 @@ use std::{ use crate::crypto::digest::{self, Digest, DigestType}; use bytes::{BufMut, Bytes, BytesMut}; #[cfg(feature = "openssl")] +use openssl::nid::Nid; +#[cfg(feature = "openssl")] use openssl::symm; use rand::{self, RngCore}; use ring::aead::{AES_128_GCM, AES_256_GCM, CHACHA20_POLY1305}; @@ -107,6 +109,31 @@ const CIPHER_AES_192_CTR: &str = "aes-192-ctr"; #[cfg(feature = "aes-ctr")] const CIPHER_AES_256_CTR: &str = "aes-256-ctr"; +#[cfg(feature = "camellia-cfb")] +const CIPHER_CAMELLIA_128_CFB: &str = "camellia-128-cfb"; +#[cfg(feature = "camellia-cfb")] +const CIPHER_CAMELLIA_192_CFB: &str = "camellia-192-cfb"; +#[cfg(feature = "camellia-cfb")] +const CIPHER_CAMELLIA_256_CFB: &str = "camellia-256-cfb"; +#[cfg(feature = "camellia-cfb")] +const CIPHER_CAMELLIA_128_CFB_1: &str = "camellia-128-cfb1"; +#[cfg(feature = "camellia-cfb")] +const CIPHER_CAMELLIA_192_CFB_1: &str = "camellia-192-cfb1"; +#[cfg(feature = "camellia-cfb")] +const CIPHER_CAMELLIA_256_CFB_1: &str = "camellia-256-cfb1"; +#[cfg(feature = "camellia-cfb")] +const CIPHER_CAMELLIA_128_CFB_8: &str = "camellia-128-cfb8"; +#[cfg(feature = "camellia-cfb")] +const CIPHER_CAMELLIA_192_CFB_8: &str = "camellia-192-cfb8"; +#[cfg(feature = "camellia-cfb")] +const CIPHER_CAMELLIA_256_CFB_8: &str = "camellia-256-cfb8"; +#[cfg(feature = "camellia-cfb")] +const CIPHER_CAMELLIA_128_CFB_128: &str = "camellia-128-cfb128"; +#[cfg(feature = "camellia-cfb")] +const CIPHER_CAMELLIA_192_CFB_128: &str = "camellia-192-cfb128"; +#[cfg(feature = "camellia-cfb")] +const CIPHER_CAMELLIA_256_CFB_128: &str = "camellia-256-cfb128"; + #[cfg(feature = "rc4")] const CIPHER_RC4: &str = "rc4"; #[cfg(feature = "rc4")] @@ -176,6 +203,31 @@ pub enum CipherType { #[cfg(feature = "aes-ctr")] Aes256Ctr, + #[cfg(feature = "camellia-cfb")] + Camellia128Cfb, + #[cfg(feature = "camellia-cfb")] + Camellia192Cfb, + #[cfg(feature = "camellia-cfb")] + Camellia256Cfb, + #[cfg(feature = "camellia-cfb")] + Camellia128Cfb1, + #[cfg(feature = "camellia-cfb")] + Camellia192Cfb1, + #[cfg(feature = "camellia-cfb")] + Camellia256Cfb1, + #[cfg(feature = "camellia-cfb")] + Camellia128Cfb8, + #[cfg(feature = "camellia-cfb")] + Camellia192Cfb8, + #[cfg(feature = "camellia-cfb")] + Camellia256Cfb8, + #[cfg(feature = "camellia-cfb")] + Camellia128Cfb128, + #[cfg(feature = "camellia-cfb")] + Camellia192Cfb128, + #[cfg(feature = "camellia-cfb")] + Camellia256Cfb128, + #[cfg(feature = "rc4")] Rc4, #[cfg(feature = "rc4")] @@ -244,6 +296,55 @@ impl CipherType { #[cfg(feature = "aes-ctr")] CipherType::Aes256Ctr => symm::Cipher::aes_256_ctr().key_len(), + #[cfg(feature = "camellia-cfb")] + CipherType::Camellia128Cfb => symm::Cipher::from_nid(Nid::CAMELLIA_128_CFB128) + .expect("openssl doesn't support camellia-128-cfb") + .key_len(), + #[cfg(feature = "camellia-cfb")] + CipherType::Camellia128Cfb1 => symm::Cipher::from_nid(Nid::CAMELLIA_128_CFB1) + .expect("openssl doesn't support camellia-128-cfb1") + .key_len(), + #[cfg(feature = "camellia-cfb")] + CipherType::Camellia128Cfb8 => symm::Cipher::from_nid(Nid::CAMELLIA_128_CFB8) + .expect("openssl doesn't support camellia-128-cfb8") + .key_len(), + #[cfg(feature = "camellia-cfb")] + CipherType::Camellia128Cfb128 => symm::Cipher::from_nid(Nid::CAMELLIA_128_CFB128) + .expect("openssl doesn't support camellia-128-cfb128") + .key_len(), + #[cfg(feature = "camellia-cfb")] + CipherType::Camellia192Cfb => symm::Cipher::from_nid(Nid::CAMELLIA_192_CFB128) + .expect("openssl doesn't support camellia-192-cfb") + .key_len(), + #[cfg(feature = "camellia-cfb")] + CipherType::Camellia192Cfb1 => symm::Cipher::from_nid(Nid::CAMELLIA_192_CFB1) + .expect("openssl doesn't support camellia-192-cfb1") + .key_len(), + #[cfg(feature = "camellia-cfb")] + CipherType::Camellia192Cfb8 => symm::Cipher::from_nid(Nid::CAMELLIA_192_CFB8) + .expect("openssl doesn't support camellia-192-cfb8") + .key_len(), + #[cfg(feature = "camellia-cfb")] + CipherType::Camellia192Cfb128 => symm::Cipher::from_nid(Nid::CAMELLIA_192_CFB128) + .expect("openssl doesn't support camellia-192-cfb128") + .key_len(), + #[cfg(feature = "camellia-cfb")] + CipherType::Camellia256Cfb => symm::Cipher::from_nid(Nid::CAMELLIA_256_CFB128) + .expect("openssl doesn't support camellia-256-cfb") + .key_len(), + #[cfg(feature = "camellia-cfb")] + CipherType::Camellia256Cfb1 => symm::Cipher::from_nid(Nid::CAMELLIA_256_CFB1) + .expect("openssl doesn't support camellia-256-cfb1") + .key_len(), + #[cfg(feature = "camellia-cfb")] + CipherType::Camellia256Cfb8 => symm::Cipher::from_nid(Nid::CAMELLIA_256_CFB8) + .expect("openssl doesn't support camellia-256-cfb8") + .key_len(), + #[cfg(feature = "camellia-cfb")] + CipherType::Camellia256Cfb128 => symm::Cipher::from_nid(Nid::CAMELLIA_256_CFB128) + .expect("openssl doesn't support camellia-256-cfb128") + .key_len(), + #[cfg(feature = "rc4")] CipherType::Rc4 | CipherType::Rc4Md5 => symm::Cipher::rc4().key_len(), @@ -350,6 +451,67 @@ impl CipherType { #[cfg(feature = "aes-ctr")] CipherType::Aes256Ctr => symm::Cipher::aes_256_ctr().iv_len().expect("iv_len should not be None"), + #[cfg(feature = "camellia-cfb")] + CipherType::Camellia128Cfb => symm::Cipher::from_nid(Nid::CAMELLIA_128_CFB128) + .expect("openssl doesn't support camellia-128-cfb") + .iv_len() + .expect("iv_len should not be None"), + #[cfg(feature = "camellia-cfb")] + CipherType::Camellia128Cfb1 => symm::Cipher::from_nid(Nid::CAMELLIA_128_CFB1) + .expect("openssl doesn't support camellia-128-cfb1") + .iv_len() + .expect("iv_len should not be None"), + #[cfg(feature = "camellia-cfb")] + CipherType::Camellia128Cfb8 => symm::Cipher::from_nid(Nid::CAMELLIA_128_CFB8) + .expect("openssl doesn't support camellia-128-cfb8") + .iv_len() + .expect("iv_len should not be None"), + #[cfg(feature = "camellia-cfb")] + CipherType::Camellia128Cfb128 => symm::Cipher::from_nid(Nid::CAMELLIA_128_CFB128) + .expect("openssl doesn't support camellia-128-cfb128") + .iv_len() + .expect("iv_len should not be None"), + #[cfg(feature = "camellia-cfb")] + CipherType::Camellia192Cfb => symm::Cipher::from_nid(Nid::CAMELLIA_192_CFB128) + .expect("openssl doesn't support camellia-192-cfb") + .iv_len() + .expect("iv_len should not be None"), + #[cfg(feature = "camellia-cfb")] + CipherType::Camellia192Cfb1 => symm::Cipher::from_nid(Nid::CAMELLIA_192_CFB1) + .expect("openssl doesn't support camellia-192-cfb1") + .iv_len() + .expect("iv_len should not be None"), + #[cfg(feature = "camellia-cfb")] + CipherType::Camellia192Cfb8 => symm::Cipher::from_nid(Nid::CAMELLIA_192_CFB8) + .expect("openssl doesn't support camellia-192-cfb8") + .iv_len() + .expect("iv_len should not be None"), + #[cfg(feature = "camellia-cfb")] + CipherType::Camellia192Cfb128 => symm::Cipher::from_nid(Nid::CAMELLIA_192_CFB128) + .expect("openssl doesn't support camellia-192-cfb128") + .iv_len() + .expect("iv_len should not be None"), + #[cfg(feature = "camellia-cfb")] + CipherType::Camellia256Cfb => symm::Cipher::from_nid(Nid::CAMELLIA_256_CFB128) + .expect("openssl doesn't support camellia-256-cfb") + .iv_len() + .expect("iv_len should not be None"), + #[cfg(feature = "camellia-cfb")] + CipherType::Camellia256Cfb1 => symm::Cipher::from_nid(Nid::CAMELLIA_256_CFB1) + .expect("openssl doesn't support camellia-256-cfb1") + .iv_len() + .expect("iv_len should not be None"), + #[cfg(feature = "camellia-cfb")] + CipherType::Camellia256Cfb8 => symm::Cipher::from_nid(Nid::CAMELLIA_256_CFB8) + .expect("openssl doesn't support camellia-256-cfb8") + .iv_len() + .expect("iv_len should not be None"), + #[cfg(feature = "camellia-cfb")] + CipherType::Camellia256Cfb128 => symm::Cipher::from_nid(Nid::CAMELLIA_256_CFB128) + .expect("openssl doesn't support camellia-256-cfb128") + .iv_len() + .expect("iv_len should not be None"), + #[cfg(feature = "rc4")] CipherType::Rc4 => symm::Cipher::rc4().iv_len().expect("iv_len should not be None"), #[cfg(feature = "rc4")] @@ -478,6 +640,31 @@ impl FromStr for CipherType { #[cfg(feature = "aes-ctr")] CIPHER_AES_256_CTR => Ok(CipherType::Aes256Ctr), + #[cfg(feature = "camellia-cfb")] + CIPHER_CAMELLIA_128_CFB => Ok(CipherType::Camellia128Cfb), + #[cfg(feature = "camellia-cfb")] + CIPHER_CAMELLIA_128_CFB_1 => Ok(CipherType::Camellia128Cfb1), + #[cfg(feature = "camellia-cfb")] + CIPHER_CAMELLIA_128_CFB_8 => Ok(CipherType::Camellia128Cfb8), + #[cfg(feature = "camellia-cfb")] + CIPHER_CAMELLIA_128_CFB_128 => Ok(CipherType::Camellia128Cfb128), + #[cfg(feature = "camellia-cfb")] + CIPHER_CAMELLIA_192_CFB => Ok(CipherType::Camellia192Cfb), + #[cfg(feature = "camellia-cfb")] + CIPHER_CAMELLIA_192_CFB_1 => Ok(CipherType::Camellia192Cfb1), + #[cfg(feature = "camellia-cfb")] + CIPHER_CAMELLIA_192_CFB_8 => Ok(CipherType::Camellia192Cfb8), + #[cfg(feature = "camellia-cfb")] + CIPHER_CAMELLIA_192_CFB_128 => Ok(CipherType::Camellia192Cfb128), + #[cfg(feature = "camellia-cfb")] + CIPHER_CAMELLIA_256_CFB => Ok(CipherType::Camellia256Cfb), + #[cfg(feature = "camellia-cfb")] + CIPHER_CAMELLIA_256_CFB_1 => Ok(CipherType::Camellia256Cfb1), + #[cfg(feature = "camellia-cfb")] + CIPHER_CAMELLIA_256_CFB_8 => Ok(CipherType::Camellia256Cfb8), + #[cfg(feature = "camellia-cfb")] + CIPHER_CAMELLIA_256_CFB_128 => Ok(CipherType::Camellia256Cfb128), + #[cfg(feature = "rc4")] CIPHER_RC4 => Ok(CipherType::Rc4), #[cfg(feature = "rc4")] @@ -548,6 +735,31 @@ impl Display for CipherType { #[cfg(feature = "aes-ctr")] CipherType::Aes256Ctr => write!(f, "{}", CIPHER_AES_256_CTR), + #[cfg(feature = "camellia-cfb")] + CipherType::Camellia128Cfb => write!(f, "{}", CIPHER_CAMELLIA_128_CFB), + #[cfg(feature = "camellia-cfb")] + CipherType::Camellia128Cfb1 => write!(f, "{}", CIPHER_CAMELLIA_128_CFB_1), + #[cfg(feature = "camellia-cfb")] + CipherType::Camellia128Cfb8 => write!(f, "{}", CIPHER_CAMELLIA_128_CFB_8), + #[cfg(feature = "camellia-cfb")] + CipherType::Camellia128Cfb128 => write!(f, "{}", CIPHER_CAMELLIA_128_CFB_128), + #[cfg(feature = "camellia-cfb")] + CipherType::Camellia192Cfb => write!(f, "{}", CIPHER_CAMELLIA_192_CFB), + #[cfg(feature = "camellia-cfb")] + CipherType::Camellia192Cfb1 => write!(f, "{}", CIPHER_CAMELLIA_192_CFB_1), + #[cfg(feature = "camellia-cfb")] + CipherType::Camellia192Cfb8 => write!(f, "{}", CIPHER_CAMELLIA_192_CFB_8), + #[cfg(feature = "camellia-cfb")] + CipherType::Camellia192Cfb128 => write!(f, "{}", CIPHER_CAMELLIA_192_CFB_128), + #[cfg(feature = "camellia-cfb")] + CipherType::Camellia256Cfb => write!(f, "{}", CIPHER_CAMELLIA_256_CFB), + #[cfg(feature = "camellia-cfb")] + CipherType::Camellia256Cfb1 => write!(f, "{}", CIPHER_CAMELLIA_256_CFB_1), + #[cfg(feature = "camellia-cfb")] + CipherType::Camellia256Cfb8 => write!(f, "{}", CIPHER_CAMELLIA_256_CFB_8), + #[cfg(feature = "camellia-cfb")] + CipherType::Camellia256Cfb128 => write!(f, "{}", CIPHER_CAMELLIA_256_CFB_128), + #[cfg(feature = "rc4")] CipherType::Rc4 => write!(f, "{}", CIPHER_RC4), #[cfg(feature = "rc4")] diff --git a/src/crypto/openssl.rs b/src/crypto/openssl.rs index 4b9ef372..cb6fee2f 100644 --- a/src/crypto/openssl.rs +++ b/src/crypto/openssl.rs @@ -7,6 +7,7 @@ use crate::crypto::{cipher, CipherResult, CipherType, StreamCipher}; use crate::crypto::CryptoMode; use bytes::{BufMut, BytesMut}; +use openssl::nid::Nid; use openssl::symm; /// Core cipher of OpenSSL @@ -18,37 +19,84 @@ pub struct OpenSSLCrypto { impl OpenSSLCrypto { /// Creates by type pub fn new(cipher_type: cipher::CipherType, key: &[u8], iv: &[u8], mode: CryptoMode) -> OpenSSLCrypto { - let t = match cipher_type { - #[cfg(feature = "aes-cfb")] - CipherType::Aes128Cfb => symm::Cipher::aes_128_cfb128(), - #[cfg(feature = "aes-cfb")] - CipherType::Aes128Cfb1 => symm::Cipher::aes_128_cfb1(), - #[cfg(feature = "aes-cfb")] - CipherType::Aes128Cfb128 => symm::Cipher::aes_128_cfb128(), - #[cfg(feature = "aes-cfb")] - CipherType::Aes192Cfb => symm::Cipher::aes_192_cfb128(), - #[cfg(feature = "aes-cfb")] - CipherType::Aes192Cfb1 => symm::Cipher::aes_192_cfb1(), - #[cfg(feature = "aes-cfb")] - CipherType::Aes192Cfb128 => symm::Cipher::aes_192_cfb128(), - #[cfg(feature = "aes-cfb")] - CipherType::Aes256Cfb => symm::Cipher::aes_256_cfb128(), - #[cfg(feature = "aes-cfb")] - CipherType::Aes256Cfb1 => symm::Cipher::aes_256_cfb1(), - #[cfg(feature = "aes-cfb")] - CipherType::Aes256Cfb128 => symm::Cipher::aes_256_cfb128(), + let t = + match cipher_type { + #[cfg(feature = "aes-cfb")] + CipherType::Aes128Cfb => symm::Cipher::aes_128_cfb128(), + #[cfg(feature = "aes-cfb")] + CipherType::Aes128Cfb1 => symm::Cipher::aes_128_cfb1(), + #[cfg(feature = "aes-cfb")] + CipherType::Aes128Cfb128 => symm::Cipher::aes_128_cfb128(), + #[cfg(feature = "aes-cfb")] + CipherType::Aes192Cfb => symm::Cipher::aes_192_cfb128(), + #[cfg(feature = "aes-cfb")] + CipherType::Aes192Cfb1 => symm::Cipher::aes_192_cfb1(), + #[cfg(feature = "aes-cfb")] + CipherType::Aes192Cfb128 => symm::Cipher::aes_192_cfb128(), + #[cfg(feature = "aes-cfb")] + CipherType::Aes256Cfb => symm::Cipher::aes_256_cfb128(), + #[cfg(feature = "aes-cfb")] + CipherType::Aes256Cfb1 => symm::Cipher::aes_256_cfb1(), + #[cfg(feature = "aes-cfb")] + CipherType::Aes256Cfb128 => symm::Cipher::aes_256_cfb128(), - #[cfg(feature = "aes-ctr")] - CipherType::Aes128Ctr => symm::Cipher::aes_128_ctr(), - #[cfg(feature = "aes-ctr")] - CipherType::Aes192Ctr => symm::Cipher::aes_192_ctr(), - #[cfg(feature = "aes-ctr")] - CipherType::Aes256Ctr => symm::Cipher::aes_256_ctr(), + #[cfg(feature = "aes-ctr")] + CipherType::Aes128Ctr => symm::Cipher::aes_128_ctr(), + #[cfg(feature = "aes-ctr")] + CipherType::Aes192Ctr => symm::Cipher::aes_192_ctr(), + #[cfg(feature = "aes-ctr")] + CipherType::Aes256Ctr => symm::Cipher::aes_256_ctr(), - #[cfg(feature = "rc4")] - CipherType::Rc4 => symm::Cipher::rc4(), - _ => panic!("Cipher type {:?} does not supported by OpenSSLCrypt yet", cipher_type), - }; + #[cfg(feature = "camellia-cfb")] + CipherType::Camellia128Cfb => { + symm::Cipher::from_nid(Nid::CAMELLIA_128_CFB128).expect("openssl doesn't support camellia-128-cfb") + } + #[cfg(feature = "camellia-cfb")] + CipherType::Camellia128Cfb1 => { + symm::Cipher::from_nid(Nid::CAMELLIA_128_CFB1).expect("openssl doesn't support camellia-128-cfb1") + } + #[cfg(feature = "camellia-cfb")] + CipherType::Camellia128Cfb8 => { + symm::Cipher::from_nid(Nid::CAMELLIA_128_CFB8).expect("openssl doesn't support camellia-128-cfb8") + } + #[cfg(feature = "camellia-cfb")] + CipherType::Camellia128Cfb128 => symm::Cipher::from_nid(Nid::CAMELLIA_128_CFB128) + .expect("openssl doesn't support camellia-128-cfb128"), + #[cfg(feature = "camellia-cfb")] + CipherType::Camellia192Cfb => { + symm::Cipher::from_nid(Nid::CAMELLIA_192_CFB128).expect("openssl doesn't support camellia-192-cfb") + } + #[cfg(feature = "camellia-cfb")] + CipherType::Camellia192Cfb1 => { + symm::Cipher::from_nid(Nid::CAMELLIA_192_CFB1).expect("openssl doesn't support camellia-192-cfb1") + } + #[cfg(feature = "camellia-cfb")] + CipherType::Camellia192Cfb8 => { + symm::Cipher::from_nid(Nid::CAMELLIA_192_CFB8).expect("openssl doesn't support camellia-192-cfb8") + } + #[cfg(feature = "camellia-cfb")] + CipherType::Camellia192Cfb128 => symm::Cipher::from_nid(Nid::CAMELLIA_192_CFB128) + .expect("openssl doesn't support camellia-192-cfb128"), + #[cfg(feature = "camellia-cfb")] + CipherType::Camellia256Cfb => { + symm::Cipher::from_nid(Nid::CAMELLIA_256_CFB128).expect("openssl doesn't support camellia-256-cfb") + } + #[cfg(feature = "camellia-cfb")] + CipherType::Camellia256Cfb1 => { + symm::Cipher::from_nid(Nid::CAMELLIA_256_CFB1).expect("openssl doesn't support camellia-256-cfb1") + } + #[cfg(feature = "camellia-cfb")] + CipherType::Camellia256Cfb8 => { + symm::Cipher::from_nid(Nid::CAMELLIA_256_CFB8).expect("openssl doesn't support camellia-256-cfb8") + } + #[cfg(feature = "camellia-cfb")] + CipherType::Camellia256Cfb128 => symm::Cipher::from_nid(Nid::CAMELLIA_256_CFB128) + .expect("openssl doesn't support camellia-256-cfb128"), + + #[cfg(feature = "rc4")] + CipherType::Rc4 => symm::Cipher::rc4(), + _ => panic!("Cipher type {:?} does not supported by OpenSSLCrypt yet", cipher_type), + }; // Panic if error occurs let cipher = symm::Crypter::new(t, From::from(mode), key, Some(iv)).unwrap(); diff --git a/src/crypto/rc4_md5.rs b/src/crypto/rc4_md5.rs index 9d16d7fe..3ccb5098 100644 --- a/src/crypto/rc4_md5.rs +++ b/src/crypto/rc4_md5.rs @@ -3,10 +3,7 @@ use crate::crypto::{ digest::{self, Digest, DigestType}, openssl::OpenSSLCrypto, - CipherResult, - CipherType, - CryptoMode, - StreamCipher, + CipherResult, CipherType, CryptoMode, StreamCipher, }; use bytes::{BufMut, BytesMut}; diff --git a/src/crypto/ring.rs b/src/crypto/ring.rs index 99bda868..db4a0734 100644 --- a/src/crypto/ring.rs +++ b/src/crypto/ring.rs @@ -3,24 +3,13 @@ use std::{mem, ptr}; use ring::aead::{ - open_in_place, - seal_in_place, - Aad, - Nonce, - OpeningKey, - SealingKey, - AES_128_GCM, - AES_256_GCM, - CHACHA20_POLY1305, + open_in_place, seal_in_place, Aad, Nonce, OpeningKey, SealingKey, AES_128_GCM, AES_256_GCM, CHACHA20_POLY1305, }; use crate::crypto::{ aead::{increase_nonce, make_skey}, cipher::Error, - AeadDecryptor, - AeadEncryptor, - CipherResult, - CipherType, + AeadDecryptor, AeadEncryptor, CipherResult, CipherType, }; use byte_string::ByteStr; diff --git a/src/crypto/siv.rs b/src/crypto/siv.rs index f644176e..1e93b6a8 100644 --- a/src/crypto/siv.rs +++ b/src/crypto/siv.rs @@ -7,10 +7,7 @@ use miscreant::aead::{Aead, Aes128PmacSivAead, Aes256PmacSivAead}; use crate::crypto::{ aead::{increase_nonce, make_skey}, cipher::Error, - AeadDecryptor, - AeadEncryptor, - CipherResult, - CipherType, + AeadDecryptor, AeadEncryptor, CipherResult, CipherType, }; use byte_string::ByteStr; diff --git a/src/crypto/table.rs b/src/crypto/table.rs index 95e4c453..a0507fab 100644 --- a/src/crypto/table.rs +++ b/src/crypto/table.rs @@ -4,9 +4,7 @@ use std::io::Cursor; use crate::crypto::{ digest::{self, Digest, DigestType}, - CipherResult, - CryptoMode, - StreamCipher, + CipherResult, CryptoMode, StreamCipher, }; use byteorder::{LittleEndian, ReadBytesExt}; diff --git a/src/relay/tcprelay/client.rs b/src/relay/tcprelay/client.rs index 4b33bda5..c226dc1e 100644 --- a/src/relay/tcprelay/client.rs +++ b/src/relay/tcprelay/client.rs @@ -12,14 +12,7 @@ use tokio::net::TcpStream; use tokio_io::{io::flush, AsyncRead, AsyncWrite}; use crate::relay::socks5::{ - self, - Address, - Command, - HandshakeRequest, - HandshakeResponse, - Reply, - TcpRequestHeader, - TcpResponseHeader, + self, Address, Command, HandshakeRequest, HandshakeResponse, Reply, TcpRequestHeader, TcpResponseHeader, }; use crate::{config::ServerConfig, context::SharedContext}; diff --git a/src/relay/tcprelay/crypto_io.rs b/src/relay/tcprelay/crypto_io.rs index dd19d49b..f9c18bf4 100644 --- a/src/relay/tcprelay/crypto_io.rs +++ b/src/relay/tcprelay/crypto_io.rs @@ -11,9 +11,7 @@ use futures::{Async, Future, Poll}; use tokio::timer::Delay; use tokio_io::{ io::{copy, Copy}, - try_nb, - AsyncRead, - AsyncWrite, + try_nb, AsyncRead, AsyncWrite, }; use super::{ diff --git a/src/relay/tcprelay/utils.rs b/src/relay/tcprelay/utils.rs index 340beebc..bf6f89e9 100644 --- a/src/relay/tcprelay/utils.rs +++ b/src/relay/tcprelay/utils.rs @@ -9,9 +9,7 @@ use futures::{Async, Future, Poll}; use tokio::timer::Delay; use tokio_io::{ io::{copy, Copy}, - try_nb, - AsyncRead, - AsyncWrite, + try_nb, AsyncRead, AsyncWrite, }; use super::BUFFER_SIZE; diff --git a/src/relay/udprelay/dns.rs b/src/relay/udprelay/dns.rs index 14135c01..63a0b3f9 100644 --- a/src/relay/udprelay/dns.rs +++ b/src/relay/udprelay/dns.rs @@ -14,9 +14,7 @@ use tokio::{self, net::UdpSocket}; use super::{ crypto_io::{decrypt_payload, encrypt_payload}, - PacketStream, - SendDgramRc, - SharedUdpSocket, + PacketStream, SendDgramRc, SharedUdpSocket, }; use crate::{ config::{ServerAddr, ServerConfig}, diff --git a/src/relay/udprelay/local.rs b/src/relay/udprelay/local.rs index b2dc5ce4..af18cc43 100644 --- a/src/relay/udprelay/local.rs +++ b/src/relay/udprelay/local.rs @@ -24,9 +24,7 @@ use crate::{ use super::{ crypto_io::{decrypt_payload, encrypt_payload}, - PacketStream, - SendDgramRc, - MAXIMUM_UDP_PAYLOAD_SIZE, + PacketStream, SendDgramRc, MAXIMUM_UDP_PAYLOAD_SIZE, }; /// Resolves server address to SocketAddr diff --git a/src/relay/udprelay/mod.rs b/src/relay/udprelay/mod.rs index 6e7eb42f..04f6a20f 100644 --- a/src/relay/udprelay/mod.rs +++ b/src/relay/udprelay/mod.rs @@ -38,8 +38,7 @@ //! +-------+--------------+ use std::{ - io, - mem, + io, mem, net::SocketAddr, sync::{Arc, Mutex}, }; diff --git a/src/relay/udprelay/server.rs b/src/relay/udprelay/server.rs index 57766f43..ad7ec4ce 100644 --- a/src/relay/udprelay/server.rs +++ b/src/relay/udprelay/server.rs @@ -19,9 +19,7 @@ use crate::{ use super::{ crypto_io::{decrypt_payload, encrypt_payload}, - PacketStream, - SendDgramRc, - MAXIMUM_UDP_PAYLOAD_SIZE, + PacketStream, SendDgramRc, MAXIMUM_UDP_PAYLOAD_SIZE, }; fn resolve_remote_addr( diff --git a/tests/dns.rs b/tests/dns.rs index f283827d..f1454030 100644 --- a/tests/dns.rs +++ b/tests/dns.rs @@ -9,8 +9,7 @@ use dns_parser::{Builder, Packet, QueryClass, QueryType}; use log::trace; use shadowsocks::{ config::{Config, ConfigType}, - run_dns, - run_server, + run_dns, run_server, }; use tokio::runtime::current_thread::Runtime; diff --git a/tests/socks5.rs b/tests/socks5.rs index 6038e7c1..d54665db 100644 --- a/tests/socks5.rs +++ b/tests/socks5.rs @@ -12,8 +12,7 @@ use shadowsocks::{ config::{Config, ConfigType, Mode, ServerConfig}, crypto::CipherType, relay::{socks5::Address, tcprelay::client::Socks5Client}, - run_local, - run_server, + run_local, run_server, }; pub struct Socks5TestServer { diff --git a/tests/udp.rs b/tests/udp.rs index b7ec169c..5d821727 100644 --- a/tests/udp.rs +++ b/tests/udp.rs @@ -20,8 +20,7 @@ use shadowsocks::{ socks5::{Address, UdpAssociateHeader}, tcprelay::client::Socks5Client, }, - run_local, - run_server, + run_local, run_server, }; const SERVER_ADDR: &str = "127.0.0.1:8093";