Repository navigation
Fix SignCheck signature verification and interop issues - #16667
Conversation
- Migrate StgOpenStorage to StgOpenStorageEx per Microsoft recommendation - Add WinVerifyTrust file integrity check (WTD_HASH_ONLY_FLAG) to detect post-signing file modifications that CMS-only validation would miss - Fix double Marshal.ReleaseComObject on rootStorage in StructuredStorage that crashed MSP patch verification; preserve intentional lock release before Database open to avoid STGM_SHARE_EXCLUSIVE sharing violations - Fix rootStorage COM leak on non-patch compound files - Propagate recursive MSI/Binary-table extraction errors to SignatureVerificationResult instead of only logging them - Fix unmanaged string leak in WinTrustFileInfo marshaling via DestroyStructure before FreeHGlobal Co-authored-by: Copilot <[email protected]>
There was a problem hiding this comment.
Pull request overview
This PR improves SignCheck’s Windows Authenticode/structured-storage verification by modernizing OLE storage interop, tightening signature integrity validation, and ensuring extraction errors propagate to callers.
Changes:
- Migrates OLE compound storage opening from
StgOpenStoragetoStgOpenStorageExand fixes COM object lifecycle/release behavior. - Adds a Windows-only
WinVerifyTrustintegrity check (hash validation) after CMS validation to detect post-signing tampering. - Improves MSI nested verification error reporting by adding extraction failures to
SignatureVerificationResult.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
src/SignCheck/Microsoft.SignCheck/Verification/OleStorageSecurityInfoProvider.cs |
Switches OLE storage open to StgOpenStorageEx for reading the \x05DigitalSignature stream. |
src/SignCheck/Microsoft.SignCheck/Verification/MsiVerifier.cs |
Propagates extraction exceptions into SignatureVerificationResult details. |
src/SignCheck/Microsoft.SignCheck/Verification/AuthentiCodeVerifier.cs |
Adds WinVerifyTrust-based file integrity validation (hash-only) after CMS validation on Windows. |
src/SignCheck/Microsoft.SignCheck/Interop/StructuredStorage.cs |
Uses StgOpenStorageEx and fixes IStorage release timing/leaks for MSP extraction scenarios. |
src/SignCheck/Microsoft.SignCheck/Interop/Ole32.cs |
Replaces StgOpenStorage P/Invoke with StgOpenStorageEx and adds STGFMT_STORAGE. |
|
@copilot address feedback |
Addressed both review comments in c532e67:
|
…gnature The C# \x hex escape greedily consumes up to 4 hex digits, so \x05DigitalSignature was parsed as \x05D (U+005D = ']') followed by 'igitalSignature' instead of U+0005 followed by 'DigitalSignature'. This caused IStorage.OpenStream to search for the wrong stream name, making MSI signature verification always report files as unsigned. Fix: use \u0005 which always takes exactly 4 hex digits. Co-authored-by: Copilot <[email protected]>
|
Tested E2E locally on the sdk .exe bundle that contains the workload msis. |
PR dotnet#16667 added WinVerifyTrust-based content-integrity validation to SignCheck. Unlike the other Authenticode SIPs, the legacy Windows Script Host SIP cannot locate embedded JavaScript signatures when invoked from an MTA thread and returns TRUST_E_NOSIGNATURE. Run JavaScript WinVerifyTrust verification on an STA thread so signed scripts are recognized correctly. Add signed, tampered, and unsigned JavaScript coverage. Fixes regression from dotnet#16667 Co-authored-by: Copilot <[email protected]>
PR dotnet#16667 added WinVerifyTrust-based content-integrity validation to SignCheck. Unlike the other Authenticode SIPs, the legacy Windows Script Host SIP cannot locate embedded JavaScript signatures when invoked from an MTA thread and returns TRUST_E_NOSIGNATURE. Run JavaScript WinVerifyTrust verification on an STA thread so signed scripts are recognized correctly. Add signed, tampered, and unsigned JavaScript coverage. Fixes regression from dotnet#16667 Co-authored-by: Copilot <[email protected]>
PR dotnet#16667 added WinVerifyTrust-based content-integrity validation to SignCheck. Unlike the other Authenticode SIPs, the legacy Windows Script Host SIP cannot locate embedded JavaScript signatures when invoked from an MTA thread and returns TRUST_E_NOSIGNATURE. Run JavaScript WinVerifyTrust verification on an STA thread so signed scripts are recognized correctly. Add signed, tampered, and unsigned JavaScript coverage. Fixes regression from dotnet#16667 Co-authored-by: Copilot <[email protected]>
PR dotnet#16667 added WinVerifyTrust-based content-integrity validation to SignCheck. Unlike the other Authenticode SIPs, the legacy Windows Script Host SIP cannot locate embedded JavaScript signatures when invoked from an MTA thread and returns TRUST_E_NOSIGNATURE. Run JavaScript WinVerifyTrust verification on an STA thread so signed scripts are recognized correctly. Add signed, tampered, and unsigned JavaScript coverage. Fixes regression from dotnet#16667 Co-authored-by: Copilot <[email protected]>
PR dotnet#16667 added WinVerifyTrust-based content-integrity validation to SignCheck. Unlike the other Authenticode SIPs, the legacy Windows Script Host SIP cannot locate embedded JavaScript signatures when invoked from an MTA thread and returns TRUST_E_NOSIGNATURE. Run JavaScript WinVerifyTrust verification on an STA thread so signed scripts are recognized correctly. Add signed, tampered, and unsigned JavaScript coverage. Fixes regression from dotnet#16667 Co-authored-by: Copilot <[email protected]>
PR dotnet#16667 added WinVerifyTrust-based content-integrity validation to SignCheck. Unlike the other Authenticode SIPs, the legacy Windows Script Host SIP cannot locate embedded JavaScript signatures when invoked from an MTA thread and returns TRUST_E_NOSIGNATURE. Run JavaScript WinVerifyTrust verification on an STA thread so signed scripts are recognized correctly. Add signed, tampered, and unsigned JavaScript coverage. Fixes regression from dotnet#16667 Co-authored-by: Copilot <[email protected]>
PR #16667 added WinVerifyTrust-based content-integrity validation to SignCheck. Unlike the other Authenticode SIPs, the legacy Windows Script Host SIP cannot locate embedded JavaScript signatures when invoked from an MTA thread and returns TRUST_E_NOSIGNATURE. Run JavaScript WinVerifyTrust verification on an STA thread so signed scripts are recognized correctly. Add signed, tampered, and unsigned JavaScript coverage. Fixes regression from #16667 Co-authored-by: Copilot <[email protected]>
Summary
Addresses feedback from dotnet/dotnet#5834 and fixes several bugs found during code review.
Changes
StgOpenStorageEx migration (PR feedback from @teo-tsirpanis)
StgOpenStoragewithStgOpenStorageExin Ole32.cs, OleStorageSecurityInfoProvider.cs, and StructuredStorage.cs per Microsoft recommendation.WinVerifyTrust file integrity check (new)
WinVerifyTrustwithWTD_HASH_ONLY_FLAGafter CMS blob validation to detect files modified after signing. Previously,AuthentiCode.IsSignedonly validated the CMS signature was well-formed—a file with a valid signature blob but tampered content would pass.WinTrustFileInfo Unicode interop fix (bug)
WinTrustFileInfostruct to useCharSet.UnicodeandUnmanagedType.LPWStrforpcwszFilePathinstead ofLPTStr. This ensures the path is always marshaled as a Unicode (LPCWSTR) string as required byWinVerifyTrust, preventing corruption of non-ASCII paths.StructuredStorage COM object lifecycle fixes (bug)
Marshal.ReleaseComObjectonrootStoragethat threwInvalidComObjectExceptionon every MSP patch verification, crashing nested verification and leaking temp directories.new Database()to avoidSTGM_SHARE_EXCLUSIVEsharing violations.rootStorageCOM leak on non-patch compound files (only released insideIsPatchbranch).if (enumStg != null)toif (rootStorageEnum != null)so the guard correctly protectsMarshal.ReleaseComObject(rootStorageEnum)whenEnumElementsfails.MsiVerifier error propagation (bug)
SignatureVerificationResultviaAddDetail, not justLog.WriteError. Callers consuming results programmatically now see extraction failures instead of silent passes.WinTrustFileInfo string leak fix (bug)
Marshal.DestroyStructurebeforeFreeHGlobalto free the inner unmanaged string allocated byStructureToPtrforpcwszFilePath.To double check: