1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
|
//------------------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------------------------
namespace System.ServiceModel.Configuration
{
using System;
using System.ServiceModel;
using System.Configuration;
using System.ServiceModel.Channels;
using System.ServiceModel.Security;
using System.Xml;
using System.Security.Cryptography.X509Certificates;
using System.IdentityModel.Selectors;
public sealed partial class X509ServiceCertificateAuthenticationElement : ConfigurationElement
{
public X509ServiceCertificateAuthenticationElement()
{
}
[ConfigurationProperty(ConfigurationStrings.CustomCertificateValidatorType, DefaultValue = "")]
[StringValidator(MinLength = 0)]
public string CustomCertificateValidatorType
{
get { return (string)base[ConfigurationStrings.CustomCertificateValidatorType]; }
set
{
if (String.IsNullOrEmpty(value))
{
value = String.Empty;
}
base[ConfigurationStrings.CustomCertificateValidatorType] = value;
}
}
[ConfigurationProperty(ConfigurationStrings.CertificateValidationMode, DefaultValue = X509ServiceCertificateAuthentication.DefaultCertificateValidationMode)]
[ServiceModelEnumValidator(typeof(X509CertificateValidationModeHelper))]
public X509CertificateValidationMode CertificateValidationMode
{
get { return (X509CertificateValidationMode)base[ConfigurationStrings.CertificateValidationMode]; }
set { base[ConfigurationStrings.CertificateValidationMode] = value; }
}
[ConfigurationProperty(ConfigurationStrings.RevocationMode, DefaultValue = X509ServiceCertificateAuthentication.DefaultRevocationMode)]
[StandardRuntimeEnumValidator(typeof(X509RevocationMode))]
public X509RevocationMode RevocationMode
{
get { return (X509RevocationMode)base[ConfigurationStrings.RevocationMode]; }
set { base[ConfigurationStrings.RevocationMode] = value; }
}
[ConfigurationProperty(ConfigurationStrings.TrustedStoreLocation, DefaultValue = X509ServiceCertificateAuthentication.DefaultTrustedStoreLocation)]
[StandardRuntimeEnumValidator(typeof(StoreLocation))]
public StoreLocation TrustedStoreLocation
{
get { return (StoreLocation)base[ConfigurationStrings.TrustedStoreLocation]; }
set { base[ConfigurationStrings.TrustedStoreLocation] = value; }
}
public void Copy(X509ServiceCertificateAuthenticationElement from)
{
if (this.IsReadOnly())
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ConfigurationErrorsException(SR.GetString(SR.ConfigReadOnly)));
}
if (null == from)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("from");
}
this.CertificateValidationMode = from.CertificateValidationMode;
this.RevocationMode = from.RevocationMode;
this.TrustedStoreLocation = from.TrustedStoreLocation;
this.CustomCertificateValidatorType = from.CustomCertificateValidatorType;
}
internal void ApplyConfiguration(X509ServiceCertificateAuthentication cert)
{
if (cert == null)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("cert");
}
cert.CertificateValidationMode = this.CertificateValidationMode;
cert.RevocationMode = this.RevocationMode;
cert.TrustedStoreLocation = this.TrustedStoreLocation;
if (!string.IsNullOrEmpty(this.CustomCertificateValidatorType))
{
Type validatorType = System.Type.GetType(this.CustomCertificateValidatorType, true);
if (!typeof(X509CertificateValidator).IsAssignableFrom(validatorType))
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ConfigurationErrorsException(
SR.GetString(SR.ConfigInvalidCertificateValidatorType, this.CustomCertificateValidatorType, typeof(X509CertificateValidator).ToString())));
}
cert.CustomCertificateValidator = (X509CertificateValidator)Activator.CreateInstance(validatorType);
}
}
}
}
|