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
- DispatcherOperation.cs
- ChangeBlockUndoRecord.cs
- BuildManager.cs
- OlePropertyStructs.cs
- Vector3DCollection.cs
- MetaDataInfo.cs
- NameValuePair.cs
- NodeLabelEditEvent.cs
- PageThemeParser.cs
- ProviderManager.cs
- BuildProvider.cs
- UshortList2.cs
- Int16Animation.cs
- SiteOfOriginPart.cs
- ManifestSignedXml.cs
- ImplicitInputBrush.cs
- ChtmlImageAdapter.cs
- InternalDispatchObject.cs
- RequestTimeoutManager.cs
- NamedPermissionSet.cs
- PropertyItemInternal.cs
- AnimationClock.cs
- WeakHashtable.cs
- DBConnection.cs
- XmlReflectionMember.cs
- Overlapped.cs
- Parser.cs
- ErrorItem.cs
- WorkflowServiceAttributesTypeConverter.cs
- WindowsListView.cs
- Storyboard.cs
- EnumBuilder.cs
- XmlParser.cs
- EventData.cs
- AddToCollection.cs
- DispatcherExceptionEventArgs.cs
- FromReply.cs
- Component.cs
- ComponentSerializationService.cs
- FontDifferentiator.cs
- MaskInputRejectedEventArgs.cs
- KernelTypeValidation.cs
- StylusButton.cs
- Highlights.cs
- IfAction.cs
- BeginStoryboard.cs
- codemethodreferenceexpression.cs
- CompiledQueryCacheKey.cs
- IntPtr.cs
- NetworkInformationException.cs
- BitmapEffectDrawingContextWalker.cs
- ZoomPercentageConverter.cs
- SHA1Managed.cs
- KerberosSecurityTokenProvider.cs
- DbMetaDataColumnNames.cs
- MouseEvent.cs
- SqlDataSourceCustomCommandPanel.cs
- StorageEntitySetMapping.cs
- XmlSchemaAll.cs
- ResourceSet.cs
- SplitterEvent.cs
- GroupBox.cs
- DataGridViewTopRowAccessibleObject.cs
- ComponentResourceManager.cs
- DbParameterHelper.cs
- BidOverLoads.cs
- CapabilitiesState.cs
- BevelBitmapEffect.cs
- IsolatedStorage.cs
- ColorConvertedBitmapExtension.cs
- URL.cs
- TypeDescriptionProviderAttribute.cs
- HttpListenerException.cs
- DeferredElementTreeState.cs
- JoinCqlBlock.cs
- SrgsDocumentParser.cs
- SqlRemoveConstantOrderBy.cs
- RayHitTestParameters.cs
- StylusEventArgs.cs
- XamlStream.cs
- HttpModuleAction.cs
- ButtonColumn.cs
- TransformDescriptor.cs
- BoolExpressionVisitors.cs
- Color.cs
- TraceInternal.cs
- Crypto.cs
- InvariantComparer.cs
- OracleBinary.cs
- BamlTreeMap.cs
- SystemColors.cs
- StateWorkerRequest.cs
- ReflectionTypeLoadException.cs
- odbcmetadatacollectionnames.cs
- XmlSchemaObjectCollection.cs
- UriScheme.cs
- BinHexEncoder.cs
- PropertyTabChangedEvent.cs
- SqlDataSourceFilteringEventArgs.cs
- XPathQilFactory.cs