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

Creation of X509Certificate2 fails on Linux but works on Windows #1145

Closed
secana opened this issue Dec 10, 2017 · 1 comment
Closed

Creation of X509Certificate2 fails on Linux but works on Windows #1145

secana opened this issue Dec 10, 2017 · 1 comment

Comments

@secana
Copy link

secana commented Dec 10, 2017

Creation of X509Certificate2 fails on Linux but works on Windows

Creating a X509Certificate2 instance from a byte array works on Windows but fails on Linux with a "CryptographicException".

General

Tested Systems:
Windows 10
Ubuntu 16.04, Ubuntu 17.10
OpenSuse 42

All tested with:
Dotnet Core Version: 2.0.2

Example code:

static void Main(string[] args)
{
      var cert = new X509Certificate2(Cert.CertBytes);
}

On Windows: Valid X509Certificate2 instance is created
On Linux: An exception is thrown:

{System.Security.Cryptography.CryptographicException: Cannot find the original signer.
   at Internal.Cryptography.Pal.PkcsFormatReader.TryReadPkcs7(SafePkcs7Handle pkcs7, Boolean single, ICertificatePal& certPal, List`1& certPals)
   at Internal.Cryptography.Pal.PkcsFormatReader.TryReadPkcs7Der(Byte[] rawData, Boolean single, ICertificatePal& certPal, List`1& certPals)
   at Internal.Cryptography.Pal.CertificatePal.FromBlob(Byte[] rawData, SafePasswordHandle password, X509KeyStorageFlags keyStorageFlags)
   at System.Security.Cryptography.X509Certificates.X509Certificate..ctor(Byte[] data)
   at System.Security.Cryptography.X509Certificates.X509Certificate2..ctor(Byte[] rawData)
   at CertTest.Program.Main(String[] args) in /home/CertTest/Program.cs:line 14}

If the certificate is first parsed by BouncyCastle and then converted into a X509Certificate2 it works.
Example which works on Linux

static void Main(string[] args)
{
       var bouncy = new Org.BouncyCastle.X509.X509CertificateParser();
       var bcert = bouncy.ReadCertificate(Cert.CertBytes);
       var wcert = new System.Security.Cryptography.X509Certificates.X509Certificate2(bcert.GetEncoded());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants