Skip to content
Merged
Show file tree
Hide file tree
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 @@ -127,7 +127,7 @@ public async Task GetAsync_AllowedSSLVersion_Succeeds(SslProtocols acceptedProto
}

// Use a different SNI for each connection to prevent TLS 1.3 renegotiation issue: https://github.com/dotnet/runtime/issues/47378
client.DefaultRequestHeaders.Host = getTestSNIName();
client.DefaultRequestHeaders.Host = GetTestSNIName();

var options = new LoopbackServer.Options { UseSsl = true, SslProtocols = acceptedProtocol };
await LoopbackServer.CreateServerAsync(async (server, url) =>
Expand All @@ -140,7 +140,7 @@ await TestHelper.WhenAllCompletedOrAnyFailed(
Assert.Equal(1, count);
}

string getTestSNIName()
string GetTestSNIName()
{
return $"{nameof(GetAsync_AllowedSSLVersion_Succeeds)}_{acceptedProtocol}_{requestOnlyThisProtocol}";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,13 @@ private async Task ClientAsyncSslHelper(
using (var client = new TcpClient())
{
server.SslProtocols = serverSslProtocols;
// Use a different SNI for each connection to prevent TLS 1.3 renegotiation issue: https://github.com/dotnet/runtime/issues/47378
string serverName = TestHelper.GetTestSNIName(nameof(ClientAsyncSslHelper), clientSslProtocols, serverSslProtocols);

await client.ConnectAsync(server.RemoteEndPoint.Address, server.RemoteEndPoint.Port);
using (SslStream sslStream = new SslStream(client.GetStream(), false, certificateCallback != null ? certificateCallback : AllowAnyServerCertificate, null))
{
Task clientAuthTask = sslStream.AuthenticateAsClientAsync("localhost", null, clientSslProtocols, false);
Task clientAuthTask = sslStream.AuthenticateAsClientAsync(serverName, null, clientSslProtocols, false);
await clientAuthTask.TimeoutAfter(TestConfiguration.PassingTestTimeoutMilliseconds);

_log.WriteLine("Client authenticated to server({0}) with encryption cipher: {1} {2}-bit strength",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,8 @@ private async Task ServerAsyncSslHelper(
return true;
}))
{
string serverName = _serverCertificate.GetNameInfo(X509NameType.SimpleName, false);
// Use a different SNI for each connection to prevent TLS 1.3 renegotiation issue: https://github.com/dotnet/runtime/issues/47378
string serverName = TestHelper.GetTestSNIName(nameof(ServerAsyncSslHelper), clientSslProtocols, serverSslProtocols);

_log.WriteLine("Connected on {0} {1} ({2} {3})", clientStream.Socket.LocalEndPoint, clientStream.Socket.RemoteEndPoint, clientStream.Socket.Handle, serverStream.Socket.Handle);
_log.WriteLine("client SslStream#{0} server SslStream#{1}", sslClientStream.GetHashCode(), sslServerStream.GetHashCode());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public async Task ClientAndServer_OneOrBothUseDefault_Ok(SslProtocols? clientPro
using (X509Certificate2 clientCertificate = Configuration.Certificates.GetClientCertificate())
{
// Use a different SNI for each connection to prevent TLS 1.3 renegotiation issue: https://github.com/dotnet/runtime/issues/47378
string serverHost = getTestSNIName();
string serverHost = TestHelper.GetTestSNIName(nameof(ClientAndServer_OneOrBothUseDefault_Ok), clientProtocols, serverProtocols);
var clientCertificates = new X509CertificateCollection() { clientCertificate };

await TestConfiguration.WhenAllOrAnyFailedWithTimeout(
Expand All @@ -100,16 +100,6 @@ await TestConfiguration.WhenAllOrAnyFailedWithTimeout(
_clientStream.SslProtocol + " " + _clientStream.HashAlgorithm);
}
}

string getTestSNIName()
{
static string ProtocolToString(SslProtocols? protocol)
{
return (protocol?.ToString() ?? "null").Replace(", ", "_");
}

return $"{nameof(ClientAndServer_OneOrBothUseDefault_Ok)}_{ProtocolToString(clientProtocols)}_{ProtocolToString(serverProtocols)}";
}
}

[ConditionalTheory(nameof(IsNotWindows7))]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
// The .NET Foundation licenses this file to you under the MIT license.

using System.IO;
using System.Linq;
using System.Net.Sockets;
using System.Net.Test.Common;
using System.Security.Authentication;
using System.Security.Cryptography;
using System.Security.Cryptography.X509Certificates;
using System.Security.Cryptography.X509Certificates.Tests.Common;
Expand Down Expand Up @@ -157,7 +159,7 @@ internal static (X509Certificate2 certificate, X509Certificate2Collection) Gener
intermedPub3.Dispose();
CertificateAuthority intermediateAuthority3 = new CertificateAuthority(intermedCert3, null, null, null);

RSA eeKey = (RSA)endEntity.PrivateKey;
RSA eeKey = (RSA)endEntity.PrivateKey;
endEntity = intermediateAuthority3.CreateEndEntity(
$"CN=\"A SSL Test\", O=\"testName\"",
eeKey,
Expand Down Expand Up @@ -212,5 +214,18 @@ internal static async Task PingPong(SslStream client, SslStream server)
Assert.Equal(s_pong, buffer);
await t;
}

internal static string GetTestSNIName(string testMethodName, params SslProtocols?[] protocols)
{
static string ProtocolToString(SslProtocols? protocol)
{
return (protocol?.ToString() ?? "null").Replace(", ", "-");
}

var args = string.Join(".", protocols.Select(p => ProtocolToString(p)));
var name = testMethodName.Length > 63 ? testMethodName.Substring(0, 63) : testMethodName;

return $"{name}.{args}";
}
}
}