Code:
/ WCF / WCF / 3.5.30729.1 / untmp / Orcas / SP / ndp / cdf / src / WCF / ServiceModel / System / ServiceModel / Security / X509ClientCertificateAuthentication.cs / 1 / X509ClientCertificateAuthentication.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 X509ClientCertificateAuthentication
{
internal const X509CertificateValidationMode DefaultCertificateValidationMode = X509CertificateValidationMode.ChainTrust;
internal const X509RevocationMode DefaultRevocationMode = X509RevocationMode.Online;
internal const StoreLocation DefaultTrustedStoreLocation = StoreLocation.LocalMachine;
internal const bool DefaultMapCertificateToWindowsAccount = false;
static X509CertificateValidator defaultCertificateValidator;
X509CertificateValidationMode certificateValidationMode = DefaultCertificateValidationMode;
X509RevocationMode revocationMode = DefaultRevocationMode;
StoreLocation trustedStoreLocation = DefaultTrustedStoreLocation;
X509CertificateValidator customCertificateValidator = null;
bool mapClientCertificateToWindowsAccount = DefaultMapCertificateToWindowsAccount;
bool includeWindowsGroups = SspiSecurityTokenProvider.DefaultExtractWindowsGroupClaims;
bool isReadOnly;
internal X509ClientCertificateAuthentication()
{
}
internal X509ClientCertificateAuthentication(X509ClientCertificateAuthentication other)
{
this.certificateValidationMode = other.certificateValidationMode;
this.customCertificateValidator = other.customCertificateValidator;
this.includeWindowsGroups = other.includeWindowsGroups;
this.mapClientCertificateToWindowsAccount = other.mapClientCertificateToWindowsAccount;
this.trustedStoreLocation = other.trustedStoreLocation;
this.revocationMode = other.revocationMode;
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;
}
}
public bool MapClientCertificateToWindowsAccount
{
get
{
return this.mapClientCertificateToWindowsAccount;
}
set
{
ThrowIfImmutable();
this.mapClientCertificateToWindowsAccount = value;
}
}
public bool IncludeWindowsGroups
{
get
{
return this.includeWindowsGroups;
}
set
{
ThrowIfImmutable();
this.includeWindowsGroups = value;
}
}
internal X509CertificateValidator GetCertificateValidator()
{
if (this.certificateValidationMode == X509CertificateValidationMode.None)
{
return X509CertificateValidator.None;
}
else if (this.certificateValidationMode == X509CertificateValidationMode.PeerTrust)
{
return X509CertificateValidator.PeerTrust;
}
else if (this.certificateValidationMode == X509CertificateValidationMode.Custom)
{
if (this.customCertificateValidator == null)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(SR.MissingCustomCertificateValidator)));
}
return this.customCertificateValidator;
}
else
{
bool useMachineContext = this.trustedStoreLocation == StoreLocation.LocalMachine;
X509ChainPolicy chainPolicy = new X509ChainPolicy();
chainPolicy.RevocationMode = this.revocationMode;
if (this.certificateValidationMode == X509CertificateValidationMode.ChainTrust)
{
return X509CertificateValidator.CreateChainTrustValidator(useMachineContext, chainPolicy);
}
else
{
return X509CertificateValidator.CreatePeerOrChainTrustValidator(useMachineContext, chainPolicy);
}
}
}
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
- OleDbFactory.cs
- XhtmlBasicFormAdapter.cs
- SqlDataReaderSmi.cs
- AnimationLayer.cs
- PeerHelpers.cs
- NonPrimarySelectionGlyph.cs
- TCPListener.cs
- InstalledFontCollection.cs
- RadioButtonPopupAdapter.cs
- HtmlInputCheckBox.cs
- WindowsFormsHelpers.cs
- TypeForwardedToAttribute.cs
- Int32Animation.cs
- UnsafeNativeMethods.cs
- SystemIPGlobalStatistics.cs
- CultureNotFoundException.cs
- AnonymousIdentificationModule.cs
- StickyNoteAnnotations.cs
- NavigationProperty.cs
- FastEncoderWindow.cs
- SharedUtils.cs
- RowsCopiedEventArgs.cs
- DefaultValueConverter.cs
- EndpointConfigContainer.cs
- WorkflowValidationFailedException.cs
- RectangleHotSpot.cs
- PictureBox.cs
- ProfileSettings.cs
- CodeTypeDeclaration.cs
- ActivationWorker.cs
- SmiXetterAccessMap.cs
- HasCopySemanticsAttribute.cs
- ExpressionVisitorHelpers.cs
- DbConnectionPool.cs
- TransformedBitmap.cs
- Menu.cs
- FixedNode.cs
- path.cs
- ListViewTableRow.cs
- IISMapPath.cs
- InternalReceiveMessage.cs
- SqlStatistics.cs
- HotCommands.cs
- ProfileService.cs
- Wildcard.cs
- InputProcessorProfilesLoader.cs
- SkewTransform.cs
- WebPartHelpVerb.cs
- XmlWellformedWriterHelpers.cs
- TextStore.cs
- DynamicObjectAccessor.cs
- Triplet.cs
- XamlRtfConverter.cs
- ClientSideProviderDescription.cs
- Identity.cs
- WebPartVerb.cs
- HighlightVisual.cs
- CacheChildrenQuery.cs
- _ListenerResponseStream.cs
- DocumentOrderQuery.cs
- RtfToXamlReader.cs
- TemplateKey.cs
- CatalogPartChrome.cs
- Decimal.cs
- ProcessHostMapPath.cs
- Gdiplus.cs
- FixedSOMGroup.cs
- ApplicationDirectoryMembershipCondition.cs
- ReferenceService.cs
- CustomValidator.cs
- CodeExporter.cs
- PreProcessInputEventArgs.cs
- HMACSHA384.cs
- HeaderedContentControl.cs
- GroupPartitionExpr.cs
- TraceProvider.cs
- AnonymousIdentificationSection.cs
- CaseExpr.cs
- BackEase.cs
- HostingEnvironment.cs
- ContractAdapter.cs
- Binding.cs
- EventLogTraceListener.cs
- SchemaType.cs
- EntityDescriptor.cs
- PersonalizationProviderHelper.cs
- PropertyPath.cs
- ScrollBar.cs
- _HelperAsyncResults.cs
- CharacterString.cs
- MenuItem.cs
- DataGridRowsPresenter.cs
- PowerModeChangedEventArgs.cs
- UnknownBitmapEncoder.cs
- LogReservationCollection.cs
- Int64Animation.cs
- ServicePointManagerElement.cs
- ComponentResourceKeyConverter.cs
- AlignmentXValidation.cs
- XmlChildNodes.cs