e2b347fbe2b7cc4d2680c0cd3a00b095f5646a19
[mono.git] / mcs / class / Mono.Security.Providers.NewTls / Mono.Security.Providers.NewTls / NewTlsProvider.cs
1 //
2 // NewTlsProvider.cs
3 //
4 // Author:
5 //       Martin Baulig <martin.baulig@xamarin.com>
6 //
7 // Copyright (c) 2015 Xamarin, Inc.
8 //
9 // Permission is hereby granted, free of charge, to any person obtaining a copy
10 // of this software and associated documentation files (the "Software"), to deal
11 // in the Software without restriction, including without limitation the rights
12 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 // copies of the Software, and to permit persons to whom the Software is
14 // furnished to do so, subject to the following conditions:
15 //
16 // The above copyright notice and this permission notice shall be included in
17 // all copies or substantial portions of the Software.
18 //
19 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 // THE SOFTWARE.
26
27 extern alias NewSystemSource;
28
29 using System;
30 using System.IO;
31 using System.Net;
32 using System.Net.Security;
33 using System.Security.Authentication;
34
35 using MSI = Mono.Security.Interface;
36 using MX = Mono.Security.X509;
37
38 using PSSCX = System.Security.Cryptography.X509Certificates;
39 using SSCX = System.Security.Cryptography.X509Certificates;
40
41 namespace Mono.Security.Providers.NewTls
42 {
43         public class NewTlsProvider : MSI.MonoTlsProvider
44         {
45                 static readonly Guid id = new Guid ("e5ff34f1-8b7a-4aa6-aff9-24719d709693");
46
47                 public override Guid ID {
48                         get { return id; }
49                 }
50
51                 public override string Name {
52                         get { return "newtls"; }
53                 }
54
55                 public override bool SupportsSslStream {
56                         get { return true; }
57                 }
58
59                 public override bool SupportsConnectionInfo {
60                         get { return true; }
61                 }
62
63                 public override bool SupportsMonoExtensions {
64                         get { return true; }
65                 }
66
67                 internal override bool SupportsTlsContext {
68                         get { return true; }
69                 }
70
71                 public override SslProtocols SupportedProtocols {
72                         get { return SslProtocols.Tls12 | SslProtocols.Tls11 | SslProtocols.Tls; }
73                 }
74
75                 public override MSI.IMonoSslStream CreateSslStream (
76                         Stream innerStream, bool leaveInnerStreamOpen,
77                         MSI.MonoTlsSettings settings = null)
78                 {
79                         return MonoNewTlsStreamFactory.CreateSslStream (innerStream, leaveInnerStreamOpen, this, settings);
80                 }
81
82                 internal override MSI.IMonoTlsContext CreateTlsContext (
83                         string hostname, bool serverMode, MSI.TlsProtocols protocolFlags,
84                         SSCX.X509Certificate serverCertificate, PSSCX.X509CertificateCollection clientCertificates,
85                         bool remoteCertRequired, MSI.MonoEncryptionPolicy encryptionPolicy,
86                         MSI.MonoTlsSettings settings)
87                 {
88                         var config = TlsProviderFactory.CreateTlsConfiguration (
89                                 hostname, serverMode, protocolFlags, serverCertificate,
90                                 remoteCertRequired, settings);
91                         return new TlsContextWrapper (config, serverMode);
92                 }
93         }
94 }
95