Skip to content

Commit 9aa010a

Browse files
committed
fix(v2): Do not allow encrpytion with a forwarding key
1 parent 91c2e9e commit 9aa010a

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

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, config *packet.Config
163163
for _, subkey := range e.Subkeys {
164164
subkeySelfSig, err := subkey.LatestValidBindingSignature(date, config)
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
@@ -796,6 +796,12 @@ func isValidCertificationKey(signature *packet.Signature, algo packet.PublicKeyA
796796
}
797797

798798
func isValidEncryptionKey(signature *packet.Signature, algo packet.PublicKeyAlgorithm) bool {
799+
return algo.CanEncrypt() &&
800+
signature.FlagsValid &&
801+
(signature.FlagEncryptCommunications || signature.FlagEncryptStorage)
802+
}
803+
804+
func isValidDecryptionKey(signature *packet.Signature, algo packet.PublicKeyAlgorithm) bool {
799805
return algo.CanEncrypt() &&
800806
signature.FlagsValid &&
801807
(signature.FlagEncryptCommunications || signature.FlagForward || signature.FlagEncryptStorage)

0 commit comments

Comments
 (0)