From b1260788896643288dd246e7774a159f949d2f64 Mon Sep 17 00:00:00 2001 From: Radek Zikmund Date: Wed, 19 Jun 2024 20:57:00 +0200 Subject: [PATCH 1/2] Add DefaultMutualHandshakeContext* benchmarks --- .../SslStreamTests.Context.cs | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/benchmarks/micro/libraries/System.Net.Security/SslStreamTests.Context.cs b/src/benchmarks/micro/libraries/System.Net.Security/SslStreamTests.Context.cs index 9df90c91bfc..d18d5b5b282 100644 --- a/src/benchmarks/micro/libraries/System.Net.Security/SslStreamTests.Context.cs +++ b/src/benchmarks/micro/libraries/System.Net.Security/SslStreamTests.Context.cs @@ -2,7 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using System; +using System; using System.IO; using System.IO.Pipes; using System.Net.Security; @@ -29,26 +29,34 @@ public partial class SslStreamTests [BenchmarkCategory(Categories.NoAOT)] public Task DefaultHandshakeContextIPv6Async() => DefaultContextHandshake(_clientIPv6, _serverIPv6); - private async Task DefaultContextHandshake(Stream client, Stream server) + + [Benchmark] + [BenchmarkCategory(Categories.NoAOT)] + public Task DefaultMutualHandshakeContextIPv4Async() => DefaultContextHandshake(_clientIPv4, _serverIPv4, true); + + [Benchmark] + [BenchmarkCategory(Categories.NoAOT)] + public Task DefaultMutualHandshakeContextIPv6Async() => DefaultContextHandshake(_clientIPv6, _serverIPv6, true); + private async Task DefaultContextHandshake(Stream client, Stream server, bool requireClientCert = false) { if (_context == null) { _context = SslStreamCertificateContext.Create(_cert, null); } - + SslServerAuthenticationOptions serverOptions = new SslServerAuthenticationOptions { AllowRenegotiation = false, EnabledSslProtocols = SslProtocols.None, CertificateRevocationCheckMode = X509RevocationMode.NoCheck, - ServerCertificateContext = _context, + ServerCertificateContext = _context, }; using (var sslClient = new SslStream(client, leaveInnerStreamOpen: true, delegate { return true; })) using (var sslServer = new SslStream(server, leaveInnerStreamOpen: true, delegate { return true; })) { await Task.WhenAll( - sslClient.AuthenticateAsClientAsync("localhost", null, SslProtocols.None, checkCertificateRevocation: false), + sslClient.AuthenticateAsClientAsync("localhost", requireClientCert ? new X509CertificateCollection() { _clientCert } : null, SslProtocols.None, checkCertificateRevocation: false), sslServer.AuthenticateAsServerAsync(serverOptions, default)); // In Tls1.3 part of handshake happens with data exchange. From 402ae0c59fd22572836259665c41f8039ba8e2c3 Mon Sep 17 00:00:00 2001 From: Radek Zikmund Date: Wed, 19 Jun 2024 21:01:03 +0200 Subject: [PATCH 2/2] Cleanup --- .../libraries/System.Net.Security/SslStreamTests.Context.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/benchmarks/micro/libraries/System.Net.Security/SslStreamTests.Context.cs b/src/benchmarks/micro/libraries/System.Net.Security/SslStreamTests.Context.cs index d18d5b5b282..626210560ad 100644 --- a/src/benchmarks/micro/libraries/System.Net.Security/SslStreamTests.Context.cs +++ b/src/benchmarks/micro/libraries/System.Net.Security/SslStreamTests.Context.cs @@ -2,7 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using System; using System.IO; using System.IO.Pipes; using System.Net.Security; @@ -29,7 +28,6 @@ public partial class SslStreamTests [BenchmarkCategory(Categories.NoAOT)] public Task DefaultHandshakeContextIPv6Async() => DefaultContextHandshake(_clientIPv6, _serverIPv6); - [Benchmark] [BenchmarkCategory(Categories.NoAOT)] public Task DefaultMutualHandshakeContextIPv4Async() => DefaultContextHandshake(_clientIPv4, _serverIPv4, true); @@ -37,6 +35,7 @@ public partial class SslStreamTests [Benchmark] [BenchmarkCategory(Categories.NoAOT)] public Task DefaultMutualHandshakeContextIPv6Async() => DefaultContextHandshake(_clientIPv6, _serverIPv6, true); + private async Task DefaultContextHandshake(Stream client, Stream server, bool requireClientCert = false) { if (_context == null)