private static Signature GetSignatureFromWintrustData( string filePath, uint error, System.Management.Automation.Security.NativeMethods.WINTRUST_DATA wtd) { Signature signature = (Signature)null; X509Certificate2 timestamper = (X509Certificate2)null; SignatureHelper.tracer.WriteLine("GetSignatureFromWintrustData: error: {0}", (object)error); IntPtr pProvData = System.Management.Automation.Security.NativeMethods.WTHelperProvDataFromStateData(wtd.hWVTStateData); if (pProvData != IntPtr.Zero) { IntPtr provSignerFromChain = System.Management.Automation.Security.NativeMethods.WTHelperGetProvSignerFromChain(pProvData, 0U, 0U, 0U); if (provSignerFromChain != IntPtr.Zero) { X509Certificate2 certFromChain = SignatureHelper.GetCertFromChain(provSignerFromChain); if (certFromChain != null) { System.Management.Automation.Security.NativeMethods.CRYPT_PROVIDER_SGNR structure = (System.Management.Automation.Security.NativeMethods.CRYPT_PROVIDER_SGNR)Marshal.PtrToStructure(provSignerFromChain, typeof(System.Management.Automation.Security.NativeMethods.CRYPT_PROVIDER_SGNR)); if (structure.csCounterSigners == 1U) { timestamper = SignatureHelper.GetCertFromChain(structure.pasCounterSigners); } signature = timestamper == null ? new Signature(filePath, error, certFromChain) : new Signature(filePath, error, certFromChain, timestamper); } } } if (signature == null && error != 0U) { signature = new Signature(filePath, error); } return(signature); }
private static System.Management.Automation.Signature GetSignatureFromWintrustData(string filePath, uint error, System.Management.Automation.Security.NativeMethods.WINTRUST_DATA wtd) { System.Management.Automation.Signature signature = null; X509Certificate2 signer = null; X509Certificate2 timestamper = null; tracer.WriteLine("GetSignatureFromWintrustData: error: {0}", new object[] { error }); IntPtr pProvData = System.Management.Automation.Security.NativeMethods.WTHelperProvDataFromStateData(wtd.hWVTStateData); if (pProvData != IntPtr.Zero) { IntPtr pSigner = System.Management.Automation.Security.NativeMethods.WTHelperGetProvSignerFromChain(pProvData, 0, 0, 0); if (pSigner != IntPtr.Zero) { signer = GetCertFromChain(pSigner); if (signer != null) { System.Management.Automation.Security.NativeMethods.CRYPT_PROVIDER_SGNR crypt_provider_sgnr = (System.Management.Automation.Security.NativeMethods.CRYPT_PROVIDER_SGNR)Marshal.PtrToStructure(pSigner, typeof(System.Management.Automation.Security.NativeMethods.CRYPT_PROVIDER_SGNR)); if (crypt_provider_sgnr.csCounterSigners == 1) { timestamper = GetCertFromChain(crypt_provider_sgnr.pasCounterSigners); } if (timestamper != null) { signature = new System.Management.Automation.Signature(filePath, error, signer, timestamper); } else { signature = new System.Management.Automation.Signature(filePath, error, signer); } } } } if ((signature == null) && (error != 0)) { signature = new System.Management.Automation.Signature(filePath, error); } return(signature); }