This commit is contained in:
Martin Baulig 2015-03-07 00:10:51 +01:00
Родитель 7c72be59aa
Коммит 36a32f5f7b
11 изменённых файлов: 18 добавлений и 203 удалений

Просмотреть файл

@ -8,18 +8,14 @@ using System.Collections.Generic;
using System.Security.Cryptography.X509Certificates;
using Mono.Security.NewTls.TestFramework;
using Mono.Security.NewTls.TestProvider;
using Xamarin.AsyncTests;
namespace Mono.Security.NewTls.TestProvider
{
public class OpenSslServer : OpenSslConnection, IServer
{
public ServerCertificate Certificate {
get;
private set;
}
IServerCertificate IServer.Certificate {
get { return Certificate; }
public IServerCertificate Certificate {
get { return Parameters.ServerCertificate; }
}
new public IServerParameters Parameters {
@ -29,7 +25,6 @@ namespace Mono.Security.NewTls.TestProvider
public OpenSslServer (IPEndPoint endpoint, IServerParameters parameters)
: base (endpoint, parameters)
{
Certificate = new ServerCertificate (parameters.ServerCertificate);
}
protected override void Initialize ()

Просмотреть файл

@ -1,20 +0,0 @@
using System;
using System.Security.Cryptography.X509Certificates;
namespace Mono.Security.NewTls.TestProvider
{
public class CertificateAndKeyAsPFX : PrivateFile
{
public X509Certificate2 Certificate {
get;
private set;
}
public CertificateAndKeyAsPFX (byte[] data, string password)
: base (data, password)
{
Certificate = new X509Certificate2 (data, password);
}
}
}

Просмотреть файл

@ -1,15 +0,0 @@
using System;
namespace Mono.Security.NewTls.TestProvider
{
using TestFramework;
public class CertificateAsPEM : PrivateFile, ICertificateAsPEM
{
public CertificateAsPEM (byte[] data)
: base (data, null)
{
}
}
}

Просмотреть файл

@ -1,16 +0,0 @@
using System;
namespace Mono.Security.NewTls.TestProvider
{
using TestFramework;
public sealed class ClientCertificate : CertificateAndKeyAsPFX, IClientCertificate
{
public ClientCertificate (byte[] data, string password)
: base (data, password)
{
}
}
}

Просмотреть файл

@ -32,8 +32,8 @@ namespace Mono.Security.NewTls.TestProvider
var clientCerts = new X509Certificate2Collection ();
if (Parameters.ClientCertificate != null) {
var clientCert = (ClientCertificate)Parameters.ClientCertificate;
clientCerts.Add (clientCert.Certificate);
var clientCert = new X509Certificate2 (Parameters.ClientCertificate.Data, Parameters.ClientCertificate.Password);
clientCerts.Add (clientCert);
}
var targetHost = "Hamiller-Tube.local";

Просмотреть файл

@ -17,13 +17,8 @@ namespace Mono.Security.NewTls.TestProvider
{
public class DotNetServer : DotNetConnection, IServer
{
public ServerCertificate Certificate {
get;
private set;
}
IServerCertificate IServer.Certificate {
get { return Certificate; }
public IServerCertificate Certificate {
get { return Parameters.ServerCertificate; }
}
new public IServerParameters Parameters {
@ -33,7 +28,6 @@ namespace Mono.Security.NewTls.TestProvider
public DotNetServer (IPEndPoint endpoint, IServerParameters parameters)
: base (endpoint, parameters)
{
Certificate = new ServerCertificate (parameters.ServerCertificate);
}
protected override async Task<Stream> Start (TestContext ctx, Socket socket, CancellationToken cancellationToken)
@ -43,9 +37,11 @@ namespace Mono.Security.NewTls.TestProvider
if (Parameters.AskForClientCertificate || Parameters.RequireClientCertificate)
throw new NotSupportedException ();
var serverCert = new X509Certificate2 (Certificate.Data, Certificate.Password);
var stream = new NetworkStream (socket);
var server = new SslStream (stream, false);
await server.AuthenticateAsServerAsync (Certificate.Certificate, false, SslProtocols.Tls12, false);
await server.AuthenticateAsServerAsync (serverCert, false, SslProtocols.Tls12, false);
ctx.LogMessage ("Successfully authenticated.");

Просмотреть файл

@ -35,17 +35,12 @@
</ItemGroup>
<ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="CertificateAndKeyAsPFX.cs" />
<Compile Include="CertificateAsPEM.cs" />
<Compile Include="ClientAndServer.cs" />
<Compile Include="ClientCertificate.cs" />
<Compile Include="Connection.cs" />
<Compile Include="DotNetClient.cs" />
<Compile Include="DotNetConnection.cs" />
<Compile Include="DotNetServer.cs" />
<Compile Include="MonoCryptoProvider.cs" />
<Compile Include="PrivateFile.cs" />
<Compile Include="ServerCertificate.cs" />
<Compile Include="SymmetricAlgorithmProxy.cs" />
<Compile Include="MonoClient.cs" />
<Compile Include="MonoConnection.cs" />

Просмотреть файл

@ -57,8 +57,8 @@ namespace Mono.Security.NewTls.TestProvider
var clientCerts = new X509Certificate2Collection ();
if (Parameters.ClientCertificate != null) {
var clientCert = new ClientCertificate (Parameters.ClientCertificate.Data, Parameters.ClientCertificate.Password);
clientCerts.Add (clientCert.Certificate);
var clientCert = new X509Certificate2 (Parameters.ClientCertificate.Data, Parameters.ClientCertificate.Password);
clientCerts.Add (clientCert);
}
var targetHost = "Hamiller-Tube.local";

Просмотреть файл

@ -20,18 +20,14 @@ using Mono.Security.Providers.NewTls;
using SSCX = System.Security.Cryptography.X509Certificates;
using MX = Mono.Security.X509;
using Xamarin.AsyncTests;
namespace Mono.Security.NewTls.TestProvider
{
public class MonoServer : MonoConnection, IServer
{
public ServerCertificate Certificate {
get;
private set;
}
IServerCertificate IServer.Certificate {
get { return Certificate; }
public IServerCertificate Certificate {
get { return Parameters.ServerCertificate; }
}
new public IServerParameters Parameters {
@ -41,7 +37,6 @@ namespace Mono.Security.NewTls.TestProvider
public MonoServer (IPEndPoint endpoint, IServerParameters parameters)
: base (endpoint, parameters)
{
Certificate = new ServerCertificate (parameters.ServerCertificate);
}
protected override TlsSettings GetSettings ()
@ -65,10 +60,12 @@ namespace Mono.Security.NewTls.TestProvider
settings.ClientCertValidationCallback = ClientCertValidationCallback;
var serverCert = new SSCX.X509Certificate2 (Certificate.Data, Certificate.Password);
var stream = new NetworkStream (socket);
return MonoNewTlsStreamFactory.CreateServer (
stream, false, null, null, EncryptionPolicy.RequireEncryption, settings,
Certificate.Certificate, false, SslProtocols.Tls12, false);
serverCert, false, SslProtocols.Tls12, false);
}
bool ClientCertValidationCallback (ClientCertificateParameters certParams, MX.X509Certificate certificate, MX.X509Chain chain, SslPolicyErrors sslPolicyErrors)

Просмотреть файл

@ -1,97 +0,0 @@
using System;
using System.IO;
namespace Mono.Security.NewTls.TestProvider
{
public abstract class PrivateFile : IDisposable
{
string filename;
byte[] data;
public string Password {
get;
private set;
}
public PrivateFile (string filename, string password)
{
this.filename = filename;
Password = password;
}
public PrivateFile (byte[] data, string password)
{
this.data = data;
Password = password;
}
public byte[] Data {
get {
if (data == null)
data = ReadFromFile (filename);
return data;
}
}
public string FileName {
get {
if (filename == null)
filename = WriteToTempFile (data);
return filename;
}
}
static byte[] ReadFromFile (string path)
{
using (var stream = new FileStream (path, FileMode.Open)) {
var buffer = new byte [stream.Length];
var ret = stream.Read (buffer, 0, buffer.Length);
if (ret != buffer.Length)
throw new IOException ();
return buffer;
}
}
static string WriteToTempFile (byte[] bytes)
{
var path = Path.GetTempFileName ();
using (var stream = new FileStream (path, FileMode.Create, FileAccess.Write))
stream.Write (bytes, 0, bytes.Length);
return path;
}
void DeleteFile (string filename)
{
try {
if (File.Exists (filename))
File.Delete (filename);
} catch {
}
}
public void Dispose ()
{
Dispose (true);
GC.SuppressFinalize (this);
}
protected virtual void Dispose (bool disposing)
{
if (data != null) {
Array.Clear (data, 0, data.Length);
data = null;
}
Password = null;
if (filename != null) {
DeleteFile (filename);
filename = null;
}
}
~PrivateFile ()
{
Dispose (false);
}
}
}

Просмотреть файл

@ -1,20 +0,0 @@
using System;
namespace Mono.Security.NewTls.TestProvider
{
using TestFramework;
public sealed class ServerCertificate : CertificateAndKeyAsPFX, IServerCertificate
{
public ServerCertificate (byte[] data, string password)
: base (data, password)
{
}
public ServerCertificate (IServerCertificate certificate)
: base (certificate.Data, certificate.Password)
{
}
}
}