Implementation of the 2.0 session state model
[mono.git] / mcs / class / Mono.Security / Mono.Security.Protocol.Tls / TlsServerSettings.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.Security.Cryptography;
27
28 using Mono.Security.Cryptography;
29 using Mono.Security.X509;
30 using Mono.Security.Protocol.Tls.Handshake;
31
32 namespace Mono.Security.Protocol.Tls
33 {
34         internal class TlsServerSettings
35         {
36                 #region Fields
37
38                 private X509CertificateCollection       certificates;
39                 private RSA                                                     certificateRSA;
40                 private RSAParameters                           rsaParameters;
41                 private byte[]                                          signedParams;
42                 private string[]                                        distinguisedNames;
43                 private bool                                            serverKeyExchange;
44                 private bool                                            certificateRequest;
45                 private ClientCertificateType[]         certificateTypes;
46
47                 #endregion
48
49                 #region Properties
50                 
51                 public bool     ServerKeyExchange
52                 {
53                         get { return this.serverKeyExchange; }
54                         set { this.serverKeyExchange = value; }
55                 }               
56
57                 public X509CertificateCollection Certificates
58                 {
59                         get { return this.certificates; }
60                         set { this.certificates = value; }
61                 }
62
63                 public RSA CertificateRSA
64                 {
65                         get { return this.certificateRSA; }
66                 }
67                 
68                 public RSAParameters RsaParameters
69                 {
70                         get { return this.rsaParameters; }
71                         set { this.rsaParameters = value; }
72                 }
73
74                 public byte[] SignedParams
75                 {
76                         get { return this.signedParams; }
77                         set { this.signedParams = value; }
78                 }
79
80                 public bool     CertificateRequest
81                 {
82                         get { return this.certificateRequest; }
83                         set { this.certificateRequest = value; }
84                 }
85                 
86                 public ClientCertificateType[] CertificateTypes
87                 {
88                         get { return this.certificateTypes; }
89                         set { this.certificateTypes = value; }
90                 }
91
92                 public string[] DistinguisedNames
93                 {
94                         get { return this.distinguisedNames; }
95                         set { this.distinguisedNames = value; }
96                 }
97                 
98                 #endregion
99
100                 #region Constructors
101
102                 public TlsServerSettings()
103                 {
104                 }
105
106                 #endregion
107
108                 #region Methods
109
110                 public void UpdateCertificateRSA()
111                 {
112                         if (this.certificates == null ||
113                                 this.certificates.Count == 0)
114                         {
115                                 this.certificateRSA = null;
116                         }
117                         else
118                         {
119                                 this.certificateRSA = new RSAManaged(
120                                         this.certificates[0].RSA.KeySize);
121
122                                 this.certificateRSA.ImportParameters(
123                                         this.certificates[0].RSA.ExportParameters(false));
124                         }
125                 }
126
127                 #endregion
128         }
129 }