Skip to content

Commit 34f579c

Browse files
committed
try control registry settings
1 parent d7fd8f9 commit 34f579c

File tree

3 files changed

+43
-13
lines changed

3 files changed

+43
-13
lines changed

src/BenchmarksApps/TLS/HttpSys/Program.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ void OnShutdown()
136136

137137
if (tlsRegistryLogsEnabled)
138138
{
139+
Console.WriteLine("Fetching registry info");
139140
RegistryController.ShowRegistryKeys();
140141
}
141142
if (httpSysLogsEnabled)
Lines changed: 41 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,53 @@
11
using System.Text;
22
using Microsoft.Win32;
33

4-
namespace HttpSys
4+
namespace HttpSys;
5+
6+
public static class RegistryController
57
{
6-
public static class RegistryController
8+
private const string TLS12Key = @"HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.2\Server";
9+
private const string TLS13Key = @"SYSTEM\CurrentControlSet\Services\HTTP\Parameters";
10+
11+
public static void ShowRegistryKeys()
712
{
8-
private const string TLS12Key = @"HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.2\Server";
9-
private const string TLS13Key = @"HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\HTTP\Parameters";
13+
var tls12Enabled = GetRegistryValue(TLS12Key, "");
14+
var tls13Enabled = GetRegistryValue(TLS13Key, "EnableHTTP3");
1015

11-
[System.Diagnostics.CodeAnalysis.SuppressMessage("Interoperability", "CA1416:Validate platform compatibility", Justification = "benchmark only runs on windows")]
12-
public static void ShowRegistryKeys()
13-
{
14-
var strBuilder = new StringBuilder("Registry TLS settings: \n");
16+
var strBuilder = new StringBuilder("Registry TLS settings: \n");
17+
strBuilder.AppendLine("\tTLS 1.2: " + tls12Enabled?.ToString());
18+
strBuilder.AppendLine("\tTLS 1.3: " + tls13Enabled?.ToString());
19+
strBuilder.AppendLine("\t------");
20+
21+
Console.WriteLine(strBuilder.ToString());
22+
}
23+
24+
private static void EnableTls12()
25+
{
26+
// todo
27+
}
1528

16-
var tls12Enabled = Registry.GetValue(TLS12Key, "Enabled", "not defined");
17-
strBuilder.AppendLine("\tTLS 1.2: " + tls12Enabled?.ToString());
29+
private static void EnableTls13()
30+
{
31+
var localKey = Environment.Is64BitOperatingSystem
32+
? RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64)
33+
: RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32);
1834

19-
var tls13Enabled = Registry.GetValue(TLS13Key, "EnableHTTP3", "not defined");
20-
strBuilder.AppendLine("\tTLS 1.3: " + tls12Enabled?.ToString());
35+
localKey.OpenSubKey(TLS13Key).SetValue("EnableHTTP3", 1);
36+
}
2137

22-
Console.WriteLine(strBuilder.ToString());
38+
[System.Diagnostics.CodeAnalysis.SuppressMessage("Interoperability", "CA1416:Validate platform compatibility", Justification = "benchmark only runs on windows")]
39+
private static string? GetRegistryValue(string path, string name)
40+
{
41+
var localKey = Environment.Is64BitOperatingSystem
42+
? RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64)
43+
: RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32);
44+
45+
var registrySubKey = localKey.OpenSubKey(path);
46+
if (registrySubKey is not null)
47+
{
48+
return registrySubKey.GetValue(name)?.ToString();
2349
}
50+
51+
return null;
2452
}
2553
}

src/BenchmarksApps/TLS/HttpSys/appsettings.Development.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
},
88
"mTLS": "false",
99
"httpSysLogs": "true",
10+
"tlsRegistryLogs": "true",
1011
"tlsRenegotiation": "true",
1112
"certValidationConsoleEnabled": "true"
1213
}

0 commit comments

Comments
 (0)