Skip to content

Commit 6e22285

Browse files
committed
bw-ssh-agent-filter: add more log output
1 parent 3fbb94c commit 6e22285

4 files changed

Lines changed: 22 additions & 10 deletions

File tree

pkgs/by-name/bw/bw-ssh-agent-filter/authorize_darwin.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"context"
77
"errors"
88
"fmt"
9+
"log"
910
"time"
1011

1112
touchid "github.com/noamcohen97/touchid-go"
@@ -31,10 +32,9 @@ func (a *touchIDAuthorizer) Authorize(key ssh.PublicKey, comment string, flags a
3132

3233
reason := fmt.Sprintf("Allow SSH signature using %s\n%s", comment, ssh.FingerprintSHA256(key))
3334

34-
if err := touchid.CanAuthenticate(a.policy); err != nil {
35-
return fmt.Errorf("local authentication unavailable: %w", err)
36-
}
35+
started := time.Now()
3736
if err := touchid.Authenticate(ctx, a.policy, reason); err != nil {
37+
log.Printf("auth failed after %s: %s", time.Since(started).Round(time.Millisecond), ssh.FingerprintSHA256(key))
3838
if errors.Is(err, context.DeadlineExceeded) {
3939
return errors.New("local authentication timed out")
4040
}
@@ -46,6 +46,7 @@ func (a *touchIDAuthorizer) Authorize(key ssh.PublicKey, comment string, flags a
4646
}
4747
return fmt.Errorf("local authentication denied: %w", err)
4848
}
49+
log.Printf("auth ok after %s: %s", time.Since(started).Round(time.Millisecond), ssh.FingerprintSHA256(key))
4950

5051
return nil
5152
}

pkgs/by-name/bw/bw-ssh-agent-filter/go.mod

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ module bw-ssh-agent-filter
22

33
go 1.26
44

5-
require golang.org/x/crypto v0.52.0
6-
75
require (
8-
github.com/noamcohen97/touchid-go v0.3.0 // indirect
9-
golang.org/x/sys v0.45.0 // indirect
6+
github.com/noamcohen97/touchid-go v0.3.0
7+
golang.org/x/crypto v0.52.0
108
)
9+
10+
require golang.org/x/sys v0.45.0 // indirect

pkgs/by-name/bw/bw-ssh-agent-filter/main.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"path/filepath"
1414
"strings"
1515
"syscall"
16+
"time"
1617

1718
"golang.org/x/crypto/ssh"
1819
"golang.org/x/crypto/ssh/agent"
@@ -223,22 +224,32 @@ func (a *filterAgent) Sign(key ssh.PublicKey, data []byte) (*ssh.Signature, erro
223224
if !a.isAllowed(key) {
224225
return nil, errors.New("key not allowed")
225226
}
227+
started := time.Now()
226228
if err := a.auth.Authorize(key, a.commentFor(key), 0); err != nil {
227229
return nil, err
228230
}
231+
log.Printf("authorize finished after %s: %s", time.Since(started).Round(time.Millisecond), ssh.FingerprintSHA256(key))
229232

230-
return a.upstream.Sign(key, data)
233+
started = time.Now()
234+
sig, err := a.upstream.Sign(key, data)
235+
log.Printf("upstream sign finished after %s: %s", time.Since(started).Round(time.Millisecond), ssh.FingerprintSHA256(key))
236+
return sig, err
231237
}
232238

233239
func (a *filterAgent) SignWithFlags(key ssh.PublicKey, data []byte, flags agent.SignatureFlags) (*ssh.Signature, error) {
234240
if !a.isAllowed(key) {
235241
return nil, errors.New("key not allowed")
236242
}
243+
started := time.Now()
237244
if err := a.auth.Authorize(key, a.commentFor(key), flags); err != nil {
238245
return nil, err
239246
}
247+
log.Printf("authorize finished after %s flags=%d: %s", time.Since(started).Round(time.Millisecond), flags, ssh.FingerprintSHA256(key))
240248

241-
return a.upstream.SignWithFlags(key, data, flags)
249+
started = time.Now()
250+
sig, err := a.upstream.SignWithFlags(key, data, flags)
251+
log.Printf("upstream sign finished after %s flags=%d: %s", time.Since(started).Round(time.Millisecond), flags, ssh.FingerprintSHA256(key))
252+
return sig, err
242253
}
243254

244255
func (a *filterAgent) isAllowed(key ssh.PublicKey) bool {

pkgs/by-name/bw/bw-ssh-agent-filter/package.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
}:
99
buildGoModule (finalAttrs: {
1010
pname = "bw-ssh-agent-filter";
11-
version = "1.2.0";
11+
version = "1.2.1";
1212

1313
src = ./.;
1414

0 commit comments

Comments
 (0)