Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Fix RSA OAEP decryption in OpenSSL with non-power-of-two keys lengths - #43153

Closed
vcsjones wants to merge 1 commit into
dotnet:release/3.1from
vcsjones:fix-openssl-decrypt-rsa
Closed

vcsjones wants to merge 1 commit into
dotnet:release/3.1from
vcsjones:fix-openssl-decrypt-rsa

Conversation

@vcsjones

@vcsjones vcsjones commented Jul 5, 2022

Copy link
Copy Markdown
Member

Customer Impact

A customer reported in dotnet/runtime#71607 that decrypting RSA OAEP with SHA2 and a 3072-bit key on Linux resulted in a OAEP de-padding error, while other platforms were able to perform these operations successfully.

Investigation in to the issue led to uncover that RSA OAEP decryption that uses the managed implementation does not work with non-power-of-two keys because we do not slice a rented buffer accordingly. The current implementation only works because CryptoPool.Rent happens to give back power-of-two arrays which are exactly the same size as the key.

The fix is to slice the data to the correct size.

This does not affect dotnet/runtime because the managed implementation of RSA OAEP is no longer used for OpenSSL RSA decryption. This change was introduced in dotnet/runtime#50063.

Testing

Unit tests were introduced to test RSA OAEP encryption with a 3072-bit RSA key. These tests will be forward-ported to dotnet/runtime.

Risk

Minimal. The change is localized and understood that a Slice was missing.

@bartonjs bartonjs added the Servicing-consider Issue for next servicing release review label Jul 5, 2022
@bartonjs

bartonjs commented Jul 5, 2022

Copy link
Copy Markdown
Member

The macOS version was already doing the slicing correctly, which the test matrix will ideally corroborate.

unpaddedData = new Span<byte>(rented, 0, paddedSize);
return processor.DepadOaep(unpaddedData, destination, out bytesWritten);

@bartonjs

bartonjs commented Jul 5, 2022

Copy link
Copy Markdown
Member

@vcsjones There's a typo in your second commit message (OARP instead of OAEP) that'll bug me if it gets merged in with the final squash description. Would you mind force-pushing to clean it up (or even just squash the second commit into the first)?

@vcsjones
vcsjones force-pushed the fix-openssl-decrypt-rsa branch from 032c1c3 to 4538c30 Compare July 5, 2022 22:55
@bartonjs

bartonjs commented Jul 6, 2022

Copy link
Copy Markdown
Member

None of the test failures look relevant

@jeffhandley jeffhandley added Servicing-rejected and removed Servicing-consider Issue for next servicing release review labels Jul 12, 2022
@jeffhandley

Copy link
Copy Markdown
Member

Per tactics consideration, we concluded that the backport to .NET Core 3.1 is not warranted by the impact known at this time. I left a comment on the original issue; if more substantial impact is recognized, this can be reconsidered.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants