Skip to content

Could not use CreateFromEncryptedPemFile to load certificates when using dotnet 7 in FIPS environment.  #94800

@Samcoder2000

Description

@Samcoder2000

Description

Hi there, we are seeing this error when using dotnet 7 to load certificates.

Unhandled exception. Interop+Crypto+OpenSslCryptographicException: error:020000AB:rsa routines::invalid keypair
   at Interop.Crypto.DecodePkcs8PrivateKey(ReadOnlySpan`1 source, EvpAlgorithmId algorithmId)
   at System.Security.Cryptography.RSAOpenSsl.ImportParameters(RSAParameters parameters)
   at System.Security.Cryptography.RSA.ImportEncryptedPkcs8PrivateKey(ReadOnlySpan`1 password, ReadOnlySpan`1 source, Int32& bytesRead)
   at System.Security.Cryptography.PemKeyHelpers.ImportEncryptedPem[TPass](ReadOnlySpan`1 input, ReadOnlySpan`1 password, ImportEncryptedKeyAction`1 importAction)
   at System.Security.Cryptography.X509Certificates.X509Certificate2.ExtractKeyFromEncryptedPem[TAlg](ReadOnlySpan`1 keyPem, ReadOnlySpan`1 password, Func`1 factory, Func`2 import)
   at System.Security.Cryptography.X509Certificates.X509Certificate2.CreateFromEncryptedPem(ReadOnlySpan`1 certPem, ReadOnlySpan`1 keyPem, ReadOnlySpan`1 password)
   at SimpleWebServer.Program.Main(String[] args) in /app/SimpleWebServer/Program.cs:line 17
   at SimpleWebServer.Program.<Main>(String[] args)

I have created two simple applications: one is using C#, the other is using C++ to demonstrate this issue. Both applications are using same certificates. Could you pls help us to figure out how to solve this issue? Thanks.
dotnet.tar.gz

Reproduction Steps

For C# application:

  1. Unzip the file.
  2. cd ./dotnet-issue/SimpleWebServer
  3. ./simplewebserver build
  4. docker run -d --name simplewebserver --publish 443:10001 simplewebserver
  5. docker logs simplewebserver.
    Should be able to see the issue.

For C++ application:

  1. Unzip the file.
  2. cd ./dotnet-issue/SimpleWebServer
  3. ./simplewebserver build-cpp
  4. docker run -d --name simplewebservercpp --publish 443:8080 simplewebservercpp
  5. docker logs simplewebservercpp.
    The application is running without issue.

Expected behavior

Dotnet application should be able to load the certificates.

Actual behavior

Dotnet application could not load the certificates.

Regression?

No response

Known Workarounds

No response

Configuration

No response

Other information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-System.SecurityquestionAnswer questions and provide assistance, not an issue with source code or documentation.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions