-
Notifications
You must be signed in to change notification settings - Fork 694
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
Add HTTPS client certificate support #3273
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't look at the code, but there are some things that can be improved before then.
src/NuGet.Core/NuGet.CommandLine.XPlat/NuGet.CommandLine.XPlat.csproj
Outdated
Show resolved
Hide resolved
src/NuGet.Core/NuGet.Commands/NuGet.Commands.csproj.DotSettings
Outdated
Show resolved
Hide resolved
src/NuGet.Core/NuGet.Configuration/Settings/Items/BaseCertItem.cs
Outdated
Show resolved
Hide resolved
src/NuGet.Core/NuGet.Configuration/Settings/Items/FileCertItem.cs
Outdated
Show resolved
Hide resolved
Resolved all above issues |
Because of XPlat templating I reformatted generic command runner to separated ones. The way how command executes now is unified for both command line tools. I am afraid command runners must be revalidated again. |
Any progress? |
Sorry, I had a very busy week last week. Some very quick comments:
|
I just thought of another reason why getting rid of statics with side-effects is important. They can cause problems with long-lived processes like Visual Studio, Visual Studio for Mac, and Rider. I only know about Visual Studio (the Windows one), but if the static class is kept, it needs to correctly handle when the user closes the solution and loads a solution with different HTTPS client cert settings. I think it would be less effort, and would "just work" for VS for Mac and Rider, if we got rid of the static class and had the values flow through in a similar way to username/password credentials do. |
I will research possibility to apply client certificates without static. I am agree that this is not so handy solution (was copied from TLS functionality) |
Did a research. I am afraid it is not possible to apply certificates with out static invocation. All stuff around in private static HttpHandlerResourceV3 CreateResource(PackageSource packageSource)
{
var sourceUri = packageSource.SourceUri;
var proxy = ProxyCache.Instance.GetProxy(sourceUri);
// replace the handler with the proxy aware handler
var clientHandler = new HttpClientHandler
{
Proxy = proxy,
AutomaticDecompression = (DecompressionMethods.GZip | DecompressionMethods.Deflate)
};
// Setup http client handler client certificates
ClientCertificates.SetupClientHandler(clientHandler, packageSource);
// HTTP handler pipeline can be injected here, around the client handler
HttpMessageHandler messageHandler = new ServerWarningLogHandler(clientHandler);
if (proxy != null)
{
messageHandler = new ProxyAuthenticationHandler(clientHandler, HttpHandlerResourceV3.CredentialService?.Value, ProxyCache.Instance);
}
#if !IS_CORECLR
{
var innerHandler = messageHandler;
messageHandler = new StsAuthenticationHandler(packageSource, TokenStore.Instance)
{
InnerHandler = messageHandler
};
}
#endif
{
var innerHandler = messageHandler;
messageHandler = new HttpSourceAuthenticationHandler(packageSource, clientHandler, HttpHandlerResourceV3.CredentialService?.Value)
{
InnerHandler = innerHandler
};
}
var resource = new HttpHandlerResourceV3(clientHandler, messageHandler);
return resource;
} Static calls:
Last chance to patch ClientHandler is Сorrect me if I'm missed something. |
One option, if it helps, is to remove the static keyword. Since A second option is to do the same as how credentials are passed. The A third option is, as I mentioned previously, use NuGet.Protcol's resource & provider patterm. Add a new ClientCertificateResource. Since the code snippet you used is from a A fourth option, which I really don't like, is to extend the static A fifth option, is to add a public method to Those are all my ideas at this time. So, unfortunately for you, you're experiencing one of the things that causes the NuGet team problems. New features are hard to add because we need to try to keep not only API compatibility, but also ABI backwards compatibility, so that other assemblies that are compiled against the NuGet SDK keep working. The current PR has a bug when someone opens and closes solutions in Visual Studio, VS for Mac, JetBrains Rider, and other apps that use the NuGet SDK, without restarting the whole process. Some of the proposed ideas will work for VS, but depending on which APIs other apps use, it might mean that http client certs won't work unless the app changes which NuGet APIs they use. The idea that is most likely to work without needing changes in apps using the NuGet SDK, feels dirty because it's changing a configuration class to add a property that isn't saved to that part of the configuration file. |
Yep I meant exactly that) |
I was looking deeper into how credentials work in the configuration code, and I found out that So ignore my previous message suggesting there's multiple options on how this could be implemented. I'm now convinced that adding client certs into the On a similar topic, your branch adds 3 new classes in the |
Already working on packageSource extending with client certs. Hard to test cases from several entry points(command line utils. VS plugin etc) so it will take some time. Will rename classes later. |
With some minor changes in upstream List nuget command was able to remove all static calls. Also new approach is more generic and will be automatically applied to all clients who are using Btw |
Client certificate items were renamed |
2f95186
to
899dbca
Compare
Updated all tt files with proper InitCaps and "-" replacement
This time built even without glitches :) |
Updated Commands.xml with required missed attributes
@rrelyea docs.tt and commands.xml files extended and fixed. |
@zivkan changes should not have affected assembly and tests. But seems you need to rebuild CI again in order to pass checks. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
docs.tt changes look good. thx.
@zivkan is it merge time?) |
@BlackGad thanks you so much for your patience and all your efforts 🥳🎉 |
@zivkan Hooray! So when it will be released? NuGet.exe, VS etc? |
I added a comment in the issue tracking the feature: NuGet/Home#5773 (comment) |
You all rock. Thank you so much for this <3 |
Implements: NuGet/Home#5773
Specification: https://github.com/NuGet/Home/blob/dev/proposed/archive/NuGet-ClientCertificates.md
Added feature implementation accordingly to merged specification