Code:
/ WCF / WCF / 3.5.30729.1 / untmp / Orcas / SP / ndp / cdf / src / WCF / ServiceModel / System / ServiceModel / Security / X509ServiceCertificateAuthentication.cs / 1 / X509ServiceCertificateAuthentication.cs
//------------------------------------------------------------------------------ // Copyright (c) Microsoft Corporation. All rights reserved. //----------------------------------------------------------------------------- namespace System.ServiceModel.Security { using System.IdentityModel.Selectors; using System.ServiceModel; using System.Security.Cryptography.X509Certificates; public class X509ServiceCertificateAuthentication { internal const X509CertificateValidationMode DefaultCertificateValidationMode = X509CertificateValidationMode.ChainTrust; internal const X509RevocationMode DefaultRevocationMode = X509RevocationMode.Online; internal const StoreLocation DefaultTrustedStoreLocation = StoreLocation.CurrentUser; static X509CertificateValidator defaultCertificateValidator; X509CertificateValidationMode certificateValidationMode = DefaultCertificateValidationMode; X509RevocationMode revocationMode = DefaultRevocationMode; StoreLocation trustedStoreLocation = DefaultTrustedStoreLocation; X509CertificateValidator customCertificateValidator = null; bool isReadOnly; internal X509ServiceCertificateAuthentication() { } internal X509ServiceCertificateAuthentication(X509ServiceCertificateAuthentication other) { this.certificateValidationMode = other.certificateValidationMode; this.customCertificateValidator = other.customCertificateValidator; this.revocationMode = other.revocationMode; this.trustedStoreLocation = other.trustedStoreLocation; this.isReadOnly = other.isReadOnly; } internal static X509CertificateValidator DefaultCertificateValidator { get { if (defaultCertificateValidator == null) { bool useMachineContext = DefaultTrustedStoreLocation == StoreLocation.LocalMachine; X509ChainPolicy chainPolicy = new X509ChainPolicy(); chainPolicy.RevocationMode = DefaultRevocationMode; defaultCertificateValidator = X509CertificateValidator.CreateChainTrustValidator(useMachineContext, chainPolicy); } return defaultCertificateValidator; } } public X509CertificateValidationMode CertificateValidationMode { get { return this.certificateValidationMode; } set { X509CertificateValidationModeHelper.Validate(value); ThrowIfImmutable(); this.certificateValidationMode = value; } } public X509RevocationMode RevocationMode { get { return this.revocationMode; } set { ThrowIfImmutable(); this.revocationMode = value; } } public StoreLocation TrustedStoreLocation { get { return this.trustedStoreLocation; } set { ThrowIfImmutable(); this.trustedStoreLocation = value; } } public X509CertificateValidator CustomCertificateValidator { get { return this.customCertificateValidator; } set { ThrowIfImmutable(); this.customCertificateValidator = value; } } internal bool TryGetCertificateValidator(out X509CertificateValidator validator) { validator = null; if (this.certificateValidationMode == X509CertificateValidationMode.None) { validator = X509CertificateValidator.None; } else if (this.certificateValidationMode == X509CertificateValidationMode.PeerTrust) { validator = X509CertificateValidator.PeerTrust; } else if (this.certificateValidationMode == X509CertificateValidationMode.Custom) { validator = this.customCertificateValidator; } else { bool useMachineContext = this.trustedStoreLocation == StoreLocation.LocalMachine; X509ChainPolicy chainPolicy = new X509ChainPolicy(); chainPolicy.RevocationMode = this.revocationMode; if (this.certificateValidationMode == X509CertificateValidationMode.ChainTrust) { validator = X509CertificateValidator.CreateChainTrustValidator(useMachineContext, chainPolicy); } else { validator = X509CertificateValidator.CreatePeerOrChainTrustValidator(useMachineContext, chainPolicy); } } return (validator != null); } internal X509CertificateValidator GetCertificateValidator() { X509CertificateValidator result; if (!TryGetCertificateValidator(out result)) { DiagnosticUtility.DebugAssert(this.customCertificateValidator == null, ""); throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(SR.MissingCustomCertificateValidator))); } return result; } internal void MakeReadOnly() { this.isReadOnly = true; } void ThrowIfImmutable() { if (this.isReadOnly) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(SR.ObjectIsReadOnly))); } } } } // 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
- XPathNavigator.cs
- DataGridCellItemAutomationPeer.cs
- HtmlShim.cs
- FixUp.cs
- SqlTriggerAttribute.cs
- Overlapped.cs
- HttpRequest.cs
- ByteFacetDescriptionElement.cs
- SQLBytesStorage.cs
- QuestionEventArgs.cs
- ColorMap.cs
- EntityContainerAssociationSet.cs
- XmlSerializationWriter.cs
- HashCodeCombiner.cs
- OpenFileDialog.cs
- SvcMapFileSerializer.cs
- OutputCacheSettings.cs
- Operand.cs
- ListContractAdapter.cs
- UpdatableWrapper.cs
- DefaultValueMapping.cs
- DesignDataSource.cs
- Bezier.cs
- UnsignedPublishLicense.cs
- HandledEventArgs.cs
- TypeLoader.cs
- CatalogZone.cs
- SemanticAnalyzer.cs
- BrowserInteropHelper.cs
- ChangeDirector.cs
- PropagatorResult.cs
- DataTableReaderListener.cs
- TextElementEnumerator.cs
- WebMessageEncodingElement.cs
- XmlReflectionImporter.cs
- AttributeTable.cs
- EffectiveValueEntry.cs
- DataServiceEntityAttribute.cs
- ObjectQueryProvider.cs
- XslTransform.cs
- RTLAwareMessageBox.cs
- ByteStream.cs
- WorkflowServiceNamespace.cs
- Queue.cs
- WindowCollection.cs
- OdbcException.cs
- DataServiceHostFactory.cs
- TableLayoutStyle.cs
- VirtualizingStackPanel.cs
- RemoteCryptoRsaServiceProvider.cs
- DataObjectCopyingEventArgs.cs
- documentsequencetextpointer.cs
- CryptoKeySecurity.cs
- HostProtectionException.cs
- StylusSystemGestureEventArgs.cs
- CallSiteBinder.cs
- PenContext.cs
- RowType.cs
- ToolboxDataAttribute.cs
- InternalCache.cs
- ReflectionTypeLoadException.cs
- CompilerError.cs
- SemaphoreFullException.cs
- DocumentOrderQuery.cs
- Mapping.cs
- DataGridViewSelectedColumnCollection.cs
- ClientBuildManagerCallback.cs
- Mappings.cs
- Matrix3DStack.cs
- WindowsHyperlink.cs
- ISCIIEncoding.cs
- CommandBinding.cs
- CfgParser.cs
- TagPrefixAttribute.cs
- BlockingCollection.cs
- ByteAnimation.cs
- DefaultBinder.cs
- StringComparer.cs
- ControlPersister.cs
- DataGridClipboardCellContent.cs
- QilSortKey.cs
- ScrollPattern.cs
- ClientRoleProvider.cs
- ScrollViewerAutomationPeer.cs
- ContractSearchPattern.cs
- XmlSchemaComplexContent.cs
- UserPreferenceChangingEventArgs.cs
- TextOnlyOutput.cs
- ClockGroup.cs
- TextServicesCompartmentContext.cs
- XsdDuration.cs
- TemplatePagerField.cs
- ImageUrlEditor.cs
- FixedSOMPageConstructor.cs
- XamlSerializer.cs
- Error.cs
- Queue.cs
- ConditionalWeakTable.cs
- XsltException.cs
- GraphicsContainer.cs