[System]: Remove unpredictable pluggable setup and cleanup APIs.
authorMartin Baulig <martin.baulig@xamarin.com>
Tue, 19 Jan 2016 17:16:46 +0000 (18:16 +0100)
committerMartin Baulig <martin.baulig@xamarin.com>
Wed, 20 Jan 2016 00:03:06 +0000 (01:03 +0100)
(cherry picked from commit 2d945d75bb1abb3a750e6fa2bc0facb768228dbb)

34 files changed:
mcs/class/Makefile
mcs/class/Mono.Security.Providers.DotNet/Mono.Security.Providers.DotNet/DotNetTlsProvider.cs
mcs/class/Mono.Security.Providers.NewSystemSource/Mono.Security.Providers.NewSystemSource.dll.sources
mcs/class/Mono.Security.Providers.NewSystemSource/Properties/AssemblyInfo.cs
mcs/class/Mono.Security.Providers.NewTls/Makefile [new file with mode: 0644]
mcs/class/Mono.Security.Providers.NewTls/Mono.Security.Providers.NewTls.dll.sources [new file with mode: 0644]
mcs/class/Mono.Security.Providers.NewTls/Mono.Security.Providers.NewTls/ITlsConfiguration.cs [new file with mode: 0644]
mcs/class/Mono.Security.Providers.NewTls/Mono.Security.Providers.NewTls/ITlsContext.cs [new file with mode: 0644]
mcs/class/Mono.Security.Providers.NewTls/Mono.Security.Providers.NewTls/MonoNewTlsStream.cs [new file with mode: 0644]
mcs/class/Mono.Security.Providers.NewTls/Mono.Security.Providers.NewTls/MonoNewTlsStreamFactory.cs [new file with mode: 0644]
mcs/class/Mono.Security.Providers.NewTls/Mono.Security.Providers.NewTls/NewTlsProvider.cs [new file with mode: 0644]
mcs/class/Mono.Security.Providers.NewTls/Mono.Security.Providers.NewTls/TlsContextWrapper.cs [new file with mode: 0644]
mcs/class/Mono.Security.Providers.NewTls/Mono.Security.Providers.NewTls/TlsProviderFactory.cs [new file with mode: 0644]
mcs/class/Mono.Security.Providers.NewTls/Properties/AssemblyInfo.cs [new file with mode: 0644]
mcs/class/Mono.Security.Providers.NewTls/mobile_Mono.Security.Providers.NewTls.dll.sources [new file with mode: 0644]
mcs/class/Mono.Security.Providers.NewTls/mobile_static_Mono.Security.Providers.NewTls.dll.sources [new file with mode: 0644]
mcs/class/Mono.Security.Providers.OldTls/Mono.Security.Providers.OldTls/OldTlsProvider.cs
mcs/class/Mono.Security/Assembly/AssemblyInfo.cs
mcs/class/Mono.Security/Mono.Security.Interface/BufferOffsetSize.cs [new file with mode: 0644]
mcs/class/Mono.Security/Mono.Security.Interface/IMonoTlsContext.cs
mcs/class/Mono.Security/Mono.Security.Interface/MonoTlsProvider.cs
mcs/class/Mono.Security/Mono.Security.Interface/MonoTlsProviderFactory.cs
mcs/class/Mono.Security/Mono.Security.Interface/SecretParameters.cs [new file with mode: 0644]
mcs/class/Mono.Security/Mono.Security.Interface/SecureBuffer.cs [new file with mode: 0644]
mcs/class/Mono.Security/Mono.Security.Interface/TlsBuffer.cs [new file with mode: 0644]
mcs/class/Mono.Security/Mono.Security.Interface/TlsMultiBuffer.cs [new file with mode: 0644]
mcs/class/Mono.Security/Mono.Security.dll.sources
mcs/class/Mono.Security/mobile_Mono.Security.dll.sources
mcs/class/System/Assembly/AssemblyInfo.cs
mcs/class/System/Mono.Net.Security/MonoDefaultTlsProvider.cs
mcs/class/System/Mono.Net.Security/MonoTlsProviderFactory.cs
mcs/class/System/Mono.Net.Security/MonoTlsProviderImpl.cs
mcs/class/System/Mono.Net.Security/NoReflectionHelper.cs
mcs/class/corlib/Assembly/AssemblyInfo.cs

index ae9651fc59e5beaa755cf690483571fd7e33c72d..a0dd126efacb776fefa47b3c8ff98cb1d107d0fc 100644 (file)
@@ -54,7 +54,8 @@ mobile_common_dirs := \
        Microsoft.CSharp \
        Mono.Security.Providers.DotNet  \
        Mono.Security.Providers.OldTls \
-       Mono.Security.Providers.NewSystemSource
+       Mono.Security.Providers.NewSystemSource \
+       Mono.Security.Providers.NewTls
 
 mobile_static_dirs := \
        $(mobile_common_dirs)   \
@@ -133,6 +134,7 @@ xammac_4_5_dirs := \
        Mono.Security.Providers.DotNet \
        Mono.Security.Providers.OldTls \
        Mono.Security.Providers.NewSystemSource \
+       Mono.Security.Providers.NewTls \
        $(pcl_facade_dirs)
 
 net_4_x_dirs := \
@@ -217,7 +219,9 @@ net_4_x_dirs := \
        System.Net.Http.Formatting \
        System.Web.Http \
        System.Web.Http.SelfHost \
-       System.Web.Http.WebHost
+       System.Web.Http.WebHost \
+       Mono.Security.Providers.NewSystemSource \
+       Mono.Security.Providers.NewTls
 
 # These are the subdirs which depends on libs in net_4_x_dirs
 # or have proper dependencies between each other
@@ -262,7 +266,6 @@ net_4_x_parallel_dirs := \
        System.Xml.Serialization \
        Mono.Security.Providers.DotNet \
        Mono.Security.Providers.OldTls \
-       Mono.Security.Providers.NewSystemSource \
        System.DirectoryServices.Protocols      \
        RabbitMQ.Client                 \
        Microsoft.VisualC               \
index 74b2a8e71c7a19a2367ab46498d2b91144978f51..3be685a46d240ac731cc9403d0c72761bc0b75ee 100644 (file)
@@ -62,7 +62,7 @@ namespace Mono.Security.Providers.DotNet
                        get { return false; }
                }
 
-               public override bool SupportsTlsContext {
+               internal override bool SupportsTlsContext {
                        get { return false; }
                }
 
@@ -88,7 +88,7 @@ namespace Mono.Security.Providers.DotNet
                        return new DotNetSslStreamImpl (innerStream, leaveInnerStreamOpen, this, validation_callback, selection_callback);
                }
 
-               public override IMonoTlsContext CreateTlsContext (
+               internal override IMonoTlsContext CreateTlsContext (
                        string hostname, bool serverMode, TlsProtocols protocolFlags,
                        X509Certificate serverCertificate, X509CertificateCollection clientCertificates,
                        bool remoteCertRequired, MonoEncryptionPolicy encryptionPolicy,
index 80d1238c4b625723dfc42f14af952fb82fbd8f80..c8974658e27d8f153be3ac0e74f7dd56369b5de7 100644 (file)
@@ -30,3 +30,4 @@
 ../System/Mono.Net.Security/IMonoTlsProvider.cs
 ../System/Mono.Net.Security/MonoTlsProviderFactory.cs
 ../System/Mono.Net.Security/MonoTlsProviderWrapper.cs
+
index b3178b82c3ad029aae19f7cf81d16f0bb2d804fb..23ba5bb253714f3a38ba9edf282d5147a5c9ba3a 100644 (file)
@@ -45,3 +45,4 @@ using System.Runtime.InteropServices;
 [assembly: NeutralResourcesLanguage ("en-US")]
 
 [assembly: InternalsVisibleTo ("Mono.Security.Providers.NewTls, PublicKey=002400000480000094000000060200000024000052534131000400001100000003336d6aed41624ca156ab579881fe90a576f1dfec48378fc94e4e440f4556776224e2d70c18996d91f36227f539fdb44340e07651f1455a489b29a7e6219a8f85e52b0f8588b4f8a857746a8468d37b556223d1452f3fcbaf0f269cdf1900ceb68f69485dc5887750d19571030c732331e00387d9b813a9ad52891087301793")]
+[assembly: InternalsVisibleTo ("Mono.Security.Providers.NewTls, PublicKey=002400000480000094000000060200000024000052534131000400000100010079159977d2d03a8e6bea7a2e74e8d1afcc93e8851974952bb480a12c9134474d04062447c37e0e68c080536fcf3c3fbe2ff9c979ce998475e506e8ce82dd5b0f350dc10e93bf2eeecf874b24770c5081dbea7447fddafa277b22de47d6ffea449674a4f9fccf84d15069089380284dbdd35f46cdff12a1bd78e4ef0065d016df")]
diff --git a/mcs/class/Mono.Security.Providers.NewTls/Makefile b/mcs/class/Mono.Security.Providers.NewTls/Makefile
new file mode 100644 (file)
index 0000000..a5f6412
--- /dev/null
@@ -0,0 +1,12 @@
+thisdir = class/Mono.Security.Providers.NewTls
+SUBDIRS = 
+include ../../build/rules.make
+
+LIBRARY = Mono.Security.Providers.NewTls.dll
+LIB_MCS_FLAGS = -unsafe -nowarn:1030 -keyfile:../mono.pub -delaysign -r:System.dll \
+       -r:NewSystemSource=Mono.Security.Providers.NewSystemSource.dll -r:Mono.Security.dll
+
+include ../../build/library.make
+
+$(the_lib): ../Mono.Security/Makefile
+
diff --git a/mcs/class/Mono.Security.Providers.NewTls/Mono.Security.Providers.NewTls.dll.sources b/mcs/class/Mono.Security.Providers.NewTls/Mono.Security.Providers.NewTls.dll.sources
new file mode 100644 (file)
index 0000000..12d8a20
--- /dev/null
@@ -0,0 +1,13 @@
+./Properties/AssemblyInfo.cs
+../../build/common/SR.cs
+../../build/common/Consts.cs
+../../build/common/Locale.cs
+
+./Mono.Security.Providers.NewTls/ITlsConfiguration.cs
+./Mono.Security.Providers.NewTls/ITlsContext.cs
+
+./Mono.Security.Providers.NewTls/MonoNewTlsStream.cs
+./Mono.Security.Providers.NewTls/MonoNewTlsStreamFactory.cs
+./Mono.Security.Providers.NewTls/NewTlsProvider.cs
+./Mono.Security.Providers.NewTls/TlsContextWrapper.cs
+./Mono.Security.Providers.NewTls/TlsProviderFactory.cs
diff --git a/mcs/class/Mono.Security.Providers.NewTls/Mono.Security.Providers.NewTls/ITlsConfiguration.cs b/mcs/class/Mono.Security.Providers.NewTls/Mono.Security.Providers.NewTls/ITlsConfiguration.cs
new file mode 100644 (file)
index 0000000..401afd7
--- /dev/null
@@ -0,0 +1,47 @@
+//
+// ITlsContext.cs
+//
+// Author:
+//       Martin Baulig <martin.baulig@xamarin.com>
+//
+// Copyright (c) 2015-2016 Xamarin, Inc.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+
+using System;
+using System.Security.Cryptography;
+
+using Mono.Security.Interface;
+using MX = Mono.Security.X509;
+
+namespace Mono.Security.Providers.NewTls
+{
+       interface ITlsConfiguration
+       {
+               bool HasCredentials {
+                       get;
+               }
+
+               void SetCertificate (MX.X509Certificate certificate, AsymmetricAlgorithm privateKey);
+
+               bool? AskForClientCertificate {
+                       get; set;
+               }
+       }
+}
diff --git a/mcs/class/Mono.Security.Providers.NewTls/Mono.Security.Providers.NewTls/ITlsContext.cs b/mcs/class/Mono.Security.Providers.NewTls/Mono.Security.Providers.NewTls/ITlsContext.cs
new file mode 100644 (file)
index 0000000..0d69805
--- /dev/null
@@ -0,0 +1,70 @@
+//
+// ITlsContext.cs
+//
+// Author:
+//       Martin Baulig <martin.baulig@xamarin.com>
+//
+// Copyright (c) 2015-2016 Xamarin, Inc.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+
+extern alias NewSystemSource;
+
+using System;
+using System.Security.Cryptography;
+
+using Mono.Security.Interface;
+using MX = Mono.Security.X509;
+
+namespace Mono.Security.Providers.NewTls
+{
+       interface ITlsContext : IDisposable
+       {
+               bool IsValid {
+                       get;
+               }
+
+               TlsException LastError {
+                       get;
+               }
+
+               bool ReceivedCloseNotify {
+                       get;
+               }
+
+               MonoTlsConnectionInfo ConnectionInfo {
+                       get;
+               }
+
+               MX.X509Certificate GetRemoteCertificate (out MX.X509CertificateCollection remoteCertificateStore);
+
+               bool VerifyRemoteCertificate ();
+
+               int GenerateNextToken (TlsBuffer incoming, TlsMultiBuffer outgoing);
+
+               int DecryptMessage (ref TlsBuffer incoming);
+
+               int EncryptMessage (ref TlsBuffer incoming);
+
+               byte[] CreateAlert (Alert alert);
+
+               byte[] CreateHelloRequest ();
+       }
+}
+
diff --git a/mcs/class/Mono.Security.Providers.NewTls/Mono.Security.Providers.NewTls/MonoNewTlsStream.cs b/mcs/class/Mono.Security.Providers.NewTls/Mono.Security.Providers.NewTls/MonoNewTlsStream.cs
new file mode 100644 (file)
index 0000000..6117f0f
--- /dev/null
@@ -0,0 +1,93 @@
+//
+// MonoNewTlsStream.cs
+//
+// Author:
+//       Martin Baulig <martin.baulig@xamarin.com>
+//
+// Copyright (c) 2015 Xamarin, Inc.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+
+extern alias NewSystemSource;
+
+using EncryptionPolicy = NewSystemSource::System.Net.Security.EncryptionPolicy;
+using LocalCertificateSelectionCallback = NewSystemSource::System.Net.Security.LocalCertificateSelectionCallback;
+using RemoteCertificateValidationCallback = NewSystemSource::System.Net.Security.RemoteCertificateValidationCallback;
+using SslStream = NewSystemSource::System.Net.Security.SslStream;
+
+using System;
+using System.IO;
+using System.Threading.Tasks;
+
+using MSI = Mono.Security.Interface;
+
+using XAuthenticatedStream = System.Net.Security.AuthenticatedStream;
+using System.Security.Cryptography.X509Certificates;
+
+namespace Mono.Security.Providers.NewTls
+{
+       public class MonoNewTlsStream : SslStream, MSI.IMonoSslStream
+       {
+               MSI.MonoTlsProvider provider;
+
+               internal MonoNewTlsStream (Stream innerStream, MSI.MonoTlsProvider provider, MSI.MonoTlsSettings settings)
+                       : this (innerStream, false, provider, settings)
+               {
+               }
+
+               internal MonoNewTlsStream (Stream innerStream, bool leaveOpen, MSI.MonoTlsProvider provider, MSI.MonoTlsSettings settings)
+                       : base (innerStream, leaveOpen, EncryptionPolicy.RequireEncryption, provider, settings)
+               {
+                       this.provider = provider;
+               }
+
+               public MSI.MonoTlsProvider Provider {
+                       get { return provider; }
+               }
+
+               new public bool IsClosed {
+                       get { return base.IsClosed; }
+               }
+
+               public MSI.MonoTlsConnectionInfo GetConnectionInfo ()
+               {
+                       return GetMonoConnectionInfo ();
+               }
+
+               public Task Shutdown ()
+               {
+                       return Task.Factory.FromAsync ((state, result) => BeginShutdown (state, result), EndShutdown, null);
+               }
+
+               public Task RequestRenegotiation ()
+               {
+                       return Task.Factory.FromAsync ((state, result) => BeginRenegotiate (state, result), EndRenegotiate, null);
+               }
+
+                X509Certificate MSI.IMonoSslStream.InternalLocalCertificate {
+                       get { return InternalLocalCertificate; }
+               }
+
+               XAuthenticatedStream MSI.IMonoSslStream.AuthenticatedStream {
+                       get { return this; }
+               }
+       }
+}
+
+
diff --git a/mcs/class/Mono.Security.Providers.NewTls/Mono.Security.Providers.NewTls/MonoNewTlsStreamFactory.cs b/mcs/class/Mono.Security.Providers.NewTls/Mono.Security.Providers.NewTls/MonoNewTlsStreamFactory.cs
new file mode 100644 (file)
index 0000000..d39f1bb
--- /dev/null
@@ -0,0 +1,91 @@
+//
+// MonoNewTlsStreamFactory.cs
+//
+// Author:
+//       Martin Baulig <martin.baulig@xamarin.com>
+//
+// Copyright (c) 2015 Xamarin, Inc.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+
+extern alias NewSystemSource;
+
+using XEncryptionPolicy = NewSystemSource::System.Net.Security.EncryptionPolicy;
+using XSslPolicyErrors = NewSystemSource::System.Net.Security.SslPolicyErrors;
+using XLocalCertificateSelectionCallback = NewSystemSource::System.Net.Security.LocalCertificateSelectionCallback;
+using XRemoteCertificateValidationCallback = NewSystemSource::System.Net.Security.RemoteCertificateValidationCallback;
+
+using System;
+using System.IO;
+using System.Net.Security;
+using System.Security.Authentication;
+
+using Mono.Security.Interface;
+
+using PSSCX = System.Security.Cryptography.X509Certificates;
+using SSCX = System.Security.Cryptography.X509Certificates;
+
+namespace Mono.Security.Providers.NewTls
+{
+       public static class MonoNewTlsStreamFactory
+       {
+               internal static IMonoSslStream CreateSslStream (
+                       Stream innerStream, bool leaveInnerStreamOpen,
+                       MonoTlsProvider provider, MonoTlsSettings settings = null)
+               {
+                       return new MonoNewTlsStream (innerStream, leaveInnerStreamOpen, provider, settings);
+               }
+
+               public static MonoNewTlsStream CreateServer (
+                       Stream innerStream, bool leaveOpen, MonoTlsProvider provider, MonoTlsSettings settings,
+                       SSCX.X509Certificate serverCertificate, bool clientCertificateRequired,
+                       SslProtocols enabledSslProtocols, bool checkCertificateRevocation)
+               {
+                       var stream = new MonoNewTlsStream (innerStream, leaveOpen, provider, settings);
+
+                       try {
+                               stream.AuthenticateAsServer (serverCertificate, clientCertificateRequired, enabledSslProtocols, checkCertificateRevocation);
+                       } catch (Exception ex) {
+                               var tlsEx = stream.LastError;
+                               if (tlsEx != null)
+                                       throw new AggregateException (ex, tlsEx);
+                               throw;
+                       }
+
+                       return stream;
+               }
+
+               public static MonoNewTlsStream CreateClient (
+                       Stream innerStream, bool leaveOpen, MonoTlsProvider provider, MonoTlsSettings settings,
+                       string targetHost, PSSCX.X509CertificateCollection clientCertificates, SslProtocols enabledSslProtocols, bool checkCertificateRevocation)
+               {
+                       var stream = new MonoNewTlsStream (innerStream, leaveOpen, provider, settings);
+
+                       try {
+                               stream.AuthenticateAsClient (targetHost, clientCertificates, enabledSslProtocols, checkCertificateRevocation);
+                       } catch (Exception ex) {
+                               var tlsEx = stream.LastError;
+                               if (tlsEx != null)
+                                       throw new AggregateException (ex, tlsEx);
+                               throw;
+                       }
+                       return stream;
+               }
+       }
+}
diff --git a/mcs/class/Mono.Security.Providers.NewTls/Mono.Security.Providers.NewTls/NewTlsProvider.cs b/mcs/class/Mono.Security.Providers.NewTls/Mono.Security.Providers.NewTls/NewTlsProvider.cs
new file mode 100644 (file)
index 0000000..e2b347f
--- /dev/null
@@ -0,0 +1,95 @@
+//
+// NewTlsProvider.cs
+//
+// Author:
+//       Martin Baulig <martin.baulig@xamarin.com>
+//
+// Copyright (c) 2015 Xamarin, Inc.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+
+extern alias NewSystemSource;
+
+using System;
+using System.IO;
+using System.Net;
+using System.Net.Security;
+using System.Security.Authentication;
+
+using MSI = Mono.Security.Interface;
+using MX = Mono.Security.X509;
+
+using PSSCX = System.Security.Cryptography.X509Certificates;
+using SSCX = System.Security.Cryptography.X509Certificates;
+
+namespace Mono.Security.Providers.NewTls
+{
+       public class NewTlsProvider : MSI.MonoTlsProvider
+       {
+               static readonly Guid id = new Guid ("e5ff34f1-8b7a-4aa6-aff9-24719d709693");
+
+               public override Guid ID {
+                       get { return id; }
+               }
+
+               public override string Name {
+                       get { return "newtls"; }
+               }
+
+               public override bool SupportsSslStream {
+                       get { return true; }
+               }
+
+               public override bool SupportsConnectionInfo {
+                       get { return true; }
+               }
+
+               public override bool SupportsMonoExtensions {
+                       get { return true; }
+               }
+
+               internal override bool SupportsTlsContext {
+                       get { return true; }
+               }
+
+               public override SslProtocols SupportedProtocols {
+                       get { return SslProtocols.Tls12 | SslProtocols.Tls11 | SslProtocols.Tls; }
+               }
+
+               public override MSI.IMonoSslStream CreateSslStream (
+                       Stream innerStream, bool leaveInnerStreamOpen,
+                       MSI.MonoTlsSettings settings = null)
+               {
+                       return MonoNewTlsStreamFactory.CreateSslStream (innerStream, leaveInnerStreamOpen, this, settings);
+               }
+
+               internal override MSI.IMonoTlsContext CreateTlsContext (
+                       string hostname, bool serverMode, MSI.TlsProtocols protocolFlags,
+                       SSCX.X509Certificate serverCertificate, PSSCX.X509CertificateCollection clientCertificates,
+                       bool remoteCertRequired, MSI.MonoEncryptionPolicy encryptionPolicy,
+                       MSI.MonoTlsSettings settings)
+               {
+                       var config = TlsProviderFactory.CreateTlsConfiguration (
+                               hostname, serverMode, protocolFlags, serverCertificate,
+                               remoteCertRequired, settings);
+                       return new TlsContextWrapper (config, serverMode);
+               }
+       }
+}
+
diff --git a/mcs/class/Mono.Security.Providers.NewTls/Mono.Security.Providers.NewTls/TlsContextWrapper.cs b/mcs/class/Mono.Security.Providers.NewTls/Mono.Security.Providers.NewTls/TlsContextWrapper.cs
new file mode 100644 (file)
index 0000000..389dd1a
--- /dev/null
@@ -0,0 +1,221 @@
+//
+// TlsContextWrapper.cs
+//
+// Author:
+//       Martin Baulig <martin.baulig@xamarin.com>
+//
+// Copyright (c) 2015 Xamarin, Inc.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+
+extern alias NewSystemSource;
+
+using System;
+using System.Security.Cryptography;
+
+using SSCX = System.Security.Cryptography.X509Certificates;
+using PSSCX = System.Security.Cryptography.X509Certificates;
+
+using MSI = Mono.Security.Interface;
+using MX = Mono.Security.X509;
+
+namespace Mono.Security.Providers.NewTls
+{
+       class TlsContextWrapper : IDisposable, MSI.IMonoTlsContext
+       {
+               ITlsConfiguration config;
+               ITlsContext context;
+               bool serverMode;
+
+               public TlsContextWrapper (ITlsConfiguration config, bool serverMode)
+               {
+                       this.config = config;
+                       this.serverMode = serverMode;
+               }
+
+               public bool IsServer {
+                       get { return serverMode; }
+               }
+
+               public bool IsValid {
+                       get { return context != null && context.IsValid; }
+               }
+
+               public void Initialize (MSI.IMonoTlsEventSink eventSink)
+               {
+                       if (context != null)
+                               throw new InvalidOperationException ();
+                       context = TlsProviderFactory.CreateTlsContext (config, serverMode, eventSink);
+               }
+
+               void Clear ()
+               {
+                       if (context != null) {
+                               context.Dispose ();
+                               context = null;
+                       }
+               }
+
+               public ITlsConfiguration Configuration {
+                       get {
+                               if (config == null)
+                                       throw new ObjectDisposedException ("TlsConfiguration");
+                               return config;
+                       }
+               }
+
+               public ITlsContext Context {
+                       get {
+                               if (!IsValid)
+                                       throw new ObjectDisposedException ("TlsContext");
+                               return context;
+                       }
+               }
+
+               public bool HasCredentials {
+                       get { return Configuration.HasCredentials; }
+               }
+
+               public void SetCertificate (SSCX.X509Certificate certificate, AsymmetricAlgorithm privateKey)
+               {
+                       var monoCert = new MX.X509Certificate (certificate.GetRawCertData ());
+                       Configuration.SetCertificate (monoCert, privateKey);
+               }
+
+               public int GenerateNextToken (MSI.IBufferOffsetSize incoming, out MSI.IBufferOffsetSize outgoing)
+               {
+                       var input = incoming != null ? new MSI.TlsBuffer (BOSWrapper.Wrap (incoming)) : null;
+                       var output = new MSI.TlsMultiBuffer ();
+                       var retval = Context.GenerateNextToken (input, output);
+                       if (output.IsEmpty)
+                               outgoing = null;
+                       outgoing = BOSWrapper.Wrap (output.StealBuffer ());
+                       return (int)retval;
+               }
+
+               public int EncryptMessage (ref MSI.IBufferOffsetSize incoming)
+               {
+                       var buffer = new MSI.TlsBuffer (BOSWrapper.Wrap (incoming));
+                       var retval = Context.EncryptMessage (ref buffer);
+                       incoming = BOSWrapper.Wrap (buffer.GetRemaining ());
+                       return (int)retval;
+               }
+
+               public int DecryptMessage (ref MSI.IBufferOffsetSize incoming)
+               {
+                       var buffer = new MSI.TlsBuffer (BOSWrapper.Wrap (incoming));
+                       var retval = Context.DecryptMessage (ref buffer);
+                       incoming = buffer != null ? BOSWrapper.Wrap (buffer.GetRemaining ()) : null;
+                       return (int)retval;
+               }
+
+               class BOSWrapper : MSI.IBufferOffsetSize
+               {
+                       public byte[] Buffer {
+                               get;
+                               private set;
+                       }
+
+                       public int Offset {
+                               get;
+                               private set;
+                       }
+
+                       public int Size {
+                               get;
+                               private set;
+                       }
+
+                       BOSWrapper (byte[] buffer, int offset, int size)
+                       {
+                               Buffer = buffer;
+                               Offset = offset;
+                               Size = size;
+                       }
+
+                       public static BOSWrapper Wrap (MSI.IBufferOffsetSize bos)
+                       {
+                               return bos != null ? new BOSWrapper (bos.Buffer, bos.Offset, bos.Size) : null;
+                       }
+               }
+
+               public byte[] CreateCloseNotify ()
+               {
+                       return Context.CreateAlert (new MSI.Alert (MSI.AlertLevel.Warning, MSI.AlertDescription.CloseNotify));
+               }
+
+               public byte[] CreateHelloRequest ()
+               {
+                       return Context.CreateHelloRequest ();
+               }
+
+               public SSCX.X509Certificate GetRemoteCertificate (out PSSCX.X509CertificateCollection remoteCertificateStore)
+               {
+                       MX.X509CertificateCollection monoCollection;
+                       var remoteCert = Context.GetRemoteCertificate (out monoCollection);
+                       if (remoteCert == null) {
+                               remoteCertificateStore = null;
+                               return null;
+                       }
+
+                       remoteCertificateStore = new PSSCX.X509CertificateCollection ();
+                       foreach (var cert in monoCollection) {
+                               remoteCertificateStore.Add (new PSSCX.X509Certificate2 (cert.RawData));
+                       }
+                       return new PSSCX.X509Certificate2 (remoteCert.RawData);
+
+               }
+
+               public bool VerifyRemoteCertificate ()
+               {
+                       return Context.VerifyRemoteCertificate ();
+               }
+
+               public Exception LastError {
+                       get {
+                               if (context != null)
+                                       return context.LastError;
+                               return null;
+                       }
+               }
+
+               public bool ReceivedCloseNotify {
+                       get {
+                               return Context.ReceivedCloseNotify;
+                       }
+               }
+
+               public MSI.MonoTlsConnectionInfo GetConnectionInfo ()
+               {
+                       return Context.ConnectionInfo;
+               }
+
+               public void Dispose ()
+               {
+                       Dispose (true);
+                       GC.SuppressFinalize (this);
+               }
+
+               void Dispose (bool disposing)
+               {
+                       Clear ();
+               }
+       }
+}
+
diff --git a/mcs/class/Mono.Security.Providers.NewTls/Mono.Security.Providers.NewTls/TlsProviderFactory.cs b/mcs/class/Mono.Security.Providers.NewTls/Mono.Security.Providers.NewTls/TlsProviderFactory.cs
new file mode 100644 (file)
index 0000000..92d8ab0
--- /dev/null
@@ -0,0 +1,97 @@
+//
+// TlsProviderFactory.cs
+//
+// Author:
+//       Martin Baulig <martin.baulig@xamarin.com>
+//
+// Copyright (c) 2015-2016 Xamarin, Inc.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+
+extern alias NewSystemSource;
+
+using System;
+using System.IO;
+
+using System.Net;
+using System.Net.Security;
+using System.Security.Authentication;
+
+using MSI = Mono.Security.Interface;
+using MX = Mono.Security.X509;
+
+using PSSCX = System.Security.Cryptography.X509Certificates;
+using SSCX = System.Security.Cryptography.X509Certificates;
+
+namespace Mono.Security.Providers.NewTls
+{
+       static class TlsProviderFactory
+       {
+               const string assemblyName = "Mono.Security.NewTls, Version=4.0.0.0, Culture=neutral, PublicKeyToken=84e3aee7225169c2";
+               const string tlsConfigTypeName = "Mono.Security.NewTls.TlsConfiguration";
+               const string tlsContextTypeName = "Mono.Security.NewTls.TlsContext";
+
+               static object CreateInstance (string typeName, object[] args)
+               {
+                       var type = Type.GetType (typeName + ", " + assemblyName);
+                       return Activator.CreateInstance (type, args);
+               }
+
+               internal static ITlsConfiguration CreateTlsConfiguration (
+                       string hostname, bool serverMode, MSI.TlsProtocols protocolFlags,
+                       SSCX.X509Certificate serverCertificate, bool remoteCertRequired,
+                       MSI.MonoTlsSettings settings)
+               {
+                       object[] args;
+                       ITlsConfiguration config;
+                       if (serverMode) {
+                               var cert = (PSSCX.X509Certificate2)serverCertificate;
+                               var monoCert = new MX.X509Certificate (cert.RawData);
+                               args = new object[] {
+                                       (MSI.TlsProtocols)protocolFlags,
+                                       (MSI.MonoTlsSettings)settings,
+                                       monoCert,
+                                       cert.PrivateKey
+                               };
+                       } else {
+                               args = new object[] {
+                                       (MSI.TlsProtocols)protocolFlags,
+                                       (MSI.MonoTlsSettings)settings,
+                                       hostname
+                               };
+                       }
+
+                       config = (ITlsConfiguration)CreateInstance (tlsConfigTypeName, args);
+
+                       if (serverMode && remoteCertRequired)
+                               config.AskForClientCertificate = true;
+
+                       return config;
+               }
+
+               internal static ITlsContext CreateTlsContext (
+                       ITlsConfiguration config, bool serverMode,
+                       MSI.IMonoTlsEventSink eventSink)
+               {
+                       return (ITlsContext)CreateInstance (
+                               tlsContextTypeName,
+                               new object[] { config, serverMode, eventSink });
+               }
+       }
+}
diff --git a/mcs/class/Mono.Security.Providers.NewTls/Properties/AssemblyInfo.cs b/mcs/class/Mono.Security.Providers.NewTls/Properties/AssemblyInfo.cs
new file mode 100644 (file)
index 0000000..e369093
--- /dev/null
@@ -0,0 +1,47 @@
+//
+// AssemblyInfo.cs
+//
+// Author:
+//       Martin Baulig <martin.baulig@xamarin.com>
+//
+// Copyright (c) 2015 Xamarin, Inc.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+using System;
+using System.Reflection;
+using System.Resources;
+using System.Security;
+using System.Security.Permissions;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+
+// General Information about the system assembly
+
+[assembly: AssemblyVersion (Consts.FxVersion)]
+
+[assembly: AssemblyCompany ("Xamarin")]
+[assembly: AssemblyCopyright ("(c) 2015 Xamarin")]
+[assembly: AssemblyDescription ("Mono.Security.Providers.NewTls.dll")]
+[assembly: AssemblyProduct ("MONO CLI")]
+[assembly: AssemblyTitle ("Mono.Security.Providers.NewTls.dll")]
+[assembly: CLSCompliant (false)]
+[assembly: ComVisible (false)]
+[assembly: NeutralResourcesLanguage ("en-US")]
+
+[assembly: InternalsVisibleTo ("Mono.Security.NewTls, PublicKey=002400000480000094000000060200000024000052534131000400001100000003336d6aed41624ca156ab579881fe90a576f1dfec48378fc94e4e440f4556776224e2d70c18996d91f36227f539fdb44340e07651f1455a489b29a7e6219a8f85e52b0f8588b4f8a857746a8468d37b556223d1452f3fcbaf0f269cdf1900ceb68f69485dc5887750d19571030c732331e00387d9b813a9ad52891087301793")]
diff --git a/mcs/class/Mono.Security.Providers.NewTls/mobile_Mono.Security.Providers.NewTls.dll.sources b/mcs/class/Mono.Security.Providers.NewTls/mobile_Mono.Security.Providers.NewTls.dll.sources
new file mode 100644 (file)
index 0000000..7218dab
--- /dev/null
@@ -0,0 +1,7 @@
+Properties/AssemblyInfo.cs
+
+Mono.Security.Providers.NewTls/ITlsConfiguration.cs
+Mono.Security.Providers.NewTls/ITlsContext.cs
+
+Mono.Security.Providers.NewTls/MonoNewTlsStream.cs
+Mono.Security.Providers.NewTls/MonoNewTlsStreamFactory.cs
diff --git a/mcs/class/Mono.Security.Providers.NewTls/mobile_static_Mono.Security.Providers.NewTls.dll.sources b/mcs/class/Mono.Security.Providers.NewTls/mobile_static_Mono.Security.Providers.NewTls.dll.sources
new file mode 100644 (file)
index 0000000..baded51
--- /dev/null
@@ -0,0 +1 @@
+#include mobile_Mono.Security.Providers.NewTls.dll.sources
index 82bd9d5437bd23023a90c219665526fe28e396c5..4532a17e02fb2e8c9031c89fc407ef0bf51f54ee 100644 (file)
@@ -58,7 +58,7 @@ namespace Mono.Security.Providers.OldTls
                        get { return false; }
                }
 
-               public override bool SupportsTlsContext {
+               internal override bool SupportsTlsContext {
                        get { return false; }
                }
 
@@ -74,7 +74,7 @@ namespace Mono.Security.Providers.OldTls
                        return new MNS.Private.MonoSslStreamImpl (impl);
                }
 
-               public override IMonoTlsContext CreateTlsContext (
+               internal override IMonoTlsContext CreateTlsContext (
                        string hostname, bool serverMode, TlsProtocols protocolFlags,
                        X509Certificate serverCertificate, X509CertificateCollection clientCertificates,
                        bool remoteCertRequired, MonoEncryptionPolicy encryptionPolicy,
index 85244bc1e4fb8b2255b9025e442ec8236a9ceae2..55e17aad73d7012b058a7295e29c9a4e050974f4 100644 (file)
@@ -60,6 +60,13 @@ using System.Runtime.InteropServices;
 [assembly: AssemblyDelaySign (true)]
 [assembly: AssemblyKeyFile ("../mono.pub")]
 
-#if MOBILE
+#if NET_2_1
 [assembly: InternalsVisibleTo ("System, PublicKey=00240000048000009400000006020000002400005253413100040000010001008D56C76F9E8649383049F383C44BE0EC204181822A6C31CF5EB7EF486944D032188EA1D3920763712CCB12D75FB77E9811149E6148E5D32FBAAB37611C1878DDC19E20EF135D0CB2CFF2BFEC3D115810C3D9069638FE4BE215DBF795861920E5AB6F7DB2E2CEEF136AC23D5DD2BF031700AEC232F6C6B1C785B4305C123B37AB")]
+#else
+[assembly: InternalsVisibleTo ("System, PublicKey=00000000000000000400000000000000")]
 #endif
+
+[assembly: InternalsVisibleTo ("Mono.Security.Providers.NewTls, PublicKey=002400000480000094000000060200000024000052534131000400000100010079159977d2d03a8e6bea7a2e74e8d1afcc93e8851974952bb480a12c9134474d04062447c37e0e68c080536fcf3c3fbe2ff9c979ce998475e506e8ce82dd5b0f350dc10e93bf2eeecf874b24770c5081dbea7447fddafa277b22de47d6ffea449674a4f9fccf84d15069089380284dbdd35f46cdff12a1bd78e4ef0065d016df")]
+[assembly: InternalsVisibleTo ("Mono.Security.Providers.OldTls, PublicKey=002400000480000094000000060200000024000052534131000400000100010079159977d2d03a8e6bea7a2e74e8d1afcc93e8851974952bb480a12c9134474d04062447c37e0e68c080536fcf3c3fbe2ff9c979ce998475e506e8ce82dd5b0f350dc10e93bf2eeecf874b24770c5081dbea7447fddafa277b22de47d6ffea449674a4f9fccf84d15069089380284dbdd35f46cdff12a1bd78e4ef0065d016df")]
+[assembly: InternalsVisibleTo ("Mono.Security.Providers.DotNet, PublicKey=002400000480000094000000060200000024000052534131000400000100010079159977d2d03a8e6bea7a2e74e8d1afcc93e8851974952bb480a12c9134474d04062447c37e0e68c080536fcf3c3fbe2ff9c979ce998475e506e8ce82dd5b0f350dc10e93bf2eeecf874b24770c5081dbea7447fddafa277b22de47d6ffea449674a4f9fccf84d15069089380284dbdd35f46cdff12a1bd78e4ef0065d016df")]
+[assembly: InternalsVisibleTo ("Mono.Security.Providers.NewSystemSource, PublicKey=002400000480000094000000060200000024000052534131000400000100010079159977d2d03a8e6bea7a2e74e8d1afcc93e8851974952bb480a12c9134474d04062447c37e0e68c080536fcf3c3fbe2ff9c979ce998475e506e8ce82dd5b0f350dc10e93bf2eeecf874b24770c5081dbea7447fddafa277b22de47d6ffea449674a4f9fccf84d15069089380284dbdd35f46cdff12a1bd78e4ef0065d016df")]
diff --git a/mcs/class/Mono.Security/Mono.Security.Interface/BufferOffsetSize.cs b/mcs/class/Mono.Security/Mono.Security.Interface/BufferOffsetSize.cs
new file mode 100644 (file)
index 0000000..7138962
--- /dev/null
@@ -0,0 +1,96 @@
+//
+// BufferOffsetSize.cs
+//
+// Author:
+//       Martin Baulig <martin.baulig@xamarin.com>
+//
+// Copyright (c) 2014-2016 Xamarin Inc. (http://www.xamarin.com)
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+using System;
+
+namespace Mono.Security.Interface
+{
+       public class BufferOffsetSize : SecretParameters, IBufferOffsetSize
+       {
+               public byte[] Buffer {
+                       get;
+                       private set;
+               }
+
+               public int Offset {
+                       get;
+                       internal set;
+               }
+
+               public int Size {
+                       get { return EndOffset - Offset; }
+               }
+
+               public int EndOffset {
+                       get;
+                       internal set;
+               }
+
+               public BufferOffsetSize (byte[] buffer, int offset, int size)
+               {
+                       Buffer = buffer;
+                       Offset = offset;
+                       EndOffset = offset + size;
+               }
+
+               public BufferOffsetSize (byte[] buffer)
+                       : this (buffer, 0, buffer.Length)
+               {
+               }
+
+               public BufferOffsetSize (int size)
+                       : this (new byte [size])
+               {
+               }
+
+               public byte[] GetBuffer ()
+               {
+                       var copy = new byte [Size];
+                       Array.Copy (Buffer, Offset, copy, 0, Size);
+                       return copy;
+               }
+
+               public void TruncateTo (int newSize)
+               {
+                       if (newSize > Size)
+                               throw new ArgumentException ("newSize");
+                       EndOffset = Offset + newSize;
+               }
+
+               protected void SetBuffer (byte[] buffer, int offset, int size)
+               {
+                       Buffer = buffer;
+                       Offset = offset;
+                       EndOffset = offset + size;
+               }
+
+               protected override void Clear ()
+               {
+                       Buffer = null;
+                       Offset = EndOffset = 0;
+               }
+       }
+}
+
index 508bdc4fe61532fa6bee06ad7b1dcf2fa2de34a8..d1ac4e27d0eda996688dada49ede134f9e2245f3 100644 (file)
@@ -29,7 +29,7 @@ using System.Security.Cryptography.X509Certificates;
 
 namespace Mono.Security.Interface
 {
-       public interface IMonoTlsContext : IDisposable
+       interface IMonoTlsContext : IDisposable
        {
                bool IsServer {
                        get;
index 740d79536481597c38bebe58cea2470c5fd8fdbe..753cd97e5a23952166c2f74f6effd7524a407c6d 100644 (file)
@@ -72,6 +72,10 @@ namespace Mono.Security.Interface
 
        public abstract class MonoTlsProvider
        {
+               internal MonoTlsProvider ()
+               {
+               }
+
                public abstract Guid ID {
                        get;
                }
@@ -155,11 +159,11 @@ namespace Mono.Security.Interface
                 * The managed SSPI implementation from the new TLS code.
                 */
 
-               public abstract bool SupportsTlsContext {
+               internal abstract bool SupportsTlsContext {
                        get;
                }
 
-               public abstract IMonoTlsContext CreateTlsContext (
+               internal abstract IMonoTlsContext CreateTlsContext (
                        string hostname, bool serverMode, TlsProtocols protocolFlags,
                        X509Certificate serverCertificate, X509CertificateCollection clientCertificates,
                        bool remoteCertRequired, MonoEncryptionPolicy encryptionPolicy,
index 9548da030fe1d3029c71ec35f0811337896d15e5..770680cbb8cab51b7ffb47504fa2ef4beeaafa6b 100644 (file)
@@ -72,14 +72,14 @@ namespace Mono.Security.Interface
                }
 
                /*
-                * Installs a custom TLS Provider.
+                * Selects the default TLS Provider.
                 *
                 * May only be called at application startup and will throw
                 * @InvalidOperationException if a provider has already been installed.
                 */
-               public static void InstallProvider (MonoTlsProvider provider)
+               public static void SetDefaultProvider (string name)
                {
-                       NoReflectionHelper.InstallProvider (provider);
+                       NoReflectionHelper.SetDefaultProvider (name);
                }
 
                /*
diff --git a/mcs/class/Mono.Security/Mono.Security.Interface/SecretParameters.cs b/mcs/class/Mono.Security/Mono.Security.Interface/SecretParameters.cs
new file mode 100644 (file)
index 0000000..a225ba6
--- /dev/null
@@ -0,0 +1,67 @@
+//
+// SecretParameters.cs
+//
+// Author:
+//       Martin Baulig <martin.baulig@xamarin.com>
+//
+// Copyright (c) 2014-2016 Xamarin Inc. (http://www.xamarin.com)
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+using System;
+
+namespace Mono.Security.Interface
+{
+       public abstract class SecretParameters : IDisposable
+       {
+               protected abstract void Clear ();
+
+               bool disposed;
+
+               protected void CheckDisposed ()
+               {
+                       if (disposed)
+                               throw new ObjectDisposedException (GetType ().Name);
+               }
+
+               protected static void Clear (byte[] array)
+               {
+                       Array.Clear (array, 0, array.Length);
+               }
+
+               public void Dispose ()
+               {
+                       Dispose (true);
+                       GC.SuppressFinalize (this);
+               }
+
+               void Dispose (bool disposing)
+               {
+                       if (!disposed) {
+                               disposed = true;
+                               Clear ();
+                       }
+               }
+
+               ~SecretParameters ()
+               {
+                       Dispose (false);
+               }
+       }
+}
+
diff --git a/mcs/class/Mono.Security/Mono.Security.Interface/SecureBuffer.cs b/mcs/class/Mono.Security/Mono.Security.Interface/SecureBuffer.cs
new file mode 100644 (file)
index 0000000..fc05f7a
--- /dev/null
@@ -0,0 +1,86 @@
+//
+// SecureBuffer.cs
+//
+// Author:
+//       Martin Baulig <martin.baulig@xamarin.com>
+//
+// Copyright (c) 2014-2016 Xamarin Inc. (http://www.xamarin.com)
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+using System;
+
+namespace Mono.Security.Interface
+{
+       public class SecureBuffer : SecretParameters, IBufferOffsetSize
+       {
+               byte[] buffer;
+
+               public byte[] Buffer {
+                       get {
+                               CheckDisposed ();
+                               return buffer;
+                       }
+               }
+
+               public int Size {
+                       get {
+                               CheckDisposed ();
+                               return buffer != null ? buffer.Length : 0;
+                       }
+               }
+
+               int IBufferOffsetSize.Offset {
+                       get { return 0; }
+               }
+
+               public SecureBuffer (int size)
+               {
+                       buffer = new byte [size];
+               }
+
+               public SecureBuffer (byte[] buffer)
+               {
+                       this.buffer = buffer;
+               }
+
+               public byte[] StealBuffer ()
+               {
+                       CheckDisposed ();
+                       var retval = this.buffer;
+                       this.buffer = null;
+                       return retval;
+               }
+
+               public static SecureBuffer CreateCopy (byte[] buffer)
+               {
+                       var copy = new byte [buffer.Length];
+                       Array.Copy (buffer, copy, buffer.Length);
+                       return new SecureBuffer (copy);
+               }
+
+               protected override void Clear ()
+               {
+                       if (buffer != null) {
+                               Array.Clear (buffer, 0, buffer.Length);
+                               buffer = null;
+                       }
+               }
+       }
+}
+
diff --git a/mcs/class/Mono.Security/Mono.Security.Interface/TlsBuffer.cs b/mcs/class/Mono.Security/Mono.Security.Interface/TlsBuffer.cs
new file mode 100644 (file)
index 0000000..be3c007
--- /dev/null
@@ -0,0 +1,334 @@
+//
+// TlsBuffer.cs
+//
+// Author:
+//       Martin Baulig <martin.baulig@xamarin.com>
+//
+// Copyright (c) 2014-2016 Xamarin Inc. (http://www.xamarin.com)
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+using System;
+
+namespace Mono.Security.Interface
+{
+       public class TlsBuffer : SecretParameters
+       {
+               public int Position {
+                       get; set;
+               }
+
+               public int Remaining {
+                       get { return Size - (Position - Offset); }
+               }
+
+               public byte[] Buffer {
+                       get { return innerBuffer.Buffer; }
+               }
+
+               public int Offset {
+                       get { return innerBuffer.Offset; }
+               }
+
+               public int Size {
+                       get { return innerBuffer.Size; }
+               }
+
+               public int EndOffset {
+                       get { return Offset + Size; }
+               }
+
+               IBufferOffsetSize innerBuffer;
+
+               protected TlsBuffer ()
+                       : this (null, 0, 0)
+               {
+               }
+
+               public TlsBuffer (IBufferOffsetSize bos)
+               {
+                       innerBuffer = bos;
+                       Position = bos.Offset;
+               }
+
+               public TlsBuffer (byte[] buffer, int offset, int size)
+                       : this (new BufferOffsetSize (buffer, offset, size))
+               {
+               }
+
+               public TlsBuffer (byte[] buffer)
+                       : this (buffer, 0, buffer.Length)
+               {
+               }
+
+               public TlsBuffer (int size)
+                       : this (new byte [size], 0, size)
+               {
+               }
+
+               public byte ReadByte ()
+               {
+                       if (Position >= EndOffset)
+                               throw new TlsException (AlertDescription.DecodeError, "Buffer overflow");
+                       return Buffer [Position++];
+               }
+
+               public short ReadInt16 ()
+               {
+                       if (Position + 1 >= EndOffset)
+                               throw new TlsException (AlertDescription.DecodeError, "Buffer overflow");
+                       var retval = (short)(Buffer [Position] << 8 | Buffer [Position + 1]);
+                       Position += 2;
+                       return retval;
+               }
+
+               public int ReadInt24 ()
+               {
+                       if (Position + 2 >= EndOffset)
+                               throw new TlsException (AlertDescription.DecodeError, "Buffer overflow");
+                       var retval = ((Buffer [Position] << 16) | (Buffer [Position+1] << 8) | Buffer [Position+2]);
+                       Position += 3;
+                       return retval;
+               }
+
+               public int ReadInt32 ()
+               {
+                       if (Position + 3 >= EndOffset)
+                               throw new TlsException (AlertDescription.DecodeError, "Buffer overflow");
+                       var retval = ((Buffer [Position] << 24) | (Buffer [Position+1] << 16) | (Buffer [Position+2] << 8) | Buffer [Position+3]);
+                       Position += 4;
+                       return retval;
+               }
+
+               public TlsBuffer ReadBuffer (int length)
+               {
+                       if (Position + length > EndOffset)
+                               throw new TlsException (AlertDescription.DecodeError, "Buffer overflow");
+                       var retval = new TlsBuffer (Buffer, Position, length);
+                       Position += length;
+                       return retval;
+               }
+
+               public IBufferOffsetSize GetRemaining ()
+               {
+                       return new BufferOffsetSize (Buffer, Position, Remaining);
+               }
+
+               protected virtual void MakeRoomInternal (int size)
+               {
+                       if (Position + size > EndOffset)
+                               throw new TlsException (AlertDescription.DecodeError, "Buffer overflow");
+               }
+
+               public void Write (byte value)
+               {
+                       MakeRoomInternal (1);
+                       Buffer [Position++] = value;
+               }
+
+               public void Write (short value)
+               {
+                       MakeRoomInternal (2);
+                       WriteInt16 (Buffer, Position, value);
+                       Position += 2;
+               }
+
+               public static void WriteInt16 (byte[] buffer, int offset, short value)
+               {
+                       buffer[offset] = ((byte)(value >> 8));
+                       buffer[offset+1] = ((byte)value);
+               }
+
+               public void Write (int value)
+               {
+                       MakeRoomInternal (4);
+                       WriteInt32 (Buffer, Position, value);
+                       Position += 4;
+               }
+
+               public void WriteInt24 (int value)
+               {
+                       MakeRoomInternal (3);
+                       WriteInt24 (Buffer, Position, value);
+                       Position += 3;
+               }
+
+               #pragma warning disable 3001
+               public void Write (ulong value)
+               #pragma warning restore 3001
+               {
+                       MakeRoomInternal (8);
+                       WriteInt64 (Buffer, Position, value);
+                       Position += 8;
+               }
+
+               public static void WriteInt24 (byte[] buffer, int offset, int value)
+               {
+                       buffer[offset] = ((byte)(value >> 16));
+                       buffer[offset+1] = ((byte)(value >> 8));
+                       buffer[offset+2] = ((byte)value);
+               }
+
+               public static void WriteInt32 (byte[] buffer, int offset, int value)
+               {
+                       buffer[offset] = ((byte)(value >> 24));
+                       buffer[offset+1] = ((byte)(value >> 16));
+                       buffer[offset+2] = ((byte)(value >> 8));
+                       buffer[offset+3] = ((byte)value);
+               }
+
+               #pragma warning disable 3001
+               public static void WriteInt64 (byte[] buffer, int offset, ulong value)
+               #pragma warning restore 3001
+               {
+                       buffer[offset] = (byte) (value >> 56);
+                       buffer[offset+1] = (byte) (value >> 48);
+                       buffer[offset+2] = (byte) (value >> 40);
+                       buffer[offset+3] = (byte) (value >> 32);
+                       buffer[offset+4] = (byte) (value >> 24);
+                       buffer[offset+5] = (byte) (value >> 16);
+                       buffer[offset+6] = (byte) (value >> 8);
+                       buffer[offset+7] = (byte) value;
+               }
+
+               public void Write (byte[] buffer)
+               {
+                       Write (buffer, 0, buffer.Length);
+               }
+
+               public void Write (byte[] buffer, int offset, int size)
+               {
+                       MakeRoomInternal (size);
+                       Array.Copy (buffer, offset, Buffer, Position, size);
+                       Position += size;
+               }
+
+               public void Write (IBufferOffsetSize buffer)
+               {
+                       Write (buffer.Buffer, buffer.Offset, buffer.Size);
+               }
+
+               public SecureBuffer ReadSecureBuffer (int count)
+               {
+                       return new SecureBuffer (ReadBytes (count));
+               }
+
+               public byte[] ReadBytes (int count)
+               {
+                       if (Position + count > EndOffset)
+                               throw new TlsException (AlertDescription.DecodeError, "Buffer overflow");
+                       var retval = new byte [count];
+                       Array.Copy (Buffer, Position, retval, 0, count);
+                       Position += count;
+                       return retval;
+               }
+
+               internal static bool Compare (SecureBuffer buffer1, SecureBuffer buffer2)
+               {
+                       if (buffer1 == null || buffer2 == null)
+                               return false;
+
+                       if (buffer1.Size != buffer2.Size)
+                               return false;
+
+                       for (int i = 0; i < buffer1.Size; i++) {
+                               if (buffer1.Buffer [i] != buffer2.Buffer [i])
+                                       return false;
+                       }
+                       return true;
+               }
+
+               public static bool Compare (IBufferOffsetSize buffer1, IBufferOffsetSize buffer2)
+               {
+                       if (buffer1 == null || buffer2 == null)
+                               return false;
+
+                       if (buffer1.Size != buffer2.Size)
+                               return false;
+
+                       for (int i = 0; i < buffer1.Size; i++) {
+                               if (buffer1.Buffer [buffer1.Offset + i] != buffer2.Buffer [buffer2.Offset + i])
+                                       return false;
+                       }
+                       return true;
+               }
+
+               public static bool Compare (byte[] buffer1, byte[] buffer2)
+               {
+                       if (buffer1 == null || buffer2 == null)
+                               return false;
+
+                       return Compare (buffer1, 0, buffer1.Length, buffer2, 0, buffer2.Length);
+               }
+
+               public static bool Compare (byte[] buffer1, int offset1, int size1, byte[] buffer2, int offset2, int size2)
+               {
+                       if (buffer1 == null || buffer2 == null)
+                               return false;
+
+                       if (size1 != size2)
+                               return false;
+
+                       for (int i = 0; i < size1; i++) {
+                               if (buffer1 [offset1 + i] != buffer2 [offset2 + i])
+                                       return false;
+                       }
+                       return true;
+
+               }
+
+               public static int ConstantTimeCompare (byte[] buffer1, int offset1, int size1, byte[] buffer2, int offset2, int size2)
+               {
+                       int status = 0;
+                       int effectiveSize;
+                       if (size1 < size2) {
+                               status--;
+                               effectiveSize = size1;
+                       } else if (size2 < size1) {
+                               status--;
+                               effectiveSize = size2;
+                       } else {
+                               effectiveSize = size1;
+                       }
+
+                       for (int i = 0; i < effectiveSize; i++) {
+                               if (buffer1 [offset1 + i] != buffer2 [offset2 + i])
+                                       status--;
+                       }
+
+                       return status;
+               }
+
+               protected void SetBuffer (byte[] buffer, int offset, int size)
+               {
+                       innerBuffer = new BufferOffsetSize (buffer, offset, size);
+               }
+
+               protected override void Clear ()
+               {
+                       var disposable = innerBuffer as IDisposable;
+                       if (disposable != null)
+                               disposable.Dispose ();
+                       innerBuffer = null;
+                       Position = 0;
+               }
+
+               public static readonly byte[] EmptyArray = new byte [0];
+       }
+}
+
diff --git a/mcs/class/Mono.Security/Mono.Security.Interface/TlsMultiBuffer.cs b/mcs/class/Mono.Security/Mono.Security.Interface/TlsMultiBuffer.cs
new file mode 100644 (file)
index 0000000..de2975a
--- /dev/null
@@ -0,0 +1,119 @@
+//
+// TlsMultiBuffer.cs
+//
+// Author:
+//       Martin Baulig <martin.baulig@xamarin.com>
+//
+// Copyright (c) 2014-2016 Xamarin Inc. (http://www.xamarin.com)
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+using System;
+
+namespace Mono.Security.Interface
+{
+       public class TlsMultiBuffer
+       {
+               MemoryChunk first, last;
+
+               private class MemoryChunk : BufferOffsetSize
+               {
+                       public MemoryChunk next;
+
+                       public MemoryChunk (byte[] buffer, int offset, int size)
+                               : base (buffer, offset, size)
+                       {
+                       }
+               }
+
+               public bool IsEmpty {
+                       get { return first == null; }
+               }
+
+               public bool IsSingle {
+                       get { return first != null && first.next == null; }
+               }
+
+               public void Add (TlsBuffer buffer)
+               {
+                       Add (buffer.Buffer, buffer.Offset, buffer.Size);
+               }
+
+               public void Add (byte[] buffer)
+               {
+                       Add (buffer, 0, buffer.Length);
+               }
+
+               public void Add (byte[] buffer, int offset, int size)
+               {
+                       var chunk = new MemoryChunk (buffer, offset, size);
+                       if (last == null)
+                               first = last = chunk;
+                       else {
+                               last.next = chunk;
+                               last = chunk;
+                       }
+               }
+
+               public BufferOffsetSize[] GetBufferArray ()
+               {
+                       int count = 0;
+                       for (var ptr = first; ptr != null; ptr = ptr.next)
+                               count++;
+                       var array = new BufferOffsetSize [count];
+                       count = 0;
+                       for (var ptr = first; ptr != null; ptr = ptr.next)
+                               array [count++] = ptr;
+                       return array;
+               }
+
+               public void Clear ()
+               {
+                       for (var ptr = first; ptr != null; ptr = ptr.next)
+                               ptr.Dispose ();
+                       first = last = null;
+               }
+
+               public BufferOffsetSize GetBuffer ()
+               {
+                       int totalSize = 0;
+                       for (var ptr = first; ptr != null; ptr = ptr.next)
+                               totalSize += ptr.Size;
+
+                       var outBuffer = new BufferOffsetSize (new byte [totalSize]);
+                       int offset = 0;
+                       for (var ptr = first; ptr != null; ptr = ptr.next) {
+                               Buffer.BlockCopy (ptr.Buffer, ptr.Offset, outBuffer.Buffer, offset, ptr.Size);
+                               offset += ptr.Size;
+                       }
+                       return outBuffer;
+               }
+
+               public BufferOffsetSize StealBuffer ()
+               {
+                       if (IsSingle) {
+                               var retval = first;
+                               first = last = null;
+                               return retval;
+                       }
+
+                       return GetBuffer ();
+               }
+       }
+}
+
index 7d6e4aaca19172150a6f2e8f4d3f3d4c8ed95aa7..7330f81b7be20dedc948fa3528216673d7a20af4 100644 (file)
 ./Mono.Security.Interface/TlsException.cs
 ./Mono.Security.Interface/TlsProtocolCode.cs
 ./Mono.Security.Interface/TlsProtocols.cs
+
+./Mono.Security.Interface/BufferOffsetSize.cs
+./Mono.Security.Interface/SecretParameters.cs
+./Mono.Security.Interface/SecureBuffer.cs
+./Mono.Security.Interface/TlsBuffer.cs
+./Mono.Security.Interface/TlsMultiBuffer.cs
\ No newline at end of file
index dba5c34020948fc64bac9fa1063dc72d127dbaa7..05cc4faad16b660c7fd75e70f302800576974fcb 100644 (file)
 ./Mono.Security.Protocol.Tls.Handshake.Server/TlsServerKeyExchange.cs
 ./Mono.Xml/MiniParser.cs
 ./Mono.Xml/SecurityParser.cs
+
+./Mono.Security.Interface/BufferOffsetSize.cs
+./Mono.Security.Interface/SecretParameters.cs
+./Mono.Security.Interface/SecureBuffer.cs
+./Mono.Security.Interface/TlsBuffer.cs
+./Mono.Security.Interface/TlsMultiBuffer.cs
index 4f0d50bf06504991c01ec1ac1abb9c8a538406f6..a7651da891f7900adbb0b0cead4fa0ad03b94ce3 100644 (file)
@@ -80,4 +80,6 @@ using System.Runtime.InteropServices;
 
        [assembly: InternalsVisibleTo ("Mono.Security.Providers.NewSystemSource, PublicKey=002400000480000094000000060200000024000052534131000400000100010079159977d2d03a8e6bea7a2e74e8d1afcc93e8851974952bb480a12c9134474d04062447c37e0e68c080536fcf3c3fbe2ff9c979ce998475e506e8ce82dd5b0f350dc10e93bf2eeecf874b24770c5081dbea7447fddafa277b22de47d6ffea449674a4f9fccf84d15069089380284dbdd35f46cdff12a1bd78e4ef0065d016df")]
        [assembly: InternalsVisibleTo ("Mono.Security.Providers.OldTls, PublicKey=002400000480000094000000060200000024000052534131000400000100010079159977d2d03a8e6bea7a2e74e8d1afcc93e8851974952bb480a12c9134474d04062447c37e0e68c080536fcf3c3fbe2ff9c979ce998475e506e8ce82dd5b0f350dc10e93bf2eeecf874b24770c5081dbea7447fddafa277b22de47d6ffea449674a4f9fccf84d15069089380284dbdd35f46cdff12a1bd78e4ef0065d016df")]
+       [assembly: InternalsVisibleTo ("Mono.Security.Providers.NewTls, PublicKey=002400000480000094000000060200000024000052534131000400000100010079159977d2d03a8e6bea7a2e74e8d1afcc93e8851974952bb480a12c9134474d04062447c37e0e68c080536fcf3c3fbe2ff9c979ce998475e506e8ce82dd5b0f350dc10e93bf2eeecf874b24770c5081dbea7447fddafa277b22de47d6ffea449674a4f9fccf84d15069089380284dbdd35f46cdff12a1bd78e4ef0065d016df")]
+       [assembly: InternalsVisibleTo ("Mono.Security.Providers.DotNet, PublicKey=002400000480000094000000060200000024000052534131000400000100010079159977d2d03a8e6bea7a2e74e8d1afcc93e8851974952bb480a12c9134474d04062447c37e0e68c080536fcf3c3fbe2ff9c979ce998475e506e8ce82dd5b0f350dc10e93bf2eeecf874b24770c5081dbea7447fddafa277b22de47d6ffea449674a4f9fccf84d15069089380284dbdd35f46cdff12a1bd78e4ef0065d016df")]
        [assembly: InternalsVisibleTo ("Mono.Security, PublicKey=002400000480000094000000060200000024000052534131000400000100010079159977d2d03a8e6bea7a2e74e8d1afcc93e8851974952bb480a12c9134474d04062447c37e0e68c080536fcf3c3fbe2ff9c979ce998475e506e8ce82dd5b0f350dc10e93bf2eeecf874b24770c5081dbea7447fddafa277b22de47d6ffea449674a4f9fccf84d15069089380284dbdd35f46cdff12a1bd78e4ef0065d016df")]
index c39b2144781bb83dd9f2c0f68a82b030e5ce3382..d6f6e5296f454a65ac7ca9f27b6d3e001087e539 100644 (file)
@@ -86,7 +86,7 @@ namespace Mono.Net.Security.Private
                        get { return false; }
                }
 
-               public override bool SupportsTlsContext {
+               internal override bool SupportsTlsContext {
                        get { return false; }
                }
 
index 85023644aee04643c8df76549a27d3ab92786b6e..f2cf321677deab8b6c4a5810deb8587c56934f29 100644 (file)
@@ -134,25 +134,35 @@ namespace Mono.Net.Security
 
 #if SECURITY_DEP && !MONO_FEATURE_NEW_SYSTEM_SOURCE
 
-#if !MOBILE
                static Dictionary<string,string> providerRegistration;
 
-               internal static void RegisterProvider (string name, string type)
+               static Type LookupProviderType (string name, bool throwOnError)
                {
                        lock (locker) {
                                InitializeProviderRegistration ();
-                               providerRegistration.Add (name, type);
+                               string typeName;
+                               if (!providerRegistration.TryGetValue (name, out typeName)) {
+                                       if (throwOnError)
+                                               throw new NotSupportedException (string.Format ("No such TLS Provider: `{0}'.", name));
+                                       return null;
+                               }
+                               var type = Type.GetType (typeName, false);
+                               if (type == null && throwOnError)
+                                       throw new NotSupportedException (string.Format ("Could not find TLS Provider: `{0}'.", typeName));
+                               return type;
                        }
                }
 
-               static string LookupProvider (string name)
+               static MSI.MonoTlsProvider LookupProvider (string name, bool throwOnError)
                {
-                       lock (locker) {
-                               InitializeProviderRegistration ();
-                               string type;
-                               if (!providerRegistration.TryGetValue (name, out type))
-                                       type = null;
-                               return type;
+                       var type = LookupProviderType (name, throwOnError);
+                       if (type == null)
+                               return null;
+
+                       try {
+                               return (MSI.MonoTlsProvider)Activator.CreateInstance (type);
+                       } catch (Exception ex) {
+                               throw new NotSupportedException (string.Format ("Unable to instantiate TLS Provider `{0}'.", type), ex);
                        }
                }
 
@@ -162,11 +172,12 @@ namespace Mono.Net.Security
                                if (providerRegistration != null)
                                        return;
                                providerRegistration = new Dictionary<string,string> ();
-                               providerRegistration.Add ("newtls", "Mono.Security.Providers.NewTls.NewTlsProvider, Mono.Security.Providers.NewTls, Version=4.0.0.0, Culture=neutral, PublicKeyToken=84e3aee7225169c2");
-                               providerRegistration.Add ("oldtls", "Mono.Security.Providers.OldTls.OldTlsProvider, Mono.Security.Providers.OldTls, Version=4.0.0.0, Culture=neutral, PublicKeyToken=84e3aee7225169c2");
+                               providerRegistration.Add ("newtls", "Mono.Security.Providers.NewTls.NewTlsProvider, Mono.Security.Providers.NewTls, Version=4.0.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756");
+                               providerRegistration.Add ("oldtls", "Mono.Security.Providers.OldTls.OldTlsProvider, Mono.Security.Providers.OldTls, Version=4.0.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756");
                        }
                }
 
+#if !MOBILE
                static IMonoTlsProvider TryDynamicLoad ()
                {
                        var variable = Environment.GetEnvironmentVariable ("MONO_TLS_PROVIDER");
@@ -176,25 +187,7 @@ namespace Mono.Net.Security
                        if (string.Equals (variable, "default", StringComparison.OrdinalIgnoreCase))
                                return null;
 
-                       string typeName;
-                       if (variable.IndexOfAny (new char[] { ',', '.', '=' }) > 0) {
-                               typeName = variable;
-                       } else {
-                               typeName = LookupProvider (variable);
-                               if (typeName == null)
-                                       throw new NotSupportedException (string.Format ("No such TLS Provider: `{0}'.", typeName));
-                       }
-
-                       var type = Type.GetType (typeName, false);
-                       if (type == null)
-                               throw new NotSupportedException (string.Format ("Could not find TLS Provider: `{0}'.", typeName));
-
-                       MSI.MonoTlsProvider provider;
-                       try {
-                               provider = (MSI.MonoTlsProvider)Activator.CreateInstance (type);
-                       } catch (Exception ex) {
-                               throw new NotSupportedException (string.Format ("Unable to instantiate TLS Provider `{0}'.", typeName), ex);
-                       }
+                       var provider = LookupProvider (variable, true);
 
                        return new Private.MonoTlsProviderWrapper (provider);
                }
@@ -245,9 +238,10 @@ namespace Mono.Net.Security
                        }
                }
 
-               internal static void InstallProvider (MSI.MonoTlsProvider provider)
+               internal static void SetDefaultProvider (string name)
                {
                        lock (locker) {
+                               var provider = LookupProvider (name, true);
                                currentProvider = new Private.MonoTlsProviderWrapper (provider);
                        }
                }
index 4216e5809f3ca9b44bb2684d485093463118554b..b0ae5d82c724627ca2360a856b159af606f23104 100644 (file)
@@ -100,7 +100,7 @@ namespace Mono.Net.Security.Private
                        bool remoteCertRequired, MSI.MonoEncryptionPolicy encryptionPolicy,
                        MSI.MonoTlsSettings settings);
 
-               public override MSI.IMonoTlsContext CreateTlsContext (
+               internal override MSI.IMonoTlsContext CreateTlsContext (
                        string hostname, bool serverMode, MSI.TlsProtocols protocolFlags,
                        X509Certificate serverCertificate, XX509CertificateCollection clientCertificates,
                        bool remoteCertRequired, MSI.MonoEncryptionPolicy encryptionPolicy,
index f4ccac81cb059fa3e847e0b449cdf1f55622ee96..a11fcec2c194ed559e80f3ead0f3fb7a4dc82931 100644 (file)
@@ -84,10 +84,10 @@ namespace Mono.Net.Security
                        }
                }
 
-               internal static void InstallProvider (object provider)
+               internal static void SetDefaultProvider (string name)
                {
                        #if SECURITY_DEP
-                       MonoTlsProviderFactory.InstallProvider ((MSI.MonoTlsProvider)provider);
+                       MonoTlsProviderFactory.SetDefaultProvider (name);
                        #else
                        throw new NotSupportedException ();
                        #endif
index 818dc50039a6657de1396873df885376f49c4b67..b3284ea78796be7b38531510d7a79ffb72f7b7b2 100644 (file)
@@ -99,4 +99,3 @@ using System.Runtime.InteropServices;
 #endif
 
 [assembly: Guid ("BED7F4EA-1A96-11D2-8F08-00A0C9A6186D")]
-