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

Removed redundant messaging authentication #1691

Merged
merged 1 commit into from
Apr 14, 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
30 changes: 9 additions & 21 deletions comms/dht/src/dht.rs
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ mod test {
use futures::{channel::mpsc, StreamExt};
use std::{sync::Arc, time::Duration};
use tari_comms::{
message::{MessageExt, MessageFlags},
message::MessageExt,
pipeline::SinkService,
test_utils::mocks::create_connection_manager_mock,
wrap_in_envelope_body,
Expand Down Expand Up @@ -354,11 +354,8 @@ mod test {
msg.to_encoded_bytes().unwrap(),
DhtMessageFlags::empty(),
);
let inbound_message = make_comms_inbound_message(
&node_identity,
dht_envelope.to_encoded_bytes().unwrap().into(),
MessageFlags::empty(),
);
let inbound_message =
make_comms_inbound_message(&node_identity, dht_envelope.to_encoded_bytes().unwrap().into());

let msg = {
service.call(inbound_message).await.unwrap();
Expand Down Expand Up @@ -400,11 +397,8 @@ mod test {
let ecdh_key = crypt::generate_ecdh_secret(node_identity.secret_key(), node_identity.public_key());
let encrypted_bytes = crypt::encrypt(&ecdh_key, &msg.to_encoded_bytes().unwrap()).unwrap();
let dht_envelope = make_dht_envelope(&node_identity, encrypted_bytes, DhtMessageFlags::ENCRYPTED);
let inbound_message = make_comms_inbound_message(
&node_identity,
dht_envelope.to_encoded_bytes().unwrap().into(),
MessageFlags::empty(),
);
let inbound_message =
make_comms_inbound_message(&node_identity, dht_envelope.to_encoded_bytes().unwrap().into());

let msg = {
service.call(inbound_message).await.unwrap();
Expand Down Expand Up @@ -460,11 +454,8 @@ mod test {
.unwrap()
.signature
.clone();
let inbound_message = make_comms_inbound_message(
&node_identity,
dht_envelope.to_encoded_bytes().unwrap().into(),
MessageFlags::empty(),
);
let inbound_message =
make_comms_inbound_message(&node_identity, dht_envelope.to_encoded_bytes().unwrap().into());

service.call(inbound_message).await.unwrap();

Expand Down Expand Up @@ -513,11 +504,8 @@ mod test {
header.message_type = DhtMessageType::SafStoredMessages as i32;
Some(header)
});
let inbound_message = make_comms_inbound_message(
&node_identity,
dht_envelope.to_encoded_bytes().unwrap().into(),
MessageFlags::empty(),
);
let inbound_message =
make_comms_inbound_message(&node_identity, dht_envelope.to_encoded_bytes().unwrap().into());

service.call(inbound_message).await.unwrap_err();
// This seems like the best way to tell that an open channel is empty without the test blocking indefinitely
Expand Down
3 changes: 1 addition & 2 deletions comms/dht/src/inbound/deserialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ mod test {
test_utils::{make_comms_inbound_message, make_dht_envelope, make_node_identity, service_spy},
};
use futures::executor::block_on;
use tari_comms::message::{MessageExt, MessageFlags};
use tari_comms::message::MessageExt;
use tari_test_utils::panic_context;

#[test]
Expand All @@ -148,7 +148,6 @@ mod test {
block_on(deserialize.call(make_comms_inbound_message(
&node_identity,
dht_envelope.to_encoded_bytes().unwrap().into(),
MessageFlags::empty(),
)))
.unwrap();

Expand Down
11 changes: 1 addition & 10 deletions comms/dht/src/outbound/broadcast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ use futures::{
use log::*;
use std::{sync::Arc, task::Poll};
use tari_comms::{
message::MessageFlags,
peer_manager::{NodeId, NodeIdentity, Peer},
pipeline::PipelineError,
types::CommsPublicKey,
Expand Down Expand Up @@ -433,15 +432,7 @@ where S: Service<DhtOutboundMessage, Response = (), Error = PipelineError>
// Construct a MessageEnvelope for each recipient
let messages = selected_peers
.into_iter()
.map(|peer| {
DhtOutboundMessage::new(
peer,
dht_header.clone(),
encryption.clone(),
MessageFlags::NONE,
body.clone(),
)
})
.map(|peer| DhtOutboundMessage::new(peer, dht_header.clone(), encryption.clone(), body.clone()))
.collect::<Vec<_>>();

Ok(messages)
Expand Down
3 changes: 0 additions & 3 deletions comms/dht/src/outbound/encryption.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ mod test {
};
use futures::executor::block_on;
use tari_comms::{
message::MessageFlags,
net_address::MultiaddressesWithStats,
peer_manager::{NodeId, Peer, PeerFeatures, PeerFlags},
types::CommsPublicKey,
Expand Down Expand Up @@ -146,7 +145,6 @@ mod test {
),
make_dht_header(&node_identity, &body, DhtMessageFlags::empty()),
OutboundEncryption::None,
MessageFlags::empty(),
body.clone(),
);
block_on(encryption.call(msg)).unwrap();
Expand Down Expand Up @@ -177,7 +175,6 @@ mod test {
),
make_dht_header(&node_identity, &body, DhtMessageFlags::ENCRYPTED),
OutboundEncryption::EncryptFor(Box::new(CommsPublicKey::default())),
MessageFlags::empty(),
body.clone(),
);
block_on(encryption.call(msg)).unwrap();
Expand Down
9 changes: 1 addition & 8 deletions comms/dht/src/outbound/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,7 @@ use crate::{
};
use futures::channel::oneshot;
use std::{fmt, fmt::Display};
use tari_comms::{
message::{MessageFlags, MessageTag},
peer_manager::Peer,
types::CommsPublicKey,
};
use tari_comms::{message::MessageTag, peer_manager::Peer, types::CommsPublicKey};
use tari_crypto::tari_utilities::hex::Hex;

/// Determines if an outbound message should be Encrypted and, if so, for which public key
Expand Down Expand Up @@ -142,7 +138,6 @@ pub struct DhtOutboundMessage {
pub tag: MessageTag,
pub destination_peer: Peer,
pub dht_header: DhtMessageHeader,
pub comms_flags: MessageFlags,
pub encryption: OutboundEncryption,
pub body: Vec<u8>,
}
Expand All @@ -153,7 +148,6 @@ impl DhtOutboundMessage {
destination_peer: Peer,
dht_header: DhtMessageHeader,
encryption: OutboundEncryption,
comms_flags: MessageFlags,
body: Vec<u8>,
) -> Self
{
Expand All @@ -162,7 +156,6 @@ impl DhtOutboundMessage {
destination_peer,
dht_header,
encryption,
comms_flags,
body,
}
}
Expand Down
10 changes: 1 addition & 9 deletions comms/dht/src/outbound/serialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ where S: Service<OutboundMessage, Response = (), Error = PipelineError>
mut dht_header,
body,
destination_peer,
comms_flags,
..
} = message;

Expand Down Expand Up @@ -115,12 +114,7 @@ where S: Service<OutboundMessage, Response = (), Error = PipelineError>
let body = Bytes::from(envelope.to_encoded_bytes().map_err(PipelineError::from_debug)?);

next_service
.oneshot(OutboundMessage::with_tag(
message.tag,
destination_peer.node_id,
comms_flags,
body,
))
.oneshot(OutboundMessage::with_tag(message.tag, destination_peer.node_id, body))
.await
}
}
Expand Down Expand Up @@ -154,7 +148,6 @@ mod test {
use futures::executor::block_on;
use prost::Message;
use tari_comms::{
message::MessageFlags,
net_address::MultiaddressesWithStats,
peer_manager::{NodeId, Peer, PeerFeatures, PeerFlags},
types::CommsPublicKey,
Expand Down Expand Up @@ -182,7 +175,6 @@ mod test {
),
make_dht_header(&node_identity, &body, DhtMessageFlags::empty()),
OutboundEncryption::None,
MessageFlags::empty(),
body,
);
block_on(serialize.call(msg)).unwrap();
Expand Down
9 changes: 2 additions & 7 deletions comms/dht/src/test_utils/makers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use crate::{
use rand::rngs::OsRng;
use std::sync::Arc;
use tari_comms::{
message::{InboundMessage, MessageEnvelopeHeader, MessageFlags},
message::InboundMessage,
multiaddr::Multiaddr,
peer_manager::{NodeIdentity, Peer, PeerFeatures, PeerFlags, PeerManager},
types::CommsDatabase,
Expand Down Expand Up @@ -72,7 +72,7 @@ pub fn make_client_identity() -> Arc<NodeIdentity> {
)
}

pub fn make_comms_inbound_message(node_identity: &NodeIdentity, message: Bytes, flags: MessageFlags) -> InboundMessage {
pub fn make_comms_inbound_message(node_identity: &NodeIdentity, message: Bytes) -> InboundMessage {
InboundMessage::new(
Arc::new(Peer::new(
node_identity.public_key().clone(),
Expand All @@ -82,11 +82,6 @@ pub fn make_comms_inbound_message(node_identity: &NodeIdentity, message: Bytes,
PeerFeatures::COMMUNICATION_NODE,
&[],
)),
MessageEnvelopeHeader {
public_key: node_identity.public_key().clone(),
signature: Bytes::new(),
flags,
},
message,
)
}
Expand Down
3 changes: 1 addition & 2 deletions comms/examples/tor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ async fn run() -> Result<(), Error> {
outbound_tx1
.send(OutboundMessage::new(
comms_node2.node_identity().node_id().clone(),
Default::default(),
Bytes::from_static(b"START"),
))
.await?;
Expand Down Expand Up @@ -272,5 +271,5 @@ async fn start_ping_ponger(

fn make_msg(node_id: &NodeId, msg: String) -> OutboundMessage {
let msg = Bytes::copy_from_slice(msg.as_bytes());
OutboundMessage::new(node_id.clone(), Default::default(), msg)
OutboundMessage::new(node_id.clone(), msg)
}
4 changes: 0 additions & 4 deletions comms/src/builder/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,6 @@ async fn peer_to_peer_messaging() {
for i in 0..NUM_MSGS {
let outbound_msg = OutboundMessage::new(
node_identity2.node_id().clone(),
Default::default(),
format!("#{:0>3} - comms messaging is so hot right now!", i).into(),
);
outbound_tx1.send(outbound_msg).await.unwrap();
Expand All @@ -227,7 +226,6 @@ async fn peer_to_peer_messaging() {
for i in 0..NUM_MSGS {
let outbound_msg = OutboundMessage::new(
node_identity1.node_id().clone(),
Default::default(),
format!("#{:0>3} - comms messaging is so hot right now!", i).into(),
);
outbound_tx2.send(outbound_msg).await.unwrap();
Expand Down Expand Up @@ -295,7 +293,6 @@ async fn peer_to_peer_messaging_simultaneous() {
for i in 0..NUM_MSGS {
let outbound_msg = OutboundMessage::new(
node_identity2.node_id().clone(),
Default::default(),
format!("#{:0>3} - comms messaging is so hot right now!", i).into(),
);
outbound_tx1.send(outbound_msg).await.unwrap();
Expand All @@ -306,7 +303,6 @@ async fn peer_to_peer_messaging_simultaneous() {
for i in 0..NUM_MSGS {
let outbound_msg = OutboundMessage::new(
node_identity1.node_id().clone(),
Default::default(),
format!("#{:0>3} - comms messaging is so hot right now!", i).into(),
);
outbound_tx2.send(outbound_msg).await.unwrap();
Expand Down
4 changes: 0 additions & 4 deletions comms/src/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,3 @@ pub const PEER_MANAGER_MAX_FLOOD_PEERS: usize = 1000;
/// The amount of time to consider a peer to be offline (i.e. dial to peer will fail without trying) after a failed
/// connection attempt
pub const PEER_OFFLINE_COOLDOWN_PERIOD: Duration = Duration::from_secs(60);

/// The envelope version. This should be increased any time a change is made to the
/// envelope proto files.
pub const ENVELOPE_VERSION: u32 = 0;
Loading