Skip to content

Commit 4834142

Browse files
committed
openpgp: fix handling expired keys
exclude expired keys from the GoodKeys
1 parent 8e5707d commit 4834142

2 files changed

Lines changed: 10 additions & 2 deletions

File tree

pgp/internal.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -446,10 +446,11 @@ func (g *GoVerifier) VerifyClearsigned(clearsigned io.Reader, showKeyTip bool) (
446446

447447
for _, signer := range signers {
448448
if signer.Entity != nil {
449-
result.GoodKeys = append(result.GoodKeys, KeyFromUint64(signer.IssuerKeyID))
449+
if !signer.IsExpired {
450+
result.GoodKeys = append(result.GoodKeys, KeyFromUint64(signer.IssuerKeyID))
451+
}
450452
} else {
451453
result.MissingKeys = append(result.MissingKeys, KeyFromUint64(signer.IssuerKeyID))
452-
453454
}
454455
}
455456

pgp/openpgp.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ func hashForSignature(hashID crypto.Hash, sigType packet.SignatureType) (hash.Ha
4040

4141
type signatureResult struct {
4242
CreationTime time.Time
43+
IsExpired bool
4344
IssuerKeyID uint64
4445
PubKeyAlgo packet.PublicKeyAlgorithm
4546
Entity *openpgp.Entity
@@ -59,6 +60,8 @@ func checkDetachedSignature(keyring openpgp.KeyRing, signed, signature io.Reader
5960
return nil, 0, e
6061
}
6162

63+
var now = time.Now()
64+
6265
packets := packet.NewReader(signature)
6366
for {
6467
p, err = packets.Next()
@@ -87,6 +90,9 @@ func checkDetachedSignature(keyring openpgp.KeyRing, signed, signature io.Reader
8790
if sig.IssuerKeyId == nil {
8891
return nil, 0, errors.StructuralError("signature doesn't have an issuer")
8992
}
93+
if sig.SigExpired(now) {
94+
continue
95+
}
9096
issuerKeyID = *sig.IssuerKeyId
9197
hashFunc = sig.Hash
9298
sigType = sig.SigType
@@ -128,6 +134,7 @@ func checkDetachedSignature(keyring openpgp.KeyRing, signed, signature io.Reader
128134
if err == nil {
129135
signers = append(signers, signatureResult{
130136
CreationTime: creationTime,
137+
IsExpired: key.PublicKey.KeyExpired(key.SelfSignature, now),
131138
IssuerKeyID: issuerKeyID,
132139
PubKeyAlgo: pubKeyAlgo,
133140
Entity: key.Entity,

0 commit comments

Comments
 (0)