Skip to content

Commit

Permalink
fix: verification of Microsoft countersignatures (#104)
Browse files Browse the repository at this point in the history
Verification of Microsoft countersignatures now takes into account signer info digest and verifies it against digest of content info (timestamp info).

The signature of the signed attributes was verified, the digest of countersigned signature was verified but what was missing is the verification that the signed attributes are actually signing the
embedded timestamp information. This would allow anyone to take a valid countersignature, replace content info of the signed data with their own timestamp info, recalculate hash against the countersigned signature and it would be verified as OK.
  • Loading branch information
metthal authored May 5, 2024
1 parent 769262a commit e50c163
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
13 changes: 13 additions & 0 deletions lib/src/modules/pe/authenticode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -345,13 +345,26 @@ impl AuthenticodeParser {
countersignature.digest_alg = oid_to_str(tst.hash_algorithm.oid());
countersignature.digest = tst.hashed_message;

let cs_si_digest = match cs_si
.get_signed_attr(&rfc5911::ID_MESSAGE_DIGEST)
.map(|value| value.data.as_bytes())
{
Some(md) => md,
None => return Err(ParseError::MissingAuthenticodeDigest),
};

countersignature.verified =
verify_message_digest(
&tst.hash_algorithm,
si.signature,
tst.hashed_message,
) && verify_message_digest(
&cs_si.digest_algorithm,
sd.content_info.content.as_bytes(),
cs_si_digest,
) && verify_signer_info(cs_si, certificates.as_slice());


countersignatures.push(countersignature);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -689,7 +689,7 @@ signatures:
not_before: 1513987200 # 2017-12-23 00:00:00 UTC
not_after: 1868918399 # 2029-03-22 23:59:59 UTC
countersignatures:
- verified: true
- verified: false
sign_time: 1634237249 # 2021-10-14 18:47:29 UTC
digest: "a6d56d546fb347a798239820467f4871bdd4c2f331548f4fdf5ab961a46c5c45"
digest_alg: "sha256"
Expand Down

0 comments on commit e50c163

Please sign in to comment.