Skip to content

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

Merged
merged 8 commits into from
Jun 5, 2020

Conversation

twiss
Copy link
Member

@twiss twiss commented May 15, 2020

This PR is adapted from @syadav2015's CL here: https://go-review.googlesource.com/c/crypto/+/161817/

This PR is on top of #50.

syadav2015 and others added 3 commits May 27, 2020 16:22
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.
Comment on lines 134 to 162
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
Copy link
Contributor

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?

Copy link
Member Author

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.

@twiss twiss requested a review from zugzwang June 3, 2020 11:56
Copy link
Contributor

@zugzwang zugzwang left a comment

Choose a reason for hiding this comment

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

Looks good, thanks.

twiss added 2 commits June 5, 2020 12:24
The spec doesn't say it must appear in the hashed area, unlike the
creation time subpacket.
@twiss twiss merged commit 11f6ee2 into master Jun 5, 2020
@twiss twiss deleted the subkeys branch June 5, 2020 10:56
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