MalwareSourceCode/MSIL/Virus/Win32/E/Virus.Win32.Expiro.w-f8f9f26e940480624825f6bddbea86e70fc4aa746c4dd8efa7d98dcb477000ed/Microsoft/InfoCards/PolicyFactory.cs
2022-08-18 06:28:56 -05:00

142 lines
7.8 KiB
C#

// Decompiled with JetBrains decompiler
// Type: Microsoft.InfoCards.PolicyFactory
// Assembly: infocard, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
// MVID: 1D4D5564-A025-490C-AF1D-DF4FBB709D1F
// Assembly location: C:\Users\Administrateur\Downloads\Virusshare-00001-msil\Virus.Win32.Expiro.w-f8f9f26e940480624825f6bddbea86e70fc4aa746c4dd8efa7d98dcb477000ed.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}</{0}:{1}>", (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<XmlElement>) 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<XmlElement>) 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<XmlElement>) 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}</{0}:{1}>", (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<XmlElement> elements = new Collection<XmlElement>();
foreach (XmlElement childNode in xmlDocument.DocumentElement.ChildNodes)
elements.Add(childNode);
ParsedPolicy parsedPolicy = PolicyFactory.CreateParsedPolicy((IEnumerable<XmlElement>) 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<XmlElement> 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);
}
}