SecurityCapabilities.cs 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. //
  2. // SecurityCapabilities.cs
  3. //
  4. // Author:
  5. // Atsushi Enomoto <[email protected]>
  6. //
  7. // Copyright (C) 2005-2007 Novell, Inc. http://www.novell.com
  8. //
  9. // Permission is hereby granted, free of charge, to any person obtaining
  10. // a copy of this software and associated documentation files (the
  11. // "Software"), to deal in the Software without restriction, including
  12. // without limitation the rights to use, copy, modify, merge, publish,
  13. // distribute, sublicense, and/or sell copies of the Software, and to
  14. // permit persons to whom the Software is furnished to do so, subject to
  15. // the following conditions:
  16. //
  17. // The above copyright notice and this permission notice shall be
  18. // included in all copies or substantial portions of the Software.
  19. //
  20. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  21. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  22. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  23. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  24. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  25. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  26. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  27. //
  28. using System.Collections.Generic;
  29. using System.Collections.ObjectModel;
  30. using System.IdentityModel.Selectors;
  31. using System.IdentityModel.Tokens;
  32. using System.Net.Security;
  33. using System.Security.Cryptography.Xml;
  34. using System.ServiceModel.Channels;
  35. using System.ServiceModel.Description;
  36. using System.ServiceModel.Security;
  37. using System.ServiceModel.Security.Tokens;
  38. using ReqType = System.ServiceModel.Security.Tokens.ServiceModelSecurityTokenRequirement;
  39. namespace System.ServiceModel.Channels.Security
  40. {
  41. internal abstract class SecurityCapabilities
  42. : ISecurityCapabilities
  43. {
  44. public abstract SecurityBindingElement Element { get; }
  45. public abstract bool AllowSerializedSigningTokenOnReply { get; }
  46. public abstract MessageProtectionOrder MessageProtectionOrder { get; }
  47. public abstract SecurityTokenParameters InitiatorParameters { get; }
  48. public abstract SecurityTokenParameters RecipientParameters { get; }
  49. public abstract bool RequireSignatureConfirmation { get; }
  50. public abstract string DefaultKeyWrapAlgorithm { get; }
  51. public abstract string DefaultSignatureAlgorithm { get; }
  52. // ISecurityCapabilities
  53. // FIXME: implement correctly
  54. public ProtectionLevel SupportedRequestProtectionLevel {
  55. get { return ProtectionLevel.EncryptAndSign; }
  56. }
  57. public ProtectionLevel SupportedResponseProtectionLevel {
  58. get { return ProtectionLevel.EncryptAndSign; }
  59. }
  60. public bool SupportsClientAuthentication {
  61. get { return InitiatorParameters != null ? InitiatorParameters.InternalSupportsClientAuthentication : false; }
  62. }
  63. public bool SupportsClientWindowsIdentity {
  64. get { return InitiatorParameters != null ? InitiatorParameters.InternalSupportsClientWindowsIdentity : false; }
  65. }
  66. public bool SupportsServerAuthentication {
  67. get { return RecipientParameters != null ? RecipientParameters.InternalSupportsServerAuthentication : false; }
  68. }
  69. }
  70. internal class SymmetricSecurityCapabilities : SecurityCapabilities
  71. {
  72. SymmetricSecurityBindingElement element;
  73. public SymmetricSecurityCapabilities (
  74. SymmetricSecurityBindingElement element)
  75. {
  76. this.element = element;
  77. }
  78. public override SecurityBindingElement Element {
  79. get { return element; }
  80. }
  81. // FIXME: const true or false
  82. public override bool AllowSerializedSigningTokenOnReply {
  83. get { throw new NotImplementedException (); }
  84. }
  85. public override MessageProtectionOrder MessageProtectionOrder {
  86. get { return element.MessageProtectionOrder; }
  87. }
  88. public override SecurityTokenParameters InitiatorParameters {
  89. get { return element.ProtectionTokenParameters; }
  90. }
  91. public override SecurityTokenParameters RecipientParameters {
  92. get { return element.ProtectionTokenParameters; }
  93. }
  94. public override bool RequireSignatureConfirmation {
  95. get { return element.RequireSignatureConfirmation; }
  96. }
  97. public override string DefaultSignatureAlgorithm {
  98. get { return element.DefaultAlgorithmSuite.DefaultSymmetricSignatureAlgorithm; }
  99. }
  100. public override string DefaultKeyWrapAlgorithm {
  101. get { return element.DefaultAlgorithmSuite.DefaultSymmetricKeyWrapAlgorithm; }
  102. }
  103. }
  104. internal class AsymmetricSecurityCapabilities : SecurityCapabilities
  105. {
  106. AsymmetricSecurityBindingElement element;
  107. public AsymmetricSecurityCapabilities (
  108. AsymmetricSecurityBindingElement element)
  109. {
  110. this.element = element;
  111. }
  112. public override bool AllowSerializedSigningTokenOnReply {
  113. get { return element.AllowSerializedSigningTokenOnReply; }
  114. }
  115. public override SecurityBindingElement Element {
  116. get { return element; }
  117. }
  118. public override MessageProtectionOrder MessageProtectionOrder {
  119. get { return element.MessageProtectionOrder; }
  120. }
  121. public override SecurityTokenParameters InitiatorParameters {
  122. get { return element.InitiatorTokenParameters; }
  123. }
  124. public override SecurityTokenParameters RecipientParameters {
  125. get { return element.RecipientTokenParameters; }
  126. }
  127. public override bool RequireSignatureConfirmation {
  128. get { return element.RequireSignatureConfirmation; }
  129. }
  130. public override string DefaultSignatureAlgorithm {
  131. get { return element.DefaultAlgorithmSuite.DefaultAsymmetricSignatureAlgorithm; }
  132. }
  133. public override string DefaultKeyWrapAlgorithm {
  134. get { return element.DefaultAlgorithmSuite.DefaultAsymmetricKeyWrapAlgorithm; }
  135. }
  136. }
  137. }