WSTrustChannel.cs 57 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322
  1. //------------------------------------------------------------------------------
  2. // Copyright (c) Microsoft Corporation. All rights reserved.
  3. //------------------------------------------------------------------------------
  4. namespace System.ServiceModel.Security
  5. {
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Collections.ObjectModel;
  9. using System.IdentityModel;
  10. using System.IdentityModel.Policy;
  11. using System.IdentityModel.Protocols.WSTrust;
  12. using System.Runtime;
  13. using System.IdentityModel.Tokens;
  14. using System.ServiceModel;
  15. using System.ServiceModel.Channels;
  16. using System.ServiceModel.Security.Tokens;
  17. using IM = System.IdentityModel;
  18. using SR = System.ServiceModel.SR;
  19. /// <summary>
  20. /// A channel that is used to send WS-Trust messages to an STS.
  21. /// </summary>
  22. public class WSTrustChannel : IWSTrustChannelContract, IChannel
  23. {
  24. // Consistent with the IDFX STS configuration default.
  25. const int DefaultKeySizeInBits = 256;
  26. const int FaultMaxBufferSize = 20 * 1024;
  27. internal class WSTrustChannelAsyncResult : System.IdentityModel.AsyncResult
  28. {
  29. public enum Operations { Cancel, Issue, Renew, Validate };
  30. IWSTrustContract _client;
  31. System.IdentityModel.Protocols.WSTrust.RequestSecurityToken _rst;
  32. WSTrustSerializationContext _serializationContext;
  33. Message _response;
  34. Operations _operation;
  35. public WSTrustChannelAsyncResult(IWSTrustContract client,
  36. Operations operation,
  37. System.IdentityModel.Protocols.WSTrust.RequestSecurityToken rst,
  38. WSTrustSerializationContext serializationContext,
  39. Message request,
  40. AsyncCallback callback,
  41. object state)
  42. : base(callback, state)
  43. {
  44. _client = client;
  45. _rst = rst;
  46. _serializationContext = serializationContext;
  47. _operation = operation;
  48. switch (_operation)
  49. {
  50. case Operations.Issue:
  51. client.BeginIssue(request, OnOperationCompleted, null);
  52. break;
  53. case Operations.Cancel:
  54. client.BeginCancel(request, OnOperationCompleted, null);
  55. break;
  56. case Operations.Renew:
  57. client.BeginRenew(request, OnOperationCompleted, null);
  58. break;
  59. case Operations.Validate:
  60. client.BeginValidate(request, OnOperationCompleted, null);
  61. break;
  62. default:
  63. throw IM.DiagnosticUtility.ThrowHelperInvalidOperation(SR.GetString(SR.ID3285, Enum.GetName(typeof(Operations), _operation)));
  64. }
  65. }
  66. public IWSTrustContract Client
  67. {
  68. get { return _client; }
  69. set { _client = value; }
  70. }
  71. public System.IdentityModel.Protocols.WSTrust.RequestSecurityToken RequestSecurityToken
  72. {
  73. get { return _rst; }
  74. set { _rst = value; }
  75. }
  76. public Message Response
  77. {
  78. get { return _response; }
  79. set { _response = value; }
  80. }
  81. public WSTrustSerializationContext SerializationContext
  82. {
  83. get { return _serializationContext; }
  84. set { _serializationContext = value; }
  85. }
  86. public new static Message End(IAsyncResult iar)
  87. {
  88. System.IdentityModel.AsyncResult.End(iar);
  89. WSTrustChannelAsyncResult tcar = iar as WSTrustChannelAsyncResult;
  90. if (tcar == null)
  91. {
  92. throw IM.DiagnosticUtility.ThrowHelperInvalidOperation(SR.GetString(SR.ID2004, typeof(WSTrustChannelAsyncResult), iar.GetType()));
  93. }
  94. return tcar.Response;
  95. }
  96. void OnOperationCompleted(IAsyncResult iar)
  97. {
  98. try
  99. {
  100. this.Response = EndOperation(iar);
  101. this.Complete(iar.CompletedSynchronously);
  102. }
  103. catch (Exception ex)
  104. {
  105. if (Fx.IsFatal(ex))
  106. {
  107. throw;
  108. }
  109. this.Complete(false, ex);
  110. }
  111. }
  112. Message EndOperation(IAsyncResult iar)
  113. {
  114. switch (_operation)
  115. {
  116. case Operations.Cancel:
  117. return this.Client.EndCancel(iar);
  118. case Operations.Issue:
  119. return this.Client.EndIssue(iar);
  120. case Operations.Renew:
  121. return this.Client.EndRenew(iar);
  122. case Operations.Validate:
  123. return this.Client.EndValidate(iar);
  124. default:
  125. throw IM.DiagnosticUtility.ThrowHelperInvalidOperation(SR.GetString(SR.ID3285, _operation));
  126. }
  127. }
  128. }
  129. //
  130. // The channel factory that created this channel.
  131. //
  132. WSTrustChannelFactory _factory;
  133. //
  134. // All IChannel calls delegate to this.
  135. //
  136. IChannel _innerChannel;
  137. //
  138. // All Message-in/Message-out calls are sent through this.
  139. //
  140. IWSTrustChannelContract _innerContract;
  141. //
  142. // The serializers and the serialization context are used to write and read
  143. // WS-Trust messages.
  144. //
  145. MessageVersion _messageVersion;
  146. TrustVersion _trustVersion;
  147. WSTrustSerializationContext _context;
  148. WSTrustRequestSerializer _wsTrustRequestSerializer;
  149. WSTrustResponseSerializer _wsTrustResponseSerializer;
  150. /// <summary>
  151. /// The <see cref="IChannel" /> this class uses for sending and receiving <see cref="Message" /> objects.
  152. /// </summary>
  153. public IChannel Channel
  154. {
  155. get
  156. {
  157. return _innerChannel;
  158. }
  159. protected set
  160. {
  161. _innerChannel = value;
  162. }
  163. }
  164. /// <summary>
  165. /// The <see cref="WSTrustChannelFactory" /> that created this object.
  166. /// </summary>
  167. public WSTrustChannelFactory ChannelFactory
  168. {
  169. get
  170. {
  171. return _factory;
  172. }
  173. protected set
  174. {
  175. _factory = value;
  176. }
  177. }
  178. /// <summary>
  179. /// The <see cref="IWSTrustChannelContract" /> this class uses for sending and receiving
  180. /// <see cref="Message" /> objects.
  181. /// </summary>
  182. public IWSTrustChannelContract Contract
  183. {
  184. get
  185. {
  186. return _innerContract;
  187. }
  188. protected set
  189. {
  190. _innerContract = value;
  191. }
  192. }
  193. /// <summary>
  194. /// The version of WS-Trust this channel will use for serializing <see cref="Message" /> objects.
  195. /// </summary>
  196. public TrustVersion TrustVersion
  197. {
  198. get
  199. {
  200. return _trustVersion;
  201. }
  202. protected set
  203. {
  204. if (!((value == null) || (value == TrustVersion.WSTrust13) || (value == TrustVersion.WSTrustFeb2005)))
  205. {
  206. }
  207. _trustVersion = value;
  208. }
  209. }
  210. /// <summary>
  211. /// The <see cref="WSTrustSerializationContext" /> this channel will use for serializing WS-Trust messages.
  212. /// </summary>
  213. public WSTrustSerializationContext WSTrustSerializationContext
  214. {
  215. get
  216. {
  217. return _context;
  218. }
  219. protected set
  220. {
  221. _context = value;
  222. }
  223. }
  224. /// <summary>
  225. /// The <see cref="WSTrustRequestSerializer" /> this channel will use for serializing WS-Trust request messages.
  226. /// </summary>
  227. public WSTrustRequestSerializer WSTrustRequestSerializer
  228. {
  229. get
  230. {
  231. return _wsTrustRequestSerializer;
  232. }
  233. protected set
  234. {
  235. _wsTrustRequestSerializer = value;
  236. }
  237. }
  238. /// <summary>
  239. /// The <see cref="WSTrustResponseSerializer" /> this channel will use for serializing WS-Trust response
  240. /// messages.
  241. /// </summary>
  242. public WSTrustResponseSerializer WSTrustResponseSerializer
  243. {
  244. get
  245. {
  246. return _wsTrustResponseSerializer;
  247. }
  248. protected set
  249. {
  250. _wsTrustResponseSerializer = value;
  251. }
  252. }
  253. /// <summary>
  254. /// Constructs a <see cref="WSTrustChannel" />.
  255. /// </summary>
  256. /// <param name="factory">The <see cref="WSTrustChannelFactory" /> that is creating this object.</param>
  257. /// <param name="inner">
  258. /// The <see cref="IWSTrustChannelContract" /> this object will use to send and receive
  259. /// <see cref="Message" /> objects.
  260. /// </param>
  261. /// <param name="trustVersion">
  262. /// The version of WS-Trust this channel will use for serializing <see cref="Message" /> objects.
  263. /// </param>
  264. /// <param name="context">
  265. /// The <see cref="WSTrustSerializationContext" /> this channel will use for serializing WS-Trust messages.
  266. /// </param>
  267. /// <param name="requestSerializer">
  268. /// The <see cref="WSTrustRequestSerializer" /> this channel will use for serializing WS-Trust request messages.
  269. /// </param>
  270. /// <param name="responseSerializer">
  271. /// The <see cref="WSTrustResponseSerializer" /> this channel will use for serializing WS-Trust response
  272. /// messages.
  273. /// </param>
  274. public WSTrustChannel(WSTrustChannelFactory factory,
  275. IWSTrustChannelContract inner,
  276. TrustVersion trustVersion,
  277. WSTrustSerializationContext context,
  278. WSTrustRequestSerializer requestSerializer,
  279. WSTrustResponseSerializer responseSerializer)
  280. {
  281. if (factory == null)
  282. {
  283. throw IM.DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("inner");
  284. }
  285. if (inner == null)
  286. {
  287. throw IM.DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("inner");
  288. }
  289. if (context == null)
  290. {
  291. throw IM.DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("context");
  292. }
  293. if (requestSerializer == null)
  294. {
  295. throw IM.DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("requestSerializer");
  296. }
  297. if (responseSerializer == null)
  298. {
  299. throw IM.DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("responseSerializer");
  300. }
  301. if (trustVersion == null)
  302. {
  303. throw IM.DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("trustVersion");
  304. }
  305. _innerChannel = inner as IChannel;
  306. if (_innerChannel == null)
  307. {
  308. throw IM.DiagnosticUtility.ThrowHelperInvalidOperation(SR.GetString(SR.ID3286));
  309. }
  310. _innerContract = inner;
  311. _factory = factory;
  312. _context = context;
  313. _wsTrustRequestSerializer = requestSerializer;
  314. _wsTrustResponseSerializer = responseSerializer;
  315. _trustVersion = trustVersion;
  316. //
  317. // Use the Binding's MessageVersion for creating our requests.
  318. //
  319. _messageVersion = MessageVersion.Default;
  320. if (_factory.Endpoint != null
  321. && _factory.Endpoint.Binding != null
  322. && _factory.Endpoint.Binding.MessageVersion != null)
  323. {
  324. _messageVersion = _factory.Endpoint.Binding.MessageVersion;
  325. }
  326. }
  327. /// <summary>
  328. /// Creates a <see cref="Message"/> object that represents a WS-Trust RST message.
  329. /// </summary>
  330. /// <param name="request">The <see cref="System.IdentityModel.Protocols.WSTrust.RequestSecurityToken"/> to serialize into the message.</param>
  331. /// <param name="requestType">The type of WS-Trust request to serialize. This parameter must be one of the
  332. /// string constants in <see cref="RequestTypes" />.</param>
  333. /// <returns>The <see cref="Message" /> object that represents the WS-Trust message.</returns>
  334. protected virtual Message CreateRequest(System.IdentityModel.Protocols.WSTrust.RequestSecurityToken request, string requestType)
  335. {
  336. return Message.CreateMessage(_messageVersion,
  337. GetRequestAction(requestType, TrustVersion),
  338. new WSTrustRequestBodyWriter(request,
  339. WSTrustRequestSerializer,
  340. WSTrustSerializationContext));
  341. }
  342. /// <summary>
  343. /// Deserializes a <see cref="System.IdentityModel.Protocols.WSTrust.RequestSecurityTokenResponse" /> from a <see cref="Message" />
  344. /// received from the WS-Trust endpoint.
  345. /// </summary>
  346. /// <param name="response">The <see cref="Message" /> received from the WS-Trust endpoint.</param>
  347. /// <returns>
  348. /// The <see cref="System.IdentityModel.Protocols.WSTrust.RequestSecurityTokenResponse" /> deserialized from <paramref name="response"/>.
  349. /// </returns>
  350. protected virtual System.IdentityModel.Protocols.WSTrust.RequestSecurityTokenResponse ReadResponse(Message response)
  351. {
  352. if (response == null)
  353. {
  354. throw IM.DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("response");
  355. }
  356. if (response.IsFault)
  357. {
  358. MessageFault fault = MessageFault.CreateFault(response, WSTrustChannel.FaultMaxBufferSize);
  359. string action = null;
  360. if (response.Headers != null)
  361. {
  362. action = response.Headers.Action;
  363. }
  364. FaultException faultException = FaultException.CreateFault(fault, action);
  365. throw FxTrace.Exception.AsError(faultException);
  366. }
  367. return WSTrustResponseSerializer.ReadXml(response.GetReaderAtBodyContents(), WSTrustSerializationContext);
  368. }
  369. /// <summary>
  370. /// Gets the WS-Addressing SOAP action that corresponds to the provided request type and
  371. /// WS-Trust version.
  372. /// </summary>
  373. /// <param name="requestType">The type of WS-Trust request. This parameter must be one of the
  374. /// string constants in <see cref="RequestTypes" />.</param>
  375. /// <param name="trustVersion">The <see cref="TrustVersion" /> of the request.</param>
  376. /// <returns>The WS-Addressing action to use.</returns>
  377. protected static string GetRequestAction(string requestType, TrustVersion trustVersion)
  378. {
  379. if (trustVersion != TrustVersion.WSTrust13 && trustVersion != TrustVersion.WSTrustFeb2005)
  380. {
  381. throw IM.DiagnosticUtility.ExceptionUtility.ThrowHelperError(
  382. new NotSupportedException(SR.GetString(SR.ID3137, trustVersion.ToString())));
  383. }
  384. switch (requestType)
  385. {
  386. case RequestTypes.Cancel:
  387. return trustVersion == TrustVersion.WSTrustFeb2005 ?
  388. WSTrustFeb2005Constants.Actions.Cancel : WSTrust13Constants.Actions.Cancel;
  389. case RequestTypes.Issue:
  390. return trustVersion == TrustVersion.WSTrustFeb2005 ?
  391. WSTrustFeb2005Constants.Actions.Issue : WSTrust13Constants.Actions.Issue;
  392. case RequestTypes.Renew:
  393. return trustVersion == TrustVersion.WSTrustFeb2005 ?
  394. WSTrustFeb2005Constants.Actions.Renew : WSTrust13Constants.Actions.Renew;
  395. case RequestTypes.Validate:
  396. return trustVersion == TrustVersion.WSTrustFeb2005 ?
  397. WSTrustFeb2005Constants.Actions.Validate : WSTrust13Constants.Actions.Validate;
  398. default:
  399. throw IM.DiagnosticUtility.ExceptionUtility.ThrowHelperError(
  400. new NotSupportedException(SR.GetString(SR.ID3141, requestType.ToString())));
  401. }
  402. }
  403. /// <summary>
  404. /// Get the security token from the RSTR
  405. /// </summary>
  406. /// <param name="request">The request used to ask for the security token.</param>
  407. /// <param name="response">The response containing the security token</param>
  408. /// <returns>parsed security token.</returns>
  409. /// <exception cref="ArgumentNullException">If response is null</exception>
  410. public virtual SecurityToken GetTokenFromResponse(System.IdentityModel.Protocols.WSTrust.RequestSecurityToken request, System.IdentityModel.Protocols.WSTrust.RequestSecurityTokenResponse response)
  411. {
  412. if (null == response)
  413. {
  414. throw IM.DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("response");
  415. }
  416. if (!response.IsFinal)
  417. {
  418. throw IM.DiagnosticUtility.ExceptionUtility.ThrowHelperError(
  419. new NotImplementedException(SR.GetString(SR.ID3270)));
  420. }
  421. if (response.RequestedSecurityToken == null)
  422. {
  423. return null;
  424. }
  425. SecurityToken issuedToken = response.RequestedSecurityToken.SecurityToken;
  426. // if we couldn't get the security token via the simple access above, try the token xml
  427. if (issuedToken == null)
  428. {
  429. if (response.RequestedSecurityToken.SecurityTokenXml == null)
  430. {
  431. throw IM.DiagnosticUtility.ExceptionUtility.ThrowHelperError(
  432. new InvalidOperationException(SR.GetString(SR.ID3138)));
  433. }
  434. SecurityToken proofToken = GetProofKey(request, response);
  435. //
  436. // If we don't see a lifetime in the response we set the expires time to
  437. // 10 hours from created time.
  438. //
  439. DateTime? created = null;
  440. DateTime? expires = null;
  441. if (response.Lifetime != null)
  442. {
  443. created = response.Lifetime.Created;
  444. expires = response.Lifetime.Expires;
  445. if (created == null)
  446. {
  447. created = DateTime.UtcNow;
  448. }
  449. if (expires == null)
  450. {
  451. expires = DateTime.UtcNow.AddHours(10);
  452. }
  453. }
  454. else
  455. {
  456. created = DateTime.UtcNow;
  457. expires = DateTime.UtcNow.AddHours(10);
  458. }
  459. return new GenericXmlSecurityToken(response.RequestedSecurityToken.SecurityTokenXml,
  460. proofToken,
  461. created.Value,
  462. expires.Value,
  463. response.RequestedAttachedReference,
  464. response.RequestedUnattachedReference,
  465. new ReadOnlyCollection<IAuthorizationPolicy>(new List<IAuthorizationPolicy>()));
  466. }
  467. else
  468. {
  469. return issuedToken;
  470. }
  471. }
  472. internal static SecurityToken GetUseKeySecurityToken(UseKey useKey, string requestKeyType)
  473. {
  474. if (useKey != null && useKey.Token != null)
  475. {
  476. return useKey.Token;
  477. }
  478. else
  479. {
  480. throw IM.DiagnosticUtility.ExceptionUtility.ThrowHelperError(
  481. new NotSupportedException(SR.GetString(SR.ID3190, requestKeyType)));
  482. }
  483. }
  484. /// <summary>
  485. /// The types of proof keys that can be issued in WS-Trust
  486. /// </summary>
  487. internal enum ProofKeyType { Unknown, Bearer, Symmetric, Asymmetric };
  488. /// <summary>
  489. /// Determines the ProofKeyType corresponding to the Uri contents
  490. /// enclosed in WS-Trust KeyType elements.
  491. /// </summary>
  492. internal static ProofKeyType GetKeyType(string keyType)
  493. {
  494. if (keyType == WSTrust13Constants.KeyTypes.Symmetric
  495. || keyType == WSTrustFeb2005Constants.KeyTypes.Symmetric
  496. || keyType == KeyTypes.Symmetric
  497. || String.IsNullOrEmpty(keyType))
  498. {
  499. return ProofKeyType.Symmetric;
  500. }
  501. else if (keyType == WSTrust13Constants.KeyTypes.Asymmetric
  502. || keyType == WSTrustFeb2005Constants.KeyTypes.Asymmetric
  503. || keyType == KeyTypes.Asymmetric)
  504. {
  505. return ProofKeyType.Asymmetric;
  506. }
  507. else if (keyType == WSTrust13Constants.KeyTypes.Bearer
  508. || keyType == WSTrustFeb2005Constants.KeyTypes.Bearer
  509. || keyType == KeyTypes.Bearer)
  510. {
  511. return ProofKeyType.Bearer;
  512. }
  513. else
  514. {
  515. return ProofKeyType.Unknown;
  516. }
  517. }
  518. internal static bool IsPsha1(string algorithm)
  519. {
  520. return (algorithm == WSTrust13Constants.ComputedKeyAlgorithms.PSHA1
  521. || algorithm == WSTrustFeb2005Constants.ComputedKeyAlgorithms.PSHA1
  522. || algorithm == ComputedKeyAlgorithms.Psha1);
  523. }
  524. /// <summary>
  525. /// Computes a SecurityToken representing the computed proof key which combines
  526. /// requestor and issuer entropies using the PSHA1 algorithm.
  527. /// </summary>
  528. internal static SecurityToken ComputeProofKey(System.IdentityModel.Protocols.WSTrust.RequestSecurityToken request,
  529. System.IdentityModel.Protocols.WSTrust.RequestSecurityTokenResponse response)
  530. {
  531. if (response.Entropy == null)
  532. {
  533. throw IM.DiagnosticUtility.ExceptionUtility.ThrowHelperError(
  534. new NotSupportedException(SR.GetString(SR.ID3193)));
  535. }
  536. if (request.Entropy == null)
  537. {
  538. throw IM.DiagnosticUtility.ExceptionUtility.ThrowHelperError(
  539. new NotSupportedException(SR.GetString(SR.ID3194)));
  540. }
  541. //
  542. // We need a key size. Use the requestor's keysize unless the issuer overrides it
  543. //
  544. int keySize = request.KeySizeInBits ?? WSTrustChannel.DefaultKeySizeInBits;
  545. if (response.KeySizeInBits.HasValue)
  546. {
  547. keySize = response.KeySizeInBits.Value;
  548. }
  549. byte[] keyMaterial = System.IdentityModel.CryptoHelper.KeyGenerator.ComputeCombinedKey(request.Entropy.GetKeyBytes(),
  550. response.Entropy.GetKeyBytes(),
  551. keySize);
  552. return new BinarySecretSecurityToken(keyMaterial);
  553. }
  554. //
  555. // Response | Request | Proof Key
  556. // =======================#========================#============================================
  557. // Contains a proof key | Ignored | Use the response's issued proof key
  558. // -----------------------+------------------------+--------------------------------------------
  559. // Contains Entropy | Contains Entropy | Compute a proof key using the specified
  560. // and MUST specify | | computation algorithm
  561. // computation algorithm | |
  562. // -----------------------+------------------------+--------------------------------------------
  563. // No proof key | Contains Entropy | Use request's entropy as proof key
  564. // -----------------------+------------------------+--------------------------------------------
  565. // No proof key | No entropy | No proof key is used
  566. // -----------------------+------------------------+--------------------------------------------
  567. // No proof key | Contains UseKey | Use UseKey as proof key
  568. // -----------------------+------------------------+--------------------------------------------
  569. //
  570. internal static SecurityToken GetProofKey(System.IdentityModel.Protocols.WSTrust.RequestSecurityToken request, System.IdentityModel.Protocols.WSTrust.RequestSecurityTokenResponse response)
  571. {
  572. //
  573. // The following attempts to get an issued proof key or compute a proof key in accordance
  574. // with WS-Trust 1.3 section 4.4.3
  575. //
  576. if (response.RequestedProofToken != null)
  577. {
  578. //
  579. // specific key
  580. // -------------
  581. // When the issuer provides a key it must be used as the proof key. This key is contained
  582. // in the RequestedProofToken element of the RSTR.
  583. //
  584. if (response.RequestedProofToken.ProtectedKey != null)
  585. {
  586. return new BinarySecretSecurityToken(response.RequestedProofToken.ProtectedKey.GetKeyBytes());
  587. }
  588. //
  589. // partial
  590. // ------------
  591. // When the issuer does not provide a key but specifies a key computation algorithm in the
  592. // RequestedProofToken element, then the requestor needs to compute the proof key using
  593. // both entropies.
  594. //
  595. else if (IsPsha1(response.RequestedProofToken.ComputedKeyAlgorithm))
  596. {
  597. return ComputeProofKey(request, response);
  598. }
  599. else
  600. {
  601. //
  602. // If there is a RequestedProofToken there must either be a
  603. // ProtectedKey or a ComputedKeyAlgorithm!
  604. //
  605. throw IM.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new NotSupportedException(SR.GetString(SR.ID3192, response.RequestedProofToken.ComputedKeyAlgorithm)));
  606. }
  607. }
  608. else
  609. {
  610. //
  611. // ommitted
  612. //
  613. // " In the case of omitted, an existing key is used or the resulting token
  614. // is not directly associated with a key. "
  615. //
  616. ProofKeyType requestKeyType = GetKeyType(request.KeyType);
  617. switch (requestKeyType)
  618. {
  619. case ProofKeyType.Asymmetric:
  620. return GetUseKeySecurityToken(request.UseKey, request.KeyType);
  621. case ProofKeyType.Symmetric:
  622. if (response.Entropy != null)
  623. {
  624. //
  625. // If there is response.Entropy then there must
  626. // also be an RSTR.RequestedProofToken containing a
  627. // ComputedKey element.
  628. //
  629. throw IM.DiagnosticUtility.ExceptionUtility.ThrowHelperError(
  630. new NotSupportedException(SR.GetString(SR.ID3191)));
  631. }
  632. if (request.Entropy != null)
  633. {
  634. return new BinarySecretSecurityToken(request.Entropy.GetKeyBytes());
  635. }
  636. else
  637. {
  638. return null;
  639. }
  640. case ProofKeyType.Bearer:
  641. return null;
  642. default:
  643. throw IM.DiagnosticUtility.ExceptionUtility.ThrowHelperError(
  644. new NotSupportedException(SR.GetString(SR.ID3139, request.KeyType)));
  645. }
  646. }
  647. }
  648. #region IChannel Members
  649. /// <summary>
  650. /// Returns a typed object requested, if present, from the appropriate layer in the channel stack.
  651. /// </summary>
  652. /// <typeparam name="T">The typed object for which the method is querying.</typeparam>
  653. /// <returns>The typed object <typeparamref name="T"/> requested if it is present or nullNothingnullptra null reference (Nothing in Visual Basic) if it is not.</returns>
  654. public T GetProperty<T>() where T : class
  655. {
  656. return Channel.GetProperty<T>();
  657. }
  658. #endregion
  659. #region ICommunicationObject Members
  660. /// <summary>
  661. /// Causes a communication object to transition immediately from its current state into the closed state.
  662. /// </summary>
  663. public void Abort()
  664. {
  665. Channel.Abort();
  666. }
  667. /// <summary>
  668. /// Begins an asynchronous operation to close a communication object with a specified timeout.
  669. /// </summary>
  670. /// <param name="timeout">
  671. /// The <see cref="TimeSpan" /> that specifies how long the close operation has to complete before timing out.
  672. /// </param>
  673. /// <param name="callback">
  674. /// The <see cref="AsyncCallback" /> delegate that receives notification of the completion of the asynchronous
  675. /// close operation.
  676. /// </param>
  677. /// <param name="state">
  678. /// An object, specified by the application, that contains state information associated with the asynchronous
  679. /// close operation.
  680. /// </param>
  681. /// <returns>The <see cref="IAsyncResult" /> that references the asynchronous close operation.</returns>
  682. public IAsyncResult BeginClose(TimeSpan timeout, AsyncCallback callback, object state)
  683. {
  684. return Channel.BeginClose(timeout, callback, state);
  685. }
  686. /// <summary>
  687. /// Begins an asynchronous operation to close a communication object.
  688. /// </summary>
  689. /// <param name="callback">
  690. /// The <see cref="AsyncCallback" /> delegate that receives notification of the completion of the asynchronous
  691. /// close operation.
  692. /// </param>
  693. /// <param name="state">
  694. /// An object, specified by the application, that contains state information associated with the asynchronous
  695. /// close operation.
  696. /// </param>
  697. /// <returns>The <see cref="IAsyncResult" /> that references the asynchronous close operation.</returns>
  698. public IAsyncResult BeginClose(AsyncCallback callback, object state)
  699. {
  700. return Channel.BeginClose(callback, state);
  701. }
  702. /// <summary>
  703. /// Begins an asynchronous operation to open a communication object within a specified interval of time.
  704. /// </summary>
  705. /// <param name="timeout">
  706. /// The <see cref="TimeSpan" /> that specifies how long the open operation has to complete before timing out.
  707. /// </param>
  708. /// <param name="callback">
  709. /// The <see cref="AsyncCallback" /> delegate that receives notification of the completion of the asynchronous
  710. /// close operation.
  711. /// </param>
  712. /// <param name="state">
  713. /// An object, specified by the application, that contains state information associated with the asynchronous
  714. /// close operation.
  715. /// </param>
  716. /// <returns>The <see cref="IAsyncResult" /> that references the asynchronous open operation.</returns>
  717. public IAsyncResult BeginOpen(TimeSpan timeout, AsyncCallback callback, object state)
  718. {
  719. return Channel.BeginOpen(timeout, callback, state);
  720. }
  721. /// <summary>
  722. /// Begins an asynchronous operation to open a communication object.
  723. /// </summary>
  724. /// <param name="callback">
  725. /// The <see cref="AsyncCallback" /> delegate that receives notification of the completion of the asynchronous
  726. /// close operation.
  727. /// </param>
  728. /// <param name="state">
  729. /// An object, specified by the application, that contains state information associated with the asynchronous
  730. /// close operation.
  731. /// </param>
  732. /// <returns>The <see cref="IAsyncResult" /> that references the asynchronous open operation.</returns>
  733. public IAsyncResult BeginOpen(AsyncCallback callback, object state)
  734. {
  735. return Channel.BeginOpen(callback, state);
  736. }
  737. /// <summary>
  738. /// Causes a communication object to transition from its current state into the closed state.
  739. /// </summary>
  740. /// <param name="timeout">
  741. /// The <see cref="TimeSpan" /> that specifies how long the open operation has to complete before timing out.
  742. /// </param>
  743. public void Close(TimeSpan timeout)
  744. {
  745. Channel.Close(timeout);
  746. }
  747. /// <summary>
  748. /// Causes a communication object to transition from its current state into the closed state.
  749. /// </summary>
  750. public void Close()
  751. {
  752. Channel.Close();
  753. }
  754. /// <summary>
  755. /// Occurs when the communication object completes its transition from the closing state into the closed state.
  756. /// </summary>
  757. public event EventHandler Closed
  758. {
  759. add
  760. {
  761. Channel.Closed += value;
  762. }
  763. remove
  764. {
  765. Channel.Closed -= value;
  766. }
  767. }
  768. /// <summary>
  769. /// Occurs when the communication object first enters the closing state.
  770. /// </summary>
  771. public event EventHandler Closing
  772. {
  773. add
  774. {
  775. Channel.Closing += value;
  776. }
  777. remove
  778. {
  779. Channel.Closing -= value;
  780. }
  781. }
  782. /// <summary>
  783. /// Completes an asynchronous operation to close a communication object.
  784. /// </summary>
  785. /// <param name="result">The <see cref="IAsyncResult" /> that is returned by a call to the BeginClose() method.</param>
  786. public void EndClose(IAsyncResult result)
  787. {
  788. Channel.EndClose(result);
  789. }
  790. /// <summary>
  791. /// Completes an asynchronous operation to open a communication object.
  792. /// </summary>
  793. /// <param name="result">The <see cref="IAsyncResult" /> that is returned by a call to the BeginClose() method.</param>
  794. public void EndOpen(IAsyncResult result)
  795. {
  796. Channel.EndOpen(result);
  797. }
  798. /// <summary>
  799. /// Occurs when the communication object first enters the faulted state.
  800. /// </summary>
  801. public event EventHandler Faulted
  802. {
  803. add
  804. {
  805. Channel.Faulted += value;
  806. }
  807. remove
  808. {
  809. Channel.Faulted -= value;
  810. }
  811. }
  812. /// <summary>
  813. /// Causes a communication object to transition from the created state into the opened state within a specified interval of time.
  814. /// </summary>
  815. /// <param name="timeout">
  816. /// The <see cref="TimeSpan" /> that specifies how long the open operation has to complete before timing out.
  817. /// </param>
  818. public void Open(TimeSpan timeout)
  819. {
  820. Channel.Open(timeout);
  821. }
  822. /// <summary>
  823. /// Causes a communication object to transition from the created state into the opened state.
  824. /// </summary>
  825. public void Open()
  826. {
  827. Channel.Open();
  828. }
  829. /// <summary>
  830. /// Occurs when the communication object completes its transition from the opening state into the opened state.
  831. /// </summary>
  832. public event EventHandler Opened
  833. {
  834. add
  835. {
  836. Channel.Opened += value;
  837. }
  838. remove
  839. {
  840. Channel.Opened -= value;
  841. }
  842. }
  843. /// <summary>
  844. /// Occurs when the communication object first enters the opening state.
  845. /// </summary>
  846. public event EventHandler Opening
  847. {
  848. add
  849. {
  850. Channel.Opening += value;
  851. }
  852. remove
  853. {
  854. Channel.Opening -= value;
  855. }
  856. }
  857. /// <summary>
  858. /// Gets the current state of the communication-oriented object.
  859. /// </summary>
  860. public System.ServiceModel.CommunicationState State
  861. {
  862. get { return Channel.State; }
  863. }
  864. #endregion
  865. #region IWSTrustChannelContract Members
  866. /// <summary>
  867. /// Sends a WS-Trust Cancel message to an endpoint.
  868. /// </summary>
  869. /// <param name="rst">The <see cref="System.IdentityModel.Protocols.WSTrust.RequestSecurityToken" /> that represents the request to the STS.</param>
  870. /// <returns>The <see cref="System.IdentityModel.Protocols.WSTrust.RequestSecurityTokenResponse" /> representing the STS response.</returns>
  871. public virtual System.IdentityModel.Protocols.WSTrust.RequestSecurityTokenResponse Cancel(System.IdentityModel.Protocols.WSTrust.RequestSecurityToken rst)
  872. {
  873. return ReadResponse(this.Contract.Cancel(CreateRequest(rst, RequestTypes.Cancel)));
  874. }
  875. /// <summary>
  876. /// Sends a WS-Trust Issue message to an endpoint STS
  877. /// </summary>
  878. /// <param name="rst">The <see cref="System.IdentityModel.Protocols.WSTrust.RequestSecurityToken" /> that represents the request to the STS.</param>
  879. /// <returns>A <see cref="SecurityToken" /> that represents the token issued by the STS.</returns>
  880. public virtual SecurityToken Issue(System.IdentityModel.Protocols.WSTrust.RequestSecurityToken rst)
  881. {
  882. System.IdentityModel.Protocols.WSTrust.RequestSecurityTokenResponse rstr = null;
  883. return this.Issue(rst, out rstr);
  884. }
  885. /// <summary>
  886. /// Sends a WS-Trust Issue message to an endpoint STS
  887. /// </summary>
  888. /// <param name="rst">The <see cref="System.IdentityModel.Protocols.WSTrust.RequestSecurityToken" /> that represents the request to the STS.</param>
  889. /// <param name="rstr">The <see cref="System.IdentityModel.Protocols.WSTrust.RequestSecurityTokenResponse" /> that represents the response from
  890. /// the STS.</param>
  891. /// <returns>A <see cref="SecurityToken" /> that represents the token issued by the STS.</returns>
  892. public virtual SecurityToken Issue(System.IdentityModel.Protocols.WSTrust.RequestSecurityToken rst, out System.IdentityModel.Protocols.WSTrust.RequestSecurityTokenResponse rstr)
  893. {
  894. Message request = CreateRequest(rst, RequestTypes.Issue);
  895. Message response = Contract.Issue(request);
  896. rstr = ReadResponse(response);
  897. return GetTokenFromResponse(rst, rstr);
  898. }
  899. /// <summary>
  900. /// Sends a WS-Trust Renew message to an endpoint.
  901. /// </summary>
  902. /// <param name="rst">The <see cref="System.IdentityModel.Protocols.WSTrust.RequestSecurityToken" /> that represents the request to the STS.</param>
  903. /// <returns>The <see cref="System.IdentityModel.Protocols.WSTrust.RequestSecurityTokenResponse" /> representing the STS response.</returns>
  904. public virtual System.IdentityModel.Protocols.WSTrust.RequestSecurityTokenResponse Renew(System.IdentityModel.Protocols.WSTrust.RequestSecurityToken rst)
  905. {
  906. return ReadResponse(this.Contract.Renew(CreateRequest(rst, RequestTypes.Renew)));
  907. }
  908. /// <summary>
  909. /// Sends a WS-Trust Validate message to an endpoint.
  910. /// </summary>
  911. /// <param name="rst">The <see cref="System.IdentityModel.Protocols.WSTrust.RequestSecurityToken" /> that represents the request to the STS.</param>
  912. /// <returns>The <see cref="System.IdentityModel.Protocols.WSTrust.RequestSecurityTokenResponse" /> representing the STS response.</returns>
  913. public virtual System.IdentityModel.Protocols.WSTrust.RequestSecurityTokenResponse Validate(System.IdentityModel.Protocols.WSTrust.RequestSecurityToken rst)
  914. {
  915. return ReadResponse(this.Contract.Validate(CreateRequest(rst, RequestTypes.Validate)));
  916. }
  917. #endregion
  918. IAsyncResult BeginOperation(WSTrustChannel.WSTrustChannelAsyncResult.Operations operation,
  919. string requestType,
  920. System.IdentityModel.Protocols.WSTrust.RequestSecurityToken rst,
  921. AsyncCallback callback,
  922. object state)
  923. {
  924. if (rst == null)
  925. {
  926. throw IM.DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("rst");
  927. }
  928. Message request = this.CreateRequest(rst, requestType);
  929. WSTrustSerializationContext context = this.WSTrustSerializationContext;
  930. return new WSTrustChannelAsyncResult(this, operation, rst, context, request, callback, state);
  931. }
  932. System.IdentityModel.Protocols.WSTrust.RequestSecurityTokenResponse EndOperation(IAsyncResult result, out WSTrustChannelAsyncResult tcar)
  933. {
  934. if (result == null)
  935. {
  936. throw IM.DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("result");
  937. }
  938. tcar = result as WSTrustChannelAsyncResult;
  939. if (tcar == null)
  940. {
  941. throw IM.DiagnosticUtility.ThrowHelperInvalidOperation(
  942. SR.GetString(SR.ID2004, typeof(WSTrustChannelAsyncResult), result.GetType()));
  943. }
  944. Message response = WSTrustChannelAsyncResult.End(result);
  945. return ReadResponse(response);
  946. }
  947. #region IWSTrustChannelContract Async Members
  948. /// <summary>
  949. /// Asynchronously sends a WS-Trust Cancel message to an endpoint.
  950. /// </summary>
  951. /// <param name="rst">The <see cref="System.IdentityModel.Protocols.WSTrust.RequestSecurityToken" /> that represents the request to the STS.</param>
  952. /// <param name="callback">An optional asynchronous callback, to be called when the send is complete.</param>
  953. /// <param name="state">A user-provided object that distinguishes this particular asynchronous send
  954. /// request from other requests.</param>
  955. /// <returns>An <see cref="IAsyncResult" /> object that represents the asynchronous send, which could still
  956. /// be pending. </returns>
  957. public IAsyncResult BeginCancel(System.IdentityModel.Protocols.WSTrust.RequestSecurityToken rst, AsyncCallback callback, object state)
  958. {
  959. return BeginOperation(WSTrustChannelAsyncResult.Operations.Cancel, RequestTypes.Cancel, rst, callback, state);
  960. }
  961. /// <summary>
  962. /// Completes the asynchronous send operation initiated by
  963. /// <see cref="BeginCancel(System.IdentityModel.Protocols.WSTrust.RequestSecurityToken,AsyncCallback,object)" />.
  964. /// </summary>
  965. /// <param name="result">A reference to the outstanding asynchronous send request.</param>
  966. /// <param name="rstr">The <see cref="System.IdentityModel.Protocols.WSTrust.RequestSecurityTokenResponse" /> representing the STS response.</param>
  967. public void EndCancel(IAsyncResult result, out System.IdentityModel.Protocols.WSTrust.RequestSecurityTokenResponse rstr)
  968. {
  969. WSTrustChannelAsyncResult tcar;
  970. rstr = EndOperation(result, out tcar);
  971. }
  972. /// <summary>
  973. /// Asynchronously sends a WS-Trust Renew message to an endpoint.
  974. /// </summary>
  975. /// <param name="rst">The <see cref="System.IdentityModel.Protocols.WSTrust.RequestSecurityToken" /> that represents the request to the STS.</param>
  976. /// <param name="callback">An optional asynchronous callback, to be called when the send is complete.</param>
  977. /// <param name="asyncState">A user-provided object that distinguishes this particular asynchronous send
  978. /// request from other requests.</param>
  979. /// <returns>An <see cref="IAsyncResult" /> object that represents the asynchronous send, which could still
  980. /// be pending. </returns>
  981. public IAsyncResult BeginIssue(System.IdentityModel.Protocols.WSTrust.RequestSecurityToken rst, AsyncCallback callback, object asyncState)
  982. {
  983. return BeginOperation(WSTrustChannelAsyncResult.Operations.Issue, RequestTypes.Issue, rst, callback, asyncState);
  984. }
  985. /// <summary>
  986. /// Completes the asynchronous send operation initiated by
  987. /// <see cref="BeginIssue(System.IdentityModel.Protocols.WSTrust.RequestSecurityToken,AsyncCallback,object)" />.
  988. /// </summary>
  989. /// <param name="result">A reference to the outstanding asynchronous send request.</param>
  990. /// <param name="rstr">The <see cref="System.IdentityModel.Protocols.WSTrust.RequestSecurityTokenResponse" /> representing the STS response.</param>
  991. /// <returns>A <see cref="SecurityToken" /> that represents the token issued by the STS.</returns>
  992. public SecurityToken EndIssue(IAsyncResult result, out System.IdentityModel.Protocols.WSTrust.RequestSecurityTokenResponse rstr)
  993. {
  994. WSTrustChannelAsyncResult tcar;
  995. rstr = EndOperation(result, out tcar);
  996. return GetTokenFromResponse(tcar.RequestSecurityToken, rstr);
  997. }
  998. /// <summary>
  999. /// Asynchronously sends a WS-Trust Renew message to an endpoint.
  1000. /// </summary>
  1001. /// <param name="rst">The <see cref="System.IdentityModel.Protocols.WSTrust.RequestSecurityToken" /> that represents the request to the STS.</param>
  1002. /// <param name="callback">An optional asynchronous callback, to be called when the send is complete.</param>
  1003. /// <param name="state">A user-provided object that distinguishes this particular asynchronous send
  1004. /// request from other requests.</param>
  1005. /// <returns>An <see cref="IAsyncResult" /> object that represents the asynchronous send, which could still
  1006. /// be pending. </returns>
  1007. public IAsyncResult BeginRenew(System.IdentityModel.Protocols.WSTrust.RequestSecurityToken rst, AsyncCallback callback, object state)
  1008. {
  1009. return BeginOperation(WSTrustChannelAsyncResult.Operations.Renew, RequestTypes.Renew, rst, callback, state);
  1010. }
  1011. /// <summary>
  1012. /// Completes the asynchronous send operation initiated by
  1013. /// <see cref="BeginRenew(System.IdentityModel.Protocols.WSTrust.RequestSecurityToken,AsyncCallback,object)" />.
  1014. /// </summary>
  1015. /// <param name="result">A reference to the outstanding asynchronous send request.</param>
  1016. /// <param name="rstr">The <see cref="System.IdentityModel.Protocols.WSTrust.RequestSecurityTokenResponse" /> representing the STS response.</param>
  1017. public void EndRenew(IAsyncResult result, out System.IdentityModel.Protocols.WSTrust.RequestSecurityTokenResponse rstr)
  1018. {
  1019. WSTrustChannelAsyncResult tcar;
  1020. rstr = EndOperation(result, out tcar);
  1021. }
  1022. /// <summary>
  1023. /// Asynchronously sends a WS-Trust Validate message to an endpoint.
  1024. /// </summary>
  1025. /// <param name="rst">The <see cref="System.IdentityModel.Protocols.WSTrust.RequestSecurityToken" /> that represents the request to the STS.</param>
  1026. /// <param name="callback">An optional asynchronous callback, to be called when the send is complete.</param>
  1027. /// <param name="state">A user-provided object that distinguishes this particular asynchronous send
  1028. /// request from other requests.</param>
  1029. /// <returns>An <see cref="IAsyncResult" /> object that represents the asynchronous send, which could still
  1030. /// be pending. </returns>
  1031. public IAsyncResult BeginValidate(System.IdentityModel.Protocols.WSTrust.RequestSecurityToken rst, AsyncCallback callback, object state)
  1032. {
  1033. return BeginOperation(WSTrustChannelAsyncResult.Operations.Validate, RequestTypes.Validate, rst, callback, state);
  1034. }
  1035. /// <summary>
  1036. /// Completes the asynchronous send operation initiated by
  1037. /// <see cref="BeginValidate(System.IdentityModel.Protocols.WSTrust.RequestSecurityToken,AsyncCallback,object)" />.
  1038. /// </summary>
  1039. /// <param name="result">A reference to the outstanding asynchronous send request.</param>
  1040. /// <param name="rstr">The <see cref="System.IdentityModel.Protocols.WSTrust.RequestSecurityTokenResponse" /> representing the STS response.</param>
  1041. public void EndValidate(IAsyncResult result, out System.IdentityModel.Protocols.WSTrust.RequestSecurityTokenResponse rstr)
  1042. {
  1043. WSTrustChannelAsyncResult tcar;
  1044. rstr = EndOperation(result, out tcar);
  1045. }
  1046. #endregion
  1047. #region IWSTrustContract Members
  1048. /// <summary>
  1049. /// Sends a WS-Trust Cancel message to an endpoint.
  1050. /// </summary>
  1051. /// <param name="message">The <see cref="Message" /> that contains the instructions for the request to the STS.</param>
  1052. /// <returns>The <see cref="Message" /> returned from the STS.</returns>
  1053. public Message Cancel(Message message)
  1054. {
  1055. return Contract.Cancel(message);
  1056. }
  1057. /// <summary>
  1058. /// Begins an asynchronous operation to send a WS-Trust Cancel message to an endpoint.
  1059. /// </summary>
  1060. /// <param name="message">The <see cref="Message" /> that contains the instructions for the request to the STS.</param>
  1061. /// <param name="callback">
  1062. /// The <see cref="AsyncCallback" /> delegate that receives notification of the completion of the asynchronous
  1063. /// close operation.
  1064. /// </param>
  1065. /// <param name="asyncState">
  1066. /// An object, specified by the application, that contains state information associated with the asynchronous
  1067. /// close operation.
  1068. /// </param>
  1069. /// <returns>The <see cref="IAsyncResult" /> that references the asynchronous close operation.</returns>
  1070. public IAsyncResult BeginCancel(Message message, AsyncCallback callback, object asyncState)
  1071. {
  1072. return Contract.BeginCancel(message, callback, asyncState);
  1073. }
  1074. /// <summary>
  1075. /// Completes an asynchronous operation to send a WS-Trust Cancel message to an endpoint.
  1076. /// </summary>
  1077. /// <param name="asyncResult">The <see cref="IAsyncResult" /> that is returned by a call to the BeginClose() method.</param>
  1078. /// <returns>The <see cref="Message" /> returned from the STS.</returns>
  1079. public Message EndCancel(IAsyncResult asyncResult)
  1080. {
  1081. return Contract.EndCancel(asyncResult);
  1082. }
  1083. /// <summary>
  1084. /// Sends a WS-Trust Issue message to an endpoint.
  1085. /// </summary>
  1086. /// <param name="message">The <see cref="Message" /> that contains the instructions for the request to the STS</param>
  1087. /// <returns>The <see cref="Message" /> returned from the STS</returns>
  1088. public Message Issue(Message message)
  1089. {
  1090. return Contract.Issue(message);
  1091. }
  1092. /// <summary>
  1093. /// Begins an asynchronous operation to send a WS-Trust Issue message to an endpoint.
  1094. /// </summary>
  1095. /// <param name="message">The <see cref="Message" /> that contains the instructions for the request to the STS.</param>
  1096. /// <param name="callback">
  1097. /// The <see cref="AsyncCallback" /> delegate that receives notification of the completion of the asynchronous
  1098. /// issue operation.
  1099. /// </param>
  1100. /// <param name="asyncState">
  1101. /// An object, specified by the application, that contains state information associated with the asynchronous
  1102. /// issue operation.
  1103. /// </param>
  1104. /// <returns>The <see cref="IAsyncResult" /> that references the asynchronous issue operation.</returns>
  1105. public IAsyncResult BeginIssue(Message message, AsyncCallback callback, object asyncState)
  1106. {
  1107. return Contract.BeginIssue(message, callback, asyncState);
  1108. }
  1109. /// <summary>
  1110. /// Completes an asynchronous operation to send a WS-Trust Issue message to an endpoint.
  1111. /// </summary>
  1112. /// <param name="asyncResult">The <see cref="IAsyncResult" /> that is returned by a call to the BeginIssue() method.</param>
  1113. /// <returns>The <see cref="Message" /> returned from the STS.</returns>
  1114. public Message EndIssue(IAsyncResult asyncResult)
  1115. {
  1116. return Contract.EndIssue(asyncResult);
  1117. }
  1118. /// <summary>
  1119. /// Sends a WS-Trust Renew message to an endpoint.
  1120. /// </summary>
  1121. /// <param name="message">The <see cref="Message" /> that contains the instructions for the request to the STS</param>
  1122. /// <returns>The <see cref="Message" /> returned from the STS</returns>
  1123. public Message Renew(Message message)
  1124. {
  1125. return Contract.Renew(message);
  1126. }
  1127. /// <summary>
  1128. /// Begins an asynchronous operation to send a WS-Trust Renew message to an endpoint.
  1129. /// </summary>
  1130. /// <param name="message">The <see cref="Message" /> that contains the instructions for the request to the STS.</param>
  1131. /// <param name="callback">
  1132. /// The <see cref="AsyncCallback" /> delegate that receives notification of the completion of the asynchronous
  1133. /// renew operation.
  1134. /// </param>
  1135. /// <param name="asyncState">
  1136. /// An object, specified by the application, that contains state information associated with the asynchronous
  1137. /// renew operation.
  1138. /// </param>
  1139. /// <returns>The <see cref="IAsyncResult" /> that references the asynchronous renew operation.</returns>
  1140. public IAsyncResult BeginRenew(Message message, AsyncCallback callback, object asyncState)
  1141. {
  1142. return Contract.BeginRenew(message, callback, asyncState);
  1143. }
  1144. /// <summary>
  1145. /// Completes an asynchronous operation to send a WS-Trust Renew message to an endpoint.
  1146. /// </summary>
  1147. /// <param name="asyncResult">The <see cref="IAsyncResult" /> that is returned by a call to the BeginRenew() method.</param>
  1148. /// <returns>The <see cref="Message" /> returned from the STS.</returns>
  1149. public Message EndRenew(IAsyncResult asyncResult)
  1150. {
  1151. return Contract.EndRenew(asyncResult);
  1152. }
  1153. /// <summary>
  1154. /// Sends a WS-Trust Validate message to an endpoint.
  1155. /// </summary>
  1156. /// <param name="message">The <see cref="Message" /> that contains the instructions for the request to the STS</param>
  1157. /// <returns>The <see cref="Message" /> returned from the STS</returns>
  1158. public Message Validate(Message message)
  1159. {
  1160. return Contract.Validate(message);
  1161. }
  1162. /// <summary>
  1163. /// Begins an asynchronous operation to send a WS-Trust Validate message to an endpoint.
  1164. /// </summary>
  1165. /// <param name="message">The <see cref="Message" /> that contains the instructions for the request to the STS.</param>
  1166. /// <param name="callback">
  1167. /// The <see cref="AsyncCallback" /> delegate that receives notification of the completion of the asynchronous
  1168. /// validate operation.
  1169. /// </param>
  1170. /// <param name="asyncState">
  1171. /// An object, specified by the application, that contains state information associated with the asynchronous
  1172. /// validate operation.
  1173. /// </param>
  1174. /// <returns>The <see cref="IAsyncResult" /> that references the asynchronous validate operation.</returns>
  1175. public IAsyncResult BeginValidate(Message message, AsyncCallback callback, object asyncState)
  1176. {
  1177. return Contract.BeginValidate(message, callback, asyncState);
  1178. }
  1179. /// <summary>
  1180. /// Completes an asynchronous operation to send a WS-Trust Validate message to an endpoint.
  1181. /// </summary>
  1182. /// <param name="asyncResult">The <see cref="IAsyncResult" /> that is returned by a call to the BeginValidate() method.</param>
  1183. /// <returns>The <see cref="Message" /> returned from the STS.</returns>
  1184. public Message EndValidate(IAsyncResult asyncResult)
  1185. {
  1186. return Contract.EndValidate(asyncResult);
  1187. }
  1188. #endregion
  1189. }
  1190. }