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:
Andrey Smirnov
2017-07-28 00:52:04 +03:00
parent cafa82f018
commit 68da8a674a
3 changed files with 74 additions and 6 deletions
+50
View File
@@ -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
}