From 5e1c11d9553e0d084295fdd18a2184b53a390749 Mon Sep 17 00:00:00 2001 From: Mygod Date: Tue, 22 Jun 2021 13:52:33 +0800 Subject: [PATCH] Log detected replay instead of dropping the connection --- crates/shadowsocks/src/relay/tcprelay/aead.rs | 9 ++------- crates/shadowsocks/src/relay/tcprelay/stream.rs | 9 ++------- crates/shadowsocks/src/relay/udprelay/crypto_io.rs | 8 +++----- 3 files changed, 7 insertions(+), 19 deletions(-) diff --git a/crates/shadowsocks/src/relay/tcprelay/aead.rs b/crates/shadowsocks/src/relay/tcprelay/aead.rs index 17e0df31601a..ef2f045ca5a1 100644 --- a/crates/shadowsocks/src/relay/tcprelay/aead.rs +++ b/crates/shadowsocks/src/relay/tcprelay/aead.rs @@ -43,7 +43,7 @@ use std::{ use byte_string::ByteStr; use bytes::{BufMut, Bytes, BytesMut}; use futures::ready; -use log::trace; +use log::{trace, warn}; use tokio::io::{AsyncRead, AsyncWrite, ReadBuf}; use crate::{ @@ -223,12 +223,7 @@ impl DecryptedReader { let salt = self.salt.take().unwrap(); if context.check_nonce_and_set(&salt) { - use std::io::Error; - - trace!("detected repeated AEAD salt {:?}", ByteStr::new(&salt)); - - let err = Error::new(ErrorKind::Other, "detected repeated salt"); - return Err(err).into(); + warn!("detected repeated AEAD salt {:?}", ByteStr::new(&salt)); } } diff --git a/crates/shadowsocks/src/relay/tcprelay/stream.rs b/crates/shadowsocks/src/relay/tcprelay/stream.rs index 8e8c979666a0..df2c2f5c9d6c 100644 --- a/crates/shadowsocks/src/relay/tcprelay/stream.rs +++ b/crates/shadowsocks/src/relay/tcprelay/stream.rs @@ -10,7 +10,7 @@ use std::{ use byte_string::ByteStr; use bytes::{BufMut, Bytes, BytesMut}; use futures::ready; -use log::trace; +use log::{trace, warn}; use tokio::io::{AsyncRead, AsyncWrite, ReadBuf}; use crate::{ @@ -113,12 +113,7 @@ impl DecryptedReader { let iv = &self.buffer[..iv_len]; if context.check_nonce_and_set(&iv) { - use std::io::Error; - - trace!("detected repeated stream iv {:?}", ByteStr::new(&iv)); - - let err = Error::new(ErrorKind::Other, "detected repeated iv"); - return Err(err).into(); +warn!("detected repeated stream iv {:?}", ByteStr::new(&iv)); } trace!("got stream iv {:?}", ByteStr::new(iv)); diff --git a/crates/shadowsocks/src/relay/udprelay/crypto_io.rs b/crates/shadowsocks/src/relay/udprelay/crypto_io.rs index 279a6b8b2049..778020b721a4 100644 --- a/crates/shadowsocks/src/relay/udprelay/crypto_io.rs +++ b/crates/shadowsocks/src/relay/udprelay/crypto_io.rs @@ -23,7 +23,7 @@ use std::io::{self, Cursor, ErrorKind}; use byte_string::ByteStr; use bytes::{BufMut, BytesMut}; -use log::{debug, trace}; +use log::{trace, warn}; use crate::{ context::Context, @@ -182,8 +182,7 @@ async fn decrypt_payload_stream( let (iv, data) = payload.split_at_mut(iv_len); if context.check_nonce_and_set(iv) { - debug!("detected repeated iv {:?}", ByteStr::new(iv)); - return Err(io::Error::new(io::ErrorKind::Other, "detected repeated iv")); + warn!("detected repeated iv {:?}", ByteStr::new(iv)); } trace!("UDP packet got stream IV {:?}", ByteStr::new(iv)); @@ -215,8 +214,7 @@ async fn decrypt_payload_aead( let (salt, data) = payload.split_at_mut(salt_len); if context.check_nonce_and_set(salt) { - debug!("detected repeated salt {:?}", ByteStr::new(salt)); - return Err(io::Error::new(io::ErrorKind::Other, "detected repeated salt")); + warn!("detected repeated salt {:?}", ByteStr::new(salt)); } trace!("UDP packet got AEAD salt {:?}", ByteStr::new(salt));