-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
[API Proposal]: Make some System.Net.Security functions/properties public for System.Net.Quic #67552
Comments
Tagging subscribers to this area: @dotnet/ncl, @vcsjones Issue DetailsBackground and motivation
cc: @wfurt API Proposal
// Public ctors, but getters are internal.
public class SslStreamCertificateContext
{
- internal readonly X509Certificate2 Certificate;
+ public readonly X509Certificate2 Certificate;
- internal readonly X509Certificate2[] IntermediateCertificates;
+ internal readonly X509Certificate2[] IntermediateCertificates;
// public ctors
}
// It has public getters, but cannot be constructed with values outside of System.Net.Security.
public readonly struct SslClientHelloInfo
{
public readonly string ServerName { get; }
public readonly SslProtocols { get; }
- internal SslClientHelloInfo(string serverName, SslProtocols sslProtocols);
+ public SslClientHelloInfo(string serverName, SslProtocols sslProtocols);
} API Usage
if (sslOptions.ServerCertificateContext is not null)
{
certificate = sslOptions.ServerCertificateContext.ContextCertificate;
intermediaries = sslOptions.ServerCertificateContext.ContextChain;
}
SslClientHelloInfo sslClientHelloInfo = new SslClientHelloInfo(targetHost, SslProtocols.Tls13); Alternative Designs
For both, RisksNot much. We'd be only exposing readonly getters and struct ctor.
|
For the |
I would suggest public X509Certificate2 TargetCertificate { get; }
public ReadOnlySpan<X509Certificate2> IntermediateCertificates { get; } |
Yeah, I only took the fields as they are now and made them public. Getters are fine choice here as well, I'll update the proposal to reflect that. |
Do we still want to keep this since #68189 was merged? |
Closing in favor of #68189 |
We weren't feeling good about the ReadOnlyMemory property, and want to have a discussion about it. // Public ctors, but getters are internal.
public class SslStreamCertificateContext
{
- internal readonly X509Certificate2 Certificate;
+ public X509Certificate2 TargetCertificate { get; }
+ public ReadOnlyMemory<X509Certificate2> IntermediateCertificates { get; }
// public ctors
}
// It has public getters, but cannot be constructed with values outside of System.Net.Security.
public readonly struct SslClientHelloInfo
{
public readonly string ServerName { get; }
public readonly SslProtocols SslProtocols { get; }
- internal SslClientHelloInfo(string serverName, SslProtocols sslProtocols);
+ public SslClientHelloInfo(string serverName, SslProtocols sslProtocols);
} |
namespace System.Net.Security;
public partial class SslStreamCertificateContext
{
public X509Certificate2 TargetCertificate { get; }
public ReadOnlyCollection<X509Certificate2> IntermediateCertificates { get; }
} |
Background and motivation
SslStreamCertificateContext
In System.Net.Quic, we're handling certificates from
SslServerAuthenticationOptions
and need to pass them to msquic. SinceSslServerAuthenticationOptions
allows to specify certificate with its intermediates viaSslStreamCertificateContext
, we need to be able to extract both properties from the class in order to convert them and pass them to msquic.SslClientHelloInfo
We'll also be adding our version of
ServerOptionsSelectionCallback
:runtime/src/libraries/System.Net.Security/src/System/Net/Security/SslStream.cs
Line 38 in 4f60211
And we'll need to be able to construct
SslClientHelloInfo
struct. Otherwise, we'll be left with reflection here as well.Current SslStreamCertificateContext takes list of additional certificates. But when
Create
method is called it is not clear if X509Chain build succeeds and how the actual list looks.Exposing the
IntermediateCertificates
would make any investigations easierSslStreamCertificateContext
is notiDisposable
(unfortunately).Exposing the inner certificates possibly allows some cleanup if needed. (also creates risk of mishandling)
API Proposal
Create
method calls the certificatetarget
and that seems too ambiguous. The proposal is to call itTaregtCertificate
to make it somewhat closer or we can use the current internalCertificate
(that is pretty generic as well)We also talk about
ReadOnlySpan<X509Certificate2>
for theIntermediateCertificates
but the consensus was to use Memory as more flexible. Current implementation use array under the cover.API Usage
Alternative Designs
SslStreamCertificateContext
Move the whole logic around certificates to System.Net.Security and get out of it only ASN1 blob (which we need for msquic).
SslClientHelloInfo
Not much options here, possibly static create method.
For both,
InternalsVisibleTo
. I'm aware it's "forbidden" in runtime, but I don't know why.For both, merging System.Net.Security with System.Net.Quic. This was voted against in our team discussion, unless we want to merge whole lot more and create omnipotent System.Net.dll.
Use reflection
That was done in early 7.0. Not great for obvious reason.
Use semi-public methods (current state)
Needed properties and methods are public but not in ref assembly.
Noted in SslStreamCertificateContext has public fields in its implementation that aren't in the contract #72226 .
Risks
Not much. We'd be only exposing readonly getters and struct ctor.
The text was updated successfully, but these errors were encountered: