Skip to content

Improve QuicImplementationProviders.MsQuic.IsSupported for TLS1.3 On Windows - #66019

Merged
wfurt merged 20 commits into
dotnet:mainfrom
hwoodiwiss:hwoodiwiss-55237
Mar 29, 2022
Merged

wfurt merged 20 commits into
dotnet:mainfrom
hwoodiwiss:hwoodiwiss-55237

Conversation

@hwoodiwiss

Copy link
Copy Markdown
Contributor

fixes #55237

Adds a registry check to detect whether TLS1.3 Has been disabled in the registry on windows.
Adds this check to MsQuic.IsSupported

Scaffolds an interoperable TLS support helper.
Needs to be multi-file so that the Microsoft.Win32 dependency can be safely used in `MsQuicTlsSupportHelper.Windows.cs`
Disabling TLS1.3 is an explicit action in supported versions of windows, and we should check for the explicit configuration
Need access to Registry API to check whether TLS 1.3 has been disabled
- Checks if key exists
- If not returns false
- Gets Value from Key "Enabled"
- If Enabled == 0 returns true
- Any other case returns false
@ghost ghost added area-System.Net.Quic community-contribution Indicates that the PR has been added by a community member labels Mar 1, 2022
@ghost

ghost commented Mar 1, 2022

Copy link
Copy Markdown

Tagging subscribers to this area: @dotnet/ncl
See info in area-owners.md if you want to be subscribed.

Issue Details

fixes #55237

Adds a registry check to detect whether TLS1.3 Has been disabled in the registry on windows.
Adds this check to MsQuic.IsSupported

Author: hwoodiwiss
Assignees: -
Labels:

area-System.Net.Quic

Milestone: -

{
internal static partial class MsQuicTlsSupportHelper
{
public static bool IsTls1_3Disabled() => false;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we just #if ... instead of putting it into extra helper class and files?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, I went a little OTT there.

{
internal static partial class MsQuicTlsSupportHelper
{
private const string SChannelTLS1_3RegKey = @"SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.3";

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BTW, in my quick search, this looks like the first registry check in product code we'd have, so @wfurt could you give it a look as well?

Is this what we want? Is there a way to get a reasonable error from OS when trying to use msquic and TSL 1.3 instead. How often this'll happen (meaning people disabling TLS 1.3 in registry)?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One alternative I had thought of was a Windows only case for MsQuicStatusCodes.GetError, however, I thought that could be unwise as the error code 0x80090331 can occur in other cases that the client and server do not support matching algorithms.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think looking at the registry would be ok if we do one only at the beginning. One can still disable the protocols (or all it's algorithms) during application run. Schannel would react to it and we won't but I think that is ok. In cases like that, the user/admin are probably aware of it.

{
if (NetEventSource.Log.IsEnabled())
{
NetEventSource.Info(null, $"TLS 1.3 has been disabled via registry. TLS 1.3 is required for QUIC.");

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if this saves the problem. I assume the @JamesNK meant QuicException.Message when he talk about "message" e.g. surface that info to the caller.

@ManickaP ManickaP Mar 9, 2022 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is "option 1.", i.e.: including TLS 1.3 check within the IsSupported flag, so if TLS 1.3 is off, Quic won't light up. Whereas previously it would light up and then throw 0x80090331.
We might opt to throw a better error instead, e.g. special case for 0x80090331, translate it to "Algorithm mismatch" and add text to the exception saying: "Make sure you have TLS 1.3 enabled: link to KB"

@hwoodiwiss hwoodiwiss Mar 9, 2022 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I was aiming for the "option 1" route originally. Although I think given that Client and Server can be independently disabled, it could be problematic/misleading to include TLS being disabled in setting IsQuicSupported.

I think the Tls13MayBeDisabled and special case error handling makes sense, as it allows for Quic to be used for a client use case when the TLS 1.3 server role has been disabled.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fine with me. That path creates silent failure that will be harder to diagnose IMHO. But that scenario may be rare and it still may be better than failing operations.

@hwoodiwiss hwoodiwiss Mar 9, 2022 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other than that, a simpler and more catch all option would be just to special case 0x80090331 in QuicExceptionHelper and have it add information relevant to the TLS 1.3 registry settings to the exception message (or a KB link as ManickaP mentions)?

I think that would probably give better coverage of users that disable TLS after the launch, my only worry would be the potential to mask or mislead in cases where disabled TLS isn't the cause of the 0x80090331

private static bool IsTls1_3Disabled()
{
#if WINDOWS
const string SChannelTLS1_3RegKey = @"SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.3";

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is correct. It should be Enabled in HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.3\Client and HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.3\Server AFAIK

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed this after I started testing a different implementation locally.

Are there any implications as to how this should be handled due to client and server being independently disableable?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since the Schannel control is separate most accurate would be to trace it also separately and distinguish between in and out connections e.g client vs server. But since something can be disabled while the process is running the accuracy is already not perfect. I feel it may be OK track it together e.g. set TLs13Disable if either side is disabled and

if (errorCode == 0x80090331 && Tls13MayBeDisabled)
{
   throw NiceDisabledException()
}
else
{
   throw lowLevelOS/Quick
}

return;
}

if (isWindows && IsTls1_3Disabled())

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (isWindows && IsTls1_3Disabled())
if (isWindows && IsTls13Disabled())

return;
}

if (isWindows && IsTls1_3Disabled())

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It also seems like there is already check for isWindows above. I would probably embed new code and IsWindowsVersionSupported into it.


private static bool IsTls1_3Disabled()
{
#if WINDOWS

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if we need this. Linker may be smart enough to trim it away. If we do, we seems to use TARGET_WINDOWS in other places like this. That makes it work for cross-targeting e.g. building Windows bit on Linux and vice versa. (needs small project file change)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I gave it a try and it didn't look like the linker could trim the Windows only bits, so I've added TARGET_WINDOWS

Update to check correct registry keys/values
Throw `QuicTlsVersionException` on specific failures of ConfigurationLoadCredential

Throw this exception if status is 0x80090331 (Algorithm Mismatch), and the registry indicated that Tls13 could be disabled
</root>

<data name="net_quic_tls_version_notsupported" xml:space="preserve">
<value>Could not use a TLS version supported by Quic. TLS 1.3 may have been disabled in the registry.</value>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be more like "Could not use a TLS version required by Quic." ???

status = MsQuicApi.Api.ConfigurationLoadCredentialDelegate(configurationHandle, ref config);
}

if (status == 0x80090331 && MsQuicApi.Tls13MayBeDisabled)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (status == 0x80090331 && MsQuicApi.Tls13MayBeDisabled)
if (status == Interop.SECURITY_STATUS.AlgorithmMismatch && MsQuicApi.Tls13MayBeDisabled)

Microsoft ResX Schema

<!--
Microsoft ResX Schema

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this seems wrong e.g. bunch of spaces added to where they should not be.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry about that, I think this was done by my IDE. I've removed all the random Whitespace changes.

@wfurt wfurt left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally looks good to me.
any more thoughts on this @ManickaP ?

@ManickaP

Copy link
Copy Markdown
Member

Yep, LGTM, thanks!

Make AlgorithmMismatch check TARGET_WINDOWS only

Interop.SECURITY_STATUS contains status values from SChannel, which is the source of this error in the first place.
public long ErrorCode { get { throw null; } }
}

public partial class QuicTlsVersionException : System.Net.Quic.QuicException

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we add a new exception type for this? Also this is basically a new API surface. I'd prefer to use the existing exception type.
What's the motivation behind introducing it?

@hwoodiwiss hwoodiwiss Mar 28, 2022 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seemed cleaner to me than the equivalent using the existing type which would be:

throw new QuicException(SR.net_ssl_app_protocols_invalid, null, (int)status);

And follows the existing pattern for Exceptions that use strings from resources.

I can appreciate not wanting to expand the API surface just for this, I'll swap the new exception the above.

@ManickaP ManickaP left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hwoodiwiss Thank you for your contribution and your patience with us. I think this is ready to get merged.

@wfurt
wfurt merged commit 0eccdba into dotnet:main Mar 29, 2022
@karelz karelz added this to the 7.0.0 milestone Apr 8, 2022
@ghost ghost locked as resolved and limited conversation to collaborators May 8, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-System.Net.Quic community-contribution Indicates that the PR has been added by a community member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

HTTP/3: Improve user experience when TLS 1.3 is not enabled on Windows

4 participants