gpg-rs / gpgme

GPGme bindings for Rust
GNU Lesser General Public License v2.1
83 stars 13 forks source link

No need for a `Key` when doing `interact_with_card` #41

Closed faern closed 1 year ago

faern commented 2 years ago

Hi! Thanks for this wrapper around gpgme. I just started using it and try to get used to it. I need to create a program that automatically configures YubiKeys. This can be done with gpg --edit-card and by extension then also gpgme_op_interact (the C function) and of course interact_with_card from this Rust library. The problem is that the latter requires a &Key to be passed in.

I can configure a smartcard without having any keys in my GnuPG keystore with gpg --edit-key. But the Rust wrapper interact_with_card requires a key. So the only way to currently do what I need is to create some mock key, just to get a handle to pass in.

I kind of get why it's implemented like this. Because the C documentation for gpgme_op_interact states that a valid key pointer must be provided. However, I did look at the source code. And nowhere is it using that key argument if the flag GPGME_INTERACT_CARD is provided.

Ultimately I should report this upstream to the gpgme mailing list or similar, and ask for advice there. How to use the C library to edit smartcards without needing a key. Hopefully they find it OK to use a null pointer for the key argument when interacting with cards. Just that they didn't properly document it. But I was too lazy to do that now. So I thought I'd start the journey by reporting this inconvenience here.

For now I think I'll just write my own interact_with_card wrapper around gpgme-sys that just uses a null pointer for key, given that I know it's safe (with the current versions of gpgme)

johnschug commented 1 year ago

The v0.11.0 release contains a new function Context::interact_with_flags that makes the key optional.