Skip to content

feat!: Require devices to be explicitly closed#15

Merged
codingllama merged 7 commits intoteleportfrom
codingllama/dev-tweaks
Jan 23, 2024
Merged

feat!: Require devices to be explicitly closed#15
codingllama merged 7 commits intoteleportfrom
codingllama/dev-tweaks

Conversation

@codingllama
Copy link
Copy Markdown

@codingllama codingllama commented Jan 12, 2024

Expose a Close method on Device, open the device on NewDevice and require devices to be explicitly closed.

Additionally, expose the SetTimeout device method as well.

This is (another) departure from upstream, where instead of doing open/close on the Device for each operation, we allow opening the device just once for the entire lifetime of interactions. The change seems to improve responsiveness and reduce flakiness when interacting with devices. It also seems to be more in-line with various libfido2 examples.

gravitational/teleport#36640

Comment thread fido2.go
@codingllama codingllama changed the title Require devices to be explicitly closed feat!: Require devices to be explicitly closed Jan 12, 2024
Comment thread examples_test.go
Comment thread examples_test.go
Comment thread examples_test.go Outdated
Comment thread fido2.go Outdated
Co-authored-by: rosstimothy <39066650+rosstimothy@users.noreply.github.com>
Comment thread fido2.go
if cErr := C.fido_dev_cancel(d.dev); cErr != C.FIDO_OK {
return errors.Wrap(errFromCode(cErr), "failed to cancel")
}
if d == nil {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's good to stay calm and not panic, but is there a valid use case where you call Cancel() on nil except for a mistake?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's probably a programming mistake if this happens, although not doing anything is reasonable for a cancel. Other methods should blow up.

As this is a library, I'd rather be safer than normal.

Comment thread fido2.go
Comment thread fido2.go
Comment thread examples_test.go Outdated
@codingllama
Copy link
Copy Markdown
Author

Thanks for the reviews, folks!

@codingllama codingllama force-pushed the codingllama/dev-tweaks branch from 843fcb8 to 728a6b7 Compare January 12, 2024 22:07
@codingllama
Copy link
Copy Markdown
Author

FYI, I've just pushed 2 more commits: b14fe43 and b267d1e.

The first (b14fe43) is based on libfido2 examples and has the practical effect of making Yubikeys stop blinking on various assertion failures.

The second (b267d1e) adds a way to set operation timeouts, which also allows us to set a hard deadline on assertions (and also makes the fobs stop blinking).

@codingllama
Copy link
Copy Markdown
Author

I'll go ahead and merge this, as I'm convinced it's a change for the best. Thanks for the prompt reviews!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants