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

V3 - Add a option to allow disabling the unauthenticated messages check #314

Open
wants to merge 3 commits into
base: v3
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions crypto/decryption_core.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ func (dh *decryptionHandle) decryptStream(encryptedMessage Reader) (plainMessage
checkIntendedRecipients := !dh.DisableIntendedRecipients
config.CheckIntendedRecipients = &checkIntendedRecipients
}
config.InsecureAllowUnauthenticatedMessages = dh.DisableUnauthenticatedMessagesCheck
if dh.VerifyKeyRing != nil {
entries = append(entries, dh.VerifyKeyRing.entities...)
}
Expand Down Expand Up @@ -167,6 +168,7 @@ func (dh *decryptionHandle) decryptStreamWithSessionAndParse(messageReader io.Re
checkPacketSequence := false
config.CheckIntendedRecipients = &checkIntendedRecipients
config.CheckPacketSequence = &checkPacketSequence
config.InsecureAllowUnauthenticatedMessages = dh.DisableUnauthenticatedMessagesCheck
md, err := openpgp.ReadMessage(decrypted, keyring, nil, config)
if err != nil {
return nil, 0, errors.Wrap(err, "gopenpgp: unable to decode symmetric packet")
Expand Down Expand Up @@ -294,6 +296,7 @@ func (dh *decryptionHandle) decryptStreamAndVerifyDetached(encryptedData, encryp
checkIntendedRecipients := !dh.DisableIntendedRecipients
config := dh.profile.EncryptionConfig()
config.CheckIntendedRecipients = &checkIntendedRecipients
config.InsecureAllowUnauthenticatedMessages = dh.DisableUnauthenticatedMessagesCheck

// Verifying reader that wraps the decryption readers to verify the signature
sigVerifyReader, err := verifyingDetachedReader(
Expand Down
17 changes: 9 additions & 8 deletions crypto/decryption_handle.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,15 @@ type decryptionHandle struct {
// DisableIntendedRecipients indicates if the signature verification should not check if
// the decryption key matches the intended recipients of the message.
// If disabled, the decryption throws no error in a non-matching case.
DisableIntendedRecipients bool
DisableVerifyTimeCheck bool
DisableStrictMessageParsing bool
DisableAutomaticTextSanitize bool
RetrieveSessionKey bool
IsUTF8 bool
clock Clock
profile EncryptionProfile
DisableIntendedRecipients bool
DisableVerifyTimeCheck bool
DisableStrictMessageParsing bool
DisableAutomaticTextSanitize bool
DisableUnauthenticatedMessagesCheck bool
RetrieveSessionKey bool
IsUTF8 bool
clock Clock
profile EncryptionProfile
}

// --- Default decryption handle to build from
Expand Down
5 changes: 5 additions & 0 deletions crypto/decryption_handle_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,11 @@ func (dpb *DecryptionHandleBuilder) DisableAutomaticTextSanitize() *DecryptionHa
return dpb
}

func (dpb *DecryptionHandleBuilder) DisableUnauthenticatedMessagesCheck() *DecryptionHandleBuilder {
JasonQuinn marked this conversation as resolved.
Show resolved Hide resolved
dpb.handle.DisableUnauthenticatedMessagesCheck = true
return dpb
}

// RetrieveSessionKey sets the flag to indicate if the session key used for decryption
// should be returned to the caller of the decryption function.
func (dpb *DecryptionHandleBuilder) RetrieveSessionKey() *DecryptionHandleBuilder {
Expand Down