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

chore(crypto): Reflect the message hash in signature verification errors #3152

Closed
wants to merge 8 commits into from

Conversation

randombit
Copy link
Contributor

@randombit randombit commented Dec 12, 2024

This makes it easier to diagnose signature verification issues from logs or user-provided error messages.

@github-actions github-actions bot added the chore label Dec 12, 2024
This makes it easier to diagnose signture verification issues from
logs or user-provided error messages.
@randombit randombit changed the title chore(crypto): Reflect the message hash during signature verification chore(crypto): Reflect the message hash in signature verification errors Dec 12, 2024
@randombit randombit marked this pull request as ready for review December 12, 2024 15:23
@randombit randombit requested a review from a team as a code owner December 12, 2024 15:23
@@ -115,6 +115,7 @@ pub fn verify_individual(
algorithm: AlgorithmId::MultiBls12_381,
public_key_bytes: public_key_bytes.0.to_vec(),
sig_bytes: signature_bytes.0.to_vec(),
msg_hash: Some(message.to_vec()),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIUC, message is not a hash here, but the output of Signable::as_signed_bytes which uses SignedBytesWithoutDomainSeparator::as_signed_bytes_without_domain_separator, which depends on the actual struct that is signed.

Looking at pub trait Crypto, multi signatures are done for NotarizationContent and FinalizationContent, and both implement SignedBytesWithoutDomainSeparator by serializing self with CBOR.

Same for verify_combined.

@@ -239,6 +239,7 @@ pub(crate) fn verify_individual_sig(
algorithm: AlgorithmId::ThresBls12_381,
public_key_bytes: PublicKeyBytes::from(public_key).0.to_vec(),
sig_bytes: IndividualSignatureBytes::from(signature).0.to_vec(),
msg_hash: Some(message.to_vec()),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar comment as for multi-sigs. message here is for many types not a hash. As far as I can see (based on pub trait Crypto), it is only a hash for CertificationContent, but not for CatchUpContent, CatchUpContentProtobufBytes, RandomBeaconContent, and RandomTapeContent.

Same for verify_combined_sig.

@@ -193,6 +194,7 @@ impl CspSigner for Csp {
algorithm: algorithm_id,
public_key_bytes: signer.as_ref().to_vec(),
sig_bytes: signature.0.to_vec(),
msg_hash: Some(msg.to_vec()),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See my other comment: I believe msg is not a hash here in practise. Given that the public key here is anyway of the wrong type, including the message in the error also doesn't seem super helpful.

@@ -341,6 +341,7 @@ pub enum CryptoError {
algorithm: AlgorithmId,
public_key_bytes: Vec<u8>,
sig_bytes: Vec<u8>,
msg_hash: Option<Vec<u8>>,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do I understand correctly that you want to include the message hash here because including the full message would cause potentially very big log entries?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Partially this, also partially for confidentiality reasons in case the message contains sensitive information. Additionally for ECDSA the crypto component IIRC never sees the actual message but just the hash.

rs/crypto/src/sign/basic_sig.rs Show resolved Hide resolved
@randombit
Copy link
Contributor Author

Closing in favor of #3239

@randombit randombit closed this Dec 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants