Page MenuHome GnuPG

First-run behaviour differs depending on which home directory is requested
Open, LowPublic

Description

GnuPG behaives differently with regard to a non-existing GnuPG home directory, depending on whether or not the specified path resolves to something ending with ".gnupg" or not.

Case 0: No home directory specified

jolson@senkommen:~$ [ -e ~/.gnupg ] && echo exists || echo does not exist
does not exist
jolson@senkommen:~$ gpg -k
gpg: directory '/home/jolson/.gnupg' created
gpg: new configuration file '/home/jolson/.gnupg/dirmngr.conf' created
gpg: new configuration file '/home/jolson/.gnupg/gpg.conf' created
gpg: keybox '/home/jolson/.gnupg/pubring.kbx' created
gpg: /home/jolson/.gnupg/trustdb.gpg: trustdb created

Case 1: Same result when a home directory is specified and it ends with ".gnupg"

jolson@senkommen:~$ [ -e ~/.config/.gnupg ] && echo exists || echo does not exist
does not exist
jolson@senkommen:~$ GNUPGHOME=~/.config/.gnupg gpg -k
gpg: directory '/home/jolson/.config/.gnupg' created
gpg: new configuration file '/home/jolson/.config/.gnupg/dirmngr.conf' created
gpg: new configuration file '/home/jolson/.config/.gnupg/gpg.conf' created
gpg: keybox '/home/jolson/.config/.gnupg/pubring.kbx' created
gpg: /home/jolson/.config/.gnupg/trustdb.gpg: trustdb created

Case 2: Different result if some other home directory path is specified

jolson@senkommen:~$ [ -e ~/.config/gnupg ] && echo exists || echo does not exist
does not exist
jolson@senkommen:~$ GNUPGHOME=~/.config/gnupg gpg -k
gpg: keyblock resource '/home/jolson/.config/gnupg/pubring.kbx': No such file or directory
gpg: Fatal: /home/jolson/.config/gnupg: directory does not exist!

Case 3: Yet another result if the home directory path ends with ".gnupg", but there is a directory earlier in the path that does not exist

jolson@senkommen:~$ GNUPGHOME=~/.config/gnupg/.gnupg gpg -k
gpg: Fatal: can't create directory '/home/jolson/.config/gnupg/.gnupg': No such file or directory

To me, expected behaviour would be that case 0, case 1, case 2, and probably also case 3 did the same thing.

Furthermore, if the would-be home directory already exists, the behaviour also differs depending on whether or not a home directory is specified or left implicit:

Case 4: Gives no error, but the result differs unexpectedly from that of case 0

jolson@senkommen:~$ mkdir --mode 700 .gnupg
jolson@senkommen:~$ gpg -k
gpg: keybox '/home/jolson/.gnupg/pubring.kbx' created
gpg: /home/jolson/.gnupg/trustdb.gpg: trustdb created

Details

Version
2.1.15

Event Timeline

jolson added a project: Bug Report.
jolson added a subscriber: jolson.
jolson raised the priority of this task from Low to Needs Triage.Jul 16 2017, 12:52 AM
jolson updated the task description. (Show Details)
werner added a subscriber: werner.

Note that current versions don't install a skeleton conf file anymore.

GnuPG tries to create its _default_ home directory because this is the common case. Creating a home directory in every case would clutter the disk with gnupg related data which may even be sensitive.