Skip to content

new X509Certificate2 fails on macOS for concatenated certificates #26276

Closed
dotnet/corefx
#35322

Description

@bgrainger

new X509Certificate2(string) and new X509Certificate2(byte[]) fail under .NET Core 2.0 on macOS if there is more than one certificate in the file being loaded. The following exception is thrown:

Unhandled Exception: Interop+AppleCrypto+AppleCommonCryptoCryptographicException: Unknown format in import.
   at Interop.AppleCrypto.X509ImportCertificate(Byte[] bytes, X509ContentType contentType, SafePasswordHandle importPassword, SafeKeychainHandle keychain, Boolean exportable, SafeSecIdentityHandle& identityHandle)
   at Internal.Cryptography.Pal.CertificatePal.FromBlob(Byte[] rawData, SafePasswordHandle password, X509KeyStorageFlags keyStorageFlags)
   at System.Security.Cryptography.X509Certificates.X509Certificate..ctor(String fileName, String password, X509KeyStorageFlags keyStorageFlags)
   at System.Security.Cryptography.X509Certificates.X509Certificate2..ctor(String fileName)
   at LoadCertificateFromBytes.Program.Main(String[] args) in /Users/bgrainger/Code/LoadCertificateFromBytes/Program.cs:line 11

The same data is accepted without failure on Windows 10 and Ubuntu 14.04 (and just the first certificate in the file is loaded).

A minimal repro is here: https://github.com/bgrainger/LoadCertificateFromBytes/blob/master/Program.cs

This issue arose when trying to load https://s3.amazonaws.com/rds-downloads/rds-combined-ca-bundle.pem (linked from https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/UsingWithRDS.SSL.html). On Linux and Windows, the file is loaded without error, but only the first certificate in the file is loaded. On macOS, an exception is thrown.

I'm not sure what the "right" behaviour should be. On the one hand, it's nice that macOS provides some feedback that most of the certificates in the file were ignored. On the other hand, changing Windows/Linux might be a major breaking change. Overall, it would just be nice to have cross-platform consistency.

Activity

  1. transferred this issue fromdotnet/corefxon Jan 31, 2020
  2. added this to the 3.0 milestone on Jan 31, 2020
  3. ayehia commented on Feb 25, 2020

    @ayehia

    I have the same issue in .net core v 3.1.2 macOs

  4. ghost locked as resolved and limited conversation to collaborators on Dec 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions