fix signing and validation

add timestamp to signed node info
This commit is contained in:
John Smith
2022-05-11 09:37:54 -04:00
parent 912869d329
commit d7ba221b48
7 changed files with 51 additions and 4 deletions

View File

@@ -108,6 +108,15 @@ impl BucketEntry {
}
pub fn update_node_info(&mut self, signed_node_info: SignedNodeInfo) {
// Don't update with older node info, or something less valid
if let Some(current_sni) = &self.opt_signed_node_info {
if current_sni.signature.valid && !signed_node_info.signature.valid {
return;
}
if signed_node_info.timestamp < current_sni.timestamp {
return;
}
}
self.opt_signed_node_info = Some(signed_node_info);
}
pub fn update_local_node_info(&mut self, local_node_info: LocalNodeInfo) {

View File

@@ -487,6 +487,16 @@ impl RoutingTable {
node_id: DHTKey,
signed_node_info: SignedNodeInfo,
) -> Result<NodeRef, String> {
// validate signed node info is not something malicious
if node_id == self.node_id() {
return Err("can't register own node id in routing table".to_owned());
}
if let Some(rpi) = &signed_node_info.node_info.relay_peer_info {
if rpi.node_id.key == node_id {
return Err("node can not be its own relay".to_owned());
}
}
let nr = self.create_node_ref(node_id, |e| {
e.update_node_info(signed_node_info);
})?;

View File

@@ -81,6 +81,13 @@ impl NodeRef {
pub fn relay(&self) -> Option<NodeRef> {
let target_rpi = self.operate(|e| e.node_info().map(|n| n.relay_peer_info))?;
target_rpi.and_then(|t| {
// If relay is ourselves, then return None, because we can't relay through ourselves
// and to contact this node we should have had an existing inbound connection
if t.node_id.key == self.routing_table.node_id() {
return None;
}
// Register relay node and return noderef
self.routing_table
.register_node_with_signed_node_info(t.node_id.key, t.signed_node_info)
.map_err(logthru_rtab!(error))