Merge pull request #1949 from lewurm/fixtype
[mono.git] / mcs / class / Mono.Security / Mono.Security.Protocol.Tls / TlsClientSettings.cs
1 // Transport Security Layer (TLS)
2 // Copyright (c) 2003-2004 Carlos Guzman Alvarez
3
4 //
5 // Permission is hereby granted, free of charge, to any person obtaining
6 // a copy of this software and associated documentation files (the
7 // "Software"), to deal in the Software without restriction, including
8 // without limitation the rights to use, copy, modify, merge, publish,
9 // distribute, sublicense, and/or sell copies of the Software, and to
10 // permit persons to whom the Software is furnished to do so, subject to
11 // the following conditions:
12 // 
13 // The above copyright notice and this permission notice shall be
14 // included in all copies or substantial portions of the Software.
15 // 
16 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 //
24
25 using System;
26 using System.Text;
27 using System.Security.Cryptography.X509Certificates;
28 using Mono.Security.Cryptography;
29 using X509 = Mono.Security.X509;
30
31 namespace Mono.Security.Protocol.Tls
32 {
33         internal sealed class TlsClientSettings
34         {
35                 #region Fields
36
37                 private string                                          targetHost;
38                 private X509CertificateCollection       certificates;
39                 //private SecurityCompressionType               compressionMethod;
40                 private X509Certificate                         clientCertificate;
41                 private RSAManaged                                      certificateRSA;
42         
43                 #endregion
44
45                 #region Properties
46
47                 public string TargetHost
48                 {
49                         get { return this.targetHost; }
50                         set { this.targetHost = value; }
51                 }
52
53                 public X509CertificateCollection Certificates
54                 {
55                         get { return this.certificates; }
56                         set { this.certificates = value; }
57                 }
58                 
59                 public X509Certificate ClientCertificate
60                 {
61                         get { return this.clientCertificate; }
62                         set 
63                         { 
64                                 this.clientCertificate = value; 
65                                 this.UpdateCertificateRSA();
66                         }
67                 }
68
69                 public RSAManaged CertificateRSA
70                 {
71                         get { return this.certificateRSA; }
72                 }
73
74                 /*
75                 public SecurityCompressionType CompressionMethod
76                 {
77                         get { return this.compressionMethod; }
78                         set 
79                         { 
80                                 if (value != SecurityCompressionType.None)
81                                 {
82                                         throw new NotSupportedException("Specified compression method is not supported");
83                                 }
84                                 this.compressionMethod = value; 
85                         }
86                 }
87                 */
88
89                 #endregion
90
91                 #region Constructors
92
93                 public TlsClientSettings()
94                 {
95                         // this.compressionMethod       = SecurityCompressionType.None;
96                         this.certificates               = new X509CertificateCollection();
97                         this.targetHost                 = String.Empty;
98                 }
99
100                 #endregion
101
102                 #region Methods
103
104                 public void UpdateCertificateRSA()
105                 {
106                         if (this.clientCertificate == null)
107                         {
108                                 this.certificateRSA = null;
109                         }
110                         else
111                         {
112                                 X509.X509Certificate cert = new X509.X509Certificate(this.clientCertificate.GetRawCertData());
113
114                                 this.certificateRSA = new RSAManaged(
115                                         cert.RSA.KeySize);
116
117                                 this.certificateRSA.ImportParameters(
118                                         cert.RSA.ExportParameters(false));
119                         }
120                 }
121
122                 #endregion
123         }
124 }