Skip to content

Commit

Permalink
Add a variant to MessageVerificationError
Browse files Browse the repository at this point in the history
  • Loading branch information
fjarri committed Oct 21, 2024
1 parent e837388 commit ee15610
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 1 deletion.
3 changes: 3 additions & 0 deletions manul/src/session/echo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,9 @@ where
Err(MessageVerificationError::InvalidSignature) => {
return Err(EchoRoundError::InvalidEcho(sender.clone()).into())
}
Err(MessageVerificationError::SignatureMismatch) => {
return Err(EchoRoundError::InvalidEcho(sender.clone()).into())
}
};

// `from` sent us a correctly signed message but from another round or another session.
Expand Down
4 changes: 4 additions & 0 deletions manul/src/session/evidence.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ impl From<MessageVerificationError> for EvidenceError {
match error {
MessageVerificationError::Local(error) => Self::Local(error),
MessageVerificationError::InvalidSignature => Self::InvalidEvidence("Invalid message signature".into()),
MessageVerificationError::SignatureMismatch => {
Self::InvalidEvidence("The signature does not match the payload".into())
}
}
}
}
Expand Down Expand Up @@ -259,6 +262,7 @@ where
Err(MessageVerificationError::Local(error)) => return Err(EvidenceError::Local(error)),
// The message was indeed incorrectly signed - fault proven
Err(MessageVerificationError::InvalidSignature) => return Ok(()),
Err(MessageVerificationError::SignatureMismatch) => return Ok(()),
};

// `from` sent us a correctly signed message but from another round or another session.
Expand Down
5 changes: 4 additions & 1 deletion manul/src/session/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@ impl SerializedSignature {
#[derive(Debug, Clone)]
pub(crate) enum MessageVerificationError {
Local(LocalError),
/// The signature could not be deserialized.
InvalidSignature,
/// The signature does not match the signed payload.
SignatureMismatch,
}

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
Expand Down Expand Up @@ -127,7 +130,7 @@ where
message_with_metadata: self.message_with_metadata,
})
} else {
Err(MessageVerificationError::InvalidSignature)
Err(MessageVerificationError::SignatureMismatch)
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions manul/src/session/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,10 @@ where
let verified_message = match checked_message.verify::<P, SP>(from) {
Ok(verified_message) => verified_message,
Err(MessageVerificationError::InvalidSignature) => {
accum.register_unprovable_error(from, RemoteError::new("The signature could not be deserialized"))?;
return Ok(None);
}
Err(MessageVerificationError::SignatureMismatch) => {
accum.register_unprovable_error(from, RemoteError::new("Message verification failed"))?;
return Ok(None);
}
Expand Down

0 comments on commit ee15610

Please sign in to comment.