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
- RuleRef.cs
- SharedStatics.cs
- _KerberosClient.cs
- ColorKeyFrameCollection.cs
- FormsAuthenticationUser.cs
- OverrideMode.cs
- WinFormsComponentEditor.cs
- ToolTip.cs
- Types.cs
- COAUTHIDENTITY.cs
- WmiEventSink.cs
- RemoteWebConfigurationHost.cs
- ListDictionary.cs
- DataFormats.cs
- Thickness.cs
- Inline.cs
- UdpChannelFactory.cs
- PartitionResolver.cs
- ConvertEvent.cs
- SymLanguageType.cs
- XamlDesignerSerializationManager.cs
- XmlDocumentFieldSchema.cs
- XmlSchemaAppInfo.cs
- ListViewGroup.cs
- invalidudtexception.cs
- _SslState.cs
- PointLightBase.cs
- objectresult_tresulttype.cs
- Input.cs
- TableSectionStyle.cs
- ConfigXmlElement.cs
- AspNetSynchronizationContext.cs
- MulticastNotSupportedException.cs
- BindingsCollection.cs
- PromptBuilder.cs
- XamlHttpHandlerFactory.cs
- DocumentXPathNavigator.cs
- ComboBoxItem.cs
- MimeMapping.cs
- DataBindingList.cs
- XhtmlCssHandler.cs
- TypeCacheManager.cs
- X509Chain.cs
- AjaxFrameworkAssemblyAttribute.cs
- ProfileService.cs
- CollectionContainer.cs
- SessionSwitchEventArgs.cs
- Section.cs
- LocalizableResourceBuilder.cs
- DecoderNLS.cs
- WasNotInstalledException.cs
- CodeThrowExceptionStatement.cs
- ValueTable.cs
- RtfControls.cs
- MaskInputRejectedEventArgs.cs
- WebPartMovingEventArgs.cs
- SqlDeflator.cs
- SessionPageStateSection.cs
- ToolboxItem.cs
- TextEditorCharacters.cs
- KeyValueSerializer.cs
- Adorner.cs
- TimeoutTimer.cs
- XmlSortKey.cs
- SystemBrushes.cs
- RuntimeHandles.cs
- PrefixQName.cs
- StringKeyFrameCollection.cs
- NativeWindow.cs
- WebPartConnectionsCancelEventArgs.cs
- RootBrowserWindowProxy.cs
- Serializer.cs
- odbcmetadatacolumnnames.cs
- UniqueEventHelper.cs
- IndentTextWriter.cs
- AmbientLight.cs
- TextRangeBase.cs
- EpmSyndicationContentSerializer.cs
- IdnElement.cs
- TreeNode.cs
- AsyncWaitHandle.cs
- LinkButton.cs
- InfocardChannelParameter.cs
- SystemWebExtensionsSectionGroup.cs
- SystemIPAddressInformation.cs
- UserCancellationException.cs
- XmlNamespaceMappingCollection.cs
- InputProcessorProfiles.cs
- Repeater.cs
- DataGridViewColumnCollectionDialog.cs
- SafeUserTokenHandle.cs
- Triplet.cs
- StatusBarPanel.cs
- ViewBox.cs
- Regex.cs
- UpdateRecord.cs
- SqlDataSourceFilteringEventArgs.cs
- MessageAction.cs
- CodeTryCatchFinallyStatement.cs
- AddInBase.cs