Skip to content

Add benchmark for mutual TLS authentication #2814

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 10, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public partial class SslStreamTests
{
private readonly Barrier _twoParticipantBarrier = new Barrier(2);
private static readonly X509Certificate2 _cert = Test.Common.Configuration.Certificates.GetServerCertificate();
private static readonly X509Certificate2 _clientCert = Test.Common.Configuration.Certificates.GetClientCertificate();
private static readonly X509Certificate2 _ec256Cert = Test.Common.Configuration.Certificates.GetEC256Certificate();
private static readonly X509Certificate2 _ec512Cert = Test.Common.Configuration.Certificates.GetEC512Certificate();
private static readonly X509Certificate2 _rsa2048Cert = Test.Common.Configuration.Certificates.GetRSA2048Certificate();
Expand Down Expand Up @@ -105,27 +106,37 @@ public void Cleanup()
[BenchmarkCategory(Categories.NoAOT)]
public Task DefaultHandshakeIPv6Async() => DefaultHandshake(_clientIPv6, _serverIPv6);

[Benchmark]
[BenchmarkCategory(Categories.NoAOT)]
public Task DefaultMutualHandshakeIPv4Async() => DefaultHandshake(_clientIPv4, _serverIPv4, requireClientCert: true);

[Benchmark]
[BenchmarkCategory(Categories.NoAOT)]
public Task DefaultMutualHandshakeIPv6Async() => DefaultHandshake(_clientIPv6, _serverIPv6, requireClientCert: true);

[Benchmark]
[OperatingSystemsFilter(allowed: true, platforms: OS.Linux)] // Not supported on Windows at the moment.
[BenchmarkCategory(Categories.NoAOT)]
public Task DefaultHandshakePipeAsync() => DefaultHandshake(_clientPipe, _serverPipe);

private async Task DefaultHandshake(Stream client, Stream server)
private async Task DefaultHandshake(Stream client, Stream server, bool requireClientCert = false)
{
SslClientAuthenticationOptions clientOptions = new SslClientAuthenticationOptions
{
AllowRenegotiation = false,
EnabledSslProtocols = SslProtocols.None,
CertificateRevocationCheckMode = X509RevocationMode.NoCheck,
TargetHost = "loopback",
ClientCertificates = requireClientCert ? new X509CertificateCollection() { _clientCert } : null,
};

SslServerAuthenticationOptions serverOptions = new SslServerAuthenticationOptions
{
AllowRenegotiation = false,
EnabledSslProtocols = SslProtocols.None,
CertificateRevocationCheckMode = X509RevocationMode.NoCheck,
ServerCertificate = _cert
ServerCertificate = _cert,
ClientCertificateRequired = requireClientCert,
};

using (var sslClient = new SslStream(client, leaveInnerStreamOpen: true, delegate { return true; }))
Expand Down