Skip to content
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

add basic support for SNI different than URI in H3 #71428

Merged
merged 2 commits into from
Jul 1, 2022
Merged

Conversation

wfurt
Copy link
Member

@wfurt wfurt commented Jun 29, 2022

We had minimal support for cases with IP address. This extends that with simple DNS lookup. While we can get more than one address and in Sockets we would try to try them all, this PR simply mimics MsQuic and only use first IP.
That may be sufficient as this scenario mostly involve testing. Also in the future we can enhance whole connect (or MsQuic) to do something better.

fixes #57169

@wfurt wfurt added this to the 7.0.0 milestone Jun 29, 2022
@wfurt wfurt requested a review from a team June 29, 2022 12:58
@wfurt wfurt self-assigned this Jun 29, 2022
@ghost
Copy link

ghost commented Jun 29, 2022

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

Issue Details

We had minimal support for cases with IP address. This extends that with simple DNS lookup. While we can get more than one address and in Sockets we would try to try them all, this PR simply mimics MsQuic and only use first IP.
That may be sufficient as this scenario mostly involve testing. Also in the future we can enhance whole connect (or MsQuic) to do something better.

fixes #57169

Author: wfurt
Assignees: wfurt
Labels:

area-System.Net.Quic

Milestone: 7.0.0

@@ -536,15 +537,32 @@ internal unsafe ValueTask ConnectAsync(CancellationToken cancellationToken = def
// We don't have way how to set separate SNI and name for connection at this moment.
// If the name is actually IP address we can use it to make at least some cases work for people
// who want to bypass DNS but connect to specific virtual host.
if (!string.IsNullOrEmpty(_state.TargetHost) && !dnsHost.Equals(_state.TargetHost, StringComparison.InvariantCultureIgnoreCase) && IPAddress.TryParse(dnsHost, out IPAddress? address))
if (!dnsHost.Equals(_state.TargetHost, StringComparison.InvariantCultureIgnoreCase) && !string.IsNullOrEmpty(_state.TargetHost))
Copy link
Member

Choose a reason for hiding this comment

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

Is there a reason to swap the IsNullOrEmpty check with the equality comparison?

Copy link
Member Author

Choose a reason for hiding this comment

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

not really. I think _state.TargetHost is unlikely to be null. (or maybe never would)

Copy link
Member

Choose a reason for hiding this comment

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

I was just asking because you swapped them, I don't mind either way.

}
else
{
IPAddress[] addresses = Dns.GetHostAddressesAsync(dnsHost, cancellationToken).GetAwaiter().GetResult();
Copy link
Member

Choose a reason for hiding this comment

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

You're in an async method, you can await or you can just use the sync version of the method.

Copy link
Member Author

Choose a reason for hiding this comment

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

While the name is ConnectAsync it does not have async keyword. I was thinking about sync method but that does not have cancellation overload.

Copy link
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 that using sync-over-async on an async method within an async method (albeit only task returning atm) is the best option here.

Copy link
Member Author

Choose a reason for hiding this comment

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

I can switch to Dns.GetHostAddresses and give up on cancellation completely. cc: @stephentoub for any additional suggestions.

Copy link
Member

Choose a reason for hiding this comment

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

Once I merge this with the static ConnectAsync, I can take the full advantage of the async and call await. So I guess it doesn't matter much here atm.

cancellationToken.ThrowIfCancellationRequested();
if (addresses.Length == 0)
{
throw new SocketException((int)SocketError.HostNotFound);
Copy link
Member

Choose a reason for hiding this comment

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

QuicException?

Copy link
Member Author

Choose a reason for hiding this comment

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

This is what we get in HTTP/Sockets and in case GetHostAddressesAsync fail to resolve. I'm not 100% we would ever get empty list without failure but if we would I did not want to cause index errors. I'm open to QuicException but fail to resolve may not be IOException.

Copy link
Member

@ManickaP ManickaP Jun 29, 2022

Choose a reason for hiding this comment

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

fail to resolve may not be IOException

Why?

We should then reconsider inheriting QuicException from IOException, but we shouldn't throw SocketException from S.N.Quic.

cc @rzikm

Copy link
Member Author

Choose a reason for hiding this comment

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

as I mentioned we may do it anyway if Dns.GetHostAddressesAsync fails. Unless you want to catch it and throw something else in both cases. We can certainly do it as well.

Copy link
Member

Choose a reason for hiding this comment

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

Baaah, I'm not sure, let's keep the SocketException for now to be consistent with NameResolution class. We can revisit this in the future if it'll cause confusion.

Copy link
Member

@ManickaP ManickaP left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

cancellationToken.ThrowIfCancellationRequested();
if (addresses.Length == 0)
{
throw new SocketException((int)SocketError.HostNotFound);
Copy link
Member

Choose a reason for hiding this comment

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

Baaah, I'm not sure, let's keep the SocketException for now to be consistent with NameResolution class. We can revisit this in the future if it'll cause confusion.

@@ -536,15 +537,32 @@ internal unsafe ValueTask ConnectAsync(CancellationToken cancellationToken = def
// We don't have way how to set separate SNI and name for connection at this moment.
// If the name is actually IP address we can use it to make at least some cases work for people
// who want to bypass DNS but connect to specific virtual host.
if (!string.IsNullOrEmpty(_state.TargetHost) && !dnsHost.Equals(_state.TargetHost, StringComparison.InvariantCultureIgnoreCase) && IPAddress.TryParse(dnsHost, out IPAddress? address))
if (!dnsHost.Equals(_state.TargetHost, StringComparison.InvariantCultureIgnoreCase) && !string.IsNullOrEmpty(_state.TargetHost))
Copy link
Member

Choose a reason for hiding this comment

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

I was just asking because you swapped them, I don't mind either way.

}
else
{
IPAddress[] addresses = Dns.GetHostAddressesAsync(dnsHost, cancellationToken).GetAwaiter().GetResult();
Copy link
Member

Choose a reason for hiding this comment

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

Once I merge this with the static ConnectAsync, I can take the full advantage of the async and call await. So I guess it doesn't matter much here atm.

@wfurt wfurt merged commit 7b89c86 into dotnet:main Jul 1, 2022
@wfurt wfurt deleted the quicSni branch July 1, 2022 17:37
@ghost ghost locked as resolved and limited conversation to collaborators Jul 31, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[HTTP/3] SNI does not use the Host header value
2 participants