-
Notifications
You must be signed in to change notification settings - Fork 44
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support TLS 1.3 #618
Open
evolutionise
wants to merge
13
commits into
main
Choose a base branch
from
sast/alix/dont-specify-tls
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Support TLS 1.3 #618
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
00505e7
what if we just like .... didn't ... specify tls versions tho?
evolutionise a7a6ebf
okay that wasnt great what if we added it instead?
evolutionise 7a2d6ab
it's weird that the docs say `SslProtocols.SystemDefault` but the cod…
evolutionise 456d5b5
Restore specification of SSL protocols and add TLS 1.3.
gb-8 7bbf6cb
Remove outdated comment.
gb-8 ad16304
Merge branch 'main' into sast/alix/dont-specify-tls
gb-8 6335269
Added TLS test.
gb-8 703b82a
Added TLS fallback test.
gb-8 d0a708c
Log platform info (temp to work out how to detect platform).
gb-8 e60006a
Fix platform logging.
gb-8 8205df8
Remove usage of RuntimeInformation.RuntimeIdentifier which is not ava…
gb-8 8e1a3ec
Update expected TLS version per platform in tests.
gb-8 4f2cf24
Disable TLS tests for websocket, as we don't log the TLS version.
gb-8 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
using System; | ||
using System.Linq; | ||
using System.Runtime.InteropServices; | ||
using System.Security.Authentication; | ||
using System.Threading.Tasks; | ||
using FluentAssertions; | ||
using Halibut.Tests.Support; | ||
using Halibut.Tests.Support.TestAttributes; | ||
using Halibut.Tests.Support.TestCases; | ||
using Halibut.Tests.TestServices.Async; | ||
using Halibut.TestUtils.Contracts; | ||
using NUnit.Framework; | ||
|
||
namespace Halibut.Tests | ||
{ | ||
public class TlsFixture : BaseTest | ||
{ | ||
[Test] | ||
[LatestClientAndLatestServiceTestCases(testWebSocket: false, testNetworkConditions: false)] | ||
public async Task LatestClientAndServiceUseBestAvailableSslProtocol(ClientAndServiceTestCase clientAndServiceTestCase) | ||
{ | ||
await using (var clientAndService = await clientAndServiceTestCase.CreateTestCaseBuilder() | ||
.WithStandardServices() | ||
.AsLatestClientAndLatestServiceBuilder() | ||
.RecordingClientLogs(out var clientLogs) | ||
.RecordingServiceLogs(out var serviceLogs) | ||
.Build(CancellationToken)) | ||
{ | ||
Logger.Information("Platform detection:"); | ||
Logger.Information("Environment.OSVersion.Platform: {EnvironmentOSVersionPlatform}", Environment.OSVersion.Platform); | ||
Logger.Information("Environment.OSVersion.Version: {EnvironmentOSVersionVersion}", Environment.OSVersion.Version); | ||
Logger.Information("Environment.OSVersion.VersionString: {EnvironmentOSVersionVersionString}", Environment.OSVersion.VersionString); | ||
Logger.Information("Environment.OSVersion.ServicePack: {EnvironmentOSVersionServicePack}", Environment.OSVersion.ServicePack); | ||
Logger.Information("RuntimeInformation.OSDescription: {RuntimeInformationOSDescription}", RuntimeInformation.OSDescription); | ||
Logger.Information("RuntimeInformation.FrameworkDescription: {RuntimeInformationFrameworkDescription}", RuntimeInformation.FrameworkDescription); | ||
Logger.Information("RuntimeInformation.ProcessArchitecture: {RuntimeInformationProcessArchitecture}", RuntimeInformation.ProcessArchitecture); | ||
Logger.Information("RuntimeInformation.OSArchitecture: {RuntimeInformationOSArchitecture}", RuntimeInformation.OSArchitecture); | ||
|
||
var echo = clientAndService.CreateAsyncClient<IEchoService, IAsyncClientEchoService>(); | ||
await echo.SayHelloAsync("World"); | ||
|
||
var connectionInitiatorLogs = clientAndServiceTestCase.ServiceConnectionType == ServiceConnectionType.Listening | ||
? clientLogs | ||
: serviceLogs; | ||
|
||
var expectedSslProtocol = GetExpectedSslProtocolForTheCurrentPlatform(); | ||
var expectedLogFragment = $"using protocol {expectedSslProtocol}"; | ||
|
||
connectionInitiatorLogs.Values | ||
.SelectMany(log => log.GetLogs()) | ||
.Should().Contain( | ||
logEvent => logEvent.FormattedMessage.Contains(expectedLogFragment), | ||
"The OS is \"{{OSDescription}}\", so we expect {{expectedSslProtocol}} to be used, and expect log output to contain \"{expectedLogFragment}\" for {tentacleType} tentacles.", | ||
RuntimeInformation.OSDescription, | ||
expectedSslProtocol, | ||
expectedLogFragment, | ||
clientAndServiceTestCase.ServiceConnectionType); | ||
} | ||
} | ||
|
||
[Test] | ||
[LatestClientAndPreviousServiceVersionsTestCases(testWebSocket: false, testNetworkConditions: false)] | ||
public async Task LatestClientAndPreviousServiceFallBackOnTls12(ClientAndServiceTestCase clientAndServiceTestCase) | ||
{ | ||
await using (var clientAndService = await clientAndServiceTestCase.CreateTestCaseBuilder() | ||
.WithStandardServices() | ||
.AsLatestClientAndPreviousServiceVersionBuilder() | ||
.RecordingClientLogs(out var clientLogs) | ||
.Build(CancellationToken)) | ||
{ | ||
var echo = clientAndService.CreateAsyncClient<IEchoService, IAsyncClientEchoService>(); | ||
await echo.SayHelloAsync("World"); | ||
|
||
var expectedLogMessage = clientAndServiceTestCase.ServiceConnectionType == ServiceConnectionType.Listening | ||
? $"using protocol {SslProtocols.Tls12}" | ||
: $"client connected with {SslProtocols.Tls12}"; | ||
|
||
clientLogs.Values | ||
.SelectMany(log => log.GetLogs()) | ||
.Should().Contain(logEvent => logEvent.FormattedMessage.Contains(expectedLogMessage)); | ||
} | ||
} | ||
|
||
SslProtocols GetExpectedSslProtocolForTheCurrentPlatform() | ||
{ | ||
// All linux platforms we test against support TLS 1.3. | ||
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) | ||
{ | ||
return SslProtocols.Tls13; | ||
} | ||
|
||
// We test against old versions of Windows which do not support TLS 1.3. | ||
// TLS 1.3 is supported since Windows Server 2022 which has build number 20348, and Windows 11 which has higher build numbers. | ||
// TLS 1.3 is partially supported in Windows 10, which can have lower build numbers, but we don't test against that so it is ignored here. | ||
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) | ||
{ | ||
const int WindowsServer2022OSBuild = 20348; | ||
return Environment.OSVersion.Version.Build >= WindowsServer2022OSBuild | ||
? SslProtocols.Tls13 | ||
: SslProtocols.Tls12; | ||
} | ||
|
||
// .NET does not support TLS 1.3 on Mac OS yet. | ||
// https://github.com/dotnet/runtime/issues/1979 | ||
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) | ||
{ | ||
return SslProtocols.Tls12; | ||
} | ||
|
||
throw new NotSupportedException($"Unsupported OS platform: {RuntimeInformation.OSDescription}"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: It might make sense to pull this list out to a single place and perhaps make it user configurable within the
HalibutRuntimeBuilder