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:
+23
-6
@@ -108,13 +108,20 @@ func (g *GoSigner) Init() error {
|
||||
return errors.Wrap(err, "error load secret keyring")
|
||||
}
|
||||
|
||||
if len(g.secretKeyring) == 0 {
|
||||
return fmt.Errorf("looks like there are no keys in gpg, please create one (official manual: http://www.gnupg.org/gph/en/manual.html)")
|
||||
}
|
||||
|
||||
if g.keyRef == "" {
|
||||
// no key reference, pick the first key
|
||||
g.signer = g.secretKeyring[0]
|
||||
for _, signer := range g.secretKeyring {
|
||||
if !validEntity(signer) {
|
||||
continue
|
||||
}
|
||||
|
||||
g.signer = signer
|
||||
break
|
||||
}
|
||||
|
||||
if g.signer == nil {
|
||||
return fmt.Errorf("looks like there are no keys in gpg, please create one (official manual: http://www.gnupg.org/gph/en/manual.html)")
|
||||
}
|
||||
} else {
|
||||
pickKeyLoop:
|
||||
for _, signer := range g.secretKeyring {
|
||||
@@ -124,6 +131,10 @@ func (g *GoSigner) Init() error {
|
||||
break
|
||||
}
|
||||
|
||||
if !validEntity(signer) {
|
||||
continue
|
||||
}
|
||||
|
||||
for name := range signer.Identities {
|
||||
if strings.Contains(name, g.keyRef) {
|
||||
g.signer = signer
|
||||
@@ -148,6 +159,12 @@ func (g *GoSigner) Init() error {
|
||||
i++
|
||||
}
|
||||
|
||||
fmt.Printf("openpgp: %s-bit %s key, ID %s, created %s\n",
|
||||
keyBits(g.signer.PrimaryKey.PublicKey),
|
||||
pubkeyAlgorithmName(g.signer.PrimaryKey.PubKeyAlgo),
|
||||
KeyFromUint64(g.signer.PrimaryKey.KeyId),
|
||||
g.signer.PrimaryKey.CreationTime.Format("2006-01-02"))
|
||||
|
||||
if g.passphrase == "" {
|
||||
if g.batch {
|
||||
return errors.New("key is locked with passphrase, but no passphrase was given in batch mode")
|
||||
@@ -456,7 +473,7 @@ func loadKeyRing(name string, ignoreMissing bool) (openpgp.EntityList, error) {
|
||||
if err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
if !ignoreMissing {
|
||||
fmt.Printf("opengpg: failure opening keyring '%s': %s", name, err)
|
||||
fmt.Printf("opengpg: failure opening keyring '%s': %s\n", name, err)
|
||||
}
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user