Skip to content

Commit

Permalink
Log detected replay instead of dropping the connection
Browse files Browse the repository at this point in the history
  • Loading branch information
Mygod committed Jun 22, 2021
1 parent 3743ffe commit 75f367e
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 19 deletions.
9 changes: 2 additions & 7 deletions crates/shadowsocks/src/relay/tcprelay/aead.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down Expand Up @@ -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));
}
}

Expand Down
9 changes: 2 additions & 7 deletions crates/shadowsocks/src/relay/tcprelay/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down Expand Up @@ -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));
Expand Down
8 changes: 3 additions & 5 deletions crates/shadowsocks/src/relay/udprelay/crypto_io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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));
Expand Down

0 comments on commit 75f367e

Please sign in to comment.