From a8fb68e7206f8c78be19b432c58eb52a6aa34462 Mon Sep 17 00:00:00 2001 From: Filippo Valsorda Date: Mon, 11 Jun 2018 14:48:21 -0400 Subject: [PATCH] openpgp: restore signing in SerializePrivate Signing was moved in NewEntity as it makes more sense there, but there might be code that relies on SerializePrivate to make signatures with parameters that were modified after NewEntity. As it used to always sign in SerializePrivate, it shouldn't break anything to sign in both places. Fixes golang/go#25463 Change-Id: Ia7f509daf31ac05fedc441225d554f333b288d70 Reviewed-on: https://go-review.googlesource.com/118015 Run-TryBot: Filippo Valsorda TryBot-Result: Gobot Gobot Reviewed-by: Yaron de Leeuw Reviewed-by: Alexandre Viau Reviewed-by: Filippo Valsorda --- openpgp/keys.go | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/openpgp/keys.go b/openpgp/keys.go index 216b812..a79a8c1 100644 --- a/openpgp/keys.go +++ b/openpgp/keys.go @@ -544,10 +544,10 @@ func NewEntity(name, comment, email string, config *packet.Config) (*Entity, err return e, nil } -// SerializePrivate serializes an Entity, including private key material, to -// the given Writer. For now, it must only be used on an Entity returned from -// NewEntity. -// config is ignored +// SerializePrivate serializes an Entity, including private key material, but +// excluding signatures from other entities, to the given Writer. +// Identities and subkeys are re-signed in case they changed since NewEntry. +// If config is nil, sensible defaults will be used. func (e *Entity) SerializePrivate(w io.Writer, config *packet.Config) (err error) { err = e.PrivateKey.Serialize(w) if err != nil { @@ -558,6 +558,10 @@ func (e *Entity) SerializePrivate(w io.Writer, config *packet.Config) (err error if err != nil { return } + err = ident.SelfSignature.SignUserId(ident.UserId.Id, e.PrimaryKey, e.PrivateKey, config) + if err != nil { + return + } err = ident.SelfSignature.Serialize(w) if err != nil { return @@ -568,6 +572,10 @@ func (e *Entity) SerializePrivate(w io.Writer, config *packet.Config) (err error if err != nil { return } + err = subkey.Sig.SignKey(subkey.PublicKey, e.PrivateKey, config) + if err != nil { + return + } err = subkey.Sig.Serialize(w) if err != nil { return @@ -576,8 +584,8 @@ func (e *Entity) SerializePrivate(w io.Writer, config *packet.Config) (err error return nil } -// Serialize writes the public part of the given Entity to w. (No private -// key material will be output). +// Serialize writes the public part of the given Entity to w, including +// signatures from other entities. No private key material will be output. func (e *Entity) Serialize(w io.Writer) error { err := e.PrimaryKey.Serialize(w) if err != nil {