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
Somewhat working update of msquic API
  • Loading branch information
ManickaP committed Mar 17, 2021
commit 6a132c56f91b1dc1880ce3bc2277bd1ee5e9fffc
6 changes: 5 additions & 1 deletion src/libraries/System.Net.Quic/src/System.Net.Quic.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,15 @@
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
</Content>
<Content Include="msquic.pdb" Condition="Exists('msquic.pdb')">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
</Content>
<Content Include="libmsquic.so" Condition="Exists('libmsquic.so')">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
</Content>
<Content Include="msquic.pdb" Condition="Exists('msquic.pdb')">
<Content Include="libmsquic.lttng.so" Condition="Exists('libmsquic.lttng.so')">
Copy link
Contributor

Choose a reason for hiding this comment

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

@scalablecory could we reference the System.Net.Experimental.Quic here instead now? https://github.com/dotnet/runtimelab/tree/feature/System.Net.Experimental.MsQuic

Copy link
Contributor

Choose a reason for hiding this comment

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

You won't need that package for .NET 6.

<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
</Content>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,9 @@ internal override bool Connected
}

// TODO: Should clone the endpoint since it is mutable
internal override IPEndPoint LocalEndPoint => _localEndPoint;
// TODO: could this be made back to non-nullable?
// For inbound we have it immidiatelly, for outbound after connect.
internal override IPEndPoint? LocalEndPoint => _localEndPoint;

// TODO: Should clone the endpoint since it is mutable
internal override EndPoint RemoteEndPoint => _remoteEndPoint!;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ internal enum QUIC_CREDENTIAL_FLAGS : uint
USE_TLS_BUILTIN_CERTIFICATE_VALIDATION = 0x00000080,
}

internal enum QUIC_CERTIFICATE_HASH_STORE_FLAGS
{
QUIC_CERTIFICATE_HASH_STORE_FLAG_NONE = 0x0000,
QUIC_CERTIFICATE_HASH_STORE_FLAG_MACHINE_STORE = 0x0001,
}

[Flags]
internal enum QUIC_CONNECTION_SHUTDOWN_FLAGS : uint
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,6 @@ internal struct CredentialConfig
{
internal QUIC_CREDENTIAL_TYPE Type;
internal QUIC_CREDENTIAL_FLAGS Flags;
// Mana: define struct for the union in C
internal IntPtr Certificate;
[MarshalAs(UnmanagedType.LPUTF8Str)]
internal string Principal;
Expand All @@ -209,6 +208,67 @@ internal struct CredentialConfig
internal IntPtr AsyncHandler;
}

[StructLayout(LayoutKind.Explicit)]
internal struct CredentialConfigCertificateUnion
{
[FieldOffset(0)]
internal CredentialConfigCertificateCertificateHash CertificateHash;

[FieldOffset(0)]
internal CredentialConfigCertificateCertificateHashStore CertificateHashStore;

[FieldOffset(0)]
internal IntPtr CertificateContext;

[FieldOffset(0)]
internal CredentialConfigCertificateCertificateFile CertificateFile;

[FieldOffset(0)]
internal CredentialConfigCertificateCertificateFileProtected CertificateFileProtected;
}

[StructLayout(LayoutKind.Sequential)]
internal struct CredentialConfigCertificateCertificateHash
{
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 20)]
internal byte[] ShaHash;
}

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
internal struct CredentialConfigCertificateCertificateHashStore
{
internal QUIC_CERTIFICATE_HASH_STORE_FLAGS Flags;

[MarshalAs(UnmanagedType.ByValArray, SizeConst = 20)]
internal byte[] ShaHash;

[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 128)]
internal char[] StoreName;
}

[StructLayout(LayoutKind.Sequential)]
internal struct CredentialConfigCertificateCertificateFile
{
[MarshalAs(UnmanagedType.LPUTF8Str)]
internal string PrivateKeyFile;

[MarshalAs(UnmanagedType.LPUTF8Str)]
internal string CertificateFile;
}

[StructLayout(LayoutKind.Sequential)]
internal struct CredentialConfigCertificateCertificateFileProtected
{
[MarshalAs(UnmanagedType.LPUTF8Str)]
internal string PrivateKeyFile;

[MarshalAs(UnmanagedType.LPUTF8Str)]
internal string CertificateFile;

[MarshalAs(UnmanagedType.LPUTF8Str)]
internal string PrivateKeyPassword;
}

[StructLayout(LayoutKind.Sequential)]
internal struct ListenerEvent
{
Expand All @@ -226,8 +286,7 @@ internal struct ListenerEventDataUnion
[StructLayout(LayoutKind.Sequential)]
internal struct ListenerEventDataNewConnection
{
// Mana: struct QUIC_NEW_CONNECTION_INFO / NewConnectionInfo
internal IntPtr Info;
internal NewConnectionInfo* Info;
internal IntPtr Connection;
}

Expand Down Expand Up @@ -545,7 +604,7 @@ internal byte[] Address
}

// Mana: why charset? rename to something C#-like, including fields.
[StructLayout(LayoutKind.Explicit, CharSet = CharSet.Ansi)]
[StructLayout(LayoutKind.Explicit)]
internal struct SOCKADDR_INET
{
[FieldOffset(0)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,14 @@ private static unsafe SafeMsQuicConfigurationHandle Create(QuicOptions options,
// If using stub TLS.
config.Type = QUIC_CREDENTIAL_TYPE.STUB_NULL;
#else
// TODO: doesn't work on non-Windows
config.Type = QUIC_CREDENTIAL_TYPE.CONTEXT;
config.Certificate = certificate.Handle;
#endif
}
else
{
// TODO: not allowed for OpenSSL and server
config.Type = QUIC_CREDENTIAL_TYPE.NONE;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ internal sealed class MsQuicConnection : QuicConnectionProvider
private GCHandle _stateHandle;
private bool _disposed;

private IPEndPoint? _localEndPoint;
private readonly IPEndPoint? _localEndPoint;
private readonly EndPoint _remoteEndPoint;
private SslApplicationProtocol _negotiatedAlpnProtocol;

Expand Down Expand Up @@ -106,8 +106,7 @@ public MsQuicConnection(QuicClientConnectionOptions options)
}
}

internal override IPEndPoint LocalEndPoint =>
new IPEndPoint(_localEndPoint!.Address, _localEndPoint!.Port);
internal override IPEndPoint? LocalEndPoint => _localEndPoint ?? _state.LocalEndPoint;

internal override EndPoint RemoteEndPoint => _remoteEndPoint;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ private static unsafe uint NativeCallbackHandler(

try
{
ref NewConnectionInfo connectionInfo = ref *(NewConnectionInfo*)evt.Data.NewConnection.Info;
ref NewConnectionInfo connectionInfo = ref *evt.Data.NewConnection.Info;

IPEndPoint localEndPoint = MsQuicAddressHelpers.INetToIPEndPoint(ref *(SOCKADDR_INET*)connectionInfo.LocalAddress);
IPEndPoint remoteEndPoint = MsQuicAddressHelpers.INetToIPEndPoint(ref *(SOCKADDR_INET*)connectionInfo.RemoteAddress);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ internal abstract class QuicConnectionProvider : IDisposable
{
internal abstract bool Connected { get; }

internal abstract IPEndPoint LocalEndPoint { get; }
internal abstract IPEndPoint? LocalEndPoint { get; }

internal abstract EndPoint RemoteEndPoint { get; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ internal QuicConnection(QuicConnectionProvider provider)
/// </summary>
public bool Connected => _provider.Connected;

public IPEndPoint LocalEndPoint => _provider.LocalEndPoint;
public IPEndPoint? LocalEndPoint => _provider.LocalEndPoint;

public EndPoint RemoteEndPoint => _provider.RemoteEndPoint;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

namespace System.Net.Quic.Tests
{
// TODO: why do we hawe 2 base clase with some duplicated methods?
public class MsQuicTestBase
{
public SslServerAuthenticationOptions GetSslServerAuthenticationOptions()
Expand All @@ -15,6 +16,7 @@ public SslServerAuthenticationOptions GetSslServerAuthenticationOptions()
{
ApplicationProtocols = new List<SslApplicationProtocol>() { new SslApplicationProtocol("quictest") },
// TODO: use a cert. MsQuic currently only allows certs that are trusted.
Copy link
Member

Choose a reason for hiding this comment

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

What is the cause of this trusted limitation? Is it a requirement of QUIC, or because we haven't added configuration to ignore invalid certificates yet?

Copy link
Member

Choose a reason for hiding this comment

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

we may need to plumb custom validation callback to managed code. I'm not sure if that was already done.

Copy link
Member

Choose a reason for hiding this comment

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

//ServerCertificate = System.Net.Test.Common.Configuration.Certificates.GetServerCertificate()
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ public async Task TestConnect()
{
using QuicListener listener = CreateQuicListener();

listener.Start();
IPEndPoint listenEndPoint = listener.ListenEndPoint;

using QuicConnection clientConnection = CreateQuicConnection(listenEndPoint);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="$(CommonTestPath)Tests\System\IO\StreamConformanceTests.cs" Link="Common\System\IO\StreamConformanceTests.cs" />
<Compile Include="$(CommonTestPath)System\Net\Configuration.Certificates.cs" Link="Common\System\Net\Configuration.Certificates.cs" />
<Compile Include="$(CommonTestPath)System\IO\CallTrackingStream.cs" Link="Common\System\IO\CallTrackingStream.cs" />
<Compile Include="$(CommonTestPath)System\IO\ConnectedStreams.cs" Link="Common\System\IO\ConnectedStreams.cs" />
<Compile Include="$(CommonTestPath)System\Threading\Tasks\TaskTimeoutExtensions.cs" Link="TestCommon\System\Threading\Tasks\TaskTimeoutExtensions.cs" />
Expand All @@ -17,4 +18,7 @@
<Compile Include="$(CommonPath)System\Net\StreamBuffer.cs" Link="ProductionCode\Common\System\Net\StreamBuffer.cs" />
<Compile Include="$(CommonPath)System\Threading\Tasks\TaskToApm.cs" Link="Common\System\Threading\Tasks\TaskToApm.cs" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="System.Net.TestData" Version="$(SystemNetTestDataVersion)" />
</ItemGroup>
</Project>