Skip to content

Commit e953778

Browse files
authored
Merge pull request #274 from smlx/gpg-247
Support gnupg 2.4.7
2 parents 80a7638 + 49d55f1 commit e953778

File tree

6 files changed

+25
-14
lines changed

6 files changed

+25
-14
lines changed

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
module github.com/smlx/piv-agent
22

33
go 1.23.2
4+
45
toolchain go1.24.1
56

67
require (

internal/assuan/assuan.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import (
2222
// version indicates the version of gpg-agent to emulate.
2323
// The gpg CLI client will emit a warning if this is lower than the version of
2424
// the gpg client itself.
25-
const version = "2.3.4"
25+
const version = "2.4.7"
2626

2727
// The KeyService interface provides functions used by the Assuan FSM.
2828
type KeyService interface {
@@ -212,7 +212,8 @@ func New(rw io.ReadWriter, log *zap.Logger, n *notify.Notify,
212212
}
213213
if err != nil {
214214
_, _ = io.WriteString(rw, "ERR 1 couldn't get key for keygrip\n")
215-
return fmt.Errorf("couldn't get key for keygrip: %v", err)
215+
log.Warn("couldn't get key for keygrip", zap.Error(err))
216+
return nil // this is not a fatal error
216217
}
217218
_, err = io.WriteString(rw, "OK\n")
218219
case setkeydesc:
@@ -253,6 +254,9 @@ func New(rw io.ReadWriter, log *zap.Logger, n *notify.Notify,
253254
}
254255
var plaintext, ciphertext []byte
255256
ciphertext = bytes.Join(chunks, []byte("\n"))
257+
// start notify timer
258+
cancel := assuan.notify.Touch()
259+
defer cancel()
256260
plaintext, err = assuan.decrypter.Decrypt(nil, ciphertext, nil)
257261
if err != nil {
258262
return fmt.Errorf("couldn't decrypt: %v", err)
@@ -303,7 +307,7 @@ func (assuan *Assuan) havekey(rw io.ReadWriter, ks []KeyService) error {
303307
_, _ = io.WriteString(rw, "ERR 1 couldn't list keygrips\n")
304308
return err
305309
}
306-
// apply buggy libgcrypt encoding
310+
// apply libgcrypt encoding
307311
_, err = io.WriteString(rw, fmt.Sprintf("D %s\nOK\n",
308312
PercentEncodeSExp(grips)))
309313
return err
@@ -371,8 +375,8 @@ func haveKey(ks []KeyService, keygrips [][]byte) (bool, []byte, error) {
371375
return false, nil, nil
372376
}
373377

374-
// allKeygrips returns all keygrips available for any keyservice, concatenated
375-
// into a single byte slice.
378+
// allKeygrips returns all keygrips available for any of the given keyservices,
379+
// concatenated into a single byte slice.
376380
func allKeygrips(ks []KeyService) ([]byte, error) {
377381
var grips []byte
378382
for _, k := range ks {

internal/assuan/assuan_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ func TestSign(t *testing.T) {
102102
"OK\n",
103103
"OK\n",
104104
"OK\n",
105-
"D 2.3.4\n",
105+
"D 2.4.7\n",
106106
"OK\n",
107107
"OK\n",
108108
"OK\n",
@@ -314,7 +314,7 @@ func TestDecryptRSAKeyfile(t *testing.T) {
314314
"OK\n",
315315
"OK\n",
316316
"OK\n",
317-
"D 2.3.4\n",
317+
"D 2.4.7\n",
318318
"OK\n",
319319
"OK\n",
320320
"OK\n",
@@ -409,7 +409,7 @@ func TestSignRSAKeyfile(t *testing.T) {
409409
"OK\n",
410410
"OK\n",
411411
"OK\n",
412-
"D 2.3.4\n",
412+
"D 2.4.7\n",
413413
"OK\n",
414414
"OK\n",
415415
"OK\n",
@@ -600,7 +600,7 @@ func TestDecryptECDHKeyfile(t *testing.T) {
600600
"OK\n",
601601
"OK\n",
602602
"OK\n",
603-
"D 2.3.4\n",
603+
"D 2.4.7\n",
604604
"OK\n",
605605
"OK\n",
606606
"OK\n",

internal/assuan/fsm.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,10 @@ var assuanTransitions = []fsm.Transition{
158158
Src: fsm.State(decryptingKeyIsSet),
159159
Event: fsm.Event(pkdecrypt),
160160
Dst: fsm.State(waitingForCiphertext),
161+
}, {
162+
Src: fsm.State(decryptingKeyIsSet),
163+
Event: fsm.Event(reset),
164+
Dst: fsm.State(connected),
161165
}, {
162166
Src: fsm.State(waitingForCiphertext),
163167
Event: fsm.Event(havekey),

internal/assuan/sign.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,9 @@ func (a *Assuan) signRSA() ([]byte, error) {
2929
if err != nil {
3030
return nil, fmt.Errorf("couldn't sign: %v", err)
3131
}
32-
return []byte(fmt.Sprintf(`D (7:sig-val(3:rsa(1:s%d:%s)))`, len(signature),
33-
PercentEncodeSExp(signature))), nil
32+
var buf []byte
33+
return fmt.Appendf(buf, `D (7:sig-val(3:rsa(1:s%d:%s)))`, len(signature),
34+
PercentEncodeSExp(signature)), nil
3435
}
3536

3637
// signECDSA returns a signature for the given hash.
@@ -60,6 +61,7 @@ func (a *Assuan) signECDSA() ([]byte, error) {
6061
return nil, fmt.Errorf("couldn't read s as asn1.Integer")
6162
}
6263
// encode the params (r, s) into s-exp
63-
return []byte(fmt.Sprintf(`D (7:sig-val(5:ecdsa(1:r32#%X#)(1:s32#%X#)))`,
64-
r.Bytes(), s.Bytes())), nil
64+
var buf []byte
65+
return fmt.Appendf(buf, `D (7:sig-val(5:ecdsa(1:r32#%X#)(1:s32#%X#)))`,
66+
r.Bytes(), s.Bytes()), nil
6567
}

internal/keyservice/gpg/keyservice.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ func (*KeyService) Name() string {
6161
func (g *KeyService) doDecrypt(k *packet.PrivateKey, uid string) error {
6262
var pass []byte
6363
var err error
64-
for i := 0; i < retries; i++ {
64+
for i := range retries {
6565
pass, err = g.pinentry.GetPassphrase(
6666
fmt.Sprintf("UserID: %s\rFingerprint: %X %X %X %X", uid,
6767
k.Fingerprint[:5], k.Fingerprint[5:10], k.Fingerprint[10:15],

0 commit comments

Comments
 (0)