@@ -255,17 +255,13 @@ func main() {
255
255
// we get a TPMRCAuthFail
256
256
func (key key.SSHTPMKeys ) ([]byte , error ) {
257
257
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 ):
267
263
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
269
265
userauth , err := askpass .ReadPassphrase (keyInfo , askpass .RP_USE_ASKPASS )
270
266
fmt .Println (err )
271
267
if ! noCache && err == nil {
@@ -275,6 +271,10 @@ func main() {
275
271
}
276
272
}
277
273
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
278
278
}
279
279
return nil , fmt .Errorf ("failed getting pin for key: %w" , err )
280
280
},
0 commit comments