LocalServiceSecuritySettings.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) Microsoft Corporation. All rights reserved.
  3. //-----------------------------------------------------------------------------
  4. namespace System.ServiceModel.Channels
  5. {
  6. using System;
  7. using System.Runtime;
  8. using System.ServiceModel;
  9. using System.ServiceModel.Security;
  10. public sealed class LocalServiceSecuritySettings
  11. {
  12. bool detectReplays;
  13. int replayCacheSize;
  14. TimeSpan replayWindow;
  15. TimeSpan maxClockSkew;
  16. TimeSpan issuedCookieLifetime;
  17. int maxStatefulNegotiations;
  18. TimeSpan negotiationTimeout;
  19. int maxCachedCookies;
  20. int maxPendingSessions;
  21. TimeSpan inactivityTimeout;
  22. TimeSpan sessionKeyRenewalInterval;
  23. TimeSpan sessionKeyRolloverInterval;
  24. bool reconnectTransportOnFailure;
  25. TimeSpan timestampValidityDuration;
  26. NonceCache nonceCache = null;
  27. LocalServiceSecuritySettings(LocalServiceSecuritySettings other)
  28. {
  29. this.detectReplays = other.detectReplays;
  30. this.replayCacheSize = other.replayCacheSize;
  31. this.replayWindow = other.replayWindow;
  32. this.maxClockSkew = other.maxClockSkew;
  33. this.issuedCookieLifetime = other.issuedCookieLifetime;
  34. this.maxStatefulNegotiations = other.maxStatefulNegotiations;
  35. this.negotiationTimeout = other.negotiationTimeout;
  36. this.maxPendingSessions = other.maxPendingSessions;
  37. this.inactivityTimeout = other.inactivityTimeout;
  38. this.sessionKeyRenewalInterval = other.sessionKeyRenewalInterval;
  39. this.sessionKeyRolloverInterval = other.sessionKeyRolloverInterval;
  40. this.reconnectTransportOnFailure = other.reconnectTransportOnFailure;
  41. this.timestampValidityDuration = other.timestampValidityDuration;
  42. this.maxCachedCookies = other.maxCachedCookies;
  43. this.nonceCache = other.nonceCache;
  44. }
  45. public bool DetectReplays
  46. {
  47. get
  48. {
  49. return this.detectReplays;
  50. }
  51. set
  52. {
  53. this.detectReplays = value;
  54. }
  55. }
  56. public int ReplayCacheSize
  57. {
  58. get
  59. {
  60. return this.replayCacheSize;
  61. }
  62. set
  63. {
  64. if (value < 0)
  65. {
  66. throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("value", value,
  67. SR.GetString(SR.ValueMustBeNonNegative)));
  68. }
  69. this.replayCacheSize = value;
  70. }
  71. }
  72. public TimeSpan ReplayWindow
  73. {
  74. get
  75. {
  76. return this.replayWindow;
  77. }
  78. set
  79. {
  80. if (value < TimeSpan.Zero)
  81. {
  82. throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("value", value,
  83. SR.GetString(SR.SFxTimeoutOutOfRange0)));
  84. }
  85. if (TimeoutHelper.IsTooLarge(value))
  86. {
  87. throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("value", value,
  88. SR.GetString(SR.SFxTimeoutOutOfRangeTooBig)));
  89. }
  90. this.replayWindow = value;
  91. }
  92. }
  93. public TimeSpan MaxClockSkew
  94. {
  95. get
  96. {
  97. return this.maxClockSkew;
  98. }
  99. set
  100. {
  101. if (value < TimeSpan.Zero)
  102. {
  103. throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("value", value,
  104. SR.GetString(SR.SFxTimeoutOutOfRange0)));
  105. }
  106. if (TimeoutHelper.IsTooLarge(value))
  107. {
  108. throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("value", value,
  109. SR.GetString(SR.SFxTimeoutOutOfRangeTooBig)));
  110. }
  111. this.maxClockSkew = value;
  112. }
  113. }
  114. public NonceCache NonceCache
  115. {
  116. get
  117. {
  118. return this.nonceCache;
  119. }
  120. set
  121. {
  122. this.nonceCache = value;
  123. }
  124. }
  125. public TimeSpan IssuedCookieLifetime
  126. {
  127. get
  128. {
  129. return this.issuedCookieLifetime;
  130. }
  131. set
  132. {
  133. if (value < TimeSpan.Zero)
  134. {
  135. throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("value", value,
  136. SR.GetString(SR.SFxTimeoutOutOfRange0)));
  137. }
  138. if (TimeoutHelper.IsTooLarge(value))
  139. {
  140. throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("value", value,
  141. SR.GetString(SR.SFxTimeoutOutOfRangeTooBig)));
  142. }
  143. this.issuedCookieLifetime = value;
  144. }
  145. }
  146. public int MaxStatefulNegotiations
  147. {
  148. get
  149. {
  150. return this.maxStatefulNegotiations;
  151. }
  152. set
  153. {
  154. if (value < 0)
  155. {
  156. throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("value", value,
  157. SR.GetString(SR.ValueMustBeNonNegative)));
  158. }
  159. this.maxStatefulNegotiations = value;
  160. }
  161. }
  162. public TimeSpan NegotiationTimeout
  163. {
  164. get
  165. {
  166. return this.negotiationTimeout;
  167. }
  168. set
  169. {
  170. if (value < TimeSpan.Zero)
  171. {
  172. throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("value", value,
  173. SR.GetString(SR.SFxTimeoutOutOfRange0)));
  174. }
  175. if (TimeoutHelper.IsTooLarge(value))
  176. {
  177. throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("value", value,
  178. SR.GetString(SR.SFxTimeoutOutOfRangeTooBig)));
  179. }
  180. this.negotiationTimeout = value;
  181. }
  182. }
  183. public int MaxPendingSessions
  184. {
  185. get
  186. {
  187. return this.maxPendingSessions;
  188. }
  189. set
  190. {
  191. if (value < 0)
  192. {
  193. throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("value", value,
  194. SR.GetString(SR.ValueMustBeNonNegative)));
  195. }
  196. this.maxPendingSessions = value;
  197. }
  198. }
  199. public TimeSpan InactivityTimeout
  200. {
  201. get
  202. {
  203. return this.inactivityTimeout;
  204. }
  205. set
  206. {
  207. if (value < TimeSpan.Zero)
  208. {
  209. throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("value", value,
  210. SR.GetString(SR.SFxTimeoutOutOfRange0)));
  211. }
  212. if (TimeoutHelper.IsTooLarge(value))
  213. {
  214. throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("value", value,
  215. SR.GetString(SR.SFxTimeoutOutOfRangeTooBig)));
  216. }
  217. this.inactivityTimeout = value;
  218. }
  219. }
  220. public TimeSpan SessionKeyRenewalInterval
  221. {
  222. get
  223. {
  224. return this.sessionKeyRenewalInterval;
  225. }
  226. set
  227. {
  228. if (value < TimeSpan.Zero)
  229. {
  230. throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("value", value,
  231. SR.GetString(SR.SFxTimeoutOutOfRange0)));
  232. }
  233. if (TimeoutHelper.IsTooLarge(value))
  234. {
  235. throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("value", value,
  236. SR.GetString(SR.SFxTimeoutOutOfRangeTooBig)));
  237. }
  238. this.sessionKeyRenewalInterval = value;
  239. }
  240. }
  241. public TimeSpan SessionKeyRolloverInterval
  242. {
  243. get
  244. {
  245. return this.sessionKeyRolloverInterval;
  246. }
  247. set
  248. {
  249. if (value < TimeSpan.Zero)
  250. {
  251. throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("value", value,
  252. SR.GetString(SR.SFxTimeoutOutOfRange0)));
  253. }
  254. if (TimeoutHelper.IsTooLarge(value))
  255. {
  256. throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("value", value,
  257. SR.GetString(SR.SFxTimeoutOutOfRangeTooBig)));
  258. }
  259. this.sessionKeyRolloverInterval = value;
  260. }
  261. }
  262. public bool ReconnectTransportOnFailure
  263. {
  264. get
  265. {
  266. return this.reconnectTransportOnFailure;
  267. }
  268. set
  269. {
  270. this.reconnectTransportOnFailure = value;
  271. }
  272. }
  273. public TimeSpan TimestampValidityDuration
  274. {
  275. get
  276. {
  277. return this.timestampValidityDuration;
  278. }
  279. set
  280. {
  281. if (value < TimeSpan.Zero)
  282. {
  283. throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("value", value,
  284. SR.GetString(SR.SFxTimeoutOutOfRange0)));
  285. }
  286. if (TimeoutHelper.IsTooLarge(value))
  287. {
  288. throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("value", value,
  289. SR.GetString(SR.SFxTimeoutOutOfRangeTooBig)));
  290. }
  291. this.timestampValidityDuration = value;
  292. }
  293. }
  294. public int MaxCachedCookies
  295. {
  296. get
  297. {
  298. return this.maxCachedCookies;
  299. }
  300. set
  301. {
  302. if (value < 0)
  303. {
  304. throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("value", value,
  305. SR.GetString(SR.ValueMustBeNonNegative)));
  306. }
  307. this.maxCachedCookies = value;
  308. }
  309. }
  310. public LocalServiceSecuritySettings()
  311. {
  312. this.DetectReplays = SecurityProtocolFactory.defaultDetectReplays;
  313. this.ReplayCacheSize = SecurityProtocolFactory.defaultMaxCachedNonces;
  314. this.ReplayWindow = SecurityProtocolFactory.defaultReplayWindow;
  315. this.MaxClockSkew = SecurityProtocolFactory.defaultMaxClockSkew;
  316. this.IssuedCookieLifetime = NegotiationTokenAuthenticator<NegotiationTokenAuthenticatorState>.defaultServerIssuedTokenLifetime;
  317. this.MaxStatefulNegotiations = NegotiationTokenAuthenticator<NegotiationTokenAuthenticatorState>.defaultServerMaxActiveNegotiations;
  318. this.NegotiationTimeout = NegotiationTokenAuthenticator<NegotiationTokenAuthenticatorState>.defaultServerMaxNegotiationLifetime;
  319. this.maxPendingSessions = SecuritySessionServerSettings.defaultMaximumPendingSessions;
  320. this.inactivityTimeout = SecuritySessionServerSettings.defaultInactivityTimeout;
  321. this.sessionKeyRenewalInterval = SecuritySessionServerSettings.defaultKeyRenewalInterval;
  322. this.sessionKeyRolloverInterval = SecuritySessionServerSettings.defaultKeyRolloverInterval;
  323. this.reconnectTransportOnFailure = SecuritySessionServerSettings.defaultTolerateTransportFailures;
  324. this.TimestampValidityDuration = SecurityProtocolFactory.defaultTimestampValidityDuration;
  325. this.maxCachedCookies = NegotiationTokenAuthenticator<NegotiationTokenAuthenticatorState>.defaultServerMaxCachedTokens;
  326. this.nonceCache = null;
  327. }
  328. public LocalServiceSecuritySettings Clone()
  329. {
  330. return new LocalServiceSecuritySettings(this);
  331. }
  332. }
  333. }