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

Initial support for SslStreamCertificateContext #38364

Merged
merged 6 commits into from
Jul 2, 2020

Conversation

wfurt
Copy link
Member

@wfurt wfurt commented Jun 24, 2020

This adds part of the new API surface approved in #37933. Internally, I switched SslStream to use CertificateContext instead of ServerCertificate and I did minimal fixes in OpenSSL pal to get that through. MacOS and Windows will follow.
So as more tests once #38182 is in. I will us that structure to create more test scenarios for partial chains.

contribues to #35844

SslStreamCertificateContext.Create() was approved with X509Certificate2Collection and I'm wondering if X509CertificateCollection would be sufficient @bartonjs since we do not need keys for the intermediate certificates.

@wfurt wfurt added this to the 5.0.0 milestone Jun 24, 2020
@wfurt wfurt requested review from stephentoub, bartonjs and a team June 24, 2020 23:45
@wfurt wfurt self-assigned this Jun 24, 2020
@ghost
Copy link

ghost commented Jun 24, 2020

Tagging subscribers to this area: @dotnet/ncl
Notify danmosemsft if you want to be subscribed.

@Dotnet-GitSync-Bot
Copy link
Collaborator

Note regarding the new-api-needs-documentation label:

This serves as a reminder for when your PR is modifying a ref *.cs file and adding/modifying public APIs, to please make sure the API implementation in the src *.cs file is documented with triple slash comments, so the PR reviewers can sign off that change.

@bartonjs
Copy link
Member

I'm wondering if X509CertificateCollection would be sufficient since we do not need keys for the intermediate certificates.

Nothing should ever use X509Certificate. It's effectively a dead type that we have to just drag around since it's the base class of the useful type. Just pretend it, and the collection for it, don't exist. That's what everyone else does.

(e.g. the new multi-pem load methods are only on X509Certificate2Collection)

intermediates[i] = chain.ChainElements[i + 1].Certificate;
}
}
}
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
}
// Dispose the copy of the target cert.
chain.ChainElements[0].Certificate.Dispose();
// Dispose the last cert, if we didn't include it.
for (int i = count + 1; i < chain.ChainElements.Count; i++)
{
chain.ChainElements[i].Certificate.Dispose();
}
}

Copy link
Member Author

Choose a reason for hiding this comment

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

if the chain is not complete, should se sent out as much as we can? e.g. the leave as well?

Copy link
Member

Choose a reason for hiding this comment

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

The leaf is always sent 😄

Copy link
Member Author

Choose a reason for hiding this comment

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

I guess bad terminology. I meant certificate closest to the root if root is missing. e.g. is certificate c is signed by i1 -> i2 -> i3 -> root and root is missing, send cert + i1 + i2 + i3.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, if the last cert isn't self-signed, then all the certs after the end-entity should be sent; that's why I checked for PartialChain (it's returned when the last cert that the builder could find wasn't self-issued).

throw new AuthenticationException(SR.net_ssl_io_no_server_cert);
}

CertificateContext = new SslStreamCertificateContext(certificateWithKey);
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
CertificateContext = new SslStreamCertificateContext(certificateWithKey);
CertificateContext = SslStreamCertificateContext.Create(certificateWithKey, null);

Copy link
Member Author

Choose a reason for hiding this comment

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

I added internal Create() to be more consistent but allowing to have SslStreamCertificateContext without building full chain to support legacy behavior on platform where we do not build chain but leave OS to do it.

@davidfowl
Copy link
Member

cc @halter73 @blowdart

@wfurt wfurt merged commit 719c58c into dotnet:master Jul 2, 2020
@wfurt wfurt deleted the certificateContext branch July 2, 2020 03:36
@ghost ghost locked as resolved and limited conversation to collaborators Dec 8, 2020
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.

None yet

4 participants