This commit was manufactured by cvs2svn to create branch 'mono-1-0'.
[mono.git] / mcs / class / Mono.Security / Mono.Security.Protocol.Tls / TlsServerSettings.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.Security.Cryptography;
48
49 using Mono.Security.Cryptography;
50 using Mono.Security.X509;
51 using Mono.Security.Protocol.Tls.Handshake;
52
53 namespace Mono.Security.Protocol.Tls
54 {
55         internal class TlsServerSettings
56         {
57                 #region Fields
58
59                 private X509CertificateCollection       certificates;
60                 private RSA                                                     certificateRSA;
61                 private RSAParameters                           rsaParameters;
62                 private byte[]                                          signedParams;
63                 private string[]                                        distinguisedNames;
64                 private bool                                            serverKeyExchange;
65                 private bool                                            certificateRequest;
66                 private ClientCertificateType[]         certificateTypes;
67
68                 #endregion
69
70                 #region Properties
71                 
72                 public bool     ServerKeyExchange
73                 {
74                         get { return this.serverKeyExchange; }
75                         set { this.serverKeyExchange = value; }
76                 }               
77
78                 public X509CertificateCollection Certificates
79                 {
80                         get { return this.certificates; }
81                         set { this.certificates = value; }
82                 }
83
84                 public RSA CertificateRSA
85                 {
86                         get { return this.certificateRSA; }
87                 }
88                 
89                 public RSAParameters RsaParameters
90                 {
91                         get { return this.rsaParameters; }
92                         set { this.rsaParameters = value; }
93                 }
94
95                 public byte[] SignedParams
96                 {
97                         get { return this.signedParams; }
98                         set { this.signedParams = value; }
99                 }
100
101                 public bool     CertificateRequest
102                 {
103                         get { return this.certificateRequest; }
104                         set { this.certificateRequest = value; }
105                 }
106                 
107                 public ClientCertificateType[] CertificateTypes
108                 {
109                         get { return this.certificateTypes; }
110                         set { this.certificateTypes = value; }
111                 }
112
113                 public string[] DistinguisedNames
114                 {
115                         get { return this.distinguisedNames; }
116                         set { this.distinguisedNames = value; }
117                 }
118                 
119                 #endregion
120
121                 #region Constructors
122
123                 public TlsServerSettings()
124                 {
125                 }
126
127                 #endregion
128
129                 #region Methods
130
131                 public void UpdateCertificateRSA()
132                 {
133                         if (this.certificates == null ||
134                                 this.certificates.Count == 0)
135                         {
136                                 this.certificateRSA = null;
137                         }
138                         else
139                         {
140                                 this.certificateRSA = new RSAManaged(
141                                         this.certificates[0].RSA.KeySize);
142
143                                 this.certificateRSA.ImportParameters(
144                                         this.certificates[0].RSA.ExportParameters(false));
145                         }
146                 }
147
148                 #endregion
149         }
150 }