Repository navigation
Improve QuicImplementationProviders.MsQuic.IsSupported for TLS1.3 On Windows - #66019
Conversation
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
|
Tagging subscribers to this area: @dotnet/ncl Issue Detailsfixes #55237 Adds a registry check to detect whether TLS1.3 Has been disabled in the registry on windows.
|
| { | ||
| internal static partial class MsQuicTlsSupportHelper | ||
| { | ||
| public static bool IsTls1_3Disabled() => false; |
There was a problem hiding this comment.
Could we just #if ... instead of putting it into extra helper class and files?
There was a problem hiding this comment.
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"; |
There was a problem hiding this comment.
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)?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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."); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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"
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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"; |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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()) |
There was a problem hiding this comment.
| if (isWindows && IsTls1_3Disabled()) | |
| if (isWindows && IsTls13Disabled()) |
| return; | ||
| } | ||
|
|
||
| if (isWindows && IsTls1_3Disabled()) |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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> |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
| if (status == 0x80090331 && MsQuicApi.Tls13MayBeDisabled) | |
| if (status == Interop.SECURITY_STATUS.AlgorithmMismatch && MsQuicApi.Tls13MayBeDisabled) |
| Microsoft ResX Schema | ||
|
|
||
| <!-- | ||
| Microsoft ResX Schema |
There was a problem hiding this comment.
this seems wrong e.g. bunch of spaces added to where they should not be.
There was a problem hiding this comment.
Sorry about that, I think this was done by my IDE. I've removed all the random Whitespace changes.
|
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 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
left a comment
There was a problem hiding this comment.
@hwoodiwiss Thank you for your contribution and your patience with us. I think this is ready to get merged.
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