Skip to content
This repository has been archived by the owner on Jun 25, 2021. It is now read-only.

Commit

Permalink
fix(dst-accumulation): verify aggregated signature with proof chain
Browse files Browse the repository at this point in the history
  • Loading branch information
lionel-faber committed Feb 25, 2021
1 parent f892838 commit bd99595
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 17 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ rand_chacha = "~0.2.2"
thiserror = "1.0.23"
xor_name = "1.1.0"
resource_proof = "0.8.0"
sn_messaging = { git = "https://github.com/lionel1704/sn_messaging", branch = "acc-at-dest" }
sn_messaging = "~6.0.0"
sn_data_types = "~0.15.0"

[dependencies.bls]
Expand Down
25 changes: 20 additions & 5 deletions src/messages/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,16 +241,31 @@ impl Message {
.map(|(_, key)| key);
self.variant.verify(self.proof_chain.as_ref(), trusted_keys)
}
SrcAuthority::BlsShare { proof_share, .. } => {
if proof_share
SrcAuthority::BlsShare {
proof_share,
public_key,
..
} => {
// Proof chain is required for accumulation at destination.
let proof_chain = if let Some(proof_chain) = self.proof_chain.as_ref() {
proof_chain
} else {
return Err(Error::InvalidMessage);
};

if !proof_share
.public_key_set
.public_key_share(proof_share.index)
.verify(&proof_share.signature_share, &bytes)
{
Ok(VerifyStatus::Full)
} else {
Err(Error::FailedSignature)
return Err(Error::FailedSignature);
}
let trusted_keys = trusted_keys
.into_iter()
.filter(|(known_prefix, _)| known_prefix.matches(&name(public_key)))
.map(|(_, key)| key);

proof_chain.check_trust(trusted_keys).into()
}
SrcAuthority::Section { prefix, signature } => {
// Proof chain is required for section-src messages.
Expand Down
29 changes: 18 additions & 11 deletions src/routing/approved.rs
Original file line number Diff line number Diff line change
Expand Up @@ -670,17 +670,24 @@ impl Approved {
Variant::UserMessage(content) => {
if msg.dst() == &DstLocation::AccumulatingNode(self.node().name()) {
if let SrcAuthority::BlsShare { proof_share, .. } = msg.src() {
match self.message_accumulator.add(
&bincode::serialize(&msg.signable_view())?,
proof_share.clone(),
) {
Ok(_) => {
let signed_bytes = bincode::serialize(&msg.signable_view())?;
match self
.message_accumulator
.add(&signed_bytes, proof_share.clone())
{
Ok(proof) => {
trace!("Successfully accumulated message: {:?}", msg);
self.handle_user_message(
msg.src().src_location(),
*msg.dst(),
content.clone(),
)
let key = msg.proof_chain_last_key()?;
if key.verify(&proof.signature, signed_bytes) {
self.handle_user_message(
msg.src().src_location(),
*msg.dst(),
content.clone(),
)
} else {
trace!("Aggregated signature is invalid. Handling message {:?} skipped", msg);
Ok(vec![])
}
}
Err(err) => {
trace!("Error accumulating message at destination: {:?}", err);
Expand Down Expand Up @@ -2061,7 +2068,7 @@ impl Approved {
self.section_keys_provider.key_share()?,
dst,
variant,
None,
Some(self.section().create_proof_chain_for_our_info(None)),
None,
)?
} else {
Expand Down

0 comments on commit bd99595

Please sign in to comment.