This commit was manufactured by cvs2svn to create branch 'mono-1-0'.
[mono.git] / mcs / class / Mono.Security / Mono.Security.Protocol.Tls / TlsClientSettings.cs
1
2 //
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:
10 // 
11 // The above copyright notice and this permission notice shall be
12 // included in all copies or substantial portions of the Software.
13 // 
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.
21 //
22 /* Transport Security Layer (TLS)
23  * Copyright (c) 2003-2004 Carlos Guzman Alvarez
24  * 
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:
32  * 
33  * The above copyright notice and this permission notice shall be included 
34  * in all copies or substantial portions of the Software.
35  * 
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.
44  */
45
46 using System;
47 using System.Text;
48 using System.Security.Cryptography.X509Certificates;
49 using Mono.Security.Cryptography;
50 using X509 = Mono.Security.X509;
51
52 namespace Mono.Security.Protocol.Tls
53 {
54         internal sealed class TlsClientSettings
55         {
56                 #region Fields
57
58                 private string                                          targetHost;
59                 private X509CertificateCollection       certificates;
60                 private SecurityCompressionType         compressionMethod;
61                 private X509Certificate                         clientCertificate;
62                 private RSAManaged                                      certificateRSA;
63         
64                 #endregion
65
66                 #region Properties
67
68                 public string TargetHost
69                 {
70                         get { return this.targetHost; }
71                         set { this.targetHost = value; }
72                 }
73
74                 public X509CertificateCollection Certificates
75                 {
76                         get { return this.certificates; }
77                         set { this.certificates = value; }
78                 }
79                 
80                 public X509Certificate ClientCertificate
81                 {
82                         get { return this.clientCertificate; }
83                         set 
84                         { 
85                                 this.clientCertificate = value; 
86                                 this.UpdateCertificateRSA();
87                         }
88                 }
89
90                 public RSAManaged CertificateRSA
91                 {
92                         get { return this.certificateRSA; }
93                 }
94
95                 /*
96                 public SecurityCompressionType CompressionMethod
97                 {
98                         get { return this.compressionMethod; }
99                         set 
100                         { 
101                                 if (value != SecurityCompressionType.None)
102                                 {
103                                         throw new NotSupportedException("Specified compression method is not supported");
104                                 }
105                                 this.compressionMethod = value; 
106                         }
107                 }
108                 */
109
110                 #endregion
111
112                 #region Constructors
113
114                 public TlsClientSettings()
115                 {
116                         this.compressionMethod  = SecurityCompressionType.None;
117                         this.certificates               = new X509CertificateCollection();
118                         this.targetHost                 = String.Empty;
119                 }
120
121                 #endregion
122
123                 #region Methods
124
125                 public void UpdateCertificateRSA()
126                 {
127                         if (this.clientCertificate == null)
128                         {
129                                 this.certificateRSA = null;
130                         }
131                         else
132                         {
133                                 X509.X509Certificate cert = new X509.X509Certificate(this.clientCertificate.GetRawCertData());
134
135                                 this.certificateRSA = new RSAManaged(
136                                         cert.RSA.KeySize);
137
138                                 this.certificateRSA.ImportParameters(
139                                         cert.RSA.ExportParameters(false));
140                         }
141                 }
142
143                 #endregion
144         }
145 }