private unsafe void VerifyLicense(System.Deployment.Internal.CodeSigning.CmiManifestVerifyFlags verifyFlags, bool oldFormat) { XmlNamespaceManager nsmgr = new XmlNamespaceManager(this.m_manifestDom.NameTable); nsmgr.AddNamespace("asm", "urn:schemas-microsoft-com:asm.v1"); nsmgr.AddNamespace("asm2", "urn:schemas-microsoft-com:asm.v2"); nsmgr.AddNamespace("ds", "http://www.w3.org/2000/09/xmldsig#"); nsmgr.AddNamespace("msrel", "http://schemas.microsoft.com/windows/rel/2005/reldata"); nsmgr.AddNamespace("r", "urn:mpeg:mpeg21:2003:01-REL-R-NS"); nsmgr.AddNamespace("as", "http://schemas.microsoft.com/windows/pki/2005/Authenticode"); XmlElement element = this.m_manifestDom.SelectSingleNode("asm:assembly/ds:Signature/ds:KeyInfo/msrel:RelData/r:license", nsmgr) as XmlElement; if (element != null) { this.VerifyAssemblyIdentity(nsmgr); this.m_authenticodeSignerInfo = new System.Deployment.Internal.CodeSigning.CmiAuthenticodeSignerInfo(-2146762485); byte[] bytes = Encoding.UTF8.GetBytes(element.OuterXml); fixed(byte *numRef = bytes) { System.Deployment.Internal.CodeSigning.Win32.AXL_SIGNER_INFO pSignerInfo = new System.Deployment.Internal.CodeSigning.Win32.AXL_SIGNER_INFO { cbSize = (uint)Marshal.SizeOf(typeof(System.Deployment.Internal.CodeSigning.Win32.AXL_SIGNER_INFO)) }; System.Deployment.Internal.CodeSigning.Win32.AXL_TIMESTAMPER_INFO pTimestamperInfo = new System.Deployment.Internal.CodeSigning.Win32.AXL_TIMESTAMPER_INFO { cbSize = (uint)Marshal.SizeOf(typeof(System.Deployment.Internal.CodeSigning.Win32.AXL_TIMESTAMPER_INFO)) }; System.Deployment.Internal.CodeSigning.Win32.CRYPT_DATA_BLOB pLicenseBlob = new System.Deployment.Internal.CodeSigning.Win32.CRYPT_DATA_BLOB(); IntPtr ptr = new IntPtr((void *)numRef); pLicenseBlob.cbData = (uint)bytes.Length; pLicenseBlob.pbData = ptr; int hr = System.Deployment.Internal.CodeSigning.Win32.CertVerifyAuthenticodeLicense(ref pLicenseBlob, (uint)verifyFlags, ref pSignerInfo, ref pTimestamperInfo); if (0x800b0100 != pSignerInfo.dwError) { this.m_authenticodeSignerInfo = new System.Deployment.Internal.CodeSigning.CmiAuthenticodeSignerInfo(pSignerInfo, pTimestamperInfo); } System.Deployment.Internal.CodeSigning.Win32.CertFreeAuthenticodeSignerInfo(ref pSignerInfo); System.Deployment.Internal.CodeSigning.Win32.CertFreeAuthenticodeTimestamperInfo(ref pTimestamperInfo); if (hr != 0) { throw new CryptographicException(hr); } } if (!oldFormat) { this.VerifyPublisherIdentity(nsmgr); } } }
internal void Verify(System.Deployment.Internal.CodeSigning.CmiManifestVerifyFlags verifyFlags) { this.m_strongNameSignerInfo = null; this.m_authenticodeSignerInfo = null; XmlNamespaceManager nsmgr = new XmlNamespaceManager(this.m_manifestDom.NameTable); nsmgr.AddNamespace("ds", "http://www.w3.org/2000/09/xmldsig#"); XmlElement element = this.m_manifestDom.SelectSingleNode("//ds:Signature", nsmgr) as XmlElement; if (element == null) { throw new CryptographicException(-2146762496); } string name = "Id"; if (!element.HasAttribute(name)) { name = "id"; if (!element.HasAttribute(name)) { name = "ID"; if (!element.HasAttribute(name)) { throw new CryptographicException(-2146762749); } } } string attribute = element.GetAttribute(name); if ((attribute == null) || (string.Compare(attribute, "StrongNameSignature", StringComparison.Ordinal) != 0)) { throw new CryptographicException(-2146762749); } bool oldFormat = false; bool flag2 = false; foreach (XmlNode node in element.SelectNodes("ds:SignedInfo/ds:Reference", nsmgr)) { XmlElement element2 = node as XmlElement; if ((element2 != null) && element2.HasAttribute("URI")) { string strA = element2.GetAttribute("URI"); if (strA != null) { if (strA.Length == 0) { XmlNode node2 = element2.SelectSingleNode("ds:Transforms", nsmgr); if (node2 == null) { throw new CryptographicException(-2146762749); } XmlNodeList list2 = node2.SelectNodes("ds:Transform", nsmgr); if (list2.Count < 2) { throw new CryptographicException(-2146762749); } bool flag3 = false; bool flag4 = false; for (int i = 0; i < list2.Count; i++) { string str4 = (list2[i] as XmlElement).GetAttribute("Algorithm"); if (str4 == null) { break; } if (string.Compare(str4, "http://www.w3.org/2001/10/xml-exc-c14n#", StringComparison.Ordinal) != 0) { flag3 = true; if (!flag4) { continue; } flag2 = true; break; } if (string.Compare(str4, "http://www.w3.org/2000/09/xmldsig#enveloped-signature", StringComparison.Ordinal) != 0) { flag4 = true; if (flag3) { flag2 = true; break; } } } } else if (string.Compare(strA, "#StrongNameKeyInfo", StringComparison.Ordinal) == 0) { oldFormat = true; XmlNode node3 = node.SelectSingleNode("ds:Transforms", nsmgr); if (node3 == null) { throw new CryptographicException(-2146762749); } XmlNodeList list3 = node3.SelectNodes("ds:Transform", nsmgr); if (list3.Count < 1) { throw new CryptographicException(-2146762749); } for (int j = 0; j < list3.Count; j++) { string str5 = (list3[j] as XmlElement).GetAttribute("Algorithm"); if (str5 == null) { break; } if (string.Compare(str5, "http://www.w3.org/2001/10/xml-exc-c14n#", StringComparison.Ordinal) != 0) { flag2 = true; break; } } } } } } if (!flag2) { throw new CryptographicException(-2146762749); } string publicKeyToken = this.VerifyPublicKeyToken(); this.m_strongNameSignerInfo = new System.Deployment.Internal.CodeSigning.CmiStrongNameSignerInfo(-2146762485, publicKeyToken); System.Deployment.Internal.CodeSigning.ManifestSignedXml xml = new System.Deployment.Internal.CodeSigning.ManifestSignedXml(this.m_manifestDom, true); xml.LoadXml(element); AsymmetricAlgorithm signingKey = null; bool flag5 = xml.CheckSignatureReturningKey(out signingKey); this.m_strongNameSignerInfo.PublicKey = signingKey; if (!flag5) { this.m_strongNameSignerInfo.ErrorCode = -2146869232; throw new CryptographicException(-2146869232); } if ((verifyFlags & System.Deployment.Internal.CodeSigning.CmiManifestVerifyFlags.StrongNameOnly) != System.Deployment.Internal.CodeSigning.CmiManifestVerifyFlags.StrongNameOnly) { this.VerifyLicense(verifyFlags, oldFormat); } }