runtime icon indicating copy to clipboard operation
runtime copied to clipboard

SslStream.AuthenticateAsClient() is popping up a challenge for the system keychain on MacOS

Open ScotMac opened this issue 2 years ago • 9 comments

Description

For some reason, SslStream.AuthenticateAsClient() is trying to modify the system keychain on MacOS, and if it doesn't have permission, it is popping up a UI to get an userid/password that does have permission.

Screenshot of the UI:

Screenshot 2024-02-27 at 3 35 34 PM

Reproduction Steps

Call SslStream.AuthenticateAsClient() on MacOS sw_vers 13.6.3 (doesn't appear to happen on 13.6).

Expected behavior

Do SSL handshake.

Actual behavior

See popup above.

Regression?

Yes.

Known Workarounds

None.

Configuration

Have tried .NET 6 and .NET 8 and both exhibit the problem, along with MacOS 13.6.3+.

Other information

No response

ScotMac avatar Mar 05 '24 22:03 ScotMac

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

Issue Details

Description

For some reason, SslStream.AuthenticateAsClient() is trying to modify the system keychain on MacOS, and if it doesn't have permission, it is popping up a UI to get an userid/password that does have permission.

Screenshot of the UI:

Screenshot 2024-02-27 at 3 35 34 PM

Reproduction Steps

Call SslStream.AuthenticateAsClient() on MacOS sw_vers 13.6.3 (doesn't appear to happen on 13.6).

Expected behavior

Do SSL handshake.

Actual behavior

See popup above.

Regression?

Yes.

Known Workarounds

None.

Configuration

Have tried .NET 6 and .NET 8 and both exhibit the problem, along with MacOS 13.6.3+.

Other information

No response

Author: ScotMac
Assignees: -
Labels:

area-System.Net.Security

Milestone: -

ghost avatar Mar 05 '24 22:03 ghost

I cannot reproduce this on .NET 6, 8, or 9-preview1 on macOS 14.3.1. Here is the code I used.

using System;
using System.Net;
using System.Net.Sockets;
using System.Net.Security;

using TcpClient tcpClient = new();
await tcpClient.ConnectAsync("github.com", 443);
using SslStream ssl = new(tcpClient.GetStream());

SslClientAuthenticationOptions options = new() {
    TargetHost = "github.com",
};
await ssl.AuthenticateAsClientAsync(options);
Console.WriteLine("Okay all done: cert: " + ssl.RemoteCertificate.Subject);
  1. Can you share the code you used to reproduce the issue?
  2. If you have access to more than one Mac, does this reproduce for you with other Macs?

vcsjones avatar Mar 05 '24 22:03 vcsjones

This issue has been marked needs-author-action and may be missing some important information.

ghost avatar Mar 06 '24 15:03 ghost

You must be logged into the console for it to happen, since the popup UI is relying on the base MacOS GUI.

ScotMac avatar Mar 06 '24 19:03 ScotMac

You must be logged into the console for it to happen

Can you explain? I was logged in to my Mac when I tried to reproduce this. I was not remotely connected. I used the code above from a Console application from Terminal, and did not see any keychain popups.

vcsjones avatar Mar 06 '24 19:03 vcsjones

Also, your AuthenticateAsClient is very different from mine:

      m_sslstream = new SslStream(m_client.GetStream(), false, this.ValidateRemoteCertificate, null);
     
      m_sslstream.AuthenticateAsClient(!string.IsNullOrEmpty(conOption.Hostname) ? conOption.Hostname : 
                      (conOption.Host == null ? "" : conOption.Host), new X509Certificate2Collection { x509 }, SSLProtocol, false);

ScotMac avatar Mar 06 '24 19:03 ScotMac

@vcsjones The x509Certificate2Collection ( "new X509Certificate2Collection { x509 }") is just a public cert that is associated with our list of trusted CAs.

ScotMac avatar Mar 06 '24 20:03 ScotMac

Do you have other machines where you can try to reproduce this problem?

Also, it would be great if you provided us a fully self-contained repro project if you feel like there is some specific setup needed. Otherwise it is hard to guess what is happening.

rzikm avatar Mar 07 '24 17:03 rzikm

Since there has been no recent activity from the reporter, I am closing this now since this is not reproducible/actionable for us at the moment. If the issue resurfaces, feel free to comment or open a new issue with more details or ideally with a small program which reproduces the issue.

rzikm avatar Apr 02 '24 09:04 rzikm