зеркало из https://github.com/mono/mono-tls.git
Add MonoConnection and friends; this requires the 'extern alias NewSystemSource'.
This commit is contained in:
Родитель
7cb8d65109
Коммит
4dcc23af75
|
@ -31,6 +31,7 @@
|
|||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="Mono.Security" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
|
@ -46,6 +47,9 @@
|
|||
<Compile Include="PrivateFile.cs" />
|
||||
<Compile Include="ServerCertificate.cs" />
|
||||
<Compile Include="SymmetricAlgorithmProxy.cs" />
|
||||
<Compile Include="MonoClient.cs" />
|
||||
<Compile Include="MonoConnection.cs" />
|
||||
<Compile Include="MonoServer.cs" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||
<ProjectExtensions>
|
||||
|
@ -74,5 +78,12 @@
|
|||
<Project>{CE125B3F-AD36-4EDD-B3D5-4CDBE430924A}</Project>
|
||||
<Name>Xamarin.AsyncTests</Name>
|
||||
</ProjectReference>
|
||||
<Reference Include="Mono.Security.Providers.NewSystemSource">
|
||||
<Aliases>NewSystemSource</Aliases>
|
||||
</Reference>
|
||||
<ProjectReference Include="..\Mono.Security.Providers\NewTls\Mono.Security.Providers.NewTls.csproj">
|
||||
<Project>{4B5EDBC8-F8EA-48E4-AA87-A3FC52202F01}</Project>
|
||||
<Name>Mono.Security.Providers.NewTls</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
</Project>
|
|
@ -0,0 +1,83 @@
|
|||
extern alias NewSystemSource;
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Net;
|
||||
using System.Net.Sockets;
|
||||
using System.Net.Security;
|
||||
using System.Diagnostics;
|
||||
using System.Collections.Generic;
|
||||
using System.Security.Cryptography.X509Certificates;
|
||||
using System.Security.Authentication;
|
||||
|
||||
using NewSslPolicyErrors = NewSystemSource::System.Net.Security.SslPolicyErrors;
|
||||
using SslProtocols = System.Security.Authentication.SslProtocols;
|
||||
using EncryptionPolicy = NewSystemSource::System.Net.Security.EncryptionPolicy;
|
||||
|
||||
using Mono.Security.NewTls;
|
||||
using Mono.Security.NewTls.TestFramework;
|
||||
using Mono.Security.NewTls.TestProvider;
|
||||
using Mono.Security.Providers.NewTls;
|
||||
|
||||
using SSCX = System.Security.Cryptography.X509Certificates;
|
||||
using MX = Mono.Security.X509;
|
||||
|
||||
namespace Mono.Security.Instrumentation.Console
|
||||
{
|
||||
public class MonoClient : MonoConnection, IClient
|
||||
{
|
||||
new public IClientParameters Parameters {
|
||||
get { return (IClientParameters)base.Parameters; }
|
||||
}
|
||||
|
||||
public MonoClient (IPEndPoint endpoint, IClientParameters parameters)
|
||||
: base (endpoint, parameters)
|
||||
{
|
||||
}
|
||||
|
||||
protected override TlsSettings GetSettings ()
|
||||
{
|
||||
var settings = new TlsSettings ();
|
||||
#if FIXME
|
||||
var monoParams = Parameters as IMonoClientParameters;
|
||||
if (monoParams != null) {
|
||||
settings.ClientCertificateParameters = monoParams.ClientCertificateParameters;
|
||||
settings.Instrumentation = monoParams.ClientInstrumentation;
|
||||
}
|
||||
#endif
|
||||
settings.RequestedCiphers = Parameters.ClientCiphers;
|
||||
return settings;
|
||||
}
|
||||
|
||||
protected override MonoNewTlsStream Start (Socket socket, TlsSettings settings)
|
||||
{
|
||||
Debug ("Connected.");
|
||||
|
||||
var clientCerts = new X509Certificate2Collection ();
|
||||
if (Parameters.ClientCertificate != null) {
|
||||
var clientCert = (ClientCertificate)Parameters.ClientCertificate;
|
||||
clientCerts.Add (clientCert.Certificate);
|
||||
}
|
||||
|
||||
var targetHost = "Hamiller-Tube.local";
|
||||
|
||||
var stream = new NetworkStream (socket);
|
||||
|
||||
return MonoNewTlsStreamFactory.CreateClient (
|
||||
stream, false, RemoteValidationCallback, null, EncryptionPolicy.RequireEncryption, settings,
|
||||
targetHost, clientCerts, SslProtocols.Tls12, false);
|
||||
}
|
||||
|
||||
bool RemoteValidationCallback (object sender, X509Certificate certificate, X509Chain chain, NewSslPolicyErrors errors)
|
||||
{
|
||||
return base.RemoteValidationCallback (sender, certificate, chain, (SslPolicyErrors)errors);
|
||||
}
|
||||
|
||||
bool ClientCertValidationCallback (ClientCertificateParameters certParams, MX.X509Certificate certificate, MX.X509Chain chain, SslPolicyErrors sslPolicyErrors)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,83 @@
|
|||
//
|
||||
// MonoConnection.cs
|
||||
//
|
||||
// Author:
|
||||
// Martin Baulig <martin.baulig@xamarin.com>
|
||||
//
|
||||
// Copyright (c) 2014 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.
|
||||
extern alias NewSystemSource;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Net;
|
||||
using System.Net.Sockets;
|
||||
using System.Net.Security;
|
||||
using System.Diagnostics;
|
||||
using System.Collections.Generic;
|
||||
using System.Security.Authentication;
|
||||
using System.Security.Cryptography.X509Certificates;
|
||||
|
||||
using Mono.Security.NewTls;
|
||||
using Mono.Security.Providers.NewTls;
|
||||
using Mono.Security.NewTls.TestFramework;
|
||||
|
||||
using Xamarin.AsyncTests;
|
||||
|
||||
namespace Mono.Security.NewTls.TestProvider
|
||||
{
|
||||
public abstract class MonoConnection : DotNetConnection, ICommonConnection
|
||||
{
|
||||
public MonoConnection (IPEndPoint endpoint, IConnectionParameters parameters)
|
||||
: base (endpoint, parameters)
|
||||
{
|
||||
}
|
||||
|
||||
TlsSettings settings;
|
||||
MonoNewTlsStream monoSslStream;
|
||||
|
||||
public override TlsConnectionInfo GetConnectionInfo ()
|
||||
{
|
||||
return settings.ConnectionInfo;
|
||||
}
|
||||
|
||||
protected abstract MonoNewTlsStream Start (Socket socket, TlsSettings settings);
|
||||
|
||||
protected abstract TlsSettings GetSettings ();
|
||||
|
||||
protected sealed override Task<Stream> Start (TestContext ctx, Socket socket, CancellationToken cancellationToken)
|
||||
{
|
||||
return Task.Run<Stream> (() => {
|
||||
settings = GetSettings ();
|
||||
settings.EnableDebugging = Parameters.EnableDebugging;
|
||||
monoSslStream = Start (socket, settings);
|
||||
return monoSslStream;
|
||||
});
|
||||
}
|
||||
|
||||
protected override async Task<bool> TryCleanShutdown (bool waitForReply)
|
||||
{
|
||||
await monoSslStream.Shutdown (waitForReply);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,79 @@
|
|||
extern alias NewSystemSource;
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Net;
|
||||
using System.Net.Sockets;
|
||||
using System.Net.Security;
|
||||
using System.Diagnostics;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using SslProtocols = System.Security.Authentication.SslProtocols;
|
||||
using EncryptionPolicy = NewSystemSource::System.Net.Security.EncryptionPolicy;
|
||||
|
||||
using Mono.Security.NewTls;
|
||||
using Mono.Security.NewTls.TestFramework;
|
||||
using Mono.Security.NewTls.TestProvider;
|
||||
using Mono.Security.Providers.NewTls;
|
||||
|
||||
using SSCX = System.Security.Cryptography.X509Certificates;
|
||||
using MX = Mono.Security.X509;
|
||||
|
||||
namespace Mono.Security.NewTls.TestProvider
|
||||
{
|
||||
public class MonoServer : MonoConnection, IServer
|
||||
{
|
||||
public ServerCertificate Certificate {
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
IServerCertificate IServer.Certificate {
|
||||
get { return Certificate; }
|
||||
}
|
||||
|
||||
new public IServerParameters Parameters {
|
||||
get { return (IServerParameters)base.Parameters; }
|
||||
}
|
||||
|
||||
public MonoServer (IPEndPoint endpoint, ServerCertificate pfx, IServerParameters parameters)
|
||||
: base (endpoint, parameters)
|
||||
{
|
||||
Certificate = pfx;
|
||||
}
|
||||
|
||||
protected override TlsSettings GetSettings ()
|
||||
{
|
||||
var settings = new TlsSettings ();
|
||||
if (Parameters.RequireClientCertificate)
|
||||
settings.RequireClientCertificate = true;
|
||||
else if (Parameters.AskForClientCertificate)
|
||||
settings.AskForClientCertificate = true;
|
||||
settings.RequestedCiphers = Parameters.ServerCiphers;
|
||||
return settings;
|
||||
}
|
||||
|
||||
protected override MonoNewTlsStream Start (Socket socket, TlsSettings settings)
|
||||
{
|
||||
#if FIXME
|
||||
var monoParams = Parameters as IMonoServerParameters;
|
||||
if (monoParams != null)
|
||||
settings.Instrumentation = monoParams.ServerInstrumentation;
|
||||
#endif
|
||||
|
||||
settings.ClientCertValidationCallback = ClientCertValidationCallback;
|
||||
|
||||
var stream = new NetworkStream (socket);
|
||||
return MonoNewTlsStreamFactory.CreateServer (
|
||||
stream, false, null, null, EncryptionPolicy.RequireEncryption, settings,
|
||||
Certificate.Certificate, false, SslProtocols.Tls12, false);
|
||||
}
|
||||
|
||||
bool ClientCertValidationCallback (ClientCertificateParameters certParams, MX.X509Certificate certificate, MX.X509Chain chain, SslPolicyErrors sslPolicyErrors)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
Загрузка…
Ссылка в новой задаче