You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
X509Certificate2/CommonCrypto: Exporting a certificate without a private key to a PKCS12 store with a password fails #23636
If you have a X509Certificate2 object which represents a certificate without a private key, exporting that certificate to a Pkcs12 store will work on Windows and Linux but fails on Mac (which use CommonCrypto).
This is a regression on macOS as this worked with .NET Core 1.x (when using OpenSSL) and no longer works with .NET Core 2.0.
The test passes on Windows & Linux but fails on macOS with the following error message:
Failed certs.UnitTest1.Test1
Error Message:
Interop+AppleCrypto+AppleCommonCryptoCryptographicException : One or more parameters passed to a function were not valid.
Stack Trace:
at Interop.AppleCrypto.X509Export(X509ContentType contentType, SafeCreateHandle cfPassphrase, IntPtr[] certHandles)
at Interop.AppleCrypto.X509ExportPfx(IntPtr[] certHandles, SafePasswordHandle exportPassword)
at Internal.Cryptography.Pal.StorePal.AppleCertificateExporter.ExportPkcs12(SafePasswordHandle password)
at Internal.Cryptography.Pal.StorePal.AppleCertificateExporter.Export(X509ContentType contentType, SafePasswordHandle password)
at System.Security.Cryptography.X509Certificates.X509Certificate.Export(X509ContentType contentType, String password)
at certs.UnitTest1.Test1() in /Users/quamotion/scratch/certs/UnitTest1.cs:line 13
my_cert.crt can be generated using the following script:
Is it an option to have corefx do that in managed code instead of calling the native layer?
Maybe. There's a cost-of-work vs benefit-of-feature problem, though. PKCS12 is a very complicated spec, and even limiting it to the case where we called into the OS and it returned an error and then we see that !certs.Any(cert => cert.HasPrivateKey) it's a lot of code to carry around for what Apple presumably believes to be a low value scenario.
The naive question on my end is: If you don't have any private keys, why aren't you just exporting as PKCS7?
Activity
qmfrederik commentedon Sep 23, 2017
/cc @bartonjs
jnm2 commentedon Sep 24, 2017
This is off topic, but I'm curious what the use case is for password-protecting a public key.
bartonjs commentedon Sep 24, 2017
Yep, this is a known problem, documented on https://github.com/dotnet/corefx/blob/master/Documentation/architecture/cross-platform-cryptography.md#writing-a-pkcs12pfx.
The ideal case would be that Apple fix this, which would require people to complain via https://developer.apple.com/bug-reporting/.
qmfrederik commentedon Sep 25, 2017
@bartonjs Looking at that list, it appears the issue on macOS is writing PKCS12 files which contain no private keys.
Is it an option to have corefx do that in managed code instead of calling the native layer?
(For now, my workaround will most likely be to use BouncyCastle for that)
qmfrederik commentedon Sep 26, 2017
Just as a FYI for others who may hit the same limitaiton, this is how, as a workaround, you can create the PKCS#12 store on macOS using BouncyCastle:
bartonjs commentedon Oct 4, 2017
Maybe. There's a cost-of-work vs benefit-of-feature problem, though. PKCS12 is a very complicated spec, and even limiting it to the case where we called into the OS and it returned an error and then we see that
!certs.Any(cert => cert.HasPrivateKey)it's a lot of code to carry around for what Apple presumably believes to be a low value scenario.The naive question on my end is: If you don't have any private keys, why aren't you just exporting as PKCS7?