The authors of MacGPG have been very responsive to reports of issues, and are in the process of creating an uninstall script. The purpose of this blog post is to dig into how this software runs in the system, and learn a little about OSX 10.4 along the way.
So what's running?
$ ps aux | grep gpg
******* 6986 0.0 -0.0 29644 308 ?? Ss 10:46AM 0:00.01 gpg-agent --daemon --write-env-file
******* 7025 0.0 -0.0 27376 420 p1 S+ 10:47AM 0:00.01 grep gpg
You'll notice that this process is started for any user of the system, not just the user that installed the software. From the manpage:
gpg-agent is a daemon to manage secret (private) keys independently from any protocol. It is used as a backend for gpg and gpgsm as well as for a couple of other utilities. The usual way to run the agent is from the ~/.xsession file: eval `gpg-agent --daemon` If you don't use an X server, you can also put this into your regular startup file ~/.profile or .bash_profile. It is best not to run multi- ple instance of the gpg-agent, so you should make sure that only one is running: gpg-agent uses an environment variable to inform clients about the communication parameters. You can write the content of this envi- ronment variable to a file so that you can test for a running agent. This short script may do the job: if test -f $HOME/.gpg-agent-info && kill -0 `cut -d: -f 2 $HOME/.gpg-agent-info` 2>/dev/null; then GPG_AGENT_INFO=`cat $HOME/.gpg-agent-info` export GPG_AGENT_INFO else eval `gpg-agent --daemon` echo $GPG_AGENT_INFO >$HOME/.gpg-agent-info fi Note that the new option --write-env-file may be used instead.
You should have a .gpg-agent-info file in your home directory, but there isn't a .bashrc or .profile file. We do however have a .MacOSX directory. Inside there should be a file called environment.plist with the following:
This is confirmed running lsof -p 6986 gives the following:
**********:~ *******$ lsof -p 6986
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
gpg-agent 6986 ******* cwd VDIR 14,2 1122 2 /
gpg-agent 6986 ******* txt VREG 14,2 4247824 1429308 /usr/local/bin/gpg-agent
gpg-agent 6986 ******* txt VREG 14,2 1797576 163657 /usr/lib/dyld
gpg-agent 6986 ******* txt VREG 14,2 4398204 1368964 /usr/lib/libSystem.B.dylib
gpg-agent 6986 ******* txt VREG 14,2 1231864 1368744 /System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation
gpg-agent 6986 ******* txt VREG 14,2 801160 1090767 /usr/lib/libobjc.A.dylib
gpg-agent 6986 ******* txt VREG 14,2 1455656 1368830 /usr/lib/libicucore.A.dylib
gpg-agent 6986 ******* txt VREG 14,2 304580 1110847 /usr/lib/libncurses.5.4.dylib
gpg-agent 6986 ******* 0r VCHR 3,2 0t0 62268292 /dev/null
gpg-agent 6986 ******* 1w VCHR 3,2 0t0 62268292 /dev/null
gpg-agent 6986 ******* 2w VCHR 3,2 0t0 62268292 /dev/null
gpg-agent 6986 ******* 3r 0x051bdd60 file struct, ty=0x3, op=0x384768
gpg-agent 6986 ******* 4r 0x051bdbb0 file struct, ty=0x6, op=0x3833ec
gpg-agent 6986 ******* 5w 0x051bd8f0 file struct, ty=0x6, op=0x3833ec
gpg-agent 6986 ******* 6u unix 0x03bb9720 0t0 /tmp/gpg-pIhMQu/S.gpg-agent
This looks a bit weird though. Why in /tmp? Why have the nonce appended to the path? We also have some timeline information. 6986 corresponds to the PID of gpg-agent at that time, so that PID was already assigned when the environment.plist was written. On my system in /tmp I have the following:
drwx------ 3 ******* wheel 102 Jan 2 10:39 gpg-wJ3ihI
drwx------ 3 ******* wheel 102 Jan 2 11:45 gpg-m2uq2i
drwx------ 3 ******* wheel 102 Jan 3 10:46 gpg-pIhMQu
According to last, this corresponds to login times. Each of these folders contains the exact same thing, S.gpg-agent, a socket link.
We also know that the gpg-agent is executed on login. A .plist file isn't present, however in OSX the defaults system shows us how the application is started:
************:~/Library/Preferences root# defaults read com.apple.loginwindow LoginHook
/usr/local/sbin/gpg-login.sh
************:~/Library/Preferences root# defaults read com.apple.loginwindow LogoutHook
/usr/local/sbin/gpg-logout.sh
Uninstalling version 2.0.9
We should be able to stop the agent from running by removing the login and logout hooks using defaults. First we want to stop the running process:
kill -9 6986 (change to your PID)
Remove the hooks:
sudo defaults delete com.apple.loginwindow LoginHook
sudo defaults delete com.apple.loginwindow LogoutHook
Reading the hooks should now give the following:
defaults read com.apple.loginwindow LoginHook
2009-01-03 18:22:49.320 defaults[7836]
The domain/default pair of (com.apple.loginwindow, LoginHook) does not exist
Logging out and back in then running ps aux | grep gpg should confirm that the gpg-agent is no longer running. We can now remove the binaries and scripts left on the system we found in the first part of the analysis:
rm /usr/local/sbin/addgnupghome
rm /usr/local/sbin/applygnupgdefaults
rm /usr/local/sbin/gpg-login.sh
rm /usr/local/sbin/gpg-logout.sh
rm -r /tmp/gpg-*
rm /usr/local/bin/gpg-agent
rm /usr/local/bin/gpg-connect-agent
rm /usr/local/bin/gpg2
rm /usr/local/bin/gpgconf
rm /usr/local/bin/gpgkey2ssh
rm /usr/local/bin/gpgparsemail
rm /usr/local/bin/gpgsm
rm /usr/local/bin/gpgsm-gencert.sh
rm /usr/local/bin/gpgv2
rm -r ~/.gnupg
rm ~/.gpg-agent-info
Finally, remove the GPG agent key from the environment.plist file by deleting these two lines:
Logout and log back in to confirm that everything is starting correctly with no errors.
2 comments:
Here's a list of all the files installed - it may be easier to delete /usr/local/ completely:
$ lsbom Archive.bom
. 40755 501/501
./usr 40755 0/0
./usr/local 40755 0/0
./usr/local/bin 40755 0/0
./usr/local/bin/gpg-agent 100755 0/0 4247824 3338701696
./usr/local/bin/gpg-connect-agent 100755 0/0 2540300 2391985222
./usr/local/bin/gpg2 100755 0/0 5252688 482091190
./usr/local/bin/gpgconf 100755 0/0 2413492 1657432488
./usr/local/bin/gpgkey2ssh 100755 0/0 3517016 838113176
./usr/local/bin/gpgparsemail 100755 0/0 86472 2076182794
./usr/local/bin/gpgsm 100755 0/0 4798796 3497903347
./usr/local/bin/gpgsm-gencert.sh 100755 0/0 4511 1115675870
./usr/local/bin/gpgv2 100755 0/0 4273808 1366678033
./usr/local/bin/kbxutil 100755 0/0 4001736 3139957028
./usr/local/bin/scdaemon 100755 0/0 4721788 3175829085
./usr/local/bin/watchgnupg 100755 0/0 51916 2496253130
./usr/local/libexec 40755 0/0
./usr/local/libexec/gnupg-pcsc-wrapper 100755 0/0 64552 100942587
./usr/local/libexec/gpg-check-pattern 100755 0/0 3676656 2376077387
./usr/local/libexec/gpg-preset-passphrase 100755 0/0 3629540 2667018131
./usr/local/libexec/gpg-protect-tool 100755 0/0 3811768 2095944773
./usr/local/libexec/gpg2keys_curl 100755 0/0 73376 1635676207
./usr/local/libexec/gpg2keys_finger 100755 0/0 2216988 3397043636
./usr/local/libexec/gpg2keys_hkp 100755 0/0 85860 1437321087
./usr/local/libexec/gpg2keys_ldap 100755 0/0 2230236 31799626
./usr/local/libexec/pinentry-mac.app 40755 0/0
./usr/local/libexec/pinentry-mac.app/Contents 40755 0/0
./usr/local/libexec/pinentry-mac.app/Contents/Info.plist 100644 0/0 929 3981751528
./usr/local/libexec/pinentry-mac.app/Contents/MacOS 40755 0/0
./usr/local/libexec/pinentry-mac.app/Contents/MacOS/pinentry-mac 100755 0/0 106748 3214628744
./usr/local/libexec/pinentry-mac.app/Contents/PkgInfo 100644 0/0 8 742937289
./usr/local/libexec/pinentry-mac.app/Contents/Resources 40755 0/0
./usr/local/libexec/pinentry-mac.app/Contents/Resources/COPYING 100755 0/0 15131 4258197600
./usr/local/libexec/pinentry-mac.app/Contents/Resources/English.lproj 40755 0/0
./usr/local/libexec/pinentry-mac.app/Contents/Resources/English.lproj/MainMenu.nib 40755 0/0
./usr/local/libexec/pinentry-mac.app/Contents/Resources/English.lproj/MainMenu.nib/classes.nib 100644 0/0 747 1963893090
./usr/local/libexec/pinentry-mac.app/Contents/Resources/English.lproj/MainMenu.nib/info.nib 100644 0/0 570 3934744636
./usr/local/libexec/pinentry-mac.app/Contents/Resources/English.lproj/MainMenu.nib/keyedobjects.nib 100644 0/0 10206 1744024385
./usr/local/libexec/pinentry-mac.app/Contents/Resources/mac-gpg-logo.png 100755 0/0 12499 1289244703
./usr/local/sbin 40755 0/0
./usr/local/sbin/._gpg-login.sh 100644 0/0 82 2210754575
./usr/local/sbin/._gpg-logout.sh 100644 0/0 82 2210754575
./usr/local/sbin/addgnupghome 100755 0/0 3126 3528967330
./usr/local/sbin/applygnupgdefaults 100755 0/0 2192 1984488774
./usr/local/sbin/gpg-login.sh 100755 0/0 1446 3240498794
./usr/local/sbin/gpg-logout.sh 100755 0/0 72 4180144188
./usr/local/share 40755 0/0
./usr/local/share/gnupg 40755 0/0
./usr/local/share/gnupg/FAQ 100644 0/0 56838 1203421149
./usr/local/share/gnupg/com-certs.pem 100644 0/0 23546 425888464
./usr/local/share/gnupg/faq.html 100644 0/0 61886 3964363408
./usr/local/share/gnupg/gpg-conf.skel 100644 0/0 7962 4161664324
./usr/local/share/gnupg/help.be.txt 100644 0/0 9740 3304473218
./usr/local/share/gnupg/help.ca.txt 100644 0/0 9740 3304473218
./usr/local/share/gnupg/help.cs.txt 100644 0/0 9740 3304473218
./usr/local/share/gnupg/help.da.txt 100644 0/0 9740 3304473218
./usr/local/share/gnupg/help.de.txt 100644 0/0 8968 68601539
./usr/local/share/gnupg/help.el.txt 100644 0/0 9740 3304473218
./usr/local/share/gnupg/help.eo.txt 100644 0/0 9740 3304473218
./usr/local/share/gnupg/help.es.txt 100644 0/0 7631 3879776408
./usr/local/share/gnupg/help.et.txt 100644 0/0 9740 3304473218
./usr/local/share/gnupg/help.fi.txt 100644 0/0 7743 1156554207
./usr/local/share/gnupg/help.fr.txt 100644 0/0 7796 2887126644
./usr/local/share/gnupg/help.gl.txt 100644 0/0 9740 3304473218
./usr/local/share/gnupg/help.hu.txt 100644 0/0 8204 201008446
./usr/local/share/gnupg/help.id.txt 100644 0/0 7534 896566218
./usr/local/share/gnupg/help.it.txt 100644 0/0 7690 1970298939
./usr/local/share/gnupg/help.ja.txt 100644 0/0 9740 3304473218
./usr/local/share/gnupg/help.nb.txt 100644 0/0 9740 3304473218
./usr/local/share/gnupg/help.pl.txt 100644 0/0 7534 3948196764
./usr/local/share/gnupg/help.pt.txt 100644 0/0 7872 334308242
./usr/local/share/gnupg/help.pt_BR.txt 100644 0/0 7875 3381631880
./usr/local/share/gnupg/help.ro.txt 100644 0/0 8111 2256532383
./usr/local/share/gnupg/help.ru.txt 100644 0/0 11515 3101641721
./usr/local/share/gnupg/help.sk.txt 100644 0/0 8084 3486724708
./usr/local/share/gnupg/help.sv.txt 100644 0/0 9740 3304473218
./usr/local/share/gnupg/help.tr.txt 100644 0/0 7650 1121333301
./usr/local/share/gnupg/help.txt 100644 0/0 11181 2032795071
./usr/local/share/gnupg/help.zh_CN.txt 100644 0/0 7070 136670975
./usr/local/share/gnupg/help.zh_TW.txt 100644 0/0 7101 2553965010
./usr/local/share/gnupg/qualified.txt 100644 0/0 8749 133553071
./usr/local/share/info 40755 0/0
./usr/local/share/info/gnupg.info 100644 0/0 4847 1827108294
./usr/local/share/info/gnupg.info-1 100644 0/0 270049 772734163
./usr/local/share/info/gnupg.info-2 100644 0/0 85490 3250439280
./usr/local/share/locale 40755 0/0
./usr/local/share/locale/be 40755 0/0
./usr/local/share/locale/be/LC_MESSAGES 40755 0/0
./usr/local/share/locale/be/LC_MESSAGES/gnupg2.mo 100644 0/0 10118 234678612
./usr/local/share/locale/ca 40755 0/0
./usr/local/share/locale/ca/LC_MESSAGES 40755 0/0
./usr/local/share/locale/ca/LC_MESSAGES/gnupg2.mo 100644 0/0 59630 3248747183
./usr/local/share/locale/cs 40755 0/0
./usr/local/share/locale/cs/LC_MESSAGES 40755 0/0
./usr/local/share/locale/cs/LC_MESSAGES/gnupg2.mo 100644 0/0 108938 1325254421
./usr/local/share/locale/da 40755 0/0
./usr/local/share/locale/da/LC_MESSAGES 40755 0/0
./usr/local/share/locale/da/LC_MESSAGES/gnupg2.mo 100644 0/0 15751 15363886
./usr/local/share/locale/de 40755 0/0
./usr/local/share/locale/de/LC_MESSAGES 40755 0/0
./usr/local/share/locale/de/LC_MESSAGES/gnupg2.mo 100644 0/0 180458 3532209887
./usr/local/share/locale/el 40755 0/0
./usr/local/share/locale/el/LC_MESSAGES 40755 0/0
./usr/local/share/locale/el/LC_MESSAGES/gnupg2.mo 100644 0/0 59766 812794431
./usr/local/share/locale/en@boldquot 40755 0/0
./usr/local/share/locale/en@boldquot/LC_MESSAGES 40755 0/0
./usr/local/share/locale/en@boldquot/LC_MESSAGES/gnupg2.mo 100644 0/0 164436 3986794669
./usr/local/share/locale/en@quot 40755 0/0
./usr/local/share/locale/en@quot/LC_MESSAGES 40755 0/0
./usr/local/share/locale/en@quot/LC_MESSAGES/gnupg2.mo 100644 0/0 162468 76508430
./usr/local/share/locale/eo 40755 0/0
./usr/local/share/locale/eo/LC_MESSAGES 40755 0/0
./usr/local/share/locale/eo/LC_MESSAGES/gnupg2.mo 100644 0/0 40415 2012034137
./usr/local/share/locale/es 40755 0/0
./usr/local/share/locale/es/LC_MESSAGES 40755 0/0
./usr/local/share/locale/es/LC_MESSAGES/gnupg2.mo 100644 0/0 110310 1703536523
./usr/local/share/locale/et 40755 0/0
./usr/local/share/locale/et/LC_MESSAGES 40755 0/0
./usr/local/share/locale/et/LC_MESSAGES/gnupg2.mo 100644 0/0 56160 805498476
./usr/local/share/locale/fi 40755 0/0
./usr/local/share/locale/fi/LC_MESSAGES 40755 0/0
./usr/local/share/locale/fi/LC_MESSAGES/gnupg2.mo 100644 0/0 59045 530803629
./usr/local/share/locale/fr 40755 0/0
./usr/local/share/locale/fr/LC_MESSAGES 40755 0/0
./usr/local/share/locale/fr/LC_MESSAGES/gnupg2.mo 100644 0/0 115097 2835689872
./usr/local/share/locale/gl 40755 0/0
./usr/local/share/locale/gl/LC_MESSAGES 40755 0/0
./usr/local/share/locale/gl/LC_MESSAGES/gnupg2.mo 100644 0/0 58534 1498920566
./usr/local/share/locale/hu 40755 0/0
./usr/local/share/locale/hu/LC_MESSAGES 40755 0/0
./usr/local/share/locale/hu/LC_MESSAGES/gnupg2.mo 100644 0/0 58450 3434879488
./usr/local/share/locale/id 40755 0/0
./usr/local/share/locale/id/LC_MESSAGES 40755 0/0
./usr/local/share/locale/id/LC_MESSAGES/gnupg2.mo 100644 0/0 56743 1290580746
./usr/local/share/locale/it 40755 0/0
./usr/local/share/locale/it/LC_MESSAGES 40755 0/0
./usr/local/share/locale/it/LC_MESSAGES/gnupg2.mo 100644 0/0 58517 1488504654
./usr/local/share/locale/ja 40755 0/0
./usr/local/share/locale/ja/LC_MESSAGES 40755 0/0
./usr/local/share/locale/ja/LC_MESSAGES/gnupg2.mo 100644 0/0 92738 1865503815
./usr/local/share/locale/nb 40755 0/0
./usr/local/share/locale/nb/LC_MESSAGES 40755 0/0
./usr/local/share/locale/nb/LC_MESSAGES/gnupg2.mo 100644 0/0 80749 4172275282
./usr/local/share/locale/pl 40755 0/0
./usr/local/share/locale/pl/LC_MESSAGES 40755 0/0
./usr/local/share/locale/pl/LC_MESSAGES/gnupg2.mo 100644 0/0 165287 263901650
./usr/local/share/locale/pt 40755 0/0
./usr/local/share/locale/pt/LC_MESSAGES 40755 0/0
./usr/local/share/locale/pt/LC_MESSAGES/gnupg2.mo 100644 0/0 50157 3752181728
./usr/local/share/locale/pt_BR 40755 0/0
./usr/local/share/locale/pt_BR/LC_MESSAGES 40755 0/0
./usr/local/share/locale/pt_BR/LC_MESSAGES/gnupg2.mo 100644 0/0 30238 1080526222
./usr/local/share/locale/ro 40755 0/0
./usr/local/share/locale/ro/LC_MESSAGES 40755 0/0
./usr/local/share/locale/ro/LC_MESSAGES/gnupg2.mo 100644 0/0 111396 2160951593
./usr/local/share/locale/ru 40755 0/0
./usr/local/share/locale/ru/LC_MESSAGES 40755 0/0
./usr/local/share/locale/ru/LC_MESSAGES/gnupg2.mo 100644 0/0 182274 1536064840
./usr/local/share/locale/sk 40755 0/0
./usr/local/share/locale/sk/LC_MESSAGES 40755 0/0
./usr/local/share/locale/sk/LC_MESSAGES/gnupg2.mo 100644 0/0 57746 1906839075
./usr/local/share/locale/sv 40755 0/0
./usr/local/share/locale/sv/LC_MESSAGES 40755 0/0
./usr/local/share/locale/sv/LC_MESSAGES/gnupg2.mo 100644 0/0 166103 455075591
./usr/local/share/locale/tr 40755 0/0
./usr/local/share/locale/tr/LC_MESSAGES 40755 0/0
./usr/local/share/locale/tr/LC_MESSAGES/gnupg2.mo 100644 0/0 160061 3014822710
./usr/local/share/locale/zh_CN 40755 0/0
./usr/local/share/locale/zh_CN/LC_MESSAGES 40755 0/0
./usr/local/share/locale/zh_CN/LC_MESSAGES/gnupg2.mo 100644 0/0 112677 2897200251
./usr/local/share/locale/zh_TW 40755 0/0
./usr/local/share/locale/zh_TW/LC_MESSAGES 40755 0/0
./usr/local/share/locale/zh_TW/LC_MESSAGES/gnupg2.mo 100644 0/0 160301 2530079912
./usr/local/share/man 40755 0/0
./usr/local/share/man/man1 40755 0/0
./usr/local/share/man/man1/gpg-agent.1 100644 0/0 19926 2413628779
./usr/local/share/man/man1/gpg-connect-agent.1 100644 0/0 8042 3767771906
./usr/local/share/man/man1/gpg-preset-passphrase.1 100644 0/0 2224 89741822
./usr/local/share/man/man1/gpg2.1 100644 0/0 97022 2847578424
./usr/local/share/man/man1/gpgconf.1 100644 0/0 18654 1225599386
./usr/local/share/man/man1/gpgparsemail.1 100644 0/0 340 3533564981
./usr/local/share/man/man1/gpgsm-gencert.sh.1 100644 0/0 635 2250454871
./usr/local/share/man/man1/gpgsm.1 100644 0/0 30483 2591902910
./usr/local/share/man/man1/gpgv2.1 100644 0/0 3406 2204158168
./usr/local/share/man/man1/scdaemon.1 100644 0/0 9103 149800686
./usr/local/share/man/man1/symcryptrun.1 100644 0/0 2886 517250939
./usr/local/share/man/man1/watchgnupg.1 100644 0/0 1249 1827069744
./usr/local/share/man/man8 40755 0/0
./usr/local/share/man/man8/addgnupghome.8 100644 0/0 780 1522274663
./usr/local/share/man/man8/applygnupgdefaults.8 100644 0/0 806 2406491713
Although not a member of the gnupg-devel team, I can explain this for you:
> /tmp/gpg-pIhMQu/S.gpg-agent
> This looks a bit weird though. Why in /tmp?
Sockets only work on a local filesystem and most locations are not guaranteed to be local. However, /tmp is most likely to be local.
> Why have the nonce appended to the path?
An instance of gpg-agent needs to run for each user needing it, since it securely stores your password. The nonce ensures that two users do not get the same path.
However, if the user's home directory is local, then the gpg-agent option "use-standard-socket" can be used. Since this is likely to be the case on a Mac and as gnupg v2.x no longer needs the environment variables set if the standard location is used, macgpg2 will no longer need to fiddle around with environment variables except in very specialised cases.
Post a Comment