/// <summary>Loads XML data from an <see cref="T:System.Xml.XmlElement" /> into a <see cref="T:System.Security.Cryptography.Xml.CipherData" /> object.</summary> /// <param name="value">An <see cref="T:System.Xml.XmlElement" /> that represents the XML data to load.</param> /// <exception cref="T:System.ArgumentNullException">The <paramref name="value" /> parameter is <see langword="null" />.</exception> /// <exception cref="T:System.Security.Cryptography.CryptographicException">The <see cref="P:System.Security.Cryptography.Xml.CipherData.CipherValue" /> property and the <see cref="P:System.Security.Cryptography.Xml.CipherData.CipherReference" /> property are <see langword="null" />.</exception> public void LoadXml(XmlElement value) { if (value == null) { throw new ArgumentNullException(nameof(value)); } XmlNamespaceManager nsmgr = new XmlNamespaceManager(value.OwnerDocument.NameTable); nsmgr.AddNamespace("enc", "http://www.w3.org/2001/04/xmlenc#"); XmlNode xmlNode1 = value.SelectSingleNode("enc:CipherValue", nsmgr); XmlNode xmlNode2 = value.SelectSingleNode("enc:CipherReference", nsmgr); if (xmlNode1 != null) { if (xmlNode2 != null) { throw new CryptographicException("Cryptography_Xml_CipherValueElementRequired"); } this.m_cipherValue = Convert.FromBase64String(Exml.DiscardWhiteSpaces(xmlNode1.InnerText)); } else { if (xmlNode2 == null) { throw new CryptographicException("Cryptography_Xml_CipherValueElementRequired"); } this.m_cipherReference = new CipherReference(); this.m_cipherReference.LoadXml((XmlElement)xmlNode2); } this.m_cachedXml = value; }
/// <summary>Parses the input <see cref="T:System.Xml.XmlElement" /> object and configures the internal state of the <see cref="T:System.Security.Cryptography.Xml.KeyInfoX509Data" /> object to match.</summary> /// <param name="element">The <see cref="T:System.Xml.XmlElement" /> object that specifies the state of the <see cref="T:System.Security.Cryptography.Xml.KeyInfoX509Data" /> object. </param> /// <exception cref="T:System.ArgumentNullException">The <paramref name="element" /> parameter is <see langword="null" />.</exception> /// <exception cref="T:System.Security.Cryptography.CryptographicException">The <paramref name="element" /> parameter does not contain an <<see langword="X509IssuerName" />> node.-or-The <paramref name="element" /> parameter does not contain an <<see langword="X509SerialNumber" />> node.</exception> public override void LoadXml(XmlElement element) { if (element == null) { throw new ArgumentNullException(nameof(element)); } XmlNamespaceManager nsmgr = new XmlNamespaceManager(element.OwnerDocument.NameTable); nsmgr.AddNamespace("ds", "http://www.w3.org/2000/09/xmldsig#"); XmlNodeList xmlNodeList1 = element.SelectNodes("ds:X509IssuerSerial", nsmgr); XmlNodeList xmlNodeList2 = element.SelectNodes("ds:X509SKI", nsmgr); XmlNodeList xmlNodeList3 = element.SelectNodes("ds:X509SubjectName", nsmgr); XmlNodeList xmlNodeList4 = element.SelectNodes("ds:X509Certificate", nsmgr); XmlNodeList xmlNodeList5 = element.SelectNodes("ds:X509CRL", nsmgr); if (xmlNodeList5.Count == 0 && xmlNodeList1.Count == 0 && (xmlNodeList2.Count == 0 && xmlNodeList3.Count == 0) && xmlNodeList4.Count == 0) { throw new CryptographicException("Invalid XML element: X509Data"); } this.Clear(); if (xmlNodeList5.Count != 0) { this.m_CRL = Convert.FromBase64String(Exml.DiscardWhiteSpaces(xmlNodeList5.Item(0).InnerText)); } foreach (XmlNode xmlNode1 in xmlNodeList1) { XmlNode xmlNode2 = xmlNode1.SelectSingleNode("ds:X509IssuerName", nsmgr); XmlNode xmlNode3 = xmlNode1.SelectSingleNode("ds:X509SerialNumber", nsmgr); if (xmlNode2 == null || xmlNode3 == null) { throw new CryptographicException("Invalid XML element: IssuerSerial"); } this.InternalAddIssuerSerial(xmlNode2.InnerText.Trim(), xmlNode3.InnerText.Trim()); } foreach (XmlNode xmlNode in xmlNodeList2) { this.AddSubjectKeyId(Convert.FromBase64String(Exml.DiscardWhiteSpaces(xmlNode.InnerText))); } foreach (XmlNode xmlNode in xmlNodeList3) { this.AddSubjectName(xmlNode.InnerText.Trim()); } foreach (XmlNode xmlNode in xmlNodeList4) { this.AddCertificate((X509Certificate) new X509Certificate2(Convert.FromBase64String(Exml.DiscardWhiteSpaces(xmlNode.InnerText)))); } }
/// <summary>Loads a <see cref="T:System.Security.Cryptography.Xml.Reference" /> state from an XML element.</summary> /// <param name="value">The XML element from which to load the <see cref="T:System.Security.Cryptography.Xml.Reference" /> state. </param> /// <exception cref="T:System.ArgumentNullException">The <paramref name="value" /> parameter is <see langword="null" />. </exception> /// <exception cref="T:System.Security.Cryptography.CryptographicException">The <paramref name="value" /> parameter does not contain any transforms.-or- The <paramref name="value" /> parameter contains an unknown transform. </exception> public void LoadXml(XmlElement value) { if (value == null) { throw new ArgumentNullException(nameof(value)); } this.m_id = GetAttribute(value, "Id", "http://www.w3.org/2000/09/xmldsig#"); this.m_uri = GetAttribute(value, "URI", "http://www.w3.org/2000/09/xmldsig#"); this.m_type = GetAttribute(value, "Type", "http://www.w3.org/2000/09/xmldsig#"); if (!VerifyAttributes(value, "Id", "URI", "Type")) { throw new CryptographicException("Cryptography exception: Invalid XML element"); } XmlNamespaceManager nsmgr = new XmlNamespaceManager(value.OwnerDocument.NameTable); nsmgr.AddNamespace("ds", "http://www.w3.org/2000/09/xmldsig#"); bool flag = false; this.TransformChain = new TransformChain(); XmlNodeList xmlNodeList1 = value.SelectNodes("ds:Transforms", nsmgr); if (xmlNodeList1 != null && xmlNodeList1.Count != 0) { flag = true; XmlElement element1 = xmlNodeList1[0] as XmlElement; if (!VerifyAttributes(element1)) { throw new CryptographicException("Cryptography error: Invalid XML element: Reference/Transforms"); } XmlNodeList xmlNodeList2 = element1.SelectNodes("ds:Transform", nsmgr); if (xmlNodeList2 != null) { if ((long)xmlNodeList2.Count > 10) { throw new CryptographicException("Cryptography error: Invalid XML element: Reference/Transforms, too many transforms"); } foreach (XmlNode xmlNode1 in xmlNodeList2) { XmlElement element2 = xmlNode1 as XmlElement; string attribute = GetAttribute(element2, "Algorithm", "http://www.w3.org/2000/09/xmldsig#"); if (attribute == null || !VerifyAttributes(element2, "Algorithm")) { throw new CryptographicException("Cryptography error: Invalid XML element: Unknown transform"); } Transform fromName = CreateFromName <Transform>(attribute); if (fromName == null) { throw new CryptographicException("Cryptography error: Invalid XML element: Unknown transform (name)"); } this.AddTransform(fromName); fromName.LoadInnerXml(element2.ChildNodes); if (fromName is XmlDsigEnvelopedSignatureTransform) { XmlNode xmlNode2 = element2.SelectSingleNode("ancestor::ds:Signature[1]", nsmgr); XmlNodeList xmlNodeList3 = element2.SelectNodes("//ds:Signature", nsmgr); if (xmlNodeList3 != null) { int num = 0; foreach (XmlNode xmlNode3 in xmlNodeList3) { ++num; if (xmlNode3 == xmlNode2) { ((XmlDsigEnvelopedSignatureTransform)fromName).SignaturePosition = num; break; } } } } } } } XmlNodeList xmlNodeList4 = value.SelectNodes("ds:DigestMethod", nsmgr); if (xmlNodeList4 == null || xmlNodeList4.Count == 0) { throw new CryptographicException("Cryptography error: XML has invalid element: Reference/DigestMethod (1)"); } XmlElement element3 = xmlNodeList4[0] as XmlElement; this.m_digestMethod = GetAttribute(element3, "Algorithm", "http://www.w3.org/2000/09/xmldsig#"); if (this.m_digestMethod == null || !VerifyAttributes(element3, "Algorithm")) { throw new CryptographicException("Cryptography error: XML has invalid element: Reference/DigestMethod (2)"); } XmlNodeList xmlNodeList5 = value.SelectNodes("ds:DigestValue", nsmgr); if (xmlNodeList5 == null || xmlNodeList5.Count == 0 || xmlNodeList5.Count > 1) { throw new CryptographicException("Cryptography error: XML has invalid element: Reference/DigestValue (1)"); } XmlElement element4 = xmlNodeList5[0] as XmlElement; this.m_digestValue = Convert.FromBase64String(Exml.DiscardWhiteSpaces(element4.InnerText, 0, element4.InnerText.Length)); if (!VerifyAttributes(element4)) { throw new CryptographicException("Cryptography error: XML has invalid element: Reference/DigestValue (2)"); } int num1 = flag ? 3 : 2; if (value.SelectNodes("*").Count != num1) { throw new CryptographicException("Cryptography error: XML has invalid element: Reference/*"); } this.m_cachedXml = value; }
/// <summary>Loads a <see cref="T:System.Security.Cryptography.Xml.Signature" /> state from an XML element.</summary> /// <param name="value">The XML element from which to load the <see cref="T:System.Security.Cryptography.Xml.Signature" /> state. </param> /// <exception cref="T:System.ArgumentNullException">The <paramref name="value" /> parameter is <see langword="null" />. </exception> /// <exception cref="T:System.Security.Cryptography.CryptographicException">The <paramref name="value" /> parameter does not contain a valid <see cref="P:System.Security.Cryptography.Xml.Signature.SignatureValue" />.-or- The <paramref name="value" /> parameter does not contain a valid <see cref="P:System.Security.Cryptography.Xml.Signature.SignedInfo" />. </exception> public void LoadXml(XmlElement value) { if (value == null) { throw new ArgumentNullException(nameof(value)); } XmlElement element1 = value; if (!element1.LocalName.Equals(nameof(Signature))) { throw new CryptographicException("Invalid element: Signature (1)"); } this.m_id = Exml.GetAttribute(element1, "Id", "http://www.w3.org/2000/09/xmldsig#"); if (!Exml.VerifyAttributes(element1, "Id")) { throw new CryptographicException("Invalid element: Signature (2)"); } XmlNamespaceManager nsmgr = new XmlNamespaceManager(value.OwnerDocument.NameTable); nsmgr.AddNamespace("ds", "http://www.w3.org/2000/09/xmldsig#"); int num1 = 0; XmlNodeList xmlNodeList1 = element1.SelectNodes("ds:SignedInfo", nsmgr); if (xmlNodeList1 == null || xmlNodeList1.Count == 0 || xmlNodeList1.Count > 1) { throw new CryptographicException("Invalid element: SignedInfo"); } XmlElement xmlElement1 = xmlNodeList1[0] as XmlElement; int num2 = num1 + xmlNodeList1.Count; this.SignedInfo = new SignedInfo(); this.SignedInfo.LoadXml(xmlElement1); XmlNodeList xmlNodeList2 = element1.SelectNodes("ds:SignatureValue", nsmgr); if (xmlNodeList2 == null || xmlNodeList2.Count == 0 || xmlNodeList2.Count > 1) { throw new CryptographicException("Invalid element: SignatureValue (1)"); } XmlElement element2 = xmlNodeList2[0] as XmlElement; int num3 = num2 + xmlNodeList2.Count; this.m_signatureValue = Convert.FromBase64String(Exml.DiscardWhiteSpaces(element2.InnerText, 0, element2.InnerText.Length)); this.m_signatureValueId = Exml.GetAttribute(element2, "Id", "http://www.w3.org/2000/09/xmldsig#"); if (!Exml.VerifyAttributes(element2, "Id")) { throw new CryptographicException("Invalid element: SignatureValue (2)"); } XmlNodeList xmlNodeList3 = element1.SelectNodes("ds:KeyInfo", nsmgr); this.m_keyInfo = new KeyInfo(); if (xmlNodeList3 != null) { if (xmlNodeList3.Count > 1) { throw new CryptographicException("Invalid element: KeyInfo"); } foreach (XmlNode xmlNode in xmlNodeList3) { XmlElement xmlElement2 = xmlNode as XmlElement; if (xmlElement2 != null) { this.m_keyInfo.LoadXml(xmlElement2); } } num3 += xmlNodeList3.Count; } XmlNodeList xmlNodeList4 = element1.SelectNodes("ds:Object", nsmgr); this.m_embeddedObjects.Clear(); if (xmlNodeList4 != null) { foreach (XmlNode xmlNode in xmlNodeList4) { XmlElement xmlElement2 = xmlNode as XmlElement; if (xmlElement2 != null) { DataObject dataObject = new DataObject(); dataObject.LoadXml(xmlElement2); this.m_embeddedObjects.Add((object)dataObject); } } num3 += xmlNodeList4.Count; } XmlNodeList xmlNodeList5 = element1.SelectNodes("//*[@Id]", nsmgr); if (xmlNodeList5 != null) { foreach (XmlNode xmlNode in xmlNodeList5) { this.m_referencedItems.Add((object)xmlNode); } } if (element1.SelectNodes("*").Count != num3) { throw new CryptographicException("Invalid element: Signature (3)"); } }