2 // MonoNewTlsStreamFactory.cs
5 // Martin Baulig <martin.baulig@xamarin.com>
7 // Copyright (c) 2015 Xamarin, Inc.
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:
16 // The above copyright notice and this permission notice shall be included in
17 // all copies or substantial portions of the Software.
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
27 extern alias NewSystemSource;
29 using XEncryptionPolicy = NewSystemSource::System.Net.Security.EncryptionPolicy;
30 using XSslPolicyErrors = NewSystemSource::System.Net.Security.SslPolicyErrors;
31 using XLocalCertificateSelectionCallback = NewSystemSource::System.Net.Security.LocalCertificateSelectionCallback;
32 using XRemoteCertificateValidationCallback = NewSystemSource::System.Net.Security.RemoteCertificateValidationCallback;
36 using System.Net.Security;
37 using System.Security.Authentication;
39 using Mono.Security.Interface;
41 using PSSCX = System.Security.Cryptography.X509Certificates;
42 using SSCX = System.Security.Cryptography.X509Certificates;
44 namespace Mono.Security.Providers.NewTls
46 public static class MonoNewTlsStreamFactory
48 internal static IMonoSslStream CreateSslStream (
49 Stream innerStream, bool leaveInnerStreamOpen,
50 MonoTlsProvider provider, MonoTlsSettings settings = null)
52 return new MonoNewTlsStream (innerStream, leaveInnerStreamOpen, provider, settings);
55 public static MonoNewTlsStream CreateServer (
56 Stream innerStream, bool leaveOpen, MonoTlsProvider provider, MonoTlsSettings settings,
57 SSCX.X509Certificate serverCertificate, bool clientCertificateRequired,
58 SslProtocols enabledSslProtocols, bool checkCertificateRevocation)
60 var stream = new MonoNewTlsStream (innerStream, leaveOpen, provider, settings);
63 stream.AuthenticateAsServer (serverCertificate, clientCertificateRequired, enabledSslProtocols, checkCertificateRevocation);
64 } catch (Exception ex) {
65 var tlsEx = stream.LastError;
67 throw new AggregateException (ex, tlsEx);
74 public static MonoNewTlsStream CreateClient (
75 Stream innerStream, bool leaveOpen, MonoTlsProvider provider, MonoTlsSettings settings,
76 string targetHost, PSSCX.X509CertificateCollection clientCertificates, SslProtocols enabledSslProtocols, bool checkCertificateRevocation)
78 var stream = new MonoNewTlsStream (innerStream, leaveOpen, provider, settings);
81 stream.AuthenticateAsClient (targetHost, clientCertificates, enabledSslProtocols, checkCertificateRevocation);
82 } catch (Exception ex) {
83 var tlsEx = stream.LastError;
85 throw new AggregateException (ex, tlsEx);