4

Microsoft is moving away from SHA1. As a result many executables now have two or more signatures; one using a SHA1 digest for backward compatibility and one using a SHA256.

For example if you look at the properties of vstest.executionengine.exe from Visual Studio 2013 (look at the properties on Windows 8 or Server 2012) you'll see it has 3 different signatures from 3 different certificates.

I already have code that uses a combination of CryptQueryObject, CryptMsgGetParam, and .NET SignedCms, but it only sees 1 of the 3 signatures. There appears to be only one message with one signer.

I need to get the certificate information for all signatures. How are multiple signatures modeled - is it multiple messages, or multiple signers in a single message? Did Microsoft add new APIs or new flags to access multiple signatures?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Scott
  • 101
  • 1
  • 4

1 Answers1

6

It turns out that Microsoft (sort of) hides subsequent signatures. When adding another signature, the entire CMS structure is added as an unsigned attribute.

So for example a dual-signed Authenticode signature decoded as a .NET SignedCms will have one signer, and that SignerInfo will have a value in UnsignedAttributes. If you take the attribute ASN RawData value and pass it to SignedCms.Decode, you get the second signature.

// decode inner signature    
signedCms2.Decode(signedCms1.SignerInfos[0].UnsignedAttributes[0].Values[0].RawData);

It also appears that instead of adding another attribute to the root signature signer, the attribute is added in the inner-most signers attributes.

Also note that not all attributes are inner signatures, I think you need to check for a proper Oid on the attribute.

Is suspect that this was the best way for Microsoft to keep backward compatibility.

Scott
  • 101
  • 1
  • 4