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
- Unit.cs
- DbConnectionPool.cs
- FamilyTypeface.cs
- IdnElement.cs
- ClassHandlersStore.cs
- MetadataArtifactLoaderCompositeResource.cs
- ThreadStateException.cs
- ClrProviderManifest.cs
- EmptyElement.cs
- Geometry3D.cs
- MarkupCompilePass2.cs
- WebBrowserSiteBase.cs
- TextBoxAutomationPeer.cs
- WebPartDisplayMode.cs
- XamlTreeBuilder.cs
- LocatorPartList.cs
- Triplet.cs
- base64Transforms.cs
- exports.cs
- UnaryNode.cs
- PropertyHelper.cs
- ListViewGroupItemCollection.cs
- SizeAnimationBase.cs
- ResourceDescriptionAttribute.cs
- loginstatus.cs
- TreeSet.cs
- CatalogZoneBase.cs
- Accessible.cs
- XmlSignatureManifest.cs
- HyperLinkStyle.cs
- XmlUrlResolver.cs
- SignatureHelper.cs
- XmlSchemaComplexContent.cs
- ListSortDescription.cs
- ItemsPresenter.cs
- SafeFindHandle.cs
- BrowserDefinitionCollection.cs
- MbpInfo.cs
- DuplicateWaitObjectException.cs
- ListBox.cs
- SQLBinaryStorage.cs
- NotSupportedException.cs
- ColorTypeConverter.cs
- SqlInfoMessageEvent.cs
- ChangesetResponse.cs
- RegexStringValidator.cs
- NamespaceList.cs
- ReferencedType.cs
- MessageSecurityException.cs
- Matrix.cs
- SpinWait.cs
- Unit.cs
- PrePrepareMethodAttribute.cs
- ProcessModule.cs
- SHA512.cs
- FontEmbeddingManager.cs
- Vector3DValueSerializer.cs
- HostingEnvironment.cs
- WebPartDisplayModeEventArgs.cs
- ClientConfigPaths.cs
- LayoutTableCell.cs
- UnsafeNativeMethods.cs
- WindowsTooltip.cs
- XamlDebuggerXmlReader.cs
- DataGridHeaderBorder.cs
- WmlTextViewAdapter.cs
- FilterableAttribute.cs
- Behavior.cs
- OleDbEnumerator.cs
- DataControlImageButton.cs
- ReadWriteObjectLock.cs
- HttpRequestCacheValidator.cs
- RoleBoolean.cs
- AudioLevelUpdatedEventArgs.cs
- RecognizedWordUnit.cs
- Stopwatch.cs
- DataGridParentRows.cs
- rsa.cs
- AnnotationObservableCollection.cs
- diagnosticsswitches.cs
- PassportAuthenticationEventArgs.cs
- DelayedRegex.cs
- DropShadowBitmapEffect.cs
- xml.cs
- GridItemPattern.cs
- AuthenticationService.cs
- SettingsPropertyWrongTypeException.cs
- RegisteredDisposeScript.cs
- SqlLiftIndependentRowExpressions.cs
- PipeException.cs
- TransformerInfoCollection.cs
- PropertyReferenceSerializer.cs
- SslStream.cs
- ExecutorLocksHeldException.cs
- XmlSerializationReader.cs
- TreePrinter.cs
- BamlLocalizabilityResolver.cs
- _CacheStreams.cs
- WorkflowApplicationAbortedEventArgs.cs
- Content.cs