1 // Transport Security Layer (TLS)
2 // Copyright (c) 2003-2004 Carlos Guzman Alvarez
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:
13 // The above copyright notice and this permission notice shall be
14 // included in all copies or substantial portions of the Software.
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.
26 using System.Security.Cryptography;
27 using System.Security.Cryptography.X509Certificates;
29 using Mono.Security.Protocol.Tls.Handshake;
30 using MonoX509 = Mono.Security.X509;
32 namespace Mono.Security.Protocol.Tls
34 internal class ServerContext : Context
38 private SslServerStream sslStream;
39 private bool clientCertificateRequired;
45 public SslServerStream SslStream
47 get { return this.sslStream; }
50 public bool ClientCertificateRequired
52 get { return this.clientCertificateRequired; }
60 SslServerStream stream,
61 SecurityProtocolType securityProtocolType,
62 X509Certificate serverCertificate,
63 bool clientCertificateRequired)
64 : base(securityProtocolType)
66 this.sslStream = stream;
67 this.clientCertificateRequired = clientCertificateRequired;
69 // Convert the System.Security cert to a Mono Cert
70 MonoX509.X509Certificate cert = new MonoX509.X509Certificate(serverCertificate.GetRawCertData());
72 // Add server certificate to the certificate collection
73 this.ServerSettings.Certificates = new MonoX509.X509CertificateCollection();
74 this.ServerSettings.Certificates.Add(cert);
76 this.ServerSettings.UpdateCertificateRSA();
78 // Add requested certificate types
79 this.ServerSettings.CertificateTypes = new ClientCertificateType[1];
80 this.ServerSettings.CertificateTypes[0] = ClientCertificateType.RSA;
82 // Add certificate authorities
83 this.ServerSettings.DistinguisedNames = new string[0];