After much searching and searching for various things, I found that the WinVerifyTrust function can read several built-in certificates. Do not pay attention to the name of the function, it can be used for many things, this is a universal function.
WinVerifyTrust takes struct WINTRUST_DATA as one of its I / O parameters. The docs say it is IN , but it is also used to return information.
WINTRUST_DATA has a pSignatureSettings field, which is a pointer to another structure, WINTRUST_SIGNATURE_SETTINGS . This element has a dwFlags field that controls what information will be returned by WinVerifyTrust.
First, you call WinVerifyTrust with WINTRUST_SIGNATURE_SETTINGS::dwFlags = WSS_GET_SECONDARY_SIG_COUNT to return the number of secondary signatures that is returned in the WINTRUST_SIGNATURE_SETTINGS::cSecondarySigs . Please note that if your file has 2 signatures, cSecondarySigs will be 1.
Then, in the for (int i = 0; i <= cSecondarySigs; i++) loop for (int i = 0; i <= cSecondarySigs; i++) you call WinVerifyTrust with WINTRUST_SIGNATURE_SETTINGS::dwFlags = WSS_VERIFY_SPECIFIC and WINTRUST_SIGNATURE_SETTINGS::dwIndex = i .
After each call to WinVerifyTrust, you can obtain certificate information (including signatures) from WINTRUST_DATA::hWVTStateData using this call sequence:
WTHelperProvDataFromStateData(hWVTStateData); WTHelperGetProvSignerFromChain(...); WTHelperGetProvCertFromChain(...);
I did not dig much in the .NET API, but it seems that it can only read the first signature. Please note that WINTRUST_SIGNATURE_SETTINGS , which seems to be the key to reading multiple signatures, was added in Windows 8, so on older OSs you cannot read it, at least not with the MS API.
source share