mirror of
https://github.com/aptly-dev/aptly.git
synced 2026-05-06 22:18:28 +00:00
Improve internal PGP provider
1. Print additional details about keys being used for signing 2. Skip expired keys 3. Add `\n` to logged messages
This commit is contained in:
@@ -3,6 +3,9 @@ package pgp
|
||||
import (
|
||||
"bytes"
|
||||
"crypto"
|
||||
"crypto/dsa"
|
||||
"crypto/ecdsa"
|
||||
"crypto/rsa"
|
||||
"hash"
|
||||
"io"
|
||||
"strconv"
|
||||
@@ -191,3 +194,50 @@ func pubkeyAlgorithmName(algorithm packet.PublicKeyAlgorithm) string {
|
||||
|
||||
return "unknown"
|
||||
}
|
||||
|
||||
func keyBits(key interface{}) string {
|
||||
switch k := key.(type) {
|
||||
case *rsa.PublicKey:
|
||||
return strconv.Itoa(k.N.BitLen())
|
||||
case *dsa.PublicKey:
|
||||
return strconv.Itoa(k.P.BitLen())
|
||||
case *ecdsa.PublicKey:
|
||||
return strconv.Itoa(k.Curve.Params().BitSize)
|
||||
default:
|
||||
return "?"
|
||||
}
|
||||
}
|
||||
|
||||
func validEntity(entity *openpgp.Entity) bool {
|
||||
var selfSig *packet.Signature
|
||||
for _, ident := range entity.Identities {
|
||||
if selfSig == nil {
|
||||
selfSig = ident.SelfSignature
|
||||
} else if ident.SelfSignature.IsPrimaryId != nil && *ident.SelfSignature.IsPrimaryId {
|
||||
selfSig = ident.SelfSignature
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if selfSig == nil {
|
||||
return false
|
||||
}
|
||||
|
||||
if len(entity.Revocations) > 0 {
|
||||
return false
|
||||
}
|
||||
|
||||
if selfSig.RevocationReason != nil {
|
||||
return false
|
||||
}
|
||||
|
||||
if !selfSig.FlagsValid {
|
||||
return false
|
||||
}
|
||||
|
||||
if selfSig.KeyLifetimeSecs != nil && selfSig.CreationTime.Add(time.Duration(*selfSig.KeyLifetimeSecs)*time.Second).Before(time.Now()) {
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user