// Decompiled with JetBrains decompiler // Type: Microsoft.InfoCards.PolicyFactory // Assembly: infocard, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 // MVID: 516D8B44-4448-4D2C-8B8E-FFBB3FFE472B // Assembly location: C:\Users\Administrateur\Downloads\Virusshare-00000-msil\Virus.Win32.Expiro.w-69bb73081eac86b8cf86f45e33515d0095855636967076e2b593d7a30cd80a07.exe using Microsoft.InfoCards.Diagnostics; using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Globalization; using System.IdentityModel.Selectors; using System.IO; using System.ServiceModel; using System.ServiceModel.Security.Tokens; using System.Text; using System.Xml; namespace Microsoft.InfoCards { internal class PolicyFactory { private PolicyFactory() { } public static Policy CreatePolicyFromUnwrappedPolicyXml(string originalPolicyXml) { string rstPolicyXml = string.Format((IFormatProvider) CultureInfo.InvariantCulture, "<{0}:{1} xmlns:{0}='{2}'>{3}", (object) XmlNames.WSSecurityPolicyXmlSoap2005.Instance.DefaultPrefix, (object) XmlNames.WSSecurityPolicyXmlSoap2005.Instance.RequestSecurityTokenTemplate, (object) XmlNames.WSSecurityPolicyXmlSoap2005.Instance.Namespace, (object) originalPolicyXml); return new Policy(originalPolicyXml, rstPolicyXml); } public static InfoCardPolicy CreatePolicyForCustomTokenProvider( EndpointAddress immediateTokenRecipient, IssuedSecurityTokenParameters issuedTokenParameters, ProtocolProfile profile) { ParsedPolicy parsedPolicy = PolicyFactory.CreateParsedPolicy((IEnumerable) issuedTokenParameters.CreateRequestParameters(profile.MsgSecurityVersion, (SecurityTokenSerializer) profile.TokenSerializer)); return new InfoCardPolicy(immediateTokenRecipient, issuedTokenParameters.IssuerAddress, parsedPolicy, PolicyUsageContext.GetToken, (string) null, 0U, (RecipientIdentity) null, false); } public static InfoCardPolicy CreatePolicyForGetBrowserTokenRequest( CardSpacePolicyElement policyElement, Uri recipientPolicyNoticeLink, uint recipientPolicyNoticeVersion, RecipientIdentity recipientIdentity, PolicyUsageContext usageContext) { EndpointAddress immediateTokenRecipient = (EndpointAddress) null; if (!string.IsNullOrEmpty(policyElement.Target.OuterXml)) immediateTokenRecipient = PolicyFactory.CreateEndpointAddressFromString(policyElement.Target.OuterXml); EndpointAddress issuer = (EndpointAddress) null; if (policyElement.Issuer != null && !string.IsNullOrEmpty(policyElement.Issuer.OuterXml)) issuer = PolicyFactory.CreateEndpointAddressFromString(policyElement.Issuer.OuterXml); ParsedPolicy parsedPolicy = PolicyFactory.CreateParsedPolicy((IEnumerable) policyElement.Parameters); return new InfoCardPolicy(immediateTokenRecipient, issuer, parsedPolicy, usageContext, (Uri) null != recipientPolicyNoticeLink ? recipientPolicyNoticeLink.ToString() : (string) null, recipientPolicyNoticeVersion, recipientIdentity, false); } public static InfoCardPolicy CreatePolicyForIntermediateGetBrowserTokenRequest( CardSpacePolicyElement policyElement, Uri recipientPolicyNoticeLink, uint recipientPolicyNoticeVersion, RecipientIdentity recipientIdentity) { EndpointAddress immediateTokenRecipient = (EndpointAddress) null; if (!string.IsNullOrEmpty(policyElement.Target.OuterXml)) immediateTokenRecipient = PolicyFactory.CreateEndpointAddressFromString(policyElement.Target.OuterXml); EndpointAddress issuer = (EndpointAddress) null; if (policyElement.Issuer != null && !string.IsNullOrEmpty(policyElement.Issuer.OuterXml)) issuer = PolicyFactory.CreateEndpointAddressFromString(policyElement.Issuer.OuterXml); ParsedPolicy parsedPolicy = PolicyFactory.CreateParsedPolicy((IEnumerable) policyElement.Parameters); return new InfoCardPolicy(immediateTokenRecipient, issuer, parsedPolicy, PolicyUsageContext.Intermediate, (Uri) null != recipientPolicyNoticeLink ? recipientPolicyNoticeLink.ToString() : (string) null, recipientPolicyNoticeVersion, recipientIdentity, false); } public static InfoCardPolicy CreatePolicyForGetTokenRequest( BinaryReader reader, string recipientXml, string issuerXml, string policyXml, bool isManaged) { if (!string.IsNullOrEmpty(policyXml)) { string xml = string.Format((IFormatProvider) CultureInfo.InvariantCulture, "<{0}:{1} xmlns:{0}='{2}'>{3}", (object) XmlNames.WSSecurityPolicyXmlSoap2005.Instance.DefaultPrefix, (object) XmlNames.WSSecurityPolicyXmlSoap2005.Instance.RequestSecurityTokenTemplate, (object) XmlNames.WSSecurityPolicyXmlSoap2005.Instance.Namespace, (object) policyXml); XmlDocument xmlDocument = new XmlDocument(); xmlDocument.LoadXml(xml); Collection elements = new Collection(); foreach (XmlElement childNode in xmlDocument.DocumentElement.ChildNodes) elements.Add(childNode); ParsedPolicy parsedPolicy = PolicyFactory.CreateParsedPolicy((IEnumerable) elements); return new InfoCardPolicy(!string.IsNullOrEmpty(recipientXml) ? PolicyFactory.CreateEndpointAddressFromString(recipientXml) : (EndpointAddress) null, !string.IsNullOrEmpty(issuerXml) ? PolicyFactory.CreateEndpointAddressFromString(issuerXml) : (EndpointAddress) null, parsedPolicy, PolicyUsageContext.GetToken, (string) null, 0U, (RecipientIdentity) null, isManaged); } if (!isManaged) throw InfoCardTrace.ThrowHelperError((Exception) new PolicyValidationException(SR.GetString("InvalidPolicySpecified"))); return new InfoCardPolicy(!string.IsNullOrEmpty(recipientXml) ? PolicyFactory.CreateEndpointAddressFromString(recipientXml) : (EndpointAddress) null, !string.IsNullOrEmpty(issuerXml) ? PolicyFactory.CreateEndpointAddressFromString(issuerXml) : (EndpointAddress) null, (ParsedPolicy) null, PolicyUsageContext.GetToken, (string) null, 0U, (RecipientIdentity) null, isManaged); } private static ParsedPolicy CreateParsedPolicy(IEnumerable elements) { try { XmlElement xmlElement = (XmlElement) null; StringBuilder stringBuilder1 = new StringBuilder(); StringBuilder stringBuilder2 = new StringBuilder(); foreach (XmlElement element in elements) { stringBuilder2.Append(element.OuterXml); if (element.LocalName == "SecondaryParameters" && element.NamespaceURI == "http://docs.oasis-open.org/ws-sx/ws-trust/200512") xmlElement = element; else stringBuilder1.Append(element.OuterXml); } return xmlElement != null ? new ParsedPolicy(stringBuilder2.ToString(), stringBuilder1.ToString(), xmlElement.InnerXml) : new ParsedPolicy(stringBuilder2.ToString(), stringBuilder1.ToString(), (string) null); } catch (XmlException ex) { throw InfoCardTrace.ThrowHelperError((Exception) new PolicyValidationException(SR.GetString("InvalidPolicySpecified"), (Exception) ex)); } } private static EndpointAddress CreateEndpointAddressFromString(string fragment) { try { using (XmlReader reader = PolicyFactory.LoadXmlIntoReader(fragment.Trim())) { reader.MoveToElement(); return EndpointAddress.ReadFrom(XmlDictionaryReader.CreateDictionaryReader(reader)); } } catch (Exception ex) { if (!InfoCardTrace.IsFatal(ex)) throw InfoCardTrace.ThrowHelperError((Exception) new PolicyValidationException(SR.GetString("ServiceInvalidEprInPolicy"), ex)); throw; } } private static XmlReader LoadXmlIntoReader(string fragment) => InfoCardSchemas.CreateReader(fragment); } }