Code:
/ WCF / WCF / 3.5.30729.1 / untmp / Orcas / SP / ndp / cdf / src / WCF / ServiceModel / System / ServiceModel / TcpTransportSecurity.cs / 1 / TcpTransportSecurity.cs
//------------------------------------------------------------ // Copyright (c) Microsoft Corporation. All rights reserved. //----------------------------------------------------------- namespace System.ServiceModel { using System; using System.ServiceModel.Channels; using System.ServiceModel.Security; using System.Net; using System.Net.Security; public sealed class TcpTransportSecurity { internal const TcpClientCredentialType DefaultClientCredentialType = TcpClientCredentialType.Windows; internal const ProtectionLevel DefaultProtectionLevel = ProtectionLevel.EncryptAndSign; TcpClientCredentialType clientCredentialType; ProtectionLevel protectionLevel; internal TcpTransportSecurity() { this.clientCredentialType = DefaultClientCredentialType; this.protectionLevel = DefaultProtectionLevel; } public TcpClientCredentialType ClientCredentialType { get { return this.clientCredentialType; } set { if (!TcpClientCredentialTypeHelper.IsDefined(value)) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("value")); } this.clientCredentialType = value; } } public ProtectionLevel ProtectionLevel { get { return this.protectionLevel; } set { if (!ProtectionLevelHelper.IsDefined(value)) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("value")); } this.protectionLevel = value; } } SslStreamSecurityBindingElement CreateSslBindingElement(bool requireClientCertificate) { if (this.protectionLevel != ProtectionLevel.EncryptAndSign) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString( SR.UnsupportedSslProtectionLevel, this.protectionLevel))); } SslStreamSecurityBindingElement result = new SslStreamSecurityBindingElement(); result.RequireClientCertificate = requireClientCertificate; return result; } static bool IsSslBindingElement(BindingElement element, TcpTransportSecurity transportSecurity, out bool requireClientCertificate) { requireClientCertificate = false; SslStreamSecurityBindingElement ssl = element as SslStreamSecurityBindingElement; if (ssl == null) return false; transportSecurity.ProtectionLevel = ProtectionLevel.EncryptAndSign; requireClientCertificate = ssl.RequireClientCertificate; return true; } internal BindingElement CreateTransportProtectionOnly() { return this.CreateSslBindingElement(false); } internal static bool SetTransportProtectionOnly(BindingElement transport, TcpTransportSecurity transportSecurity) { bool requireClientCertificate; return IsSslBindingElement(transport, transportSecurity, out requireClientCertificate); } internal BindingElement CreateTransportProtectionAndAuthentication() { if (this.clientCredentialType == TcpClientCredentialType.Certificate || this.clientCredentialType == TcpClientCredentialType.None) { return this.CreateSslBindingElement(this.clientCredentialType == TcpClientCredentialType.Certificate); } else { WindowsStreamSecurityBindingElement result = new WindowsStreamSecurityBindingElement(); result.ProtectionLevel = this.protectionLevel; return result; } } internal static bool SetTransportProtectionAndAuthentication(BindingElement transport, TcpTransportSecurity transportSecurity) { bool requireClientCertificate = false; if (transport is WindowsStreamSecurityBindingElement) { transportSecurity.ClientCredentialType = TcpClientCredentialType.Windows; transportSecurity.ProtectionLevel = ((WindowsStreamSecurityBindingElement)transport).ProtectionLevel; return true; } else if (IsSslBindingElement(transport, transportSecurity, out requireClientCertificate)) { transportSecurity.ClientCredentialType = requireClientCertificate ? TcpClientCredentialType.Certificate : TcpClientCredentialType.None; return true; } return 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
- UnmanagedMemoryStreamWrapper.cs
- EventSchemaTraceListener.cs
- RC2.cs
- KeyConstraint.cs
- ThreadStateException.cs
- GeneralTransform.cs
- SchemaNamespaceManager.cs
- TransformGroup.cs
- XsltOutput.cs
- Registry.cs
- EventMappingSettingsCollection.cs
- WeakReferenceEnumerator.cs
- OverflowException.cs
- GridViewEditEventArgs.cs
- ComponentConverter.cs
- ChannelServices.cs
- EditBehavior.cs
- ProtocolsConfiguration.cs
- Point.cs
- HtmlTextArea.cs
- ThreadInterruptedException.cs
- VideoDrawing.cs
- ProjectionPruner.cs
- TrayIconDesigner.cs
- HtmlControlPersistable.cs
- Mutex.cs
- CodeArgumentReferenceExpression.cs
- WebSysDescriptionAttribute.cs
- StaticContext.cs
- SQLSingle.cs
- ProfilePropertyMetadata.cs
- Stopwatch.cs
- XmlSchemaInfo.cs
- odbcmetadatafactory.cs
- MimeBasePart.cs
- EventData.cs
- ConstantSlot.cs
- ControlIdConverter.cs
- PolicyManager.cs
- TreeNodeClickEventArgs.cs
- FixedSOMContainer.cs
- OleDbError.cs
- Logging.cs
- DateTimeStorage.cs
- AxisAngleRotation3D.cs
- MdbDataFileEditor.cs
- Point.cs
- SubclassTypeValidator.cs
- AmbientProperties.cs
- ADMembershipUser.cs
- PeerChannelFactory.cs
- AdornerLayer.cs
- ADRole.cs
- Utilities.cs
- ColorPalette.cs
- ContractTypeNameCollection.cs
- WebPartRestoreVerb.cs
- BaseTemplateParser.cs
- embossbitmapeffect.cs
- DataGridAutoGeneratingColumnEventArgs.cs
- HtmlAnchor.cs
- EntityException.cs
- DateTimeSerializationSection.cs
- EndpointNotFoundException.cs
- ArrayWithOffset.cs
- WindowsTokenRoleProvider.cs
- TcpChannelHelper.cs
- ComplusEndpointConfigContainer.cs
- XmlObjectSerializerReadContextComplex.cs
- PackageDigitalSignatureManager.cs
- PhysicalOps.cs
- ResponseStream.cs
- SByte.cs
- XmlDataImplementation.cs
- NameValuePair.cs
- DateTimeFormatInfoScanner.cs
- RowCache.cs
- DesignerHelpers.cs
- UserControl.cs
- Button.cs
- ConsumerConnectionPoint.cs
- DetailsViewPageEventArgs.cs
- MasterPageBuildProvider.cs
- SizeAnimation.cs
- RectangleF.cs
- NameValueCollection.cs
- RequiredFieldValidator.cs
- StringUtil.cs
- CloseSequence.cs
- OpenTypeLayoutCache.cs
- CategoryGridEntry.cs
- TreeNode.cs
- LeftCellWrapper.cs
- X509Certificate.cs
- CompiledIdentityConstraint.cs
- ResolveNameEventArgs.cs
- XmlAutoDetectWriter.cs
- DbConnectionFactory.cs
- TableProviderWrapper.cs
- Renderer.cs