Merge pull request #4327 from vkargov/vk-abcremedy
[mono.git] / mcs / class / System / Mono.Net.Security / LegacyTlsProvider.cs
1 //
2 // LegacyTlsProvider.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 #if SECURITY_DEP
27 #if MONO_SECURITY_ALIAS
28 extern alias MonoSecurity;
29 #endif
30
31 #if MONO_SECURITY_ALIAS
32 using MSI = MonoSecurity::Mono.Security.Interface;
33 #else
34 using MSI = Mono.Security.Interface;
35 #endif
36
37 using System;
38 using System.IO;
39 using System.Net;
40 using System.Net.Security;
41 using System.Security.Cryptography.X509Certificates;
42 using System.Security.Authentication;
43
44 namespace Mono.Net.Security
45 {
46         /*
47          * Strictly private - do not use outside the Mono.Net.Security directory.
48          */
49         class LegacyTlsProvider : MSI.MonoTlsProvider
50         {
51                 public override Guid ID {
52                         get { return MonoTlsProviderFactory.LegacyId; }
53                 }
54
55                 public override string Name {
56                         get { return "legacy"; }
57                 }
58
59                 public override bool SupportsSslStream {
60                         get { return true; }
61                 }
62
63                 public override bool SupportsConnectionInfo {
64                         get { return false; }
65                 }
66
67                 public override bool SupportsMonoExtensions {
68                         get { return false; }
69                 }
70
71                 public override SslProtocols SupportedProtocols {
72                         get { return SslProtocols.Tls; }
73                 }
74
75                 public override MSI.IMonoSslStream CreateSslStream (
76                         Stream innerStream, bool leaveInnerStreamOpen,
77                         MSI.MonoTlsSettings settings = null)
78                 {
79                         return SslStream.CreateMonoSslStream (innerStream, leaveInnerStreamOpen, this, settings);
80                 }
81
82                 internal override MSI.IMonoSslStream CreateSslStreamInternal (
83                         SslStream sslStream, Stream innerStream, bool leaveInnerStreamOpen,
84                         MSI.MonoTlsSettings settings)
85                 {
86                         return new Private.LegacySslStream (innerStream, leaveInnerStreamOpen, sslStream, this, settings);
87                 }
88
89                 internal override bool ValidateCertificate (
90                         MSI.ICertificateValidator2 validator, string targetHost, bool serverMode,
91                         X509CertificateCollection certificates, bool wantsChain, ref X509Chain chain,
92                         ref MSI.MonoSslPolicyErrors errors, ref int status11)
93                 {
94                         if (wantsChain)
95                                 chain = SystemCertificateValidator.CreateX509Chain (certificates);
96                         var xerrors = (SslPolicyErrors)errors;
97                         var result = SystemCertificateValidator.Evaluate (validator.Settings, targetHost, certificates, chain, ref xerrors, ref status11);
98                         errors = (MSI.MonoSslPolicyErrors)xerrors;
99                         return result;
100                 }
101         }
102 }
103 #endif
104