Bug 54469 - [appletls]: Keychain popups on Desktop Mono
Summary: [appletls]: Keychain popups on Desktop Mono
Status: NEW
Alias: None
Product: Class Libraries
Classification: Mono
Component: System ()
Version: unspecified
Hardware: PC Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: Martin Baulig
URL:
Depends on:
Blocks:
 
Reported: 2017-04-04 20:38 UTC by Martin Baulig
Modified: 2017-04-05 06:04 UTC (History)
3 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:


Attachments
Popup dialog (196.56 KB, image/png)
2017-04-04 20:38 UTC, Martin Baulig
Details


Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report for Bug 54469 on GitHub or Developer Community if you have new information to add and do not yet see a matching new report.

If the latest results still closely match this report, you can use the original description:

  • Export the original title and description: GitHub Markdown or Developer Community HTML
  • Copy the title and description into the new report. Adjust them to be up-to-date if needed.
  • Add your new information.

In special cases on GitHub you might also want the comments: GitHub Markdown with public comments

Related Links:
Status:
NEW

Description Martin Baulig 2017-04-04 20:38:32 UTC
Created attachment 21193 [details]
Popup dialog

After AppleTls has been moved into the Mono class libraries, we are now getting keychain popup messages whenever
using server mode (via HttpListener, for instance) or accessing a website that's using client certificates for authentication.  The only way of making them go away is to grant the 'mono' binary - and thus every application that can possibly run with Mono - full access to the private key.

To reproduce (you don't need the web-tests module for this, I'm just using it as an easy way of referencing a certificate/private key pair; you can also create your own self-signed certificate).

One-time setup:

* open "keychain Access" and verify that your current keychain (which is usually the "login" keychain)
  does not contain a key called "Hamiller-Tube.local".

* checkout https://github.com/xamarin/web-tests

* httpcfg -add -port 8888 -p12 /Workspace/web-tests/CA/server-cert.pfx -pwd monkey

* this will not touch the OS keychain, which you can verify in the Keychain Access tool.

* Run this:

=====
	var listener = new HttpListener ();
	listener.Prefixes.Add ("https://*:8888/");
	listener.Start ();

	var context = listener.GetContext ();
	Console.WriteLine (context);
=====

* open "https://localhost:8888/" in any web browser

* you will get the attached popup dialog

* click "decline" and go back to the Keychain Access tool.  You'll see a new certificate 
  and private key called "Hamiller-Tube.local".

* click "accept" and the same popup dialog may come back several times.

* when using Safari, it will also ask you to provide a client certificate.  That's a different issue,
  we have a bug about that.
Comment 1 Martin Baulig 2017-04-04 20:45:25 UTC
I tried to disable this in https://github.com/mono/mono/pull/4642, but unfortunately removing the implicit keychain lookup does not fix the problem.

The problem is that SecPKCS12Import (https://developer.apple.com/reference/security/1396915-secpkcs12import?language=objc) always imports the SecIdentityRef into the keychain.

In a Xamarin.Mac app, this is no big deal because you can use code-sign to
grant the app access and AFAIK you can also do this on a per-key basis, so
you could add your certificate and private key to the keychain and your app
can access it without popups.

With Desktop Mono, the same approach would require granting the "mono" binary
this trust - which would then extend to every single app that's ever going to run on it.
Comment 2 Martin Baulig 2017-04-04 20:48:44 UTC
After using the above HttpListener code and selecting "Always allow", you can do something like this:

======
	static byte [] ReadFile (string name)
	{
		var fullName = "/Workspace/web-tests/CA/" + name + ".pem";
		var data = File.ReadAllBytes (fullName);
		return data;
	}

	static X509Certificate ReadCertificate (string name)
	{
		var data = ReadFile (name);
		return new X509Certificate (data);
	}

	public static void TestServer ()
	{
		var cert = ReadCertificate ("server-cert");
		var listener = MonoTlsProviderFactory.CreateHttpListener (cert);
		var listener = new HttpListener ();
		listener.Prefixes.Add ("https://*:9999/");
		listener.Start ();

		var context = listener.GetContext ();
		Console.WriteLine (context);
	}
=====

in a different app, this will use the previously password-protected private key without any questions asked.
Comment 3 Sebastien Pouliot 2017-04-04 21:04:36 UTC
The existing, managed PKCS12 code, should be used for Mono desktop. It was a good idea to try but it went a step too far