Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Code review feedback
  • Loading branch information
rzikm committed Apr 20, 2023
commit 04dcff6fec4d686920db01a5ee4937cb5f2d87d9
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,5 @@ private static unsafe bool IsValidAddress(ReadOnlySpan<char> ipSpan)

return false;
}

}
}
4 changes: 0 additions & 4 deletions src/libraries/System.Net.Quic/src/System.Net.Quic.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,6 @@
<Compile Include="$(CommonPath)System\Net\IPAddressParserStatics.cs" Link="Common\System\Net\IPAddressParserStatics.cs" />
<Compile Include="$(CommonPath)System\Net\Internals\IPEndPointExtensions.cs" Link="Common\System\Net\Internals\IPEndPointExtensions.cs" />
<Compile Include="$(CommonPath)System\Net\Security\TlsAlertMessage.cs" Link="Common\System\Net\Security\TlsAlertMessage.cs" />
<Compile Include="$(CommonPath)System\Net\Security\TargetHostNameHelper.cs" Link="Common\System\Net\Security\TargetHostNameHelper.cs" />
<!-- IP parser -->
<Compile Include="$(CommonPath)System\Net\IPv4AddressHelper.Common.cs" Link="System\Net\IPv4AddressHelper.Common.cs" />
<Compile Include="$(CommonPath)System\Net\IPv6AddressHelper.Common.cs" Link="System\Net\IPv6AddressHelper.Common.cs" />
</ItemGroup>
<!-- Unsupported platforms -->
<ItemGroup Condition="'$(TargetPlatformIdentifier)' == ''">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ private readonly struct SslConnectionOptions
/// <summary>
/// Host name send in SNI, set only for outbound/client connections. Configured via <see cref="SslClientAuthenticationOptions.TargetHost"/>.
/// </summary>
internal string TargetHost => _targetHost;
private readonly string _targetHost;
/// <summary>
/// Always <c>true</c> for outbound/client connections. Configured for inbound/server ones via <see cref="SslServerAuthenticationOptions.ClientCertificateRequired"/>.
Expand All @@ -48,6 +47,8 @@ private readonly struct SslConnectionOptions
/// </summary>
private readonly X509ChainPolicy? _certificateChainPolicy;

internal string TargetHost => _targetHost;

public SslConnectionOptions(QuicConnection connection, bool isClient,
string targetHost, bool certificateRequired, X509RevocationMode
revocationMode, RemoteCertificateValidationCallback? validationCallback,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,6 @@ public sealed partial class QuicConnection : IAsyncDisposable
/// </remarks>
public static bool IsSupported => MsQuicApi.IsQuicSupported;

/// <summary>
/// Gets the name of the server the client is trying to connect to. That name is used for server certificate validation. It can be a DNS name or an IP address.
/// </summary>
/// <returns>The name of the server the client is trying to connect to.</returns>
public string TargetHostName => _sslConnectionOptions.TargetHost ?? string.Empty;

/// <summary>
/// Creates a new <see cref="QuicConnection"/> and connects it to the peer.
/// </summary>
Expand Down Expand Up @@ -155,6 +149,12 @@ public static async ValueTask<QuicConnection> ConnectAsync(QuicClientConnectionO
/// </summary>
public IPEndPoint LocalEndPoint => _localEndPoint;

/// <summary>
/// Gets the name of the server the client is trying to connect to. That name is used for server certificate validation. It can be a DNS name or an IP address.
/// </summary>
/// <returns>The name of the server the client is trying to connect to.</returns>
public string TargetHostName => _sslConnectionOptions.TargetHost ?? string.Empty;

/// <summary>
/// The certificate provided by the peer.
/// For an outbound/client connection will always have the peer's (server) certificate; for an inbound/server one, only if the connection requested and the peer (client) provided one.
Expand Down Expand Up @@ -288,7 +288,7 @@ private async ValueTask FinishConnectAsync(QuicClientConnectionOptions options,
_sslConnectionOptions = new SslConnectionOptions(
this,
isClient: true,
TargetHostNameHelper.NormalizeHostName(options.ClientAuthenticationOptions.TargetHost),
options.ClientAuthenticationOptions.TargetHost ?? "",
certificateRequired: true,
options.ClientAuthenticationOptions.CertificateRevocationCheckMode,
options.ClientAuthenticationOptions.RemoteCertificateValidationCallback,
Expand Down
48 changes: 48 additions & 0 deletions src/libraries/System.Net.Quic/tests/FunctionalTests/MsQuicTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1204,5 +1204,53 @@ public async Task IdleTimeout_ThrowsQuicException()
await AssertThrowsQuicExceptionAsync(QuicError.ConnectionIdle, async () => await acceptTask).WaitAsync(TimeSpan.FromSeconds(10));
}
}

[Theory]
[MemberData(nameof(HostNameData))]
[ActiveIssue("https://github.com/dotnet/runtime/issues/68206", TestPlatforms.Android)]
public async Task ClientSendsSniServerReceives_Ok(string hostName)
{
using X509Certificate serverCert = Configuration.Certificates.GetSelfSignedServerCertificate();
var listenerOptions = new QuicListenerOptions()
{
ListenEndPoint = new IPEndPoint(IPAddress.Loopback, 0),
ApplicationProtocols = new List<SslApplicationProtocol>() { ApplicationProtocol },
ConnectionOptionsCallback = (_, _, _) =>
{
var serverOptions = CreateQuicServerOptions();
serverOptions.ServerAuthenticationOptions.ServerCertificateContext = null;
serverOptions.ServerAuthenticationOptions.ServerCertificate = null;
serverOptions.ServerAuthenticationOptions.ServerCertificateSelectionCallback = (sender, actualHostName) =>
{
Assert.Equal(hostName, actualHostName);
return serverCert;
};
return ValueTask.FromResult(serverOptions);
}
};

// Use whatever endpoint, it'll get overwritten in CreateConnectedQuicConnection.
QuicClientConnectionOptions clientOptions = CreateQuicClientOptions(listenerOptions.ListenEndPoint);
clientOptions.ClientAuthenticationOptions.TargetHost = hostName;
clientOptions.ClientAuthenticationOptions.RemoteCertificateValidationCallback = delegate { return true; };


(QuicConnection clientConnection, QuicConnection serverConnection) = await CreateConnectedQuicConnection(clientOptions, listenerOptions);
await using (clientConnection)
await using (serverConnection)
{
Assert.Equal(clientConnection.TargetHostName, hostName);
Assert.Equal(serverConnection.TargetHostName, hostName);
}
}

public static IEnumerable<object[]> HostNameData()
{
yield return new object[] { "a" };
yield return new object[] { "test" };
// max allowed hostname length is 63
yield return new object[] { new string('a', 63) };
yield return new object[] { "\u017C\u00F3\u0142\u0107 g\u0119\u015Bl\u0105 ja\u017A\u0144. \u7EA2\u70E7. \u7167\u308A\u713C\u304D" };
}
}
}