lajg-dev / Obsidian-Plugin-GPG-Inline-Encrypt

Obsidian Plugin GPG Inline Encrypt
Other
9 stars 1 forks source link

Inappropriate ioctl for device #3

Closed jborden closed 1 week ago

jborden commented 4 months ago

Thank you for writing this plugin, I really like the idea of offloading encryption to the tried and true GPG utils. However, I am having an issue when trying to actually encrypt a file.

I am running on: macOS 14.4.1 (23E224)

> gpg --version
gpg (GnuPG) 2.4.5
libgcrypt 1.10.3

Here is my config: GPG_Encrypt_Settings

Here is the actual message: Screenshot 2024-04-28 at 11 46 48 PM

Here is the behavior: GPG_encryt_bug

What I've found so far: (may or may not be relevant) https://stackoverflow.com/questions/72445825/gpg-error-inappropriate-ioctl-for-device

lajg-dev commented 1 month ago

Hi @jborden, thanks for using this plugin.

I've been looking into your case, and it doesn't seem like these environment variable settings need to be set in the plugin, but rather they need to be set in your Mac's environment file (For example ~/.bashrc assuming bash)

Please see https://unix.stackexchange.com/a/257065

Please let me know if you managed to set it in your environment file and if this solved the problem for you

jborden commented 1 month ago

Hi thanks for looking into this. I did try adding the entries from the SO post. I tried adding entries with

GPG_TTY=$(tty)
export GPG_TTY

in ~/.profiles, ~/.bashrc, ~/.bash_profile, but it didn't solve the issue. I'm not sure how calls to command line tools works in Obsidian plugins and what environment they load. Perhaps looking at: https://stackoverflow.com/questions/72445825/gpg-error-inappropriate-ioctl-for-device/72788147#72788147, we could have an option for setting environment vars next to the path of the GPG Executable config option? The simplest would be if it could accept export GPG_TTY=$(tty) ; /opt/homebrew/bin/gpg

Just FYI, I can run gpg commands at my terminal.

Thanks!

lajg-dev commented 1 month ago

I will work on adding a section with custom commands to run before the gpg command, I will let you know when this change is ready, so you can try it out and see if it fixes your problem.

lajg-dev commented 1 month ago

Please download last version 1.1.4 and enable the new feature called "Aditional commands", and add your command in the section "Additional Commands (Before)" (See the image as reference) Screenshot 2024-08-14 at 12 32 47 PM

lajg-dev commented 1 week ago

Please let me know if now it is working for you, so I could close this ticket.

jborden commented 1 week ago

Apologies for the late reply, I was out of town and wasn't at my computer, so I just missed the update from Github.

tl;dr - You need to encrypt text at the command line and enter your passphrase to GPG. It will cache it. After doing this, everything will work in Obsidian.

Here is how I debugged this:

  1. I tried using the Additional Commands (Before) with
    GPG_TTY=$(tty) ; export GPG_TTY

This got rid of the 'Inappropriate ioctl for device' message, but I then had a new one 'gpg: signing failed: No such file or directory'

  1. I was trying to use the command line to debug this, so the console logging of the exact command is helpful. So I did a

    "/opt/homebrew/bin/gpg" --batch --encrypt --armor --trust-model always --sign --local-user 64DD5A914D4419FF --recipient 64DD5A914D4419FF

    I entered some text, hit Ctrl-D and was prompted for my key pass phrase. I provided it. It encrypted the text. I assume it cached the password because on subsequent terminal calls, it just encrypted the text without further prompting of the password.

  2. I was then able to encrypt text in Obsidian, yay! Oddly, I also no longer need the Additional Commands (Before) entry anymore. Everything just works. I assume the caching of the passphrase will have some time component to it. I waited until the passphrase was no longer cached and tried to encrypt in Obsidian again. I got the Inappropriate ioctl for device again! I entered the passphrase and everything just worked again. In summary, the SO suggestion was a red herring.

Thanks for the additional work towards fixing this!

lajg-dev commented 1 week ago

Thanks for the feedback, I'll close this ticket, if you need further assistance in something related this Obsidian plugin, please let me know