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

basic certificate handling for quic #50613

Merged
merged 6 commits into from
Apr 9, 2021
Merged

basic certificate handling for quic #50613

merged 6 commits into from
Apr 9, 2021

Conversation

wfurt
Copy link
Member

@wfurt wfurt commented Apr 1, 2021

With microsoft/msquic#1411 support for STUB Tls was removed and we only have real option left.

This change adds server support for normal X509Certificate and plus usual verification callback so the fate of the handshake can be decided from .NET.

Right now, this is supported only ion Windows, Linux & macOS coming (hopefully) soon.

This is also missing support for custom certificate chains, SslStreamCertificateContext, and client certificates.

cc: @nibanks

@ghost
Copy link

ghost commented Apr 1, 2021

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

Issue Details

With microsoft/msquic#1411 support for STUB Tls was removed and we only have real option left.

This change adds server support for normal X509Certificate and plus usual verification callback so the fate of the handshake can be decided from .NET.

Right now, this is supported only ion Windows, Linux & macOS coming (hopefully) soon.

This is also missing support for custom certificate chains, SslStreamCertificateContext, and client certificates.

cc: @nibanks

Author: wfurt
Assignees: -
Labels:

area-System.Net.Quic

Milestone: -

@wfurt
Copy link
Member Author

wfurt commented Apr 2, 2021

Basic certificates should now work on Linux & macOS well.
Some networking tests are failing like this on macOS

System.Net.Quic.Tests.QuicConnectionTests_MsQuicProvider.TestConnect [FAIL]
        Assert.Equal() Failure
        Expected: 127.0.0.1:63445
        Actual:   [::]:63445

I will investigate in separate effort.

}
else
{
flags |= QUIC_CREDENTIAL_FLAGS.INDICATE_CERTIFICATE_RECEIVED | QUIC_CREDENTIAL_FLAGS.NO_CERTIFICATE_VALIDATION;
Copy link

@nibanks nibanks Apr 2, 2021

Choose a reason for hiding this comment

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

You never want to let the TLS stack do the certificate validation?

Copy link
Member Author

Choose a reason for hiding this comment

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

That how SslStream works now. Long term, we may check if custom callback is present or now. But that is still problematic (at least on Linux) as X509Chain would consider user stores while OS does not have any clue about them. So we would end up in situation when SslStream works and Quick does not or vice versa.


try
{
if (certificate == null)
Copy link

Choose a reason for hiding this comment

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

I don't expect this to ever happen. We shouldn't be calling you with "Peer Certificate Received" if we didn't have a certificate. Personally, I'd say you could just assert here or something.

Copy link
Member Author

Choose a reason for hiding this comment

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

The null makes perfect sense for server side where client's certificate is optional. I just need to complete that part but the validation callback will be shared.

@nibanks
Copy link

nibanks commented Apr 2, 2021 via email

byte[] asn1 = certificate.Export(X509ContentType.Pkcs12);
unsafe
{
fixed (void* ptr = asn1)
Copy link
Member

Choose a reason for hiding this comment

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

I think this is the only occurrence of fixed in here. I'm not an interop expert, but should we rather use GCHandle as we do in other places? Is there any difference in those two? If not should we rather stick to the same approach throughout?
cc: @scalablecory

Copy link
Member Author

Choose a reason for hiding this comment

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

You need to allocate GCHandle to preserve object for longer time. This basically says "don't move asn1 while I'm in this block" and it is much simpler. (and does not work for the other cases.


if (!OperatingSystem.IsWindows())
{
// TODO fix validation with OpenSSL
Copy link
Contributor

Choose a reason for hiding this comment

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

What is remaining to do here? Is there an issue?

Copy link
Member Author

Choose a reason for hiding this comment

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

The issue is that we don't have good way how to get certificate chain right now with OpenSSL.
There is not specific issue AFAIK. I mentally do this as contributions to #49574.
I will follow-up if/when microsoft/msquic#1450 (+implementation) is ready.

@wfurt
Copy link
Member Author

wfurt commented Apr 8, 2021

all the concerns should be addressed. Following outstanding issues will be follow-up changes:

  • certificate chain handling
  • client certificates
  • certificate validation with OpenSSL

@JamesNK
Copy link
Member

JamesNK commented Apr 8, 2021

I created a number of TLS issues for QUIC. It would be good to know which ones your PR makes progress on.

For #49574, it looks like this checks off RemoteCertificateValidationCallback and CertificateRevocationCheckMode.

Does this PR start to unblock #50156?

@wfurt
Copy link
Member Author

wfurt commented Apr 8, 2021

With this, self-signed (and other certificates) will work on Windows @JamesNK. Linux/macOS is getting closer.
I'm planning to go through the open issues once we have platform parity.

@wfurt wfurt merged commit 01b7e73 into dotnet:main Apr 9, 2021
@wfurt wfurt deleted the quicCert branch April 9, 2021 16:29
@ghost ghost locked as resolved and limited conversation to collaborators May 9, 2021
@karelz karelz added this to the 6.0.0 milestone May 20, 2021
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.

8 participants