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

Improve error message for decryption with a session key #237

Merged
merged 8 commits into from
Nov 18, 2024

Conversation

lubux
Copy link
Contributor

@lubux lubux commented Oct 28, 2024

This PR enhances the error messages returned during decryption with a session key by adding more context to improve clarity. Currently, a generic error like openpgp: invalid data: parsing error is returned, which makes it difficult to pinpoint the specific stage of failure and determine whether the session key itself is incorrect.

With this PR, the error message now includes additional context, for example: openpgp: decryption with session key failed: parsing error. This change helps identify the context the error occurs in while retaining the generic parsing error to avoid oracle attacks (#78).
Further, it refactors the error handling slightly to avoid repetitions.

@lubux lubux requested review from larabr and twiss October 28, 2024 15:00
@lubux lubux force-pushed the feat/error-message-decrypt-with-session-key branch 3 times, most recently from bd40c5c to f88b68e Compare November 11, 2024 13:48
openpgp/read_test.go Outdated Show resolved Hide resolved
@lubux lubux force-pushed the feat/error-message-decrypt-with-session-key branch from f88b68e to e0431bc Compare November 11, 2024 14:04
openpgp/v2/read_test.go Outdated Show resolved Hide resolved
openpgp/v2/read_test.go Outdated Show resolved Hide resolved
openpgp/v2/read.go Show resolved Hide resolved
openpgp/errors/errors.go Show resolved Hide resolved
@@ -819,7 +819,7 @@ func TestCorruptedMessageInvalidSigHeader(t *testing.T) {
promptFunc := func(keys []Key, symmetric bool) ([]byte, error) {
return passphrase, nil
}
const expectedErr string = "openpgp: invalid data: parsing error"
const expectedErr string = "openpgp: decryption with session key failed: parsing error"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's add similar tests for SEIPDv2 to test (and "demo") what kind of errors are thrown with AEAD (hopefully the AEAD chunks are not released/parsed even with streaming).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added a test for a missing last aead authentication tag:
6525f78

openpgp/errors/errors.go Outdated Show resolved Hide resolved
openpgp/read.go Outdated Show resolved Hide resolved
@lubux lubux force-pushed the feat/error-message-decrypt-with-session-key branch from 32d52e6 to 89db31a Compare November 14, 2024 15:51
@lubux lubux requested a review from twiss November 15, 2024 16:09
@lubux lubux force-pushed the feat/error-message-decrypt-with-session-key branch from 89db31a to b13d2fd Compare November 18, 2024 08:15
@lubux lubux force-pushed the feat/error-message-decrypt-with-session-key branch from b13d2fd to c895e57 Compare November 18, 2024 08:16
@lubux lubux merged commit 5e3e39d into main Nov 18, 2024
8 checks passed
@lubux lubux deleted the feat/error-message-decrypt-with-session-key branch November 18, 2024 08:29
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

Successfully merging this pull request may close these issues.

3 participants