Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: detect yubikey touches for the new gpg version #58

Merged
merged 4 commits into from
Nov 21, 2024

Conversation

Pablito2020
Copy link
Contributor

The new detection heuristic now checks whether the private key files are opened.

We specifically detect private keys that require a YubiKey touch by filtering out those that have the shadowed-private-key attribute in the S-expression inside the .key file. For more details, refer to the gnupg documentation that talks about .key format.

There may be false positives if the user has both a YubiKey and another GPG smartcard device, as the heuristic will detect that gpg opens a private key file. However, this approach is a significant improvement over the current situation, where no devices are detected.

I should mention that I am not an expert in Go (I read just enough to implement this pull request). I originally prototyped this idea in Python and then ported it to Go. Therefore, any feedback on the code would be greatly appreciated, especially if there are any issues with structure or potential bad practices. Let me know if refactoring is needed!

This closes #54

Now the new detection heuristic is to check if we open the private key
files. Since we're detecting only the keys that need a yubikey touch, we filter the
ones that have the shadowed-private-key attribute on the S-expression
inside the key file ( more information about it here:
https://github.com/gpg/gnupg/blob/6737e07a9b04064947ae37abd28b845a09abee22/doc/keyformat.txt#shadowed-private-key-format )

We can have false positives if the user has a yubikey + other gpg
smartcard device (since will detect it will try to open the private key
file too!).

This closes maximbaz#54
@maximbaz
Copy link
Owner

Veeery interesting, thanks for finding an approach, as you probably saw in #54 we were struggling to find an event-based way to do the check! I'll try to test tonight!

Copy link
Owner

@maximbaz maximbaz left a comment

Choose a reason for hiding this comment

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

Thanks! Some initial feedback - I only managed to test it on the old gpg keyring format (still works!), didn't get to test on the new one, but I believe you tested it anyway, so I have no doubt. Great solution!

Could you also run go fmt on the changed files? If not, no worries I'll do it afterwards myself.

detector/gpg.go Outdated Show resolved Hide resolved
detector/gpg.go Outdated Show resolved Hide resolved
detector/gpg.go Show resolved Hide resolved
main.go Outdated Show resolved Hide resolved
main.go Outdated Show resolved Hide resolved
main.go Outdated Show resolved Hide resolved
main.go Outdated Show resolved Hide resolved
main.go Outdated Show resolved Hide resolved
main.go Outdated Show resolved Hide resolved
@maximbaz
Copy link
Owner

By the way, I'm happy to take over the PR at any point if it becomes overwhelming, you just let me know at any point of time if you'd like me to merge and cleanup later - you've already done the most important part, figuring out how to support the new gpg format 🙏

Pablito2020 added a commit to Pablito2020/yubikey-touch-detector that referenced this pull request Nov 21, 2024
@Pablito2020 Pablito2020 force-pushed the fix-keyboxd-dont-detect branch from ff12f3c to 4e697eb Compare November 21, 2024 16:14
Pablito2020 added a commit to Pablito2020/yubikey-touch-detector that referenced this pull request Nov 21, 2024
@Pablito2020 Pablito2020 force-pushed the fix-keyboxd-dont-detect branch from 5c7d7eb to 65ee3f8 Compare November 21, 2024 16:16
@Pablito2020 Pablito2020 force-pushed the fix-keyboxd-dont-detect branch from aa029c4 to 9e24129 Compare November 21, 2024 16:18
@Pablito2020
Copy link
Contributor Author

Done!

No worries, it’s not overwhelming, I understand that it was my first time programming in Go, so there was definitely room for improvement!

Tell me if you see something that could be improved.

@maximbaz
Copy link
Owner

It looks great, I just had very minor things that I took the liberty to do myself, I thought it would be more efficient - you can review the last two commits, please feel free to ask if something is not clear. Thanks, going to merge and cut a release!

@maximbaz maximbaz merged commit 7c1dc46 into maximbaz:main Nov 21, 2024
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.

[Feature]: Support new keyboxd gpg pubring format
2 participants