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

.NET Core 3.1 RSA decryption with 3k certificates failed on Linux environments due to OAEP padding #71607

Closed
Maxyeah opened this issue Jul 4, 2022 · 9 comments
Assignees
Milestone

Comments

@Maxyeah
Copy link

Maxyeah commented Jul 4, 2022

Description

While running our en/decryption test with .Net Core 3.1 we stepped into an Issue on Linux environments.

When using 3k certificate key sizes and Aes256Sha256RsaPss security policy(RsaPaddingMode.OaepSha256), decryption failed with "Error occurred while decoding OAEP padding".

On Windows or .Net 6 on Linux everything is working fine.
Are there any known restrictions?

Reproduction Steps

Encrypt message with rsa cryptoprovider with 3k certificate and RSAEncryptionPadding.OaepSHA256 on Linux and .Net 3.1
Decrypt message with rsa cryptoprovider with 3k certificate and RSAEncryptionPadding.OaepSHA256 on Linux and .Net 3.1

Expected behavior

Message will be decrypted

Actual behavior

Decryption fails with "Error occurred while decoding OAEP padding"

Regression?

No response

Known Workarounds

No response

Configuration

  • .Net Core 3.1.420
  • Debian 11
  • Openssl 1.1.1n
  • x64

Other information

No response

@ghost ghost added the untriaged New issue has not been triaged by the area owner label Jul 4, 2022
@ghost
Copy link

ghost commented Jul 4, 2022

Tagging subscribers to this area: @dotnet/area-system-security, @vcsjones
See info in area-owners.md if you want to be subscribed.

Issue Details

Description

While running our en/decryption test with .Net Core 3.1 we stepped into an Issue on Linux environments.

When using 3k certificate key sizes and Aes256Sha256RsaPss security policy(RsaPaddingMode.OaepSha256), decryption failed with "Error occurred while decoding OAEP padding".

On Windows or .Net 6 on Linux everything is working fine.
Are there any known restrictions?

Reproduction Steps

Encrypt message with rsa cryptoprovider with 3k certificate and RSAEncryptionPadding.OaepSHA256 on Linux and .Net 3.1
Decrypt message with rsa cryptoprovider with 3k certificate and RSAEncryptionPadding.OaepSHA256 on Linux and .Net 3.1

Expected behavior

Message will be decrypted

Actual behavior

Decryption fails with "Error occurred while decoding OAEP padding"

Regression?

No response

Known Workarounds

No response

Configuration

  • .Net Core 3.1.420
  • Debian 11
  • Openssl 1.1.1n
  • x64

Other information

No response

Author: Maxyeah
Assignees: -
Labels:

area-System.Security

Milestone: -

@vcsjones
Copy link
Member

vcsjones commented Jul 4, 2022

Interestingly, a 4096-bit key works, 3072 does not.

Bisecting, it looks like this was fixed for .NET 6 by 6aa4d59 in #50063.

Small repro. (Fails in .NET Core 3.1 and .NET 5, passes in .NET 6)

using RSA rsa = RSA.Create(3072);
byte[] encrypted = rsa.Encrypt(new byte[] { 1, 2 ,3 }, RSAEncryptionPadding.OaepSHA256);
byte[] decrypted = rsa.Decrypt(encrypted, RSAEncryptionPadding.OaepSHA256);
Assert.Equal(new byte[] { 1, 2, 3}, decrypted);

@bartonjs does anything ring a bell here?

If anything, it seems at least there is an opportunity to test OAEP encryption using different key sizes.

@bartonjs
Copy link
Member

bartonjs commented Jul 5, 2022

That change would have moved us off of the managed implementation of OAEP, so there must be a logic bug there. (Which would mean other SHA-2 OAEPs would fail, but SHA-1 probably works)

@vcsjones
Copy link
Member

vcsjones commented Jul 5, 2022

Makes sense. I can take a look at this since presumably the managed implementation is still used on other platforms.

@vcsjones
Copy link
Member

vcsjones commented Jul 6, 2022

So, to summarize, this is a bug that affects key sizes that are not a power-of-two. 2048 and 4096 keys are powers of two, while 3072 is not.

  1. Non-power-of-two key sizes do not work for RSA OAEP decryption with SHA2 on OpenSSL platforms (Linux) in .NET Core 3.1. This is not applicable for .NET 6+ because the managed depadding is not used on this platform.
  2. Non-power-of-two key sizes do not work for RSA OAEP decryption with SHA2 on Android in .NET 6 and .NET 7 previews. It inherited the same bug from OpenSSL. This is not applicable for .NET Core 3.1 as there was no Android support.
  3. .NET 7 will address the issue for Android by removing use of the managed OAEP depadding, similarly to what was done for OpenSSL in .NET 6.

Some PRs have been opened for potential servicing, but are still not approved: that's up to the team that decides if issues meet the servicing requirements.

@vcsjones vcsjones added the bug label Jul 6, 2022
@Maxyeah
Copy link
Author

Maxyeah commented Jul 6, 2022

Thanks to @vcsjones that information helps us how to handle this.

@bartonjs bartonjs removed the untriaged New issue has not been triaged by the area owner label Jul 6, 2022
@jeffhandley jeffhandley added this to the Future milestone Jul 10, 2022
@danmoseley
Copy link
Member

@jeffhandley following up re being in last 6 month phase of 3.1 lifecycle.

@jeffhandley
Copy link
Member

The issue as submitted does not describe enough impact to support backporting this to .NET Core 3.1. @Maxyeah, if this issue is substantially impacting a production application (as opposed to tests), you don't have a workaround, and you can't immediately move to .NET 6.0, please let us know more of that context for us to reconsider.

We have approved the fix for port to 6.0.

@vcsjones
Copy link
Member

vcsjones commented Jul 14, 2022

I believe this issue has been resolved then.

  1. The .NET Core 3.1 OpenSSL fix was not accepted per @jeffhandley's comment.
  2. .NET 6 and up are already fixed for OpenSSL.
  3. The .NET 6 Android fix was accepted and will be in 6.0.9.
  4. The .NET 7 Android fix will be in .NET 7.0-preview7.

I'm going to close this, but @Maxyeah if you would like to re-open it to further discuss the 3.1 fix as @jeffhandley indicated please feel free to do so.

@dotnet dotnet locked as resolved and limited conversation to collaborators Aug 13, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants