Bug 575327 - findGpgDirectory() implementation too limited
Summary: findGpgDirectory() implementation too limited
Status: RESOLVED FIXED
Alias: None
Product: JGit
Classification: Technology
Component: JGit (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows 10
: P3 normal (vote)
Target Milestone: 5.13   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-08-10 03:23 EDT by Shaddy Baddah CLA
Modified: 2021-08-19 00:58 EDT (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Shaddy Baddah CLA 2021-08-10 03:23:00 EDT
At least on Windows, it is very difficult to specify an alternate "GNUPGHOME" path... you must rely on temporarily overriding the APPDATA environment variable.

Just in general, it seems the BouncyCastleGpgKeyLocator.findGpgDirectory() is too inflexible, Windows and Linux.

So even in a paradigm where Java should not rely on environment variables (such as GNUPGHOME), rather Java properties sourced from in some fashion... it isn't consistent for the Windows implementation. Which is relying on APPDATA env variable.

For the Linux implementation, it is... but only if you override the user.home system property, which seems a bit extreme.

Can there not be a System property that is the first order of precedence for setting the GPG directory? Perhaps a system property "jgit.gpg.dir"?

I cannot commit to it, but I hope I'll be able to submit a patch for consideration at some point.
Comment 1 Thomas Wolf CLA 2021-08-10 07:05:26 EDT
Yes, this is only a bare-bones implementation.

It appears GPG has several ways to define that directory[2]:

* ~/.gnupg (default on Linux)
* %APPDATA%\gnupg (default on Windows)
* Environment variable GNUPGHOME
* Windows: registry key HKCU\Software\GNU\GnuPG:HomeDir
* Windows: "portable installation", directory given by presence of a file
  "gpgconf.ctl" next to wherever gpgconf.exe is.
* --homedir command line option to gpg-agent.

Only the first two (default locations) are implemented.

The third (environment variable GNUPGHOME) could be implemented directly as is.

The last three are either not accessible to JGit (--homedir on gpg-agent) or platform-specific. For those we could use a Java system property as suggested in comment 0. (It's probably not a good idea to rely on the user setting GNUPGHOME for these cases, as that is known to GPG and might interfere.) Precedence should be system property overrides GNUPGHOME overrides default location. If the user wants to override the system property, he can start his Java application with _JAVA_OPTIONS="-Djgit.gpg.home=...".

So by default the first three cases would be handled, and the others would require the user to set the system property.

Contributions for this are most welcome!

What would also be nice: some public API by which EGit could query or set that directory. Then EGit could provide a preference UI where it could display the default location determined by the above and where the user could define or change that location in the Eclipse UI.

[2] https://www.gnupg.org/documentation/manuals/gnupg/Agent-Options.html#option-_002d_002dhomedir
Comment 2 Eclipse Genie CLA 2021-08-18 02:56:35 EDT
New Gerrit change created: https://git.eclipse.org/r/c/jgit/jgit/+/184189
Comment 4 Shaddy Baddah CLA 2021-08-19 00:58:48 EDT
Wow. Thank you very much. That was a very quick turn around. Much appreciated.