1 /* Transport Security Layer (TLS)
2 * Copyright (c) 2003-2004 Carlos Guzman Alvarez
4 * Permission is hereby granted, free of charge, to any person
5 * obtaining a copy of this software and associated documentation
6 * files (the "Software"), to deal in the Software without restriction,
7 * including without limitation the rights to use, copy, modify, merge,
8 * publish, distribute, sublicense, and/or sell copies of the Software,
9 * and to permit persons to whom the Software is furnished to do so,
10 * subject to the following conditions:
12 * The above copyright notice and this permission notice shall be included
13 * in all copies or substantial portions of the Software.
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
17 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * 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];