-
Notifications
You must be signed in to change notification settings - Fork 104
openpgp: add RevokeKey, RevokeSubkey, AddSigningSubkey and AddEncryptionSubkey methods to Entity #53
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
Conversation
The existing implementation does not support operations on subkeys using the library, so the following changes have been made to support subkey interactions as per RFC 4880 (https://tools.ietf.org/html/rfc4880). 1. AddSubkey adds support for generating new subkeys associated with an Entity. It also adds support for adding signing subkeys. 2. RevokeKey generates a 0x20 key revocation signature against the entity. 3. RevokeSubkey generates a 0x28 subkey revocation signature for a subkey. 4. Add Revocation reason subpacket and EmbeddedSignature subpacket to output subpackets with corresponding tests. 5. Re-sign the embedded signatures for subkeys in entity.SerializePrivate(). Fixes golang/go#29301 Change-Id: If8ee111e825c17ccaa19e4afbac4a756671d9bf5
Having a subkey which supports both is not recommended. Also, add support for adding ECC subkeys. Also, fix adding RSA subkeys to ECC keys, and vice versa.
openpgp/key_generation.go
Outdated
subkey := Subkey{ | ||
PublicKey: &sub.PublicKey, | ||
PrivateKey: sub, | ||
Sig: &packet.Signature{ | ||
CreationTime: creationTime, | ||
SigType: packet.SigTypeSubkeyBinding, | ||
PubKeyAlgo: e.PrimaryKey.PubKeyAlgo, | ||
Hash: config.Hash(), | ||
FlagsValid: true, | ||
FlagSign: true, | ||
IssuerKeyId: &e.PrimaryKey.KeyId, | ||
}, | ||
} | ||
|
||
embeddedSig := &packet.Signature{ | ||
CreationTime: creationTime, | ||
SigType: packet.SigTypePrimaryKeyBinding, | ||
PubKeyAlgo: subkey.PublicKey.PubKeyAlgo, | ||
Hash: config.Hash(), | ||
IssuerKeyId: &e.PrimaryKey.KeyId, | ||
} | ||
err = embeddedSig.CrossSignKey(subkey.PublicKey, e.PrimaryKey, subkey.PrivateKey, config) | ||
if err != nil { | ||
return err | ||
} | ||
subkey.Sig.EmbeddedSignature = embeddedSig | ||
|
||
subkey.PublicKey.IsSubkey = true | ||
subkey.PrivateKey.IsSubkey = true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the end, embeddedSig.PubkeyAlgo
depends on subkey
and subkey
depends on embeddedSig
. They are just values but looks circular.
Maybe create first embeddedSig
(and use e.g. config.PublicKeyAlgorithm()
) and then simply set
EmbeddedSignature: &embeddedSig
or something similar when defining subkey
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, good point. I've inlined the embedded signature creation into the subkey creation, to still keep the packet order but fix the circularity.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, thanks.
The spec doesn't say it must appear in the hashed area, unlike the creation time subpacket.
This PR is adapted from @syadav2015's CL here: https://go-review.googlesource.com/c/crypto/+/161817/
This PR is on top of #50.