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

NullPointerException when trying to decrypt non-encrypted data (v2.3.0) #58

Open
lclement57 opened this issue Jan 4, 2021 · 6 comments
Labels

Comments

@lclement57
Copy link

Describe the bug
When we call the method decryptAndVerifyStream with an input stream that contains data that is not encrypted (for example only signed), there is a NullPointerException when reading the returned InputStream later thrown by name.neuhalfen.projects.crypto.bouncycastle.openpgp.decrypting.MDCValidatingInputStream.validateMDC, where the local variable pbe is null.

In v2.2.0, there was no exception, trying to decrypt a non-encrypted stream just returned the original stream.
The same thing happens when trying to read an input stream obtained after trying to decrypt an input stream that was (incorrectly) encrypted twice (which is a unit test we are running).

The issue seems to be introduced by the following commit:
986d436#diff-f7bfd613f0ac7d22e02bd9c1727a319dad532f787e9de5ae702da71b252580b4

Here the new MDCValidatingInputStream class is introduced, and we see that the value of pbe comes from DecryptionStreamFactory, where it is initialized only if the method nextDecryptedStream finds an instance of PGPEncryptedDataList, otherwise it stays null and is passed to the MDCValidatingInputStream where there is no null check.

To Reproduce
In v2.3.0, execute a decryption with:

BouncyGPG
                        .decryptAndVerifyStream()
                        .withConfig(keyringConfig)
                        .andIgnoreSignatures()
                        .fromEncryptedInputStream(in)

where in is an input stream containing not encrypted, but signed data.

Expected behavior
No NullPointerException thrown.

** System (please complete the following information):**

  • Device: workstation
  • OS: Linux
  • Java:
openjdk version "11.0.9.1" 2020-11-04
OpenJDK Runtime Environment (build 11.0.9.1+1-Ubuntu-0ubuntu1.20.04)
OpenJDK 64-Bit Server VM (build 11.0.9.1+1-Ubuntu-0ubuntu1.20.04, mixed mode, sharing)
  • Version 2.3.0
@neuhalje neuhalje added the bug label Jan 5, 2021
@neuhalje
Copy link
Owner

neuhalje commented Jan 5, 2021

Thanks for the very detailed error report! This seems to be a bug. I'll try to get into that during the weekend (or ideally review a PR ;-) )

@miks
Copy link

miks commented Jun 16, 2021

Same here. Spent a couple of hours trying to understand what critical part is missing or I'm doing something completely wrong way. Until I searched "validateMDC" in this repo and get came upon this issue. Changed the version to 2.2.0 and it's working as expected. I'm not sure about PR in which cases MDCValidatingInputStream needs to be bypassed.

@Sauhardstark
Copy link
Contributor

It seems to be linked to my changes related to MDC verification

@neuhalje
Should we look into adding a null check at the MDC verification or should we check which streams should be wrapped with the MDCVerificationInputStream in the first place ?

@SandeepLakka
Copy link

@neuhalje / @Sauhardstark , can this be fixed asap?. we cannot downgrade to 2.2.0 as we had #56 issue in that release. Could you please check and let us know when can this be fixed. Thanks!

@Sauhardstark
Copy link
Contributor

Hi, I'll raise a PR for this immediately

Sauhardstark added a commit to Sauhardstark/bouncy-gpg that referenced this issue Dec 5, 2023
- Added a null check in MDC validation stream for signed but unencrypted streams
- Fixes bug - neuhalje#58
Sauhardstark added a commit to Sauhardstark/bouncy-gpg that referenced this issue Dec 5, 2023
- Added a null check in MDC validation stream for signed but unencrypted streams
- Fixes bug - neuhalje#58
@Sauhardstark
Copy link
Contributor

@SandeepLakka / @neuhalje - I've raised a PR for this. Please take a look

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants