Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MAC OS running new X509Certificate2() failed with error The PKCS#12 Exportable flag is not supported on this platform. #8547

Closed
Ternence opened this issue Jul 6, 2022 · 1 comment
Labels
area-infrastructure CI, Maestro / Coherency, upstream dependencies/versions platform/macOS 🍏 macOS / Mac Catalyst t/bug Something isn't working

Comments

@Ternence
Copy link

Ternence commented Jul 6, 2022

Description

new X509Certificate2(ms.ToArray(), password, X509KeyStorageFlags.Exportable);

This line causes this Exception: Cause System.PlatformNotSupportedException: The PKCS#12 Exportable flag is not supported on this platform.
366782990302900ccb0c3d75a634e16e

Code

`private static X509Certificate2 withPrivateKey(X509Certificate certificate, AsymmetricKeyParameter privateKey)
{
const string password = "password";
Pkcs12Store store;

    if (RunTime.IsRunningOnMono)
    {
        var builder = new Pkcs12StoreBuilder();
        builder.SetUseDerEncoding(true);
        store = builder.Build();
    }
    else
    {
        store = new Pkcs12Store();
    }

    var entry = new X509CertificateEntry(certificate);
    store.SetCertificateEntry(certificate.SubjectDN.ToString(), entry);

    store.SetKeyEntry(certificate.SubjectDN.ToString(), new AsymmetricKeyEntry(privateKey), new[] { entry });
    using (var ms = new MemoryStream())
    {
        store.Save(ms, password.ToCharArray(), new SecureRandom(new CryptoApiRandomGenerator()));
        try
        {
            return new X509Certificate2(ms.ToArray(), password, X509KeyStorageFlags.Exportable);
        } catch (Exception e){
            Console.WriteLine(e);
            return null;
        }              
    }
}`

Exception

2022-07-06 11:55:57.418 WebDebugger[29683:4734908] System.PlatformNotSupportedException: The PKCS#12 Exportable flag is not supported on this platform.
2022-07-06 11:55:57.418 WebDebugger[29683:4734908] at Internal.Cryptography.Pal.AppleCertificatePal.FromDerBlob(ReadOnlySpan1 rawData, X509ContentType contentType, SafePasswordHandle password, X509KeyStorageFlags keyStorageFlags) at Internal.Cryptography.Pal.AppleCertificatePal.FromBlob(ReadOnlySpan1 rawData, SafePasswordHandle password, X509KeyStorageFlags keyStorageFlags)
2022-07-06 11:55:57.418 WebDebugger[29683:4734908] at Internal.Cryptography.Pal.CertificatePal.FromBlob(ReadOnlySpan`1 rawData, SafePasswordHandle password, X509KeyStorageFlags keyStorageFlags)
at System.Security.Cryptography.X509Certificates.X509Certificate..ctor(Byte[] rawData, String password, X509KeyStorageFlags keyStorageFlags)
2022-07-06 11:55:57.418 WebDebugger[29683:4734908] at System.Security.Cryptography.X509Certificates.X509Certificate2..ctor(Byte[] rawData, String password, X509KeyStorageFlags keyStorageFlags)
2022-07-06 11:55:57.418 WebDebugger[29683:4734908] at Titanium.Web.Proxy.Network.Certificate.BCCertificateMaker.withPrivateKey(X509Certificate certificate, AsymmetricKeyParameter privateKey) in /Users/zty/Downloads/src1/Titanium.Web.Proxy/Certificates/Makers/BCCertificateMaker.cs:line 193

Steps to Reproduce

  1. using the project new X509Certificate2(); Cause System.PlatformNotSupportedException: The PKCS#12 Exportable flag is not supported on this platform in Mac OS  justcoding121/titanium-web-proxy#923
  2. convert the project into MAUI
  3. build the Mac OS version. It caused error

Version with bug

6.0.312

Last version that worked well

6.0.312

Affected platforms

macOS

Affected platform versions

MacOS 12.4 (21F79)

Did you find any workaround?

No response

Relevant log output

No response

@Ternence Ternence added s/needs-verification Indicates that this issue needs initial verification before further triage will happen t/bug Something isn't working labels Jul 6, 2022
@jfversluis
Copy link
Member

This is something that originates from the runtime. There seems to be some talk about it here and the code is linked that shows the actual exception that you mention: dotnet/runtime#52434

If this is something that should be implemented, it should happen with them. This is not a .NET MAUI functionality. I unfortunately do not have the power to transfer the issue there, please open an issue with them. Thanks!

@jfversluis jfversluis closed this as not planned Won't fix, can't repro, duplicate, stale Jul 6, 2022
@jfversluis jfversluis added area/upstream and removed s/needs-verification Indicates that this issue needs initial verification before further triage will happen labels Jul 6, 2022
@ghost ghost locked as resolved and limited conversation to collaborators Aug 5, 2022
@samhouts samhouts added the platform/macOS 🍏 macOS / Mac Catalyst label Feb 1, 2024
@Eilon Eilon added area-infrastructure CI, Maestro / Coherency, upstream dependencies/versions and removed area/upstream labels May 10, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-infrastructure CI, Maestro / Coherency, upstream dependencies/versions platform/macOS 🍏 macOS / Mac Catalyst t/bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants