Skip to content

On Linux, cannot create PFX with private key if has more than single cert in collection #24554

Description

@ayende

Sample code:

var collection = new X509Certificate2Collection();
collection.Add(certificateWithPrivateKey);
collection.Add(anotherCertWithoutPrivateKey);

var output = collection.Export(X509ContentType.Pkcs12);

The output is a pfx value that has a single certificate in place, the second one, without the private key.

I tracked it down to this piece of code:
https://github.com/dotnet/corefx/blob/master/src/System.Security.Cryptography.X509Certificates/src/Internal/Cryptography/Pal.Unix/ExportProvider.cs#L75

In particular, this loop:

https://github.com/dotnet/corefx/blob/d7dd6a4b03a7c3bb03379e03ff9dbd656913cc85/src/System.Security.Cryptography.X509Certificates/src/Internal/Cryptography/Pal.Unix/ExportProvider.cs#L101-L126

Looking at the code, I think that the code is missing setting of privateCertHandle and privateCertKeyHandle, which cause it to skip the entry with the private key.

[EDIT] Add C# syntax highlighting by @karelz

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions