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

Deleting a private key on macOS Big Sur hangs #145

Open
dvkch opened this issue Nov 8, 2021 · 4 comments
Open

Deleting a private key on macOS Big Sur hangs #145

dvkch opened this issue Nov 8, 2021 · 4 comments

Comments

@dvkch
Copy link

dvkch commented Nov 8, 2021

I've encountered an issue where deleting a key would hang forever, using the following code:

GPGME::Key.find(:public, key_id).each { |k| k.delete!(true) }

# or
GPGME::Key.find(:private key_id).each { |k| k.delete!(true) }
�(B�(B�(0lqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqk�(B�(B�(0x�(B Do you really want to permanently delete the OpenPGP secret key: �(0x�(B�(B�(0x�(B "EnsoTest <[email protected]>"�(0x�(B�(B�(0x�(B 2048-bit RSA key, ID 0FDD92544BA73B80,�(0x�(B�(B�(0x�(B created 2020-08-25.�(0x�(B�(B�(0x�(B ?�(0x�(B�(B�(0x�(B�(B�(0x�(B�(B�(0x�(B     �(B<Delete key>�(B

If the key is a public key with no associated private key it works fine. If this is a public key with an associated private key, or if it is a private key itself, it will hang for around 2 minutes.

I have been able to reproduce this every time when running rspec on a Rails 6.0 project; the key was generated once and is re-added to the my test env using:

private_key = IO.read('spec/support/test_gpg')
key_id = GPGME::Key.import(private_key).imports.map(&:fpr)

Maybe there is an additional argument or configuration that is missing to prevent user confirmation via STDIN ?

@errfanwadia
Copy link

errfanwadia commented Sep 11, 2022

@dvkch were you able to find any workaround to input the user confirmation?

@dvkch
Copy link
Author

dvkch commented Sep 13, 2022

@errfanwadia Unfortunately not. There might be a way in Ruby to connect to STDIN and STDOUT to know when the lib asks for confirmation and write it to STDOUT programmatically from another thread, but I haven't had the chance to test it though

@evgenii
Copy link

evgenii commented Mar 1, 2024

The current gem is not supporting this for now but the gpg/gpgme has an additional function gpgme_op_delete_ext where we can put the flags for the force delete:

/* Flags for the key delete functions.  */
#define GPGME_DELETE_ALLOW_SECRET (1 << 0)  /* Also delete secret key.     */
#define GPGME_DELETE_FORCE        (1 << 1)  /* Do not ask user to confirm.  */

see:

@kernelsmith
Copy link

@errfanwadia Unfortunately not. There might be a way in Ruby to connect to STDIN and STDOUT to know when the lib asks for confirmation and write it to STDOUT programmatically from another thread, but I haven't had the chance to test it though

you can definitely do this, but it is kind of painful obviously. All 3 are predefined as IO objects named STDOUT, STDIN, and STDERR. Instead tho, you might consider just marking the key untrusted. It will still be there, but not get used normally.

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

No branches or pull requests

4 participants