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

155 lines
6.7 KiB
C#

// Decompiled with JetBrains decompiler
// Type: Microsoft.InfoCards.RequestSecurityToken
// 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.Globalization;
using System.ServiceModel.Channels;
using System.ServiceModel.Security.Tokens;
using System.Xml;
namespace Microsoft.InfoCards
{
internal abstract class RequestSecurityToken : BodyWriter
{
protected RequestSecurityTokenParameters m_rstParams;
protected RequestSecurityTokenSerializer m_serializer;
protected XmlDictionaryWriter m_xmlWriter;
protected ProtocolProfile ProtocolVersionProfile => this.m_rstParams.Profile;
protected InfoCardPolicy Policy => this.m_rstParams.Policy;
protected RequestSecurityTokenSerializer Serializer
{
get => this.m_serializer;
set => this.m_serializer = value;
}
protected XmlDictionaryWriter Writer
{
get => this.m_xmlWriter;
set => this.m_xmlWriter = value;
}
protected string WstPrefix => this.ProtocolVersionProfile.WSTrust.DefaultPrefix;
public RequestSecurityToken(RequestSecurityTokenParameters rstParams)
: base(false)
{
this.m_rstParams = rstParams;
}
protected virtual void WriteRSTOpeningElement()
{
this.Writer.WriteStartElement(this.WstPrefix, this.ProtocolVersionProfile.WSTrust.RequestSecurityToken, this.ProtocolVersionProfile.WSTrust.Namespace);
this.Writer.WriteAttributeString(this.ProtocolVersionProfile.WSTrust.Context, (string) null, this.m_rstParams.Context);
}
protected virtual void WriteInfoCardReferenceElement()
{
if (this.m_rstParams.Card == null)
return;
this.Serializer.WriteInfoCardReferenceElement(this.m_rstParams.Card);
}
protected virtual void WriteKeyTypeElement() => this.Serializer.WriteKeyTypeElement(this.Policy.GetKeyTypeString());
protected virtual void WriteKeySupportingElements()
{
if (this.Policy.KeyType == SecurityKeyTypeInternal.SymmetricKey)
{
this.Serializer.WriteKeySizeElement(this.Policy.GetIntelligentKeySize(false).ToString((IFormatProvider) CultureInfo.InvariantCulture));
InfoCardTrace.Assert(null != this.m_rstParams.ClientEntropyForSymmetric, "Should not be null");
this.Serializer.WriteBinarySecretElement(new BinarySecretSecurityToken(this.m_rstParams.ClientEntropyForSymmetric));
if (!string.IsNullOrEmpty(this.Policy.OptionalRstParams.EncryptWith))
this.Serializer.WriteEncryptWithElement(this.Policy.OptionalRstParams.EncryptWith);
if (string.IsNullOrEmpty(this.Policy.OptionalRstParams.SignWith))
return;
this.Serializer.WriteSignWithElement(this.Policy.OptionalRstParams.SignWith);
}
else if (SecurityKeyTypeInternal.AsymmetricKey == this.Policy.KeyType)
{
if (XmlNames.WSSpecificationVersion.WSTrustOasis2007 == this.ProtocolVersionProfile.WSTrust.Version && !string.IsNullOrEmpty(this.Policy.OptionalRstParams.KeyWrapAlgorithm))
this.Serializer.WriteKeyWrapAlgorithmElement(this.Policy.OptionalRstParams.KeyWrapAlgorithm);
this.Serializer.WriteKeySizeElement(this.Policy.GetIntelligentKeySize(false).ToString((IFormatProvider) CultureInfo.InvariantCulture));
InfoCardTrace.Assert(null != this.m_rstParams.RSAKey, "Should have been populated in asymmetric case");
this.Serializer.WriteUseKeyElement(this.m_rstParams.RSAKey.GetXml());
if (!string.IsNullOrEmpty(this.Policy.OptionalRstParams.EncryptWith))
this.Serializer.WriteEncryptWithElement(this.Policy.OptionalRstParams.EncryptWith);
if (string.IsNullOrEmpty(this.Policy.OptionalRstParams.SignWith))
return;
this.Serializer.WriteSignWithElement(this.Policy.OptionalRstParams.SignWith);
}
else
InfoCardTrace.Assert(SecurityKeyTypeInternal.NoKey == this.Policy.KeyType, "Should be no proof key");
}
protected virtual void WriteRequestTypeElement()
{
if (!string.IsNullOrEmpty(this.Policy.RequestType))
this.Serializer.WriteRequestTypeElement(this.Policy.RequestType);
else
this.Serializer.WriteRequestTypeElement(this.ProtocolVersionProfile.WSTrust.IssueRequestType);
}
protected virtual void WritePPIDElement()
{
if (this.m_rstParams.Card == null || !this.m_rstParams.Card.GetClaims().ContainsKey(InfoCardConstants.PPIDClaimsUri))
return;
this.Serializer.WritePPIDElement(Utility.CreateHash(this.m_rstParams.Card.Key, Convert.FromBase64String(this.Policy.ImmediateTokenRecipient.GetOrganizationIdentifier()), this.m_rstParams.Card.HashSalt));
}
protected virtual void WriteEncryptionAlgorithmElement()
{
if (string.IsNullOrEmpty(this.Policy.OptionalRstParams.EncryptionAlgorithm))
return;
this.Serializer.WriteEncryptionAlgorithmElement(this.Policy.OptionalRstParams.EncryptionAlgorithm);
}
protected virtual void WriteClaimsElement() => this.Serializer.WriteClaimsElement(this.m_rstParams.DisclosedClaims, this.Policy.RequiredClaims, this.Policy.OptionalClaims);
protected virtual void WriteDisplayTokenElement()
{
if (this.m_rstParams.Culture == null)
return;
this.Serializer.WriteDisplayTokenElement(this.m_rstParams.Culture);
}
protected virtual void WriteTokenTypeElement()
{
if (string.IsNullOrEmpty(this.Policy.OptionalRstParams.TokenType))
return;
this.Serializer.WriteTokenTypeElement(this.Policy.OptionalRstParams.TokenType);
}
protected virtual void WritePassOnElements() => this.Policy.OptionalRstParams.WritePassOnElements(this.Writer, this.ProtocolVersionProfile);
protected virtual void WriteUnprocessedPolicyElements()
{
if (this.Policy.UnprocessedPolicyElements == null || this.Policy.UnprocessedPolicyElements.Length <= 0L)
return;
this.Serializer.WriteUnprocessedPolicyElements(this.Policy.UnprocessedPolicyElements);
}
protected abstract void WriteSecondaryParametersElement();
protected virtual void WriteEndElement() => this.Writer.WriteEndElement();
protected abstract void WriteAppliesToElement();
protected virtual void InitializeWriters(XmlDictionaryWriter writer)
{
this.Writer = writer;
this.Serializer = new RequestSecurityTokenSerializer((XmlWriter) writer, this.ProtocolVersionProfile);
}
protected override void OnWriteBodyContents(XmlDictionaryWriter writer) => this.CustomWriteBodyContents(writer);
protected abstract void CustomWriteBodyContents(XmlDictionaryWriter writer);
}
}