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