From 45c8bb9d815924a5ab4284cf2ea359ca56915404 Mon Sep 17 00:00:00 2001 From: ManickaP Date: Thu, 16 Nov 2023 18:35:05 +0100 Subject: [PATCH 1/2] Added the same test as we have for Quic for SSLKEYLOGFILE creation --- .../tests/FunctionalTests/System.Net.Security.Tests.csproj | 1 + 1 file changed, 1 insertion(+) diff --git a/src/libraries/System.Net.Security/tests/FunctionalTests/System.Net.Security.Tests.csproj b/src/libraries/System.Net.Security/tests/FunctionalTests/System.Net.Security.Tests.csproj index ce3d32e158cdc..2b26a1df7f117 100644 --- a/src/libraries/System.Net.Security/tests/FunctionalTests/System.Net.Security.Tests.csproj +++ b/src/libraries/System.Net.Security/tests/FunctionalTests/System.Net.Security.Tests.csproj @@ -116,6 +116,7 @@ + From 94e1c29b477a5d250ab3545d4003168e890efaf5 Mon Sep 17 00:00:00 2001 From: ManickaP Date: Thu, 16 Nov 2023 18:35:23 +0100 Subject: [PATCH 2/2] Added the same test as we have for Quic for SSLKEYLOGFILE creation --- .../SslStreamRemoteExecutorTests.cs | 64 +++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 src/libraries/System.Net.Security/tests/FunctionalTests/SslStreamRemoteExecutorTests.cs diff --git a/src/libraries/System.Net.Security/tests/FunctionalTests/SslStreamRemoteExecutorTests.cs b/src/libraries/System.Net.Security/tests/FunctionalTests/SslStreamRemoteExecutorTests.cs new file mode 100644 index 0000000000000..d162a54bf9217 --- /dev/null +++ b/src/libraries/System.Net.Security/tests/FunctionalTests/SslStreamRemoteExecutorTests.cs @@ -0,0 +1,64 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System.Collections.Generic; +using System.Diagnostics; +using System.IO; +using System.Net.Security; +using System.Security.Cryptography.X509Certificates; +using System.Threading.Tasks; +using Microsoft.DotNet.RemoteExecutor; +using Microsoft.DotNet.XUnitExtensions; +using Xunit; +using Xunit.Abstractions; + +namespace System.Net.Security.Tests +{ + using Configuration = System.Net.Test.Common.Configuration; + + public class SslStreamRemoteExecutorTests + { + public SslStreamRemoteExecutorTests() + { } + + [ConditionalFact(typeof(RemoteExecutor), nameof(RemoteExecutor.IsSupported))] + [ActiveIssue("https://github.com/dotnet/runtime/issues/94843", ~TestPlatforms.Linux)] + public void SslKeyLogFile_IsCreatedAndFilled() + { + if (PlatformDetection.IsReleaseLibrary(typeof(SslStream).Assembly)) + { + throw new SkipTestException("Retrieving SSL secrets is not supported in Release mode."); + } + + var psi = new ProcessStartInfo(); + var tempFile = Path.GetTempFileName(); + psi.Environment.Add("SSLKEYLOGFILE", tempFile); + + RemoteExecutor.Invoke(async () => + { + (Stream clientStream, Stream serverStream) = TestHelper.GetConnectedStreams(); + using (clientStream) + using (serverStream) + using (var client = new SslStream(clientStream)) + using (var server = new SslStream(serverStream)) + using (X509Certificate2 certificate = Configuration.Certificates.GetServerCertificate()) + { + SslClientAuthenticationOptions clientOptions = new SslClientAuthenticationOptions(); + clientOptions.RemoteCertificateValidationCallback = delegate { return true; }; + + SslServerAuthenticationOptions serverOptions = new SslServerAuthenticationOptions(); + serverOptions.ServerCertificate = certificate; + + await TestConfiguration.WhenAllOrAnyFailedWithTimeout( + client.AuthenticateAsClientAsync(clientOptions), + server.AuthenticateAsServerAsync(serverOptions)); + + await TestHelper.PingPong(client, server); + } + }, new RemoteInvokeOptions { StartInfo = psi }).Dispose(); + + Assert.True(File.Exists(tempFile)); + Assert.True(File.ReadAllText(tempFile).Length > 0); + } + } +} \ No newline at end of file