SecurityBindingElement.cs 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592
  1. //
  2. // SecurityBindingElement.cs
  3. //
  4. // Author:
  5. // Atsushi Enomoto <[email protected]>
  6. //
  7. // Copyright (C) 2005-2006 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.ServiceModel.Description;
  31. using System.ServiceModel.Channels;
  32. using System.ServiceModel.Security;
  33. #if !NET_2_1 && !XAMMAC_4_5
  34. using System.ServiceModel.Channels.Security;
  35. using System.IdentityModel.Selectors;
  36. using System.IdentityModel.Tokens;
  37. #endif
  38. using System.ServiceModel.Security.Tokens;
  39. using System.Text;
  40. namespace System.ServiceModel.Channels
  41. {
  42. public abstract class SecurityBindingElement : BindingElement
  43. {
  44. internal SecurityBindingElement ()
  45. {
  46. MessageSecurityVersion = MessageSecurityVersion.Default;
  47. endpoint = new SupportingTokenParameters ();
  48. #if !NET_2_1 && !XAMMAC_4_5
  49. DefaultAlgorithmSuite = SecurityAlgorithmSuite.Default;
  50. KeyEntropyMode = SecurityKeyEntropyMode.CombinedEntropy;
  51. operation = new Dictionary<string,SupportingTokenParameters> ();
  52. opt_endpoint = new SupportingTokenParameters ();
  53. opt_operation = new Dictionary<string,SupportingTokenParameters> ();
  54. service_settings = new LocalServiceSecuritySettings ();
  55. #endif
  56. IncludeTimestamp = true;
  57. LocalClientSettings = new LocalClientSecuritySettings ();
  58. }
  59. internal SecurityBindingElement (SecurityBindingElement other)
  60. {
  61. security_header_layout = other.security_header_layout;
  62. msg_security_version = other.msg_security_version;
  63. endpoint = other.endpoint.Clone ();
  64. #if !NET_2_1 && !XAMMAC_4_5
  65. alg_suite = other.alg_suite;
  66. key_entropy_mode = other.key_entropy_mode;
  67. opt_endpoint = other.opt_endpoint.Clone ();
  68. operation = new Dictionary<string,SupportingTokenParameters> ();
  69. foreach (KeyValuePair<string,SupportingTokenParameters> p in other.operation)
  70. operation.Add (p.Key, p.Value.Clone ());
  71. opt_operation = new Dictionary<string,SupportingTokenParameters> ();
  72. foreach (KeyValuePair<string,SupportingTokenParameters> p in other.opt_operation)
  73. opt_operation.Add (p.Key, p.Value.Clone ());
  74. service_settings = other.service_settings.Clone ();
  75. #endif
  76. IncludeTimestamp = other.IncludeTimestamp;
  77. LocalClientSettings = other.LocalClientSettings.Clone ();
  78. }
  79. SecurityHeaderLayout security_header_layout;
  80. MessageSecurityVersion msg_security_version;
  81. SupportingTokenParameters endpoint;
  82. #if !NET_2_1 && !XAMMAC_4_5
  83. SecurityAlgorithmSuite alg_suite;
  84. SecurityKeyEntropyMode key_entropy_mode;
  85. SupportingTokenParameters opt_endpoint;
  86. IDictionary<string,SupportingTokenParameters> operation, opt_operation;
  87. LocalServiceSecuritySettings service_settings;
  88. #endif
  89. public bool IncludeTimestamp { get; set; }
  90. public LocalClientSecuritySettings LocalClientSettings { get; private set; }
  91. public SecurityHeaderLayout SecurityHeaderLayout {
  92. get { return security_header_layout; }
  93. set { security_header_layout = value; }
  94. }
  95. public MessageSecurityVersion MessageSecurityVersion {
  96. get { return msg_security_version; }
  97. set { msg_security_version = value; }
  98. }
  99. public SupportingTokenParameters EndpointSupportingTokenParameters {
  100. get { return endpoint; }
  101. }
  102. #if !NET_2_1 && !XAMMAC_4_5
  103. public SecurityAlgorithmSuite DefaultAlgorithmSuite {
  104. get { return alg_suite; }
  105. set { alg_suite = value; }
  106. }
  107. public SecurityKeyEntropyMode KeyEntropyMode {
  108. get { return key_entropy_mode; }
  109. set { key_entropy_mode = value; }
  110. }
  111. public LocalServiceSecuritySettings LocalServiceSettings {
  112. get { return service_settings; }
  113. }
  114. public IDictionary<string,SupportingTokenParameters> OperationSupportingTokenParameters {
  115. get { return operation; }
  116. }
  117. public SupportingTokenParameters OptionalEndpointSupportingTokenParameters {
  118. get { return opt_endpoint; }
  119. }
  120. public IDictionary<string,SupportingTokenParameters> OptionalOperationSupportingTokenParameters {
  121. get { return opt_operation; }
  122. }
  123. #endif
  124. [MonoTODO ("Implement for TransportSecurityBindingElement")]
  125. public override bool CanBuildChannelFactory<TChannel> (BindingContext context)
  126. {
  127. #if NET_2_1 || XAMMAC_4_5
  128. // not sure this should be like this, but there isn't Symmetric/Asymmetric elements in 2.1 anyways.
  129. return context.CanBuildInnerChannelFactory<TChannel> ();
  130. #else
  131. if (this is TransportSecurityBindingElement)
  132. throw new NotImplementedException ();
  133. var symm = this as SymmetricSecurityBindingElement;
  134. var asymm = this as AsymmetricSecurityBindingElement;
  135. var pt = symm != null ? symm.ProtectionTokenParameters : asymm != null ? asymm.InitiatorTokenParameters : null;
  136. if (pt == null)
  137. return false;
  138. var t = typeof (TChannel);
  139. var req = new InitiatorServiceModelSecurityTokenRequirement ();
  140. pt.InitializeSecurityTokenRequirement (req);
  141. object dummy;
  142. if (req.Properties.TryGetValue (ServiceModelSecurityTokenRequirement.IssuedSecurityTokenParametersProperty, out dummy) && dummy != null) {
  143. if (t == typeof (IRequestSessionChannel))
  144. return context.CanBuildInnerChannelFactory<IRequestChannel> () ||
  145. context.CanBuildInnerChannelFactory<IRequestSessionChannel> ();
  146. else if (t == typeof (IDuplexSessionChannel))
  147. return context.CanBuildInnerChannelFactory<IDuplexChannel> () ||
  148. context.CanBuildInnerChannelFactory<IDuplexSessionChannel> ();
  149. } else {
  150. if (t == typeof (IRequestChannel))
  151. return context.CanBuildInnerChannelFactory<IRequestChannel> () ||
  152. context.CanBuildInnerChannelFactory<IRequestSessionChannel> ();
  153. else if (t == typeof (IDuplexChannel))
  154. return context.CanBuildInnerChannelFactory<IDuplexChannel> () ||
  155. context.CanBuildInnerChannelFactory<IDuplexSessionChannel> ();
  156. }
  157. return false;
  158. #endif
  159. }
  160. public override IChannelFactory<TChannel> BuildChannelFactory<TChannel> (
  161. BindingContext context)
  162. {
  163. return BuildChannelFactoryCore<TChannel> (context);
  164. }
  165. protected abstract IChannelFactory<TChannel>
  166. BuildChannelFactoryCore<TChannel> (BindingContext context);
  167. #if !NET_2_1 && !XAMMAC_4_5
  168. [MonoTODO ("Implement for TransportSecurityBindingElement")]
  169. public override bool CanBuildChannelListener<TChannel> (BindingContext context)
  170. {
  171. if (this is TransportSecurityBindingElement)
  172. throw new NotImplementedException ();
  173. var symm = this as SymmetricSecurityBindingElement;
  174. var asymm = this as AsymmetricSecurityBindingElement;
  175. var pt = symm != null ? symm.ProtectionTokenParameters : asymm != null ? asymm.RecipientTokenParameters : null;
  176. if (pt == null)
  177. return false;
  178. var t = typeof (TChannel);
  179. var req = new InitiatorServiceModelSecurityTokenRequirement ();
  180. pt.InitializeSecurityTokenRequirement (req);
  181. object dummy;
  182. if (req.Properties.TryGetValue (ServiceModelSecurityTokenRequirement.IssuedSecurityTokenParametersProperty, out dummy) && dummy != null) {
  183. if (t == typeof (IReplySessionChannel))
  184. return context.CanBuildInnerChannelListener<IReplyChannel> () ||
  185. context.CanBuildInnerChannelListener<IReplySessionChannel> ();
  186. else if (t == typeof (IDuplexSessionChannel))
  187. return context.CanBuildInnerChannelListener<IDuplexChannel> () ||
  188. context.CanBuildInnerChannelListener<IDuplexSessionChannel> ();
  189. } else {
  190. if (t == typeof (IReplyChannel))
  191. return context.CanBuildInnerChannelListener<IReplyChannel> () ||
  192. context.CanBuildInnerChannelListener<IReplySessionChannel> ();
  193. else if (t == typeof (IDuplexChannel))
  194. return context.CanBuildInnerChannelListener<IDuplexChannel> () ||
  195. context.CanBuildInnerChannelListener<IDuplexSessionChannel> ();
  196. }
  197. return false;
  198. }
  199. public override IChannelListener<TChannel> BuildChannelListener<TChannel> (
  200. BindingContext context)
  201. {
  202. return BuildChannelListenerCore<TChannel> (context);
  203. }
  204. protected abstract IChannelListener<TChannel>
  205. BuildChannelListenerCore<TChannel> (BindingContext context)
  206. where TChannel : class, IChannel;
  207. public override T GetProperty<T> (BindingContext context)
  208. {
  209. // It is documented that ISecurityCapabilities and IdentityVerifier can be returned.
  210. // Though, this class is not inheritable, and they are returned by the derived types.
  211. // So I don't care about them here.
  212. return context.GetInnerProperty<T> ();
  213. }
  214. public virtual void SetKeyDerivation (bool requireDerivedKeys)
  215. {
  216. endpoint.SetKeyDerivation (requireDerivedKeys);
  217. opt_endpoint.SetKeyDerivation (requireDerivedKeys);
  218. foreach (SupportingTokenParameters p in operation.Values)
  219. p.SetKeyDerivation (requireDerivedKeys);
  220. foreach (SupportingTokenParameters p in opt_operation.Values)
  221. p.SetKeyDerivation (requireDerivedKeys);
  222. }
  223. public override string ToString ()
  224. {
  225. var sb = new StringBuilder ();
  226. sb.Append (GetType ().FullName).Append (":\n");
  227. foreach (var pi in GetType ().GetProperties ()) {
  228. var simple = Type.GetTypeCode (pi.PropertyType) != TypeCode.Object;
  229. var val = pi.GetValue (this, null);
  230. sb.Append (pi.Name).Append (':');
  231. if (val != null)
  232. sb.AppendFormat ("{0}{1}{2}", simple ? " " : "\n", simple ? "" : " ", String.Join ("\n ", val.ToString ().Split ('\n')));
  233. sb.Append ('\n');
  234. }
  235. sb.Length--; // chop trailing EOL.
  236. return sb.ToString ();
  237. }
  238. #else
  239. [MonoTODO]
  240. public override T GetProperty<T> (BindingContext context)
  241. {
  242. return null;
  243. }
  244. #endif
  245. #region Factory methods
  246. #if !NET_2_1 && !XAMMAC_4_5
  247. public static SymmetricSecurityBindingElement
  248. CreateAnonymousForCertificateBindingElement ()
  249. {
  250. SymmetricSecurityBindingElement be = new SymmetricSecurityBindingElement ();
  251. be.RequireSignatureConfirmation = true;
  252. be.ProtectionTokenParameters = CreateProtectionTokenParameters (true);
  253. return be;
  254. }
  255. public static TransportSecurityBindingElement
  256. CreateCertificateOverTransportBindingElement ()
  257. {
  258. return CreateCertificateOverTransportBindingElement (MessageSecurityVersion.Default);
  259. }
  260. public static TransportSecurityBindingElement
  261. CreateCertificateOverTransportBindingElement (MessageSecurityVersion version)
  262. {
  263. var be = new TransportSecurityBindingElement () { MessageSecurityVersion = version };
  264. be.EndpointSupportingTokenParameters.SignedEncrypted.Add (new X509SecurityTokenParameters ());
  265. return be;
  266. }
  267. [MonoTODO]
  268. public static AsymmetricSecurityBindingElement
  269. CreateCertificateSignatureBindingElement ()
  270. {
  271. throw new NotImplementedException ();
  272. }
  273. [MonoTODO]
  274. public static SymmetricSecurityBindingElement
  275. CreateIssuedTokenBindingElement (
  276. IssuedSecurityTokenParameters issuedTokenParameters)
  277. {
  278. SymmetricSecurityBindingElement be = new SymmetricSecurityBindingElement ();
  279. be.ProtectionTokenParameters = issuedTokenParameters;
  280. return be;
  281. }
  282. public static SymmetricSecurityBindingElement
  283. CreateIssuedTokenForCertificateBindingElement (
  284. IssuedSecurityTokenParameters issuedTokenParameters)
  285. {
  286. SymmetricSecurityBindingElement be = new SymmetricSecurityBindingElement ();
  287. be.RequireSignatureConfirmation = true;
  288. be.ProtectionTokenParameters = CreateProtectionTokenParameters (true);
  289. be.EndpointSupportingTokenParameters.Endorsing.Add (
  290. issuedTokenParameters);
  291. return be;
  292. }
  293. [MonoTODO]
  294. public static SymmetricSecurityBindingElement
  295. CreateIssuedTokenForSslBindingElement (
  296. IssuedSecurityTokenParameters issuedTokenParameters)
  297. {
  298. return CreateIssuedTokenForSslBindingElement (
  299. issuedTokenParameters, false);
  300. }
  301. [MonoTODO]
  302. public static SymmetricSecurityBindingElement
  303. CreateIssuedTokenForSslBindingElement (
  304. IssuedSecurityTokenParameters issuedTokenParameters,
  305. bool requireCancellation)
  306. {
  307. SymmetricSecurityBindingElement be = new SymmetricSecurityBindingElement ();
  308. be.RequireSignatureConfirmation = true;
  309. be.ProtectionTokenParameters = CreateProtectionTokenParameters (false);
  310. be.EndpointSupportingTokenParameters.Endorsing.Add (
  311. issuedTokenParameters);
  312. return be;
  313. }
  314. [MonoTODO]
  315. public static TransportSecurityBindingElement
  316. CreateIssuedTokenOverTransportBindingElement (
  317. IssuedSecurityTokenParameters issuedTokenParameters)
  318. {
  319. throw new NotImplementedException ();
  320. }
  321. [MonoTODO]
  322. public static SymmetricSecurityBindingElement CreateKerberosBindingElement ()
  323. {
  324. SymmetricSecurityBindingElement be = new SymmetricSecurityBindingElement ();
  325. be.DefaultAlgorithmSuite = SecurityAlgorithmSuite.Basic128;
  326. be.ProtectionTokenParameters = CreateProtectionTokenParameters (false);
  327. be.ProtectionTokenParameters.InclusionMode =
  328. SecurityTokenInclusionMode.Once;
  329. return be;
  330. }
  331. [MonoTODO]
  332. public static TransportSecurityBindingElement
  333. CreateKerberosOverTransportBindingElement ()
  334. {
  335. throw new NotImplementedException ();
  336. }
  337. public static SecurityBindingElement
  338. CreateMutualCertificateBindingElement ()
  339. {
  340. return CreateMutualCertificateBindingElement (MessageSecurityVersion.Default, false);
  341. }
  342. public static SecurityBindingElement
  343. CreateMutualCertificateBindingElement (MessageSecurityVersion version)
  344. {
  345. return CreateMutualCertificateBindingElement (version, false);
  346. }
  347. [MonoTODO("Does not support allowSerializedSigningTokenOnReply.")]
  348. public static SecurityBindingElement
  349. CreateMutualCertificateBindingElement (
  350. MessageSecurityVersion version,
  351. bool allowSerializedSigningTokenOnReply)
  352. {
  353. if (version == null)
  354. throw new ArgumentNullException ("version");
  355. if (allowSerializedSigningTokenOnReply)
  356. throw new NotSupportedException ("allowSerializedSigningTokenOnReply is not supported");
  357. if (version.SecurityVersion == SecurityVersion.WSSecurity10) {
  358. var recipient = new X509SecurityTokenParameters (
  359. X509KeyIdentifierClauseType.Any,
  360. SecurityTokenInclusionMode.Never);
  361. recipient.RequireDerivedKeys = false;
  362. var initiator = new X509SecurityTokenParameters (
  363. X509KeyIdentifierClauseType.Any,
  364. SecurityTokenInclusionMode.AlwaysToRecipient);
  365. initiator.RequireDerivedKeys = false;
  366. return new AsymmetricSecurityBindingElement (recipient, initiator) {
  367. MessageSecurityVersion = version
  368. };
  369. } else {
  370. X509SecurityTokenParameters p =
  371. new X509SecurityTokenParameters (X509KeyIdentifierClauseType.Thumbprint);
  372. p.RequireDerivedKeys = false;
  373. var sym = new SymmetricSecurityBindingElement () {
  374. MessageSecurityVersion = version,
  375. RequireSignatureConfirmation = true
  376. };
  377. X509SecurityTokenParameters p2 = new X509SecurityTokenParameters (X509KeyIdentifierClauseType.Thumbprint);
  378. p2.ReferenceStyle = SecurityTokenReferenceStyle.External;
  379. sym.ProtectionTokenParameters = p2;
  380. sym.EndpointSupportingTokenParameters.Endorsing.Add (p);
  381. return sym;
  382. }
  383. }
  384. [MonoTODO]
  385. public static AsymmetricSecurityBindingElement
  386. CreateMutualCertificateDuplexBindingElement ()
  387. {
  388. throw new NotImplementedException ();
  389. }
  390. [MonoTODO]
  391. public static AsymmetricSecurityBindingElement
  392. CreateMutualCertificateDuplexBindingElement (
  393. MessageSecurityVersion version)
  394. {
  395. throw new NotImplementedException ();
  396. }
  397. public static SymmetricSecurityBindingElement
  398. CreateSslNegotiationBindingElement (bool requireClientCertificate)
  399. {
  400. return CreateSslNegotiationBindingElement (
  401. requireClientCertificate, false);
  402. }
  403. public static SymmetricSecurityBindingElement
  404. CreateSslNegotiationBindingElement (
  405. bool requireClientCertificate,
  406. bool requireCancellation)
  407. {
  408. SymmetricSecurityBindingElement be = new SymmetricSecurityBindingElement ();
  409. be.ProtectionTokenParameters = new SslSecurityTokenParameters (requireClientCertificate, requireCancellation);
  410. return be;
  411. }
  412. public static SymmetricSecurityBindingElement
  413. CreateSspiNegotiationBindingElement ()
  414. {
  415. return CreateSspiNegotiationBindingElement (true);
  416. }
  417. public static SymmetricSecurityBindingElement
  418. CreateSspiNegotiationBindingElement (bool requireCancellation)
  419. {
  420. SymmetricSecurityBindingElement be = new SymmetricSecurityBindingElement ();
  421. be.ProtectionTokenParameters = CreateProtectionTokenParameters (false);
  422. return be;
  423. }
  424. public static TransportSecurityBindingElement
  425. CreateSspiNegotiationOverTransportBindingElement ()
  426. {
  427. return CreateSspiNegotiationOverTransportBindingElement (false);
  428. }
  429. [MonoTODO]
  430. public static TransportSecurityBindingElement
  431. CreateSspiNegotiationOverTransportBindingElement (bool requireCancellation)
  432. {
  433. throw new NotImplementedException ();
  434. }
  435. static X509SecurityTokenParameters CreateProtectionTokenParameters (bool cert)
  436. {
  437. X509SecurityTokenParameters p =
  438. new X509SecurityTokenParameters ();
  439. p.X509ReferenceStyle = X509KeyIdentifierClauseType.Thumbprint;
  440. if (cert)
  441. p.InclusionMode = SecurityTokenInclusionMode.Never;
  442. return p;
  443. }
  444. public static SymmetricSecurityBindingElement
  445. CreateUserNameForCertificateBindingElement ()
  446. {
  447. SymmetricSecurityBindingElement be = new SymmetricSecurityBindingElement ();
  448. be.ProtectionTokenParameters = CreateProtectionTokenParameters (true);
  449. UserNameSecurityTokenParameters utp =
  450. new UserNameSecurityTokenParameters ();
  451. be.EndpointSupportingTokenParameters.SignedEncrypted.Add (utp);
  452. return be;
  453. }
  454. public static SymmetricSecurityBindingElement
  455. CreateUserNameForSslBindingElement ()
  456. {
  457. return CreateUserNameForSslBindingElement (false);
  458. }
  459. public static SymmetricSecurityBindingElement
  460. CreateUserNameForSslBindingElement (bool requireCancellation)
  461. {
  462. SymmetricSecurityBindingElement be = new SymmetricSecurityBindingElement ();
  463. be.ProtectionTokenParameters = CreateProtectionTokenParameters (false);
  464. UserNameSecurityTokenParameters utp =
  465. new UserNameSecurityTokenParameters ();
  466. be.EndpointSupportingTokenParameters.SignedEncrypted.Add (utp);
  467. return be;
  468. }
  469. #endif
  470. public static SecurityBindingElement
  471. CreateSecureConversationBindingElement (SecurityBindingElement binding)
  472. {
  473. return CreateSecureConversationBindingElement (binding, false);
  474. }
  475. public static SecurityBindingElement
  476. CreateSecureConversationBindingElement (
  477. SecurityBindingElement binding, bool requireCancellation)
  478. {
  479. return CreateSecureConversationBindingElement (binding, requireCancellation, null);
  480. }
  481. public static SecurityBindingElement
  482. CreateSecureConversationBindingElement (
  483. SecurityBindingElement binding, bool requireCancellation,
  484. ChannelProtectionRequirements protectionRequirements)
  485. {
  486. #if !NET_2_1 && !XAMMAC_4_5
  487. SymmetricSecurityBindingElement be =
  488. new SymmetricSecurityBindingElement ();
  489. be.ProtectionTokenParameters =
  490. new SecureConversationSecurityTokenParameters (
  491. binding, requireCancellation, protectionRequirements);
  492. return be;
  493. #else
  494. throw new NotImplementedException ();
  495. #endif
  496. }
  497. [MonoTODO]
  498. public static TransportSecurityBindingElement
  499. CreateUserNameOverTransportBindingElement ()
  500. {
  501. var be = new TransportSecurityBindingElement ();
  502. #if !NET_2_1 && !XAMMAC_4_5 // FIXME: there should be whatever else to do for 2.1 instead.
  503. be.EndpointSupportingTokenParameters.SignedEncrypted.Add (new UserNameSecurityTokenParameters ());
  504. #endif
  505. return be;
  506. }
  507. #endregion
  508. #if !NET_2_1 && !XAMMAC_4_5
  509. // It seems almost internal, hardcoded like this (I tried
  510. // custom parameters that sets IssuedTokenSecurityTokenParameters
  511. // like below ones, but that didn't trigger this method).
  512. protected static void SetIssuerBindingContextIfRequired (
  513. SecurityTokenParameters parameters,
  514. BindingContext issuerBindingContext)
  515. {
  516. if (parameters is IssuedSecurityTokenParameters ||
  517. parameters is SecureConversationSecurityTokenParameters ||
  518. parameters is SslSecurityTokenParameters ||
  519. parameters is SspiSecurityTokenParameters) {
  520. parameters.IssuerBindingContext = issuerBindingContext;
  521. }
  522. }
  523. #endif
  524. }
  525. }