Skip to content

Commit f7eb0ca

Browse files
committed
AEAD cipher protocol data.len is limited to 0x3FFF
1 parent 1b6afa2 commit f7eb0ca

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

src/relay/tcprelay/aead.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -231,19 +231,28 @@ impl EncryptedWriter {
231231
}
232232
}
233233

234-
pub fn poll_write_encrypted<W>(&mut self, ctx: &mut Context<'_>, w: &mut W, data: &[u8]) -> Poll<io::Result<usize>>
234+
pub fn poll_write_encrypted<W>(
235+
&mut self,
236+
ctx: &mut Context<'_>,
237+
w: &mut W,
238+
mut data: &[u8],
239+
) -> Poll<io::Result<usize>>
235240
where
236241
W: AsyncWrite + Unpin,
237242
{
243+
// Data.Len is a 16-bit big-endian integer indicating the length of Data. It must be smaller than 0x3FFF.
244+
if data.len() > MAX_PACKET_SIZE {
245+
data = &data[..MAX_PACKET_SIZE];
246+
}
247+
238248
ready!(self.poll_write_all_encrypted(ctx, w, data))?;
239249
Poll::Ready(Ok(data.len()))
240250
}
241251

242-
pub fn poll_write_all_encrypted<W>(&mut self, ctx: &mut Context<'_>, w: &mut W, data: &[u8]) -> Poll<io::Result<()>>
252+
fn poll_write_all_encrypted<W>(&mut self, ctx: &mut Context<'_>, w: &mut W, data: &[u8]) -> Poll<io::Result<()>>
243253
where
244254
W: AsyncWrite + Unpin,
245255
{
246-
// Data.Len is a 16-bit big-endian integer indicating the length of Data. It should be smaller than 0x3FFF.
247256
assert!(
248257
data.len() <= MAX_PACKET_SIZE,
249258
"Buffer size too large, AEAD encryption protocol requires buffer to be smaller than 0x3FFF"

src/relay/tcprelay/stream.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ impl EncryptedWriter {
115115
Poll::Ready(Ok(data.len()))
116116
}
117117

118-
pub fn poll_write_all_encrypted<W>(&mut self, ctx: &mut Context<'_>, w: &mut W, data: &[u8]) -> Poll<io::Result<()>>
118+
fn poll_write_all_encrypted<W>(&mut self, ctx: &mut Context<'_>, w: &mut W, data: &[u8]) -> Poll<io::Result<()>>
119119
where
120120
W: AsyncWrite + Unpin,
121121
{

0 commit comments

Comments
 (0)