[utils] Fix inet_pton fallback.
[mono.git] / mcs / class / System / Mono.AppleTls / AppleTlsProvider.cs
1 #if SECURITY_DEP && MONO_FEATURE_APPLETLS
2 //
3 // AppleTlsProvider.cs
4 //
5 // Author:
6 //       Martin Baulig <martin.baulig@xamarin.com>
7 //
8 // Copyright (c) 2015 Xamarin, Inc.
9 //
10
11 #if MONO_SECURITY_ALIAS
12 extern alias MonoSecurity;
13 #endif
14
15 using System;
16 using System.IO;
17 using System.Threading;
18 using System.Threading.Tasks;
19 using System.Net.Security;
20 using System.Security.Authentication;
21 using System.Security.Cryptography.X509Certificates;
22
23 using MNS = Mono.Net.Security;
24 #if MONO_SECURITY_ALIAS
25 using MonoSecurity::Mono.Security.Interface;
26 #else
27 using Mono.Security.Interface;
28 #endif
29
30 namespace Mono.AppleTls
31 {
32         class AppleTlsProvider : MonoTlsProvider
33         {
34                 public override string Name {
35                         get { return "apple-tls"; }
36                 }
37
38                 public override Guid ID {
39                         get { return MNS.MonoTlsProviderFactory.AppleTlsId; }
40                 }
41
42                 public override IMonoSslStream CreateSslStream (
43                         Stream innerStream, bool leaveInnerStreamOpen,
44                         MonoTlsSettings settings = null)
45                 {
46                         return SslStream.CreateMonoSslStream (innerStream, leaveInnerStreamOpen, this, settings);
47                 }
48
49                 internal override IMonoSslStream CreateSslStreamInternal (
50                         SslStream sslStream, Stream innerStream, bool leaveInnerStreamOpen,
51                         MonoTlsSettings settings)
52                 {
53                         return new AppleTlsStream (innerStream, leaveInnerStreamOpen, sslStream, settings, this);
54                 }
55
56                 public override bool SupportsSslStream {
57                         get { return true; }
58                 }
59
60                 public override bool SupportsMonoExtensions {
61                         get { return true; }
62                 }
63
64                 public override bool SupportsConnectionInfo {
65                         get { return true; }
66                 }
67
68                 public override SslProtocols SupportedProtocols {
69                         get { return SslProtocols.Tls12 | SslProtocols.Tls11 | SslProtocols.Tls; }
70                 }
71
72                 internal override bool ValidateCertificate (
73                         ICertificateValidator2 validator, string targetHost, bool serverMode,
74                         X509CertificateCollection certificates, bool wantsChain, ref X509Chain chain,
75                         ref MonoSslPolicyErrors errors, ref int status11)
76                 {
77                         if (wantsChain)
78                                 chain = MNS.SystemCertificateValidator.CreateX509Chain (certificates);
79                         return AppleCertificateHelper.InvokeSystemCertificateValidator (validator, targetHost, serverMode, certificates, ref errors, ref status11);
80                 }
81         }
82 }
83 #endif