Skip to content

Commit c6d46ff

Browse files
committed
kestrel
1 parent 84a9d29 commit c6d46ff

File tree

2 files changed

+41
-3
lines changed

2 files changed

+41
-3
lines changed

scenarios/tls.benchmarks.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ jobs:
2020
certValidationConsoleEnabled: false
2121
httpSysLogs: false
2222
statsEnabled: false
23-
arguments: "--urls https://{{serverAddress}}:{{serverPort}} --mTLS {{mTLS}} --certValidationConsoleEnabled {{certValidationConsoleEnabled}} --statsEnabled {{statsEnabled}} --tlsRenegotiation {{tlsRenegotiation}} --httpSysLogs {{httpSysLogs}}"
23+
tlsProtocols: "tls12"
24+
arguments: "--urls https://{{serverAddress}}:{{serverPort}} --mTLS {{mTLS}} --certValidationConsoleEnabled {{certValidationConsoleEnabled}} --statsEnabled {{statsEnabled}} --tlsRenegotiation {{tlsRenegotiation}} --httpSysLogs {{httpSysLogs}} --tlsProtocols {{tlsProtocols}}"
2425

2526
kestrelServer:
2627
source:
@@ -33,7 +34,8 @@ jobs:
3334
tlsRenegotiation: false
3435
certValidationConsoleEnabled: false
3536
statsEnabled: false
36-
arguments: "--urls https://{{serverAddress}}:{{serverPort}} --mTLS {{mTLS}} --certValidationConsoleEnabled {{certValidationConsoleEnabled}} --statsEnabled {{statsEnabled}} --tlsRenegotiation {{tlsRenegotiation}}"
37+
tlsProtocols: "tls12"
38+
arguments: "--urls https://{{serverAddress}}:{{serverPort}} --mTLS {{mTLS}} --certValidationConsoleEnabled {{certValidationConsoleEnabled}} --statsEnabled {{statsEnabled}} --tlsRenegotiation {{tlsRenegotiation}} --tlsProtocols {{tlsProtocols}}"
3739

3840
scenarios:
3941

src/BenchmarksApps/TLS/Kestrel/Program.cs

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
using System.Net;
22
using System.Net.Security;
3+
using System.Security.Authentication;
34
using System.Security.Cryptography.X509Certificates;
4-
using Microsoft.AspNetCore.Authentication.Certificate;
55
using Microsoft.AspNetCore.Server.HttpSys;
66
using Microsoft.AspNetCore.Server.Kestrel.Core;
77
using Microsoft.AspNetCore.Server.Kestrel.Https;
@@ -14,6 +14,7 @@
1414
var tlsRenegotiationEnabled = bool.TryParse(builder.Configuration["tlsRenegotiation"], out var tlsRenegotiationEnabledConfig) && tlsRenegotiationEnabledConfig;
1515
var statsEnabled = bool.TryParse(builder.Configuration["statsEnabled"], out var connectionStatsEnabledConfig) && connectionStatsEnabledConfig;
1616
var listeningEndpoints = builder.Configuration["urls"] ?? "https://localhost:5000/";
17+
var supportedTlsVersions = ParseSslProtocols(builder.Configuration["tlsProtocols"]);
1718

1819
if (mTlsEnabled && tlsRenegotiationEnabled)
1920
{
@@ -40,6 +41,8 @@ void ConfigureListen(KestrelServerOptions serverOptions, IConfigurationRoot conf
4041
// [SuppressMessage("Microsoft.Security", "CSCAN0220.DefaultPasswordContexts", Justification="Benchmark code, not a secret")]
4142
listenOptions.UseHttps("testCert.pfx", "testPassword", options =>
4243
{
44+
options.SslProtocols = supportedTlsVersions;
45+
4346
if (mTlsEnabled)
4447
{
4548
options.ClientCertificateMode = ClientCertificateMode.RequireCertificate;
@@ -137,6 +140,7 @@ bool AllowAnyCertificateValidationWithLogging(X509Certificate2 certificate, X509
137140
{
138141
Console.WriteLine($"\tenabled logging stats to console");
139142
}
143+
Console.WriteLine($"\tsupported TLS versions: {supportedTlsVersions}");
140144
Console.WriteLine($"\tlistening endpoints: {listeningEndpoints}");
141145
Console.WriteLine("--------------------------------");
142146

@@ -157,4 +161,36 @@ static IPEndPoint CreateIPEndPoint(UrlPrefix urlPrefix)
157161
}
158162

159163
return new IPEndPoint(ip, urlPrefix.PortValue);
164+
}
165+
166+
static SslProtocols ParseSslProtocols(string? supportedTlsVersions)
167+
{
168+
var protocols = SslProtocols.Tls12; // default it TLS 1.2
169+
if (string.IsNullOrEmpty(supportedTlsVersions))
170+
{
171+
return protocols;
172+
}
173+
174+
protocols = SslProtocols.None;
175+
foreach (var version in supportedTlsVersions.Split(','))
176+
{
177+
switch (version.Trim().ToLower())
178+
{
179+
#pragma warning disable SYSLIB0039 // Type or member is obsolete
180+
case "tls11":
181+
protocols |= SslProtocols.Tls11;
182+
break;
183+
#pragma warning restore SYSLIB0039 // Type or member is obsolete
184+
case "tls12":
185+
protocols |= SslProtocols.Tls12;
186+
break;
187+
case "tls13":
188+
protocols |= SslProtocols.Tls13;
189+
break;
190+
default:
191+
throw new ArgumentException($"Unsupported TLS version: {version}");
192+
}
193+
}
194+
195+
return protocols;
160196
}

0 commit comments

Comments
 (0)