title: Decode PKCS#7 Signature via Windows API?
body: <p>I wish to parse and display the contents of an Authenticode PKCS#7 signature as extracted from a Window PE binary's Security Directory.</p>
  
  <p>I can use OpenSSL to do this on the command line with "<code>openssl pkcs7 -text -in extracted_signature.pks -inform DER -print_certs</code>", however I need to do this via C/C++ and the Windows API. I cannot use the OpenSSL library itself.</p>
  
  <p>Using the <code>CryptDecodeObjectEx</code> API I can begin to decode the extracted signature:</p>
  
  <pre><code>CRYPT_CONTENT_INFO * content_info;
  DWORD len;
  
  CryptDecodeObjectEx(
      X509_ASN_ENCODING | PKCS_7_ASN_ENCODING,
      PKCS_CONTENT_INFO,
      pointer_to_extracted_signature,
      length_of_extracted_signature,
      CRYPT_DECODE_ALLOC_FLAG,
      NULL,
      &amp;content_info,
      &amp;len
  );
  </code></pre>
  
  <p>The above call completes successfully and <code>content_info-&gt;pszObjId</code> will have an OID of "1.2.840.113549.1.7.2" (szOID_RSA_signedData) however I am unable to find the structures needed to continue decoding. The available OID's for CryptDecodeObjectEx are listed <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/aa378145(v=vs.85).aspx" rel="nofollow">here</a>.</p>
  
  <p>Can anybody please advise how to decode an Authenticode PKCS#7 signature via the Windows API?</p>