Skip to content

scripts: fix compute_authenticode_hash for unsigned PEs#440

Open
jeremy-compostella wants to merge 1 commit into
microsoft:mainfrom
jeremy-compostella:jcompost/fix-compute_authenticode_hash-for-unsigned-PEs
Open

scripts: fix compute_authenticode_hash for unsigned PEs#440
jeremy-compostella wants to merge 1 commit into
microsoft:mainfrom
jeremy-compostella:jcompost/fix-compute_authenticode_hash-for-unsigned-PEs

Conversation

@jeremy-compostella

@jeremy-compostella jeremy-compostella commented Jun 23, 2026

Copy link
Copy Markdown

When the PE has no attached certificate the security data directory fields VirtualAddress and Size are both 0. The previous unconditional slicing:

pe_data[certificate_table_offset + 0x08 : 0]   # -> empty
+ pe_data[0 + 0 :]                              # -> whole file re-appended

produced a wrong digest for unsigned images.

Add an explicit branch: when VirtualAddress == 0, hash only the bytes that follow the 8-byte cert-dir data-directory entry, which is the correct tail of an unsigned PE image.

Description

When the PE has no attached certificate the security data directory
fields VirtualAddress and Size are both 0. The previous unconditional
slicing:

pe_data[certificate_table_offset + 0x08 : 0]   # -> empty
+ pe_data[0 + 0 :]                              # -> whole file re-appended

produced a wrong digest for unsigned images.

How This Was Tested

Generate Authenticode for an unsigned EFI binary and verify successful verification once enrolled in the DB.

Integration Instructions

N/A

@jeremy-compostella jeremy-compostella force-pushed the jcompost/fix-compute_authenticode_hash-for-unsigned-PEs branch from 3125e2b to 9c5720a Compare June 23, 2026 16:56
When the PE has no attached certificate the security data directory
fields VirtualAddress and Size are both 0.  The previous unconditional
slicing:

    pe_data[certificate_table_offset + 0x08 : 0]   # -> empty
    + pe_data[0 + 0 :]                              # -> whole file re-appended

produced a wrong digest for unsigned images.

Add an explicit branch: when VirtualAddress == 0, hash only the bytes
that follow the 8-byte cert-dir data-directory entry, which is the
correct tail of an unsigned PE image.

Signed-off-by: Jeremy Compostella <jeremy.compostella@intel.com>
@jeremy-compostella jeremy-compostella force-pushed the jcompost/fix-compute_authenticode_hash-for-unsigned-PEs branch from fcbcb75 to 7737602 Compare June 23, 2026 18:17
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.

1 participant