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

pe: add authenticode support / v2 #362

Merged
merged 1 commit into from
Mar 27, 2023

Conversation

baloo
Copy link
Contributor

@baloo baloo commented Mar 13, 2023

Alternative to #358

This removes the digest dependency and allows to implement hashing like:

trait AuthenticodeDigest {
    /// [`authenticode_digest`] returns the result of the provided hash algorithm.
    fn authenticode_digest<D: Digest>(&self) -> Output<D>;
}

impl AuthenticodeDigest for PE<'_> {
    fn authenticode_digest<D: Digest>(&self) -> Output<D> {
        let mut digest = D::new();

        for chunk in self.authenticode_ranges() {
            digest.update(chunk);
        }

        digest.finalize()
    }
}


fn main() {
    let mut buf = Vec::new();
    let mut f =
        File::open("/nix/store/bhsxra1hc7yhja2kzw5rdds90i3w3a54-linux-5.10.147/bzImage").unwrap();
    f.read_to_end(&mut buf).unwrap();

    let pe = PE::parse(&buf).unwrap();

    let hash = pe.authenticode_digest::<Sha256>();
    println!("hash: {:x?}", hash);
}

Copy link
Owner

@m4b m4b left a comment

Choose a reason for hiding this comment

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

this is much more palatable, thank you for making these changes so quickly!
We don't need these feature flags, as I mentioned we also tuck the mach-o bytes inside the struct, so this isn't an unusual pattern already. Otherwise just some minor things/changes I noted, but this looks ok to me :)

@baloo baloo force-pushed the baloo/authenticode-support-v2 branch 2 times, most recently from caf2324 to 4a918d8 Compare March 13, 2023 17:40
Authenticode is the hashing format used to sign PE binaries. This
provides the hash to be signed.
@baloo baloo force-pushed the baloo/authenticode-support-v2 branch from 4a918d8 to fec3ad9 Compare March 13, 2023 18:02
@baloo
Copy link
Contributor Author

baloo commented Mar 23, 2023

anything missing or can we merge as this?

Copy link
Owner

@m4b m4b left a comment

Choose a reason for hiding this comment

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

Thank you!

@m4b m4b merged commit 87821fd into m4b:master Mar 27, 2023
@m4b
Copy link
Owner

m4b commented Mar 27, 2023

This is great @baloo sorry for delay and thanks for making these changes!

@baloo baloo deleted the baloo/authenticode-support-v2 branch May 5, 2023 03:14
@m4b
Copy link
Owner

m4b commented May 15, 2023

non-breaking

@m4b
Copy link
Owner

m4b commented Jun 12, 2023

released in 0.7.0, thank you so much for your patience!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants