Code:
/ WCF / WCF / 3.5.30729.1 / untmp / Orcas / SP / ndp / cdf / src / WCF / ServiceModel / System / ServiceModel / Security / AsymmetricSecurityProtocolFactory.cs / 1 / AsymmetricSecurityProtocolFactory.cs
//----------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------
namespace System.ServiceModel.Security
{
using System.Collections.ObjectModel;
using System.ServiceModel;
using System.ServiceModel.Description;
using System.IdentityModel.Selectors;
using System.IdentityModel.Tokens;
using System.ServiceModel.Channels;
using System.ServiceModel.Security.Tokens;
class AsymmetricSecurityProtocolFactory : MessageSecurityProtocolFactory
{
SecurityTokenParameters cryptoTokenParameters;
SecurityTokenParameters asymmetricTokenParameters;
SecurityTokenProvider recipientAsymmetricTokenProvider;
ReadOnlyCollection recipientOutOfBandTokenResolverList;
SecurityTokenAuthenticator recipientCryptoTokenAuthenticator;
bool allowSerializedSigningTokenOnReply;
public AsymmetricSecurityProtocolFactory()
: base()
{
}
internal AsymmetricSecurityProtocolFactory(AsymmetricSecurityProtocolFactory factory)
: base(factory)
{
this.allowSerializedSigningTokenOnReply = factory.allowSerializedSigningTokenOnReply;
}
public bool AllowSerializedSigningTokenOnReply
{
get
{
return this.allowSerializedSigningTokenOnReply;
}
set
{
ThrowIfImmutable();
this.allowSerializedSigningTokenOnReply = value;
}
}
public SecurityTokenParameters AsymmetricTokenParameters
{
get
{
return this.asymmetricTokenParameters;
}
set
{
ThrowIfImmutable();
this.asymmetricTokenParameters = value;
}
}
public SecurityTokenProvider RecipientAsymmetricTokenProvider
{
get
{
this.CommunicationObject.ThrowIfNotOpened();
return this.recipientAsymmetricTokenProvider;
}
}
public SecurityTokenAuthenticator RecipientCryptoTokenAuthenticator
{
get
{
this.CommunicationObject.ThrowIfNotOpened();
return this.recipientCryptoTokenAuthenticator;
}
}
public ReadOnlyCollection RecipientOutOfBandTokenResolverList
{
get
{
this.CommunicationObject.ThrowIfNotOpened();
return this.recipientOutOfBandTokenResolverList;
}
}
public SecurityTokenParameters CryptoTokenParameters
{
get
{
return this.cryptoTokenParameters;
}
set
{
ThrowIfImmutable();
this.cryptoTokenParameters = value;
}
}
bool RequiresAsymmetricTokenProviderForForwardDirection
{
get
{
return ((this.ActAsInitiator && this.ApplyConfidentiality) || (!this.ActAsInitiator && this.RequireConfidentiality));
}
}
bool RequiresAsymmetricTokenProviderForReturnDirection
{
get
{
return ((this.ActAsInitiator && this.RequireIntegrity) || (!this.ActAsInitiator && this.ApplyIntegrity));
}
}
public override EndpointIdentity GetIdentityOfSelf()
{
if (this.SecurityTokenManager is IEndpointIdentityProvider && this.AsymmetricTokenParameters != null)
{
SecurityTokenRequirement requirement = CreateRecipientSecurityTokenRequirement();
this.AsymmetricTokenParameters.InitializeSecurityTokenRequirement(requirement);
return ((IEndpointIdentityProvider)this.SecurityTokenManager).GetIdentityOfSelf(requirement);
}
else
{
return base.GetIdentityOfSelf();
}
}
public override T GetProperty()
{
if (typeof(T) == typeof(Collection))
{
Collection result = base.GetProperty>();
if (this.recipientCryptoTokenAuthenticator is ISecurityContextSecurityTokenCacheProvider)
{
result.Add(((ISecurityContextSecurityTokenCacheProvider)this.recipientCryptoTokenAuthenticator).TokenCache);
}
return (T) (object) (result);
}
else
{
return base.GetProperty();
}
}
public override void OnClose(TimeSpan timeout)
{
TimeoutHelper timeoutHelper = new TimeoutHelper(timeout);
if (!this.ActAsInitiator)
{
if (this.recipientAsymmetricTokenProvider != null)
{
SecurityUtils.CloseTokenProviderIfRequired(this.recipientAsymmetricTokenProvider, timeoutHelper.RemainingTime());
}
if (this.recipientCryptoTokenAuthenticator != null)
{
SecurityUtils.CloseTokenAuthenticatorIfRequired(this.recipientCryptoTokenAuthenticator, timeoutHelper.RemainingTime());
}
}
base.OnClose(timeoutHelper.RemainingTime());
}
public override void OnAbort()
{
if (!this.ActAsInitiator)
{
if (this.recipientAsymmetricTokenProvider != null)
{
SecurityUtils.AbortTokenProviderIfRequired(this.recipientAsymmetricTokenProvider);
}
if (this.recipientCryptoTokenAuthenticator != null)
{
SecurityUtils.AbortTokenAuthenticatorIfRequired(this.recipientCryptoTokenAuthenticator);
}
}
base.OnAbort();
}
protected override SecurityProtocol OnCreateSecurityProtocol(EndpointAddress target, Uri via, object listenerSecurityState, TimeSpan timeout)
{
return new AsymmetricSecurityProtocol(this, target, via);
}
public override void OnOpen(TimeSpan timeout)
{
TimeoutHelper timeoutHelper = new TimeoutHelper(timeout);
base.OnOpen(timeoutHelper.RemainingTime());
// open forward direction
if (this.ActAsInitiator)
{
if (this.ApplyIntegrity)
{
if (this.CryptoTokenParameters == null)
{
OnPropertySettingsError("CryptoTokenParameters", true);
}
if (this.CryptoTokenParameters.RequireDerivedKeys)
{
this.ExpectKeyDerivation = true;
}
}
}
else
{
if (this.CryptoTokenParameters == null)
{
OnPropertySettingsError("CryptoTokenParameters", true);
}
if (this.CryptoTokenParameters.RequireDerivedKeys)
{
this.ExpectKeyDerivation = true;
}
SecurityTokenResolver resolver = null;
if (this.RequireIntegrity)
{
RecipientServiceModelSecurityTokenRequirement requirement = CreateRecipientSecurityTokenRequirement();
this.CryptoTokenParameters.InitializeSecurityTokenRequirement(requirement);
requirement.KeyUsage = SecurityKeyUsage.Signature;
requirement.Properties[ServiceModelSecurityTokenRequirement.MessageDirectionProperty] = MessageDirection.Input;
this.recipientCryptoTokenAuthenticator = this.SecurityTokenManager.CreateSecurityTokenAuthenticator(requirement, out resolver);
Open("RecipientCryptoTokenAuthenticator", true, this.recipientCryptoTokenAuthenticator, timeoutHelper.RemainingTime());
}
if (resolver != null)
{
Collection tmp = new Collection();
tmp.Add(resolver);
this.recipientOutOfBandTokenResolverList = new ReadOnlyCollection(tmp);
}
else
{
this.recipientOutOfBandTokenResolverList = EmptyReadOnlyCollection.Instance;
}
}
if (this.RequiresAsymmetricTokenProviderForForwardDirection || this.RequiresAsymmetricTokenProviderForReturnDirection)
{
if (this.AsymmetricTokenParameters == null)
{
OnPropertySettingsError("AsymmetricTokenParameters", this.RequiresAsymmetricTokenProviderForForwardDirection);
}
else if (this.AsymmetricTokenParameters.RequireDerivedKeys)
{
this.ExpectKeyDerivation = true;
}
if (!this.ActAsInitiator)
{
RecipientServiceModelSecurityTokenRequirement requirement = CreateRecipientSecurityTokenRequirement();
this.AsymmetricTokenParameters.InitializeSecurityTokenRequirement(requirement);
requirement.KeyUsage = (this.RequiresAsymmetricTokenProviderForForwardDirection) ? SecurityKeyUsage.Exchange : SecurityKeyUsage.Signature;
requirement.Properties[ServiceModelSecurityTokenRequirement.MessageDirectionProperty] = (this.RequiresAsymmetricTokenProviderForForwardDirection) ? MessageDirection.Input : MessageDirection.Output;
this.recipientAsymmetricTokenProvider = this.SecurityTokenManager.CreateSecurityTokenProvider(requirement);
Open("RecipientAsymmetricTokenProvider", this.RequiresAsymmetricTokenProviderForForwardDirection, this.recipientAsymmetricTokenProvider, timeoutHelper.RemainingTime());
}
}
if (this.ActAsInitiator && this.AllowSerializedSigningTokenOnReply && this.IdentityVerifier == null)
{
OnPropertySettingsError("IdentityVerifier", false);
}
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- SerializationHelper.cs
- LinkedResource.cs
- Preprocessor.cs
- TemplateModeChangedEventArgs.cs
- Attributes.cs
- UInt32Storage.cs
- ToolStripPanel.cs
- CertificateElement.cs
- FormViewPageEventArgs.cs
- CodeTypeMember.cs
- XmlLangPropertyAttribute.cs
- AsyncInvokeOperation.cs
- ProcessModule.cs
- PanningMessageFilter.cs
- XsdCachingReader.cs
- FactoryRecord.cs
- SchemaNames.cs
- RegistrationServices.cs
- CodeDOMUtility.cs
- MostlySingletonList.cs
- DataRecord.cs
- SpeakInfo.cs
- DataService.cs
- SignatureDescription.cs
- CachingHintValidation.cs
- IntegerValidatorAttribute.cs
- ConfigurationValue.cs
- SynchronizedInputPattern.cs
- GacUtil.cs
- Component.cs
- GiveFeedbackEventArgs.cs
- DefaultMemberAttribute.cs
- SafeEventHandle.cs
- XmlStreamStore.cs
- EventDescriptor.cs
- CheckoutException.cs
- PassportAuthenticationModule.cs
- WebPartVerbCollection.cs
- OdbcError.cs
- GridLength.cs
- ExtensionWindowHeader.cs
- PromptEventArgs.cs
- InlineUIContainer.cs
- RegistryKey.cs
- FieldAccessException.cs
- DataControlPagerLinkButton.cs
- RelatedImageListAttribute.cs
- HtmlTernaryTree.cs
- SqlCrossApplyToCrossJoin.cs
- MouseActionConverter.cs
- AvTrace.cs
- DrawingBrush.cs
- XPathSelfQuery.cs
- JsonQueryStringConverter.cs
- XmlDataImplementation.cs
- xml.cs
- StrokeCollection2.cs
- SettingsProviderCollection.cs
- PageVisual.cs
- ResizeGrip.cs
- DataContractSerializerSection.cs
- HandleCollector.cs
- SendActivityEventArgs.cs
- SafeCloseHandleCritical.cs
- RemotingAttributes.cs
- DBSqlParserTable.cs
- XmlComment.cs
- NameSpaceEvent.cs
- DomainUpDown.cs
- LineSegment.cs
- FileDialogPermission.cs
- DateTimeSerializationSection.cs
- BasicExpandProvider.cs
- PathNode.cs
- ProcessProtocolHandler.cs
- TimeSpan.cs
- AspNetHostingPermission.cs
- EventLogLink.cs
- ContextInformation.cs
- Helpers.cs
- InputMethod.cs
- DataControlImageButton.cs
- XamlTreeBuilderBamlRecordWriter.cs
- Model3DGroup.cs
- BaseValidatorDesigner.cs
- ActivationArguments.cs
- SequenceQuery.cs
- SkipStoryboardToFill.cs
- DataTableClearEvent.cs
- TypeForwardedToAttribute.cs
- TextBoxAutoCompleteSourceConverter.cs
- Rules.cs
- AdPostCacheSubstitution.cs
- ResourcePermissionBase.cs
- EmbeddedObject.cs
- HttpRawResponse.cs
- IPEndPoint.cs
- JoinCqlBlock.cs
- SetIterators.cs
- ToolStripPanelRow.cs