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

x/crypto/openpgp: ReadEntity does not initialize preferred hash and cipher functions for Entity's Identities' Signatures #42310

Geo25rey opened this issue Oct 31, 2020 · 4 comments


Copy link

@Geo25rey Geo25rey commented Oct 31, 2020

What version of Go are you using (go version)?

$ go version
go version go1.15.3 linux/amd64

Does this issue reproduce with the latest release?


What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build141547726=/tmp/go-build -gno-record-gcc-switches"

What did you do?

What did you expect to see?

Encrypt function to try the passed in config first OR the Entity created by ReadEntity to contain its preferred hash and cipher functions.

What did you see instead?

Encrypt function uses its default hash and cipher functions regardless of passed in config or entity.

Possible Solutions

In order from most probable/possible to least probable/possible solution:

[1] Change ReadEntity so that it initializes preferred hash and cipher functions for its Identities' Signatures since that data isn't serialized (openpgp/keys.go:417)
[1.5] Change Signature.parse so that it can infer hash and cipher prefferences (openpgp/packet/signature.go:108)
[2] Change Encrypt so it checks what the actual hash and cipher functions of the passed in entity are rather than just guessing (openpgp/write.go:295)
[3] Change Signature.Serialize so that it includes hash and cipher preferences (openpgp/packet/signature.go:599)

Edit: Added solution 1.5

@gopherbot gopherbot added this to the Unreleased milestone Oct 31, 2020
@Geo25rey Geo25rey changed the title x/crypto/openpgp: ReadEntity does not initialize preferred hash and cipher functions for Entity's Identities' SelfSignatures x/crypto/openpgp: ReadEntity does not initialize preferred hash and cipher functions for Entity's Identities' Signatures Oct 31, 2020
Copy link

@gopherbot gopherbot commented Nov 1, 2020

Change mentions this issue: openpgp: Fixed failure to encrypt data using deserialized Entity

Copy link

@toothrot toothrot commented Nov 2, 2020

Copy link

@Geo25rey Geo25rey commented Nov 4, 2020

@toothrot @FiloSottile The issue is that Signature.PreferredHash != Signature.Hash when deserialized. Also, the algorithm for choosing a compatible hash algorithm in Encrypt was too strict when the passed in config explicitedly states the correct algorithms to use. My PR golang/crypto#163 fixes this with a test to prove it.

Copy link

@FiloSottile FiloSottile commented Mar 29, 2021

Per the accepted #44226 proposal and due to lack of maintenance, the package is now frozen and deprecated. No new changes will be accepted except for security fixes. The package will not be removed.

If this is a security issue, please email and we will assess it and provide a fix.

If you're looking for alternatives, consider the crypto/ed25519 package for simple signatures, for inline signatures, or for encryption. You can read a summary of OpenPGP issues and alternatives here.

If you are required to interoperate with OpenPGP systems and need a maintained package, we suggest considering one of multiple community forks of We don't endorse any specific one.

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants