| | | 1 | | // Licensed to the .NET Foundation under one or more agreements. |
| | | 2 | | // The .NET Foundation licenses this file to you under the MIT license. |
| | | 3 | | |
| | | 4 | | using System.Security.Cryptography; |
| | | 5 | | using System.Security.Cryptography.Xml; |
| | | 6 | | using System.Xml; |
| | | 7 | | |
| | | 8 | | namespace CoreWCF.IdentityModel |
| | | 9 | | { |
| | | 10 | | /// <summary> |
| | | 11 | | /// Internal class to override GetIdElement |
| | | 12 | | /// </summary> |
| | | 13 | | internal class SignedXMLInternal : SignedXml |
| | | 14 | | { |
| | 0 | 15 | | public SignedXMLInternal() { } |
| | | 16 | | |
| | 46 | 17 | | public SignedXMLInternal(XmlDocument document) : base(document) { } |
| | | 18 | | |
| | 0 | 19 | | public SignedXMLInternal(XmlElement elem) : base(elem) { } |
| | | 20 | | |
| | | 21 | | public override XmlElement GetIdElement(XmlDocument document, string idValue) |
| | | 22 | | { |
| | | 23 | | // The default GetIdElement implementation can't find Id attributes which have a namespace specified |
| | | 24 | | // Only trying the base implementation as a last ditch effort. |
| | 25 | 25 | | return GetSingleReferenceTarget(document, "Id", idValue) ?? |
| | 25 | 26 | | GetSingleReferenceTarget(document, "id", idValue) ?? |
| | 25 | 27 | | GetSingleReferenceTarget(document, "ID", idValue) ?? |
| | 25 | 28 | | base.GetIdElement(document, idValue); |
| | | 29 | | } |
| | | 30 | | |
| | | 31 | | private static XmlElement GetSingleReferenceTarget(XmlDocument document, string idAttributeName, string idValue) |
| | | 32 | | { |
| | | 33 | | // XmlDocument.GetElementById only works for elements specified in a DTD to have an IDREF. |
| | | 34 | | // As we don't use DTD's in SOAP, that method is ineffective. |
| | 25 | 35 | | string xPath = "//*[@*[local-name()='" + idAttributeName + "']='" + idValue + "']"; |
| | | 36 | | |
| | | 37 | | // http://www.w3.org/TR/xmldsig-core/#sec-ReferenceProcessingModel says that for the form URI="#chapter1": |
| | | 38 | | // |
| | | 39 | | // Identifies a node-set containing the element with ID attribute value 'chapter1' ... |
| | | 40 | | // |
| | | 41 | | // Note that it uses the singular. Therefore, if the match is ambiguous, we should consider the document inv |
| | | 42 | | // |
| | | 43 | | // In this case, we'll treat it the same as having found nothing across all fallbacks (but shortcut so that |
| | | 44 | | // fall into a trap of finding a secondary element which wasn't the originally signed one). |
| | | 45 | | |
| | 25 | 46 | | XmlNodeList nodeList = document.SelectNodes(xPath); |
| | | 47 | | |
| | 25 | 48 | | if (nodeList == null || nodeList.Count == 0) { return null; } |
| | 50 | 49 | | if (nodeList.Count == 1) { return nodeList[0] as XmlElement; } |
| | | 50 | | |
| | | 51 | | //throw new CryptographicException(SR.Cryptography_Xml_InvalidReference); |
| | 0 | 52 | | throw new CryptographicException("Cryptography_Xml_InvalidReference"); |
| | | 53 | | } |
| | | 54 | | } |
| | | 55 | | } |