@@ -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