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

avoid Reflection in Quic #68189

Merged
merged 6 commits into from
May 2, 2022
Merged
Show file tree
Hide file tree
Changes from 4 commits
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
4 changes: 3 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 @@ -137,6 +137,9 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="$(LibrariesProjectRoot)System.Net.Security\src\System.Net.Security.csproj" >
<SkipUseReferenceAssembly>true</SkipUseReferenceAssembly>
</ProjectReference>
wfurt marked this conversation as resolved.
Show resolved Hide resolved
<Reference Include="Microsoft.Win32.Primitives" />
<Reference Include="System.Collections" />
<Reference Include="System.Collections.Concurrent" />
Expand All @@ -145,7 +148,6 @@
<Reference Include="System.Diagnostics.Tracing" />
<Reference Include="System.Memory" />
<Reference Include="System.Net.Primitives" />
<Reference Include="System.Net.Security" />
<Reference Include="System.Net.Sockets" />
<Reference Include="System.Runtime" />
<Reference Include="System.Runtime.CompilerServices.Unsafe" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using System.Collections.Generic;
using System.Diagnostics;
using System.Net.Security;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Security.Cryptography.X509Certificates;
using System.Threading;
Expand All @@ -15,9 +14,6 @@ namespace System.Net.Quic.Implementations.MsQuic.Internal
{
internal sealed class SafeMsQuicConfigurationHandle : SafeHandle
{
private static readonly FieldInfo _contextCertificate = typeof(SslStreamCertificateContext).GetField("Certificate", BindingFlags.NonPublic | BindingFlags.Instance)!;
private static readonly FieldInfo _contextChain = typeof(SslStreamCertificateContext).GetField("IntermediateCertificates", BindingFlags.NonPublic | BindingFlags.Instance)!;

public override bool IsInvalid => handle == IntPtr.Zero;

public SafeMsQuicConfigurationHandle()
Expand Down Expand Up @@ -188,13 +184,8 @@ private static unsafe SafeMsQuicConfigurationHandle Create(QuicOptions options,

if (certificateContext != null)
{
certificate = (X509Certificate2?)_contextCertificate.GetValue(certificateContext);
intermediates = (X509Certificate2[]?)_contextChain.GetValue(certificateContext);

if (certificate == null || intermediates == null)
{
throw new ArgumentException(nameof(certificateContext));
}
certificate = certificateContext.Certificate;
intermediates = certificateContext.IntermediateCertificates;
}

if (certificate != null)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Exposed publicly only in implementation for Quic
MembersMustExist : Member 'public System.Security.Cryptography.X509Certificates.X509Certificate2 System.Security.Cryptography.X509Certificates.X509Certificate2 System.Net.Security.SslStreamCertificateContext.Certificate' does not exist in the reference but it does exist in the implementation.
MembersMustExist : Member 'public System.Security.Cryptography.X509Certificates.X509Certificate2[] System.Security.Cryptography.X509Certificates.X509Certificate2[] System.Net.Security.SslStreamCertificateContext.IntermediateCertificates' does not exist in the reference but it does exist in the implementation.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<TargetFrameworks>$(NetCoreAppCurrent)-windows;$(NetCoreAppCurrent)-Unix;$(NetCoreAppCurrent)-Android;$(NetCoreAppCurrent)-OSX;$(NetCoreAppCurrent)-iOS;$(NetCoreAppCurrent)-tvOS;$(NetCoreAppCurrent)</TargetFrameworks>
<TargetFrameworks>$(NetCoreAppCurrent)-windows;$(NetCoreAppCurrent)-Linux;$(NetCoreAppCurrent)-FreeBSD;$(NetCoreAppCurrent)-Android;$(NetCoreAppCurrent)-OSX;$(NetCoreAppCurrent)-iOS;$(NetCoreAppCurrent)-tvOS;$(NetCoreAppCurrent)</TargetFrameworks>
<!-- This is needed so that code for TlsCipherSuite will have no namespace (causes compile errors) when used within T4 template -->
<DefineConstants>$(DefineConstants);PRODUCT</DefineConstants>
<Nullable>enable</Nullable>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ namespace System.Net.Security
{
public partial class SslStreamCertificateContext
{
internal readonly X509Certificate2 Certificate;
internal readonly X509Certificate2[] IntermediateCertificates;
public readonly X509Certificate2 Certificate;
public readonly X509Certificate2[] IntermediateCertificates;
Comment on lines 9 to +12
Copy link
Member

Choose a reason for hiding this comment

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

Would it make sense to add another comment here mentioning that these fields are not part of the ref assembly and are not, in fact, reachable in user code?

internal readonly SslCertificateTrust? Trust;

[EditorBrowsable(EditorBrowsableState.Never)]
Expand Down