Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/check packet length #99

Merged
merged 2 commits into from
Jan 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions nym-client/src/sockets/tcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,16 @@ impl ClientRequest {
mut input_tx: mpsc::UnboundedSender<InputMessage>,
) -> ServerResponse {
trace!("sending to: {:?}, msg: {:?}", recipient_address, msg);
if msg.len() > sphinx::constants::MAXIMUM_PLAINTEXT_LENGTH {
return ServerResponse::Error {
message: format!(
"too long message. Sent {} bytes while the maximum is {}",
msg.len(),
sphinx::constants::MAXIMUM_PLAINTEXT_LENGTH
)
.to_string(),
};
}
let dummy_surb = [0; 16];
let input_msg = InputMessage(Destination::new(recipient_address, dummy_surb), msg);
input_tx.send(input_msg).await.unwrap();
Expand Down
12 changes: 2 additions & 10 deletions nym-client/src/sockets/ws.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,20 +188,12 @@ impl ClientRequest {
mut input_tx: mpsc::UnboundedSender<InputMessage>,
) -> ServerResponse {
let message_bytes = msg.into_bytes();
// TODO: wait until 0.4.0 release to replace those constants with newly exposed
// sphinx::constants::MAXIMUM_PLAINTEXT_LENGTH
// we can't do it now for compatibility reasons as most recent sphinx revision
// has breaking changes due to packet format changes
let maximum_plaintext_length = sphinx::constants::PAYLOAD_SIZE
- sphinx::constants::SECURITY_PARAMETER
- sphinx::constants::DESTINATION_ADDRESS_LENGTH
- 1;
if message_bytes.len() > maximum_plaintext_length {
if message_bytes.len() > sphinx::constants::MAXIMUM_PLAINTEXT_LENGTH {
return ServerResponse::Error {
message: format!(
"too long message. Sent {} bytes while the maximum is {}",
message_bytes.len(),
maximum_plaintext_length
sphinx::constants::MAXIMUM_PLAINTEXT_LENGTH
)
.to_string(),
};
Expand Down