This commit was manufactured by cvs2svn to create branch 'mono-1-0'.
[mono.git] / mcs / class / Mono.Security / Mono.Security.Protocol.Tls / ServerContext.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 using System.Security.Cryptography.X509Certificates;
49
50 using Mono.Security.Protocol.Tls.Handshake;
51 using MonoX509 = Mono.Security.X509;
52
53 namespace Mono.Security.Protocol.Tls
54 {
55         internal class ServerContext : Context
56         {
57                 #region Fields
58
59                 private SslServerStream sslStream;
60                 private bool                    clientCertificateRequired;
61
62                 #endregion
63
64                 #region Properties
65
66                 public SslServerStream SslStream
67                 {
68                         get { return this.sslStream; }
69                 }
70
71                 public bool     ClientCertificateRequired
72                 {
73                         get { return this.clientCertificateRequired; }
74                 }
75
76                 #endregion
77
78                 #region Constructors
79
80                 public ServerContext(
81                         SslServerStream                 stream,
82                         SecurityProtocolType    securityProtocolType,
83                         X509Certificate                 serverCertificate,
84                         bool                                    clientCertificateRequired)
85                         : base(securityProtocolType)
86                 {
87                         this.sslStream                                  = stream;
88                         this.clientCertificateRequired  = clientCertificateRequired;
89
90                         // Convert the System.Security cert to a Mono Cert
91                         MonoX509.X509Certificate cert = new MonoX509.X509Certificate(serverCertificate.GetRawCertData());
92
93                         // Add server certificate to the certificate collection
94                         this.ServerSettings.Certificates = new MonoX509.X509CertificateCollection();
95                         this.ServerSettings.Certificates.Add(cert);
96
97                         this.ServerSettings.UpdateCertificateRSA();
98
99                         // Add requested certificate types
100                         this.ServerSettings.CertificateTypes = new ClientCertificateType[1];
101                         this.ServerSettings.CertificateTypes[0] = ClientCertificateType.RSA;
102
103                         // Add certificate authorities
104                         this.ServerSettings.DistinguisedNames = new string[0];
105                 }
106
107                 #endregion
108         }
109 }