Skip to content

Commit 9f1332b

Browse files
committed
ssh-tpm-agent: move auth cache to switch block
Signed-off-by: Morten Linderud <[email protected]>
1 parent 5be6003 commit 9f1332b

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

cmd/ssh-tpm-agent/main.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -255,17 +255,13 @@ func main() {
255255
// we get a TPMRCAuthFail
256256
func(key key.SSHTPMKeys) ([]byte, error) {
257257
auth, err := agentkeyring.ReadKey(key.Fingerprint())
258-
if err == nil {
259-
slog.Debug("providing cached userauth for key", slog.String("fp", key.Fingerprint()))
260-
// TODO: This is not great, but easier for now
261-
return auth.Read(), nil
262-
} else if errors.Is(err, syscall.ENOKEY) || errors.Is(err, syscall.EACCES) || errors.Is(err, syscall.ENOENT) {
263-
if errors.Is(err, syscall.ENOENT) {
264-
slog.Warn("kernel is missing the keyctl executable helpers. Please install the keyutils package to use the agent with caching.")
265-
}
266-
258+
switch {
259+
case errors.Is(err, syscall.ENOENT):
260+
slog.Warn("kernel is missing the keyctl executable helpers. Please install the keyutils package to use the agent with caching.")
261+
fallthrough
262+
case errors.Is(err, syscall.ENOKEY) || errors.Is(err, syscall.EACCES):
267263
keyInfo := fmt.Sprintf("Enter passphrase for (%s): ", key.GetDescription())
268-
// TODOt kjk: askpass should box the byte slice
264+
// TODO: askpass should box the byte slice
269265
userauth, err := askpass.ReadPassphrase(keyInfo, askpass.RP_USE_ASKPASS)
270266
fmt.Println(err)
271267
if !noCache && err == nil {
@@ -275,6 +271,10 @@ func main() {
275271
}
276272
}
277273
return userauth, err
274+
case err == nil:
275+
slog.Debug("providing cached userauth for key", slog.String("fp", key.Fingerprint()))
276+
// TODO: This is not great, but easier for now
277+
return auth.Read(), nil
278278
}
279279
return nil, fmt.Errorf("failed getting pin for key: %w", err)
280280
},

0 commit comments

Comments
 (0)