Skip to content

Conversation

@darjoo
Copy link
Contributor

@darjoo darjoo commented Oct 15, 2025

Summary

When encrypting with OAEP, PKCS should not be able to decrypt it. However the padding can randomly be correct.

Updated the test to ensure we validate the output and ensure it is garbage data decrypted when it is decrypting with a different padding.

Work Item(s)

Fixes AB#609358

@darjoo darjoo requested a review from a team as a code owner October 15, 2025 08:46
@github-actions github-actions bot added this to the Version 28.0 milestone Oct 15, 2025
@darjoo darjoo enabled auto-merge (squash) October 15, 2025 09:05
end;

[TryFunction]
local procedure TryDecrypt(RSA: Codeunit RSA; XmlString: SecretText; EncryptedInStream: InStream; OaepPadding: Boolean; DecryptedOutStream: OutStream)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is better to have 2 named helpers than have a boolean parameter

DecryptionFailed := not TryDecrypt(RSA, PrivateKeyXmlStringSecret, EncryptedInStream, true, DecryptedOutStream);

// [THEN] Either decryption fails with an exception, or the decrypted text is garbage (not equal to plaintext)
if not DecryptionFailed then begin
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there's no verification if encryption fails, no check whether the error is the expected one...

if not DecryptionFailed then begin
DecryptingTempBlob.CreateInStream(DecryptedInStream);
DecryptedText := Base64Convert.FromBase64(Base64Convert.ToBase64(DecryptedInStream));
LibraryAssert.AreNotEqual(PlainText, DecryptedText, 'Decryption with wrong padding should fail or return garbage data.');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

your message here should only be about garbage data no? if encryption fails you will never get to this assert

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants