Bug 46398 - X509Certificate2Collection.Import() - support PKCS#12 with intermediate certificates in it
Summary: X509Certificate2Collection.Import() - support PKCS#12 with intermediate certi...
Status: CONFIRMED
Alias: None
Product: Class Libraries
Classification: Mono
Component: System.Security ()
Version: 4.8.0 (C9)
Hardware: PC Linux
: --- normal
Target Milestone: Untriaged
Assignee: Martin Baulig
URL:
Depends on:
Blocks:
 
Reported: 2016-11-03 17:46 UTC by Alberto Pastore
Modified: 2016-11-11 11:22 UTC (History)
2 users (show)

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


Attachments
pfx file used in the test; password for private key is "test" (4.87 KB, application/x-pkcs12)
2016-11-03 17:46 UTC, Alberto Pastore
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 46398 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:
CONFIRMED

Description Alberto Pastore 2016-11-03 17:46:26 UTC
Created attachment 18320 [details]
pfx file used in the test; password for private key is "test"

The X509Certificate2Collection.Import() method in mono does not import all certificates correctly from a PCKS#12 (PFX) file.

This very simple piece of code:


public static void Main(string[] args)
{
	var coll = new X509Certificate2Collection();

	coll.Import("dev.inimcloud.com.p12", "test", X509KeyStorageFlags.PersistKeySet);

	Console.WriteLine("\nCertificates in pfx file:\n-----------------------------");

	foreach (var cert in coll)
		Console.WriteLine("Subject name: {0}", cert.Subject);

	Console.WriteLine();
	Console.ReadLine();
}


produces two different outputs when run in a mono environment (Linux Debian 8 with mono 4.6.1)
or under Windows.

Target framework is .NET 4.6.1


Output under Windows 10 (correct):

>> Certificates in pfx file:
>> -----------------------------
>> Subject name: CN=StartCom Class 3 OV Server CA, OU=StartCom Certification Authority, O=StartCom Ltd., C=IL
>> Subject name: CN=*.dev.inimcloud.com, O=B-Press Srl, L=Novara, S=Novara, C=IT


Output under Linux (wrong):

>> Certificates in pfx file:
>> -----------------------------
>> Subject name: CN=*.dev.inimcloud.com, O=B-Press Srl, L=Novara, S=Novara, C=IT


Attached is the pfx file used in the test; password for private key is "test"
Comment 1 Martin Baulig 2016-11-11 11:21:56 UTC
Well yeah - the problem is simply that X509Certificate2Collection.Import() has never been fully implemented correctly.

Up until very recent versions of AppleTls and BTLS we didn't even support PKCS#12 files with intermediate certificates, we now do and there is an internal API to retrieve them - but it has never been added to X509Certificate2Collection.

I'll look into this.