Skip to content

Commit 16f8541

Browse files
committed
fix(v2): Do not allow encrpytion with a forwarding key
1 parent 28d1c85 commit 16f8541

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

Diff for: openpgp/v2/keys.go

+8-2
Original file line numberDiff line numberDiff line change
@@ -163,12 +163,12 @@ func (e *Entity) DecryptionKeys(id uint64, date time.Time) (keys []Key) {
163163
for _, subkey := range e.Subkeys {
164164
subkeySelfSig, err := subkey.LatestValidBindingSignature(date)
165165
if err == nil &&
166-
isValidEncryptionKey(subkeySelfSig, subkey.PublicKey.PubKeyAlgo) &&
166+
isValidDecryptionKey(subkeySelfSig, subkey.PublicKey.PubKeyAlgo) &&
167167
(id == 0 || subkey.PublicKey.KeyId == id) {
168168
keys = append(keys, Key{subkey.Primary, primarySelfSignature, subkey.PublicKey, subkey.PrivateKey, subkeySelfSig})
169169
}
170170
}
171-
if isValidEncryptionKey(primarySelfSignature, e.PrimaryKey.PubKeyAlgo) {
171+
if isValidDecryptionKey(primarySelfSignature, e.PrimaryKey.PubKeyAlgo) {
172172
keys = append(keys, Key{e, primarySelfSignature, e.PrimaryKey, e.PrivateKey, primarySelfSignature})
173173
}
174174
return
@@ -794,6 +794,12 @@ func isValidCertificationKey(signature *packet.Signature, algo packet.PublicKeyA
794794
}
795795

796796
func isValidEncryptionKey(signature *packet.Signature, algo packet.PublicKeyAlgorithm) bool {
797+
return algo.CanEncrypt() &&
798+
signature.FlagsValid &&
799+
(signature.FlagEncryptCommunications || signature.FlagEncryptStorage)
800+
}
801+
802+
func isValidDecryptionKey(signature *packet.Signature, algo packet.PublicKeyAlgorithm) bool {
797803
return algo.CanEncrypt() &&
798804
signature.FlagsValid &&
799805
(signature.FlagEncryptCommunications || signature.FlagForward || signature.FlagEncryptStorage)

0 commit comments

Comments
 (0)