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

crypto.verifySignature is broken for signatures with expiration #231

Closed
DmitriyMV opened this issue Apr 7, 2023 · 8 comments
Closed

crypto.verifySignature is broken for signatures with expiration #231

DmitriyMV opened this issue Apr 7, 2023 · 8 comments

Comments

@DmitriyMV
Copy link
Contributor

DmitriyMV commented Apr 7, 2023

verifySignature is broken if it tries to retry with the actual verification time. It doesn't reset origText reader, so it has nothing to read on second attempt.

Relevant parts.

DmitriyMV added a commit to DmitriyMV/runtime that referenced this issue Apr 7, 2023
Keep 2.5.2 until ProtonMail/gopenpgp#231 is fixed.

Signed-off-by: Dmitriy Matrenichev <dmitry.matrenichev@siderolabs.com>
@marinthiercelin
Copy link
Contributor

Hey, thanks for opening the issue.
That seems indeed to be broken.
I'm a bit confused why you would revert your project to v2.5.2 though, the issue seems older than this version.
Do you have any example data that I could use to trigger the bug ?

@DmitriyMV
Copy link
Contributor Author

I'm a bit confused why you would revert your project to v2.5.2 though, the issue seems older than this version.

verifySignature is indeed broken in 2.5.2 (it doesn't return an error if signature expired) but we are not hitting it, because we have check called IsExpired which is doing what it must. So that's a reason for revert.

Do you have any example data that I could use to trigger the bug ?

Sure, here it is.

@DmitriyMV
Copy link
Contributor Author

IIUC there are two approaches to solves this, without changing the external API.

  1. Change verifySignature origText from io.Reader to func() io.Reader. That way we can ensure that it always get the new reader. the downside - it will look a bit strange, and you have to keep in mind that origText func() need to return new reader each time. Also VerifyDetachedStream accepts a reader so I dunno what can be done there.
  2. Check if origText supports Seek. If does - good! If not - read it into the local bytes.Buffer and use it instead. Downside - for io.Readers who do not support Seek you will need to read entire message before processing it.

Or change origText to ReadSeeker but that will break KeyRing.VerifyDetachedStream.

I can prepare a PR for any of those fixes if you wish.

@marinthiercelin
Copy link
Contributor

Hey, It's indeed tricky to fix while keeping the API.

I think, as a short term fix, we should go with a variant of your second approach.
If origText supports Seek use it and verify again.
But if it does not support Seek, I don't think we should read it all in a buffer, that could be quite bad for memory usage.
Instead I think we should just not reattempt the verification.
That means that if you verify with VerifyDetachedStream with a non seekable stream, the verification might fail.
So it's only a partial fix.

For a complete fix, I think we should instead rethink how we do the verification, and manually check the dates for expiration, rather than reattempting verification with a different time.

If you want to open a PR for either the partial fix, or look into the complete fix, it would be greatly appreciated.

DmitriyMV added a commit to DmitriyMV/gopenpgp that referenced this issue Apr 12, 2023
This is partial fix for ProtonMail#231

Signed-off-by: Dmitriy Matrenichev <dmitry.matrenichev@siderolabs.com>
@DmitriyMV
Copy link
Contributor Author

Opened an PR for partial fix.

DmitriyMV added a commit to DmitriyMV/gopenpgp that referenced this issue Apr 13, 2023
This is partial fix for ProtonMail#231

Signed-off-by: Dmitriy Matrenichev <dmitry.matrenichev@siderolabs.com>
@marinthiercelin
Copy link
Contributor

Thanks a lot for your submission @DmitriyMV

@smira
Copy link

smira commented May 8, 2023

@DmitriyMV is there something else which needs to fixed here? as it seems that the verification is still broken?

@DmitriyMV
Copy link
Contributor Author

@smira It's a partial fix in a sense that it only supports messages which have Seek method. It may still trigger for non Seek-able streams, but for the most part it is good enough.

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

No branches or pull requests

3 participants