Skip to content

Add cryptographic verification to authenticode_transplant.py#326

Merged
Flickdm merged 1 commit intomicrosoft:mainfrom
Flickdm:feature/auth_transplant/cryptographic_validation
Feb 24, 2026
Merged

Add cryptographic verification to authenticode_transplant.py#326
Flickdm merged 1 commit intomicrosoft:mainfrom
Flickdm:feature/auth_transplant/cryptographic_validation

Conversation

@Flickdm
Copy link
Member

@Flickdm Flickdm commented Dec 1, 2025

This commit adds comprehensive cryptographic validation to the Authenticode signature combining tool, bringing the same verification capabilities from auth_var_tool.py to PE file signature operations.

Key changes:

  • Added cryptographic signature verification using the 'cryptography' library
  • Implemented SpcIndirectDataContent parsing to extract embedded PE hashes
  • Added certificate extraction and display from PKCS#7 signatures
  • Compute Authenticode hashes using the algorithm specified in the signature
  • Verify signatures mathematically using signer's public key (RSA/ECDSA)
  • Validate that computed PE hash matches the hash in SpcIndirectDataContent

New functions:

  • _get_hash_algorithm_from_oid(): Maps OID strings to hash algorithms
  • _extract_pe_hash_from_spc_indirect_data(): Parses SPC structure for hash
  • _extract_certificates_from_pkcs7(): Extracts X.509 certificates
  • _verify_pkcs7_signature(): Performs full cryptographic verification
  • compute_authenticode_hash(): Flexible hash computation with configurable algorithm

Enhanced functions:

  • validate_pkcs7_signatures(): Now performs cryptographic verification
  • main_verify(): Displays certificate details and verification status
  • main_combine(): Validates signatures cryptographically before combining

Bug fixes:

  • Removed incorrect 8-byte padding from Authenticode hash calculation (padding only applies to WIN_CERTIFICATE structure alignment, not hash data)
  • Consolidated duplicate hash functions into single implementation

Code improvements:

  • Named constants for all magic numbers in SPC parsing
  • Better documentation and inline comments
  • Proper type annotations with Optional types

Testing:

  • Verified against Microsoft-signed bootmgfw.efi files
  • Hash computation now matches Windows AppLocker and UEFI firmware
  • Both multi-signature and nested signature modes validated
  • All test cases pass with cryptographic verification

Follows Microsoft Authenticode PE specification v1.1

Description

  • Impacts functionality?
  • Impacts security?
  • Breaking change?
  • Includes tests?
  • Includes documentation?

How This Was Tested

Ran it against copies of bootmgfw.efi and hellouefi.efi that were both singly signed and

Integration Instructions

N/A

@Flickdm Flickdm marked this pull request as ready for review December 1, 2025 22:42
@Flickdm Flickdm requested a review from Copilot December 1, 2025 22:42
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds comprehensive cryptographic verification capabilities to the Authenticode signature tool, enabling validation of PE file signatures using the cryptography library. The changes introduce hash extraction from SPC structures, certificate parsing, and full signature verification against PE files.

Key changes:

  • Added cryptographic signature verification using new helper functions for OID mapping, certificate extraction, and PKCS7 verification
  • Enhanced compute_authenticode_hash() to support multiple hash algorithms (SHA1/256/384/512) and removed incorrect padding logic
  • Updated validate_pkcs7_signatures() and verification commands to perform cryptographic validation before accepting signatures

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@Flickdm Flickdm force-pushed the feature/auth_transplant/cryptographic_validation branch 2 times, most recently from d8166a7 to 0cee114 Compare January 21, 2026 18:11
@Flickdm Flickdm requested review from Javagedes and apop5 January 21, 2026 19:23
@Flickdm Flickdm force-pushed the feature/auth_transplant/cryptographic_validation branch from b4d81a1 to 600df89 Compare January 29, 2026 19:06
@Flickdm Flickdm force-pushed the feature/auth_transplant/cryptographic_validation branch from 600df89 to 2884a4d Compare February 24, 2026 19:27
@Flickdm Flickdm enabled auto-merge (rebase) February 24, 2026 19:30
auto-merge was automatically disabled February 24, 2026 19:42

Rebase failed

Add full cryptographic verification of PKCS#7 Authenticode signatures
in authenticode_transplant.py. This includes:

- Extract and verify PE hash from SpcIndirectDataContent against the
  computed Authenticode hash using the signature's own hash algorithm
- Cryptographically verify signer signatures (RSA PKCS1v15 and ECDSA)
  against authenticated attributes
- Extract and display X.509 certificate details (subject, issuer,
  serial, validity) during verify and combine operations
- Refactor calculate_authenticode_hash to compute_authenticode_hash
  supporting multiple hash algorithms (SHA1, SHA256, SHA384, SHA512)
- Add cryptography==43.0.0 dependency and update pyasn1 to 0.6.2

Signed-off-by: Doug Flick <dougflick@microsoft.com>
@Flickdm Flickdm force-pushed the feature/auth_transplant/cryptographic_validation branch from 533a786 to 0361ddf Compare February 24, 2026 20:22
@Flickdm Flickdm merged commit f369839 into microsoft:main Feb 24, 2026
2 checks passed
@Flickdm Flickdm deleted the feature/auth_transplant/cryptographic_validation branch February 24, 2026 20:23
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.

4 participants