X509RecipientCertificateClientElement.cs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. //------------------------------------------------------------------------------
  2. // Copyright (c) Microsoft Corporation. All rights reserved.
  3. //------------------------------------------------------------------------------
  4. namespace System.ServiceModel.Configuration
  5. {
  6. using System;
  7. using System.ServiceModel;
  8. using System.Configuration;
  9. using System.ServiceModel.Channels;
  10. using System.ServiceModel.Security;
  11. using System.Xml;
  12. using System.Security.Cryptography.X509Certificates;
  13. public sealed partial class X509RecipientCertificateClientElement : ConfigurationElement
  14. {
  15. public X509RecipientCertificateClientElement()
  16. {
  17. }
  18. [ConfigurationProperty(ConfigurationStrings.DefaultCertificate)]
  19. public X509DefaultServiceCertificateElement DefaultCertificate
  20. {
  21. get { return (X509DefaultServiceCertificateElement)base[ConfigurationStrings.DefaultCertificate]; }
  22. }
  23. [ConfigurationProperty(ConfigurationStrings.ScopedCertificates)]
  24. public X509ScopedServiceCertificateElementCollection ScopedCertificates
  25. {
  26. get { return (X509ScopedServiceCertificateElementCollection)base[ConfigurationStrings.ScopedCertificates]; }
  27. }
  28. [ConfigurationProperty(ConfigurationStrings.Authentication)]
  29. public X509ServiceCertificateAuthenticationElement Authentication
  30. {
  31. get { return (X509ServiceCertificateAuthenticationElement)base[ConfigurationStrings.Authentication]; }
  32. }
  33. [ConfigurationProperty(ConfigurationStrings.SslCertificateAuthentication)]
  34. public X509ServiceCertificateAuthenticationElement SslCertificateAuthentication
  35. {
  36. get { return (X509ServiceCertificateAuthenticationElement)base[ConfigurationStrings.SslCertificateAuthentication]; }
  37. }
  38. public void Copy(X509RecipientCertificateClientElement from)
  39. {
  40. if (this.IsReadOnly())
  41. {
  42. throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ConfigurationErrorsException(SR.GetString(SR.ConfigReadOnly)));
  43. }
  44. if (null == from)
  45. {
  46. throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("from");
  47. }
  48. this.DefaultCertificate.Copy(from.DefaultCertificate);
  49. X509ScopedServiceCertificateElementCollection srcScopedCertificates = from.ScopedCertificates;
  50. X509ScopedServiceCertificateElementCollection dstScopedCertificates = this.ScopedCertificates;
  51. dstScopedCertificates.Clear();
  52. for (int i = 0; i < srcScopedCertificates.Count; ++i)
  53. {
  54. dstScopedCertificates.Add(srcScopedCertificates[i]);
  55. }
  56. this.Authentication.Copy(from.Authentication);
  57. this.SslCertificateAuthentication.Copy(from.SslCertificateAuthentication);
  58. }
  59. internal void ApplyConfiguration(X509CertificateRecipientClientCredential cert)
  60. {
  61. if (cert == null)
  62. {
  63. throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("cert");
  64. }
  65. PropertyInformationCollection propertyInfo = this.ElementInformation.Properties;
  66. if (propertyInfo[ConfigurationStrings.Authentication].ValueOrigin != PropertyValueOrigin.Default)
  67. {
  68. this.Authentication.ApplyConfiguration(cert.Authentication);
  69. }
  70. if (propertyInfo[ConfigurationStrings.SslCertificateAuthentication].ValueOrigin != PropertyValueOrigin.Default)
  71. {
  72. cert.SslCertificateAuthentication = new X509ServiceCertificateAuthentication();
  73. this.SslCertificateAuthentication.ApplyConfiguration(cert.SslCertificateAuthentication);
  74. }
  75. this.DefaultCertificate.ApplyConfiguration(cert);
  76. X509ScopedServiceCertificateElementCollection scopedCertificates = this.ScopedCertificates;
  77. for (int i = 0; i < scopedCertificates.Count; ++i)
  78. {
  79. scopedCertificates[i].ApplyConfiguration(cert);
  80. }
  81. }
  82. }
  83. }