2 // SecurityRequestChannel.cs
5 // Atsushi Enomoto <atsushi@ximian.com>
7 // Copyright (C) 2006 Novell, Inc (http://www.novell.com)
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:
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
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.
30 using System.Collections.Generic;
31 using System.Collections.ObjectModel;
32 using System.IdentityModel.Selectors;
33 using System.IdentityModel.Tokens;
34 using System.Runtime.Serialization;
35 using System.Security.Cryptography;
36 using System.Security.Cryptography.X509Certificates;
37 using System.Security.Cryptography.Xml;
38 using System.ServiceModel;
39 using System.ServiceModel.Channels;
40 using System.ServiceModel.Description;
41 using System.ServiceModel.Security;
42 using System.ServiceModel.Security.Tokens;
44 using System.Xml.XPath;
46 using ReqType = System.ServiceModel.Security.Tokens.ServiceModelSecurityTokenRequirement;
48 namespace System.ServiceModel.Channels
50 class SecurityOutputChannel : SecurityOutputChannelBase
52 SecurityChannelFactory<IOutputChannel> source;
54 public SecurityOutputChannel (IOutputChannel innerChannel, SecurityChannelFactory<IOutputChannel> source)
58 InitializeSecurityFunctionality (source.SecuritySupport);
61 public override ChannelFactoryBase Factory {
62 get { return source; }
66 class SecurityOutputSessionChannel : SecurityOutputChannelBase
68 SecurityChannelFactory<IOutputSessionChannel> source;
70 public SecurityOutputSessionChannel (IOutputSessionChannel innerChannel, SecurityChannelFactory<IOutputSessionChannel> source)
74 InitializeSecurityFunctionality (source.SecuritySupport);
77 public override ChannelFactoryBase Factory {
78 get { return source; }
82 abstract class SecurityOutputChannelBase : LayeredOutputChannel
84 InitiatorMessageSecurityBindingSupport security;
86 protected SecurityOutputChannelBase (IOutputChannel innerChannel)
89 Opened += new EventHandler (AcquireSecurityKey);
90 Closing += new EventHandler (ReleaseSecurityKey);
93 protected void InitializeSecurityFunctionality (InitiatorMessageSecurityBindingSupport security)
95 this.security = security;
98 protected override IAsyncResult OnBeginSend (Message message, TimeSpan timeout, AsyncCallback callback, object state)
100 Message secure = SecureMessage (message);
101 return base.BeginSend (secure, timeout, callback, state);
104 protected override void OnEndSend (IAsyncResult result)
106 // FIXME: it must be also asynchronized.
107 base.EndSend (result);
110 protected override void OnSend (Message message, TimeSpan timeout)
112 Message secure = SecureMessage (message);
113 base.OnSend (secure, timeout);
116 Message SecureMessage (Message msg)
118 return new InitiatorMessageSecurityGenerator (msg, security, RemoteAddress).SecureMessage ();
121 void AcquireSecurityKey (object o, EventArgs e)
123 security.Prepare (Factory, RemoteAddress);
126 void ReleaseSecurityKey (object o, EventArgs e)