3 // Permission is hereby granted, free of charge, to any person obtaining
4 // a copy of this software and associated documentation files (the
5 // "Software"), to deal in the Software without restriction, including
6 // without limitation the rights to use, copy, modify, merge, publish,
7 // distribute, sublicense, and/or sell copies of the Software, and to
8 // permit persons to whom the Software is furnished to do so, subject to
9 // the following conditions:
11 // The above copyright notice and this permission notice shall be
12 // included in all copies or substantial portions of the Software.
14 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 /* Transport Security Layer (TLS)
23 * Copyright (c) 2003-2004 Carlos Guzman Alvarez
25 * Permission is hereby granted, free of charge, to any person
26 * obtaining a copy of this software and associated documentation
27 * files (the "Software"), to deal in the Software without restriction,
28 * including without limitation the rights to use, copy, modify, merge,
29 * publish, distribute, sublicense, and/or sell copies of the Software,
30 * and to permit persons to whom the Software is furnished to do so,
31 * subject to the following conditions:
33 * The above copyright notice and this permission notice shall be included
34 * in all copies or substantial portions of the Software.
36 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
37 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
38 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
39 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
40 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
41 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
42 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
43 * DEALINGS IN THE SOFTWARE.
47 using System.Collections;
48 using System.Globalization;
49 using System.Security.Cryptography;
51 namespace Mono.Security.Protocol.Tls
53 internal sealed class CipherSuiteCollection : ICollection, IList, IEnumerable
57 private ArrayList cipherSuites;
58 private SecurityProtocolType protocol;
64 public CipherSuite this[string name]
66 get { return (CipherSuite)this.cipherSuites[this.IndexOf(name)]; }
67 set { this.cipherSuites[this.IndexOf(name)] = (CipherSuite)value; }
70 public CipherSuite this[int index]
72 get { return (CipherSuite)this.cipherSuites[index]; }
73 set { this.cipherSuites[index] = (CipherSuite)value; }
76 public CipherSuite this[short code]
78 get { return (CipherSuite)this.cipherSuites[this.IndexOf(code)]; }
79 set { this.cipherSuites[this.IndexOf(code)] = (CipherSuite)value; }
82 object IList.this[int index]
84 get { return this[index]; }
85 set { this[index] = (CipherSuite)value; }
90 #region ICollection Properties
92 bool ICollection.IsSynchronized
94 get { return this.cipherSuites.IsSynchronized; }
97 object ICollection.SyncRoot
99 get { return this.cipherSuites.SyncRoot; }
104 get { return this.cipherSuites.Count; }
109 #region IList Properties
111 public bool IsFixedSize
113 get { return this.cipherSuites.IsFixedSize; }
116 public bool IsReadOnly
118 get { return this.cipherSuites.IsReadOnly; }
125 public CipherSuiteCollection(SecurityProtocolType protocol) : base()
127 this.protocol = protocol;
128 this.cipherSuites = new ArrayList();
133 #region ICollection Methods
135 public void CopyTo(Array array, int index)
137 this.cipherSuites.CopyTo(array, index);
142 #region IEnumerable Methods
144 IEnumerator IEnumerable.GetEnumerator()
146 return this.cipherSuites.GetEnumerator();
151 #region IList Methods
155 this.cipherSuites.Clear();
158 bool IList.Contains(object value)
160 return this.cipherSuites.Contains(value as CipherSuite);
163 public int IndexOf(string name)
167 foreach (CipherSuite cipherSuite in this.cipherSuites)
169 if (this.cultureAwareCompare(cipherSuite.Name, name))
179 public int IndexOf(short code)
183 foreach (CipherSuite cipherSuite in this.cipherSuites)
185 if (cipherSuite.Code == code)
195 int IList.IndexOf(object value)
197 return this.cipherSuites.IndexOf(value as CipherSuite);
200 void IList.Insert(int index, object value)
202 this.cipherSuites.Insert(index, value as CipherSuite);
205 void IList.Remove(object value)
207 this.cipherSuites.Remove(value as CipherSuite);
210 void IList.RemoveAt(int index)
212 this.cipherSuites.RemoveAt(index);
215 public CipherSuite Add(
216 short code, string name, CipherAlgorithmType cipherType,
217 HashAlgorithmType hashType, ExchangeAlgorithmType exchangeType,
218 bool exportable, bool blockMode, byte keyMaterialSize,
219 byte expandedKeyMaterialSize, short effectiveKeyBytes,
220 byte ivSize, byte blockSize)
222 switch (this.protocol)
224 case SecurityProtocolType.Default:
225 case SecurityProtocolType.Tls:
228 code, name, cipherType, hashType, exchangeType, exportable,
229 blockMode, keyMaterialSize, expandedKeyMaterialSize,
230 effectiveKeyBytes, ivSize, blockSize));
232 case SecurityProtocolType.Ssl3:
235 code, name, cipherType, hashType, exchangeType, exportable,
236 blockMode, keyMaterialSize, expandedKeyMaterialSize,
237 effectiveKeyBytes, ivSize, blockSize));
239 case SecurityProtocolType.Ssl2:
241 throw new NotSupportedException("Unsupported security protocol type.");
245 private TlsCipherSuite add(TlsCipherSuite cipherSuite)
247 this.cipherSuites.Add(cipherSuite);
252 private SslCipherSuite add(SslCipherSuite cipherSuite)
254 this.cipherSuites.Add(cipherSuite);
259 int IList.Add(object value)
261 return this.cipherSuites.Add(value as CipherSuite);
264 private bool cultureAwareCompare(string strA, string strB)
266 return CultureInfo.CurrentCulture.CompareInfo.Compare(
269 CompareOptions.IgnoreKanaType | CompareOptions.IgnoreWidth |
270 CompareOptions.IgnoreCase) == 0 ? true : false;