1*4882a593Smuzhiyun.. _pgpguide: 2*4882a593Smuzhiyun 3*4882a593Smuzhiyun=========================== 4*4882a593SmuzhiyunKernel Maintainer PGP guide 5*4882a593Smuzhiyun=========================== 6*4882a593Smuzhiyun 7*4882a593Smuzhiyun:Author: Konstantin Ryabitsev <konstantin@linuxfoundation.org> 8*4882a593Smuzhiyun 9*4882a593SmuzhiyunThis document is aimed at Linux kernel developers, and especially at 10*4882a593Smuzhiyunsubsystem maintainers. It contains a subset of information discussed in 11*4882a593Smuzhiyunthe more general "`Protecting Code Integrity`_" guide published by the 12*4882a593SmuzhiyunLinux Foundation. Please read that document for more in-depth discussion 13*4882a593Smuzhiyunon some of the topics mentioned in this guide. 14*4882a593Smuzhiyun 15*4882a593Smuzhiyun.. _`Protecting Code Integrity`: https://github.com/lfit/itpol/blob/master/protecting-code-integrity.md 16*4882a593Smuzhiyun 17*4882a593SmuzhiyunThe role of PGP in Linux Kernel development 18*4882a593Smuzhiyun=========================================== 19*4882a593Smuzhiyun 20*4882a593SmuzhiyunPGP helps ensure the integrity of the code that is produced by the Linux 21*4882a593Smuzhiyunkernel development community and, to a lesser degree, establish trusted 22*4882a593Smuzhiyuncommunication channels between developers via PGP-signed email exchange. 23*4882a593Smuzhiyun 24*4882a593SmuzhiyunThe Linux kernel source code is available in two main formats: 25*4882a593Smuzhiyun 26*4882a593Smuzhiyun- Distributed source repositories (git) 27*4882a593Smuzhiyun- Periodic release snapshots (tarballs) 28*4882a593Smuzhiyun 29*4882a593SmuzhiyunBoth git repositories and tarballs carry PGP signatures of the kernel 30*4882a593Smuzhiyundevelopers who create official kernel releases. These signatures offer a 31*4882a593Smuzhiyuncryptographic guarantee that downloadable versions made available via 32*4882a593Smuzhiyunkernel.org or any other mirrors are identical to what these developers 33*4882a593Smuzhiyunhave on their workstations. To this end: 34*4882a593Smuzhiyun 35*4882a593Smuzhiyun- git repositories provide PGP signatures on all tags 36*4882a593Smuzhiyun- tarballs provide detached PGP signatures with all downloads 37*4882a593Smuzhiyun 38*4882a593Smuzhiyun.. _devs_not_infra: 39*4882a593Smuzhiyun 40*4882a593SmuzhiyunTrusting the developers, not infrastructure 41*4882a593Smuzhiyun------------------------------------------- 42*4882a593Smuzhiyun 43*4882a593SmuzhiyunEver since the 2011 compromise of core kernel.org systems, the main 44*4882a593Smuzhiyunoperating principle of the Kernel Archives project has been to assume 45*4882a593Smuzhiyunthat any part of the infrastructure can be compromised at any time. For 46*4882a593Smuzhiyunthis reason, the administrators have taken deliberate steps to emphasize 47*4882a593Smuzhiyunthat trust must always be placed with developers and never with the code 48*4882a593Smuzhiyunhosting infrastructure, regardless of how good the security practices 49*4882a593Smuzhiyunfor the latter may be. 50*4882a593Smuzhiyun 51*4882a593SmuzhiyunThe above guiding principle is the reason why this guide is needed. We 52*4882a593Smuzhiyunwant to make sure that by placing trust into developers we do not simply 53*4882a593Smuzhiyunshift the blame for potential future security incidents to someone else. 54*4882a593SmuzhiyunThe goal is to provide a set of guidelines developers can use to create 55*4882a593Smuzhiyuna secure working environment and safeguard the PGP keys used to 56*4882a593Smuzhiyunestablish the integrity of the Linux kernel itself. 57*4882a593Smuzhiyun 58*4882a593Smuzhiyun.. _pgp_tools: 59*4882a593Smuzhiyun 60*4882a593SmuzhiyunPGP tools 61*4882a593Smuzhiyun========= 62*4882a593Smuzhiyun 63*4882a593SmuzhiyunUse GnuPG v2 64*4882a593Smuzhiyun------------ 65*4882a593Smuzhiyun 66*4882a593SmuzhiyunYour distro should already have GnuPG installed by default, you just 67*4882a593Smuzhiyunneed to verify that you are using version 2.x and not the legacy 1.4 68*4882a593Smuzhiyunrelease -- many distributions still package both, with the default 69*4882a593Smuzhiyun``gpg`` command invoking GnuPG v.1. To check, run:: 70*4882a593Smuzhiyun 71*4882a593Smuzhiyun $ gpg --version | head -n1 72*4882a593Smuzhiyun 73*4882a593SmuzhiyunIf you see ``gpg (GnuPG) 1.4.x``, then you are using GnuPG v.1. Try the 74*4882a593Smuzhiyun``gpg2`` command (if you don't have it, you may need to install the 75*4882a593Smuzhiyungnupg2 package):: 76*4882a593Smuzhiyun 77*4882a593Smuzhiyun $ gpg2 --version | head -n1 78*4882a593Smuzhiyun 79*4882a593SmuzhiyunIf you see ``gpg (GnuPG) 2.x.x``, then you are good to go. This guide 80*4882a593Smuzhiyunwill assume you have the version 2.2 of GnuPG (or later). If you are 81*4882a593Smuzhiyunusing version 2.0 of GnuPG, then some of the commands in this guide will 82*4882a593Smuzhiyunnot work, and you should consider installing the latest 2.2 version of 83*4882a593SmuzhiyunGnuPG. Versions of gnupg-2.1.11 and later should be compatible for the 84*4882a593Smuzhiyunpurposes of this guide as well. 85*4882a593Smuzhiyun 86*4882a593SmuzhiyunIf you have both ``gpg`` and ``gpg2`` commands, you should make sure you 87*4882a593Smuzhiyunare always using GnuPG v2, not the legacy version. You can enforce this 88*4882a593Smuzhiyunby setting the appropriate alias:: 89*4882a593Smuzhiyun 90*4882a593Smuzhiyun $ alias gpg=gpg2 91*4882a593Smuzhiyun 92*4882a593SmuzhiyunYou can put that in your ``.bashrc`` to make sure it's always the case. 93*4882a593Smuzhiyun 94*4882a593SmuzhiyunConfigure gpg-agent options 95*4882a593Smuzhiyun~~~~~~~~~~~~~~~~~~~~~~~~~~~ 96*4882a593Smuzhiyun 97*4882a593SmuzhiyunThe GnuPG agent is a helper tool that will start automatically whenever 98*4882a593Smuzhiyunyou use the ``gpg`` command and run in the background with the purpose 99*4882a593Smuzhiyunof caching the private key passphrase. There are two options you should 100*4882a593Smuzhiyunknow in order to tweak when the passphrase should be expired from cache: 101*4882a593Smuzhiyun 102*4882a593Smuzhiyun- ``default-cache-ttl`` (seconds): If you use the same key again before 103*4882a593Smuzhiyun the time-to-live expires, the countdown will reset for another period. 104*4882a593Smuzhiyun The default is 600 (10 minutes). 105*4882a593Smuzhiyun- ``max-cache-ttl`` (seconds): Regardless of how recently you've used 106*4882a593Smuzhiyun the key since initial passphrase entry, if the maximum time-to-live 107*4882a593Smuzhiyun countdown expires, you'll have to enter the passphrase again. The 108*4882a593Smuzhiyun default is 30 minutes. 109*4882a593Smuzhiyun 110*4882a593SmuzhiyunIf you find either of these defaults too short (or too long), you can 111*4882a593Smuzhiyunedit your ``~/.gnupg/gpg-agent.conf`` file to set your own values:: 112*4882a593Smuzhiyun 113*4882a593Smuzhiyun # set to 30 minutes for regular ttl, and 2 hours for max ttl 114*4882a593Smuzhiyun default-cache-ttl 1800 115*4882a593Smuzhiyun max-cache-ttl 7200 116*4882a593Smuzhiyun 117*4882a593Smuzhiyun.. note:: 118*4882a593Smuzhiyun 119*4882a593Smuzhiyun It is no longer necessary to start gpg-agent manually at the 120*4882a593Smuzhiyun beginning of your shell session. You may want to check your rc files 121*4882a593Smuzhiyun to remove anything you had in place for older versions of GnuPG, as 122*4882a593Smuzhiyun it may not be doing the right thing any more. 123*4882a593Smuzhiyun 124*4882a593SmuzhiyunSet up a refresh cronjob 125*4882a593Smuzhiyun~~~~~~~~~~~~~~~~~~~~~~~~ 126*4882a593Smuzhiyun 127*4882a593SmuzhiyunYou will need to regularly refresh your keyring in order to get the 128*4882a593Smuzhiyunlatest changes on other people's public keys, which is best done with a 129*4882a593Smuzhiyundaily cronjob:: 130*4882a593Smuzhiyun 131*4882a593Smuzhiyun @daily /usr/bin/gpg2 --refresh >/dev/null 2>&1 132*4882a593Smuzhiyun 133*4882a593SmuzhiyunCheck the full path to your ``gpg`` or ``gpg2`` command and use the 134*4882a593Smuzhiyun``gpg2`` command if regular ``gpg`` for you is the legacy GnuPG v.1. 135*4882a593Smuzhiyun 136*4882a593Smuzhiyun.. _master_key: 137*4882a593Smuzhiyun 138*4882a593SmuzhiyunProtect your master PGP key 139*4882a593Smuzhiyun=========================== 140*4882a593Smuzhiyun 141*4882a593SmuzhiyunThis guide assumes that you already have a PGP key that you use for Linux 142*4882a593Smuzhiyunkernel development purposes. If you do not yet have one, please see the 143*4882a593Smuzhiyun"`Protecting Code Integrity`_" document mentioned earlier for guidance 144*4882a593Smuzhiyunon how to create a new one. 145*4882a593Smuzhiyun 146*4882a593SmuzhiyunYou should also make a new key if your current one is weaker than 2048 bits 147*4882a593Smuzhiyun(RSA). 148*4882a593Smuzhiyun 149*4882a593SmuzhiyunMaster key vs. Subkeys 150*4882a593Smuzhiyun---------------------- 151*4882a593Smuzhiyun 152*4882a593SmuzhiyunSubkeys are fully independent PGP keypairs that are tied to the "master" 153*4882a593Smuzhiyunkey using certifying key signatures (certificates). It is important to 154*4882a593Smuzhiyununderstand the following: 155*4882a593Smuzhiyun 156*4882a593Smuzhiyun1. There are no technical differences between the "master key" and "subkeys." 157*4882a593Smuzhiyun2. At creation time, we assign functional limitations to each key by 158*4882a593Smuzhiyun giving it specific capabilities. 159*4882a593Smuzhiyun3. A PGP key can have 4 capabilities: 160*4882a593Smuzhiyun 161*4882a593Smuzhiyun - **[S]** key can be used for signing 162*4882a593Smuzhiyun - **[E]** key can be used for encryption 163*4882a593Smuzhiyun - **[A]** key can be used for authentication 164*4882a593Smuzhiyun - **[C]** key can be used for certifying other keys 165*4882a593Smuzhiyun 166*4882a593Smuzhiyun4. A single key may have multiple capabilities. 167*4882a593Smuzhiyun5. A subkey is fully independent from the master key. A message 168*4882a593Smuzhiyun encrypted to a subkey cannot be decrypted with the master key. If you 169*4882a593Smuzhiyun lose your private subkey, it cannot be recreated from the master key 170*4882a593Smuzhiyun in any way. 171*4882a593Smuzhiyun 172*4882a593SmuzhiyunThe key carrying the **[C]** (certify) capability is considered the 173*4882a593Smuzhiyun"master" key because it is the only key that can be used to indicate 174*4882a593Smuzhiyunrelationship with other keys. Only the **[C]** key can be used to: 175*4882a593Smuzhiyun 176*4882a593Smuzhiyun- add or revoke other keys (subkeys) with S/E/A capabilities 177*4882a593Smuzhiyun- add, change or revoke identities (uids) associated with the key 178*4882a593Smuzhiyun- add or change the expiration date on itself or any subkey 179*4882a593Smuzhiyun- sign other people's keys for web of trust purposes 180*4882a593Smuzhiyun 181*4882a593SmuzhiyunBy default, GnuPG creates the following when generating new keys: 182*4882a593Smuzhiyun 183*4882a593Smuzhiyun- A master key carrying both Certify and Sign capabilities (**[SC]**) 184*4882a593Smuzhiyun- A separate subkey with the Encryption capability (**[E]**) 185*4882a593Smuzhiyun 186*4882a593SmuzhiyunIf you used the default parameters when generating your key, then that 187*4882a593Smuzhiyunis what you will have. You can verify by running ``gpg --list-secret-keys``, 188*4882a593Smuzhiyunfor example:: 189*4882a593Smuzhiyun 190*4882a593Smuzhiyun sec rsa2048 2018-01-23 [SC] [expires: 2020-01-23] 191*4882a593Smuzhiyun 000000000000000000000000AAAABBBBCCCCDDDD 192*4882a593Smuzhiyun uid [ultimate] Alice Dev <adev@kernel.org> 193*4882a593Smuzhiyun ssb rsa2048 2018-01-23 [E] [expires: 2020-01-23] 194*4882a593Smuzhiyun 195*4882a593SmuzhiyunAny key carrying the **[C]** capability is your master key, regardless 196*4882a593Smuzhiyunof any other capabilities it may have assigned to it. 197*4882a593Smuzhiyun 198*4882a593SmuzhiyunThe long line under the ``sec`` entry is your key fingerprint -- 199*4882a593Smuzhiyunwhenever you see ``[fpr]`` in the examples below, that 40-character 200*4882a593Smuzhiyunstring is what it refers to. 201*4882a593Smuzhiyun 202*4882a593SmuzhiyunEnsure your passphrase is strong 203*4882a593Smuzhiyun-------------------------------- 204*4882a593Smuzhiyun 205*4882a593SmuzhiyunGnuPG uses passphrases to encrypt your private keys before storing them on 206*4882a593Smuzhiyundisk. This way, even if your ``.gnupg`` directory is leaked or stolen in 207*4882a593Smuzhiyunits entirety, the attackers cannot use your private keys without first 208*4882a593Smuzhiyunobtaining the passphrase to decrypt them. 209*4882a593Smuzhiyun 210*4882a593SmuzhiyunIt is absolutely essential that your private keys are protected by a 211*4882a593Smuzhiyunstrong passphrase. To set it or change it, use:: 212*4882a593Smuzhiyun 213*4882a593Smuzhiyun $ gpg --change-passphrase [fpr] 214*4882a593Smuzhiyun 215*4882a593SmuzhiyunCreate a separate Signing subkey 216*4882a593Smuzhiyun-------------------------------- 217*4882a593Smuzhiyun 218*4882a593SmuzhiyunOur goal is to protect your master key by moving it to offline media, so 219*4882a593Smuzhiyunif you only have a combined **[SC]** key, then you should create a separate 220*4882a593Smuzhiyunsigning subkey:: 221*4882a593Smuzhiyun 222*4882a593Smuzhiyun $ gpg --quick-addkey [fpr] ed25519 sign 223*4882a593Smuzhiyun 224*4882a593SmuzhiyunRemember to tell the keyservers about this change, so others can pull down 225*4882a593Smuzhiyunyour new subkey:: 226*4882a593Smuzhiyun 227*4882a593Smuzhiyun $ gpg --send-key [fpr] 228*4882a593Smuzhiyun 229*4882a593Smuzhiyun.. note:: ECC support in GnuPG 230*4882a593Smuzhiyun 231*4882a593Smuzhiyun GnuPG 2.1 and later has full support for Elliptic Curve 232*4882a593Smuzhiyun Cryptography, with ability to combine ECC subkeys with traditional 233*4882a593Smuzhiyun RSA master keys. The main upside of ECC cryptography is that it is 234*4882a593Smuzhiyun much faster computationally and creates much smaller signatures when 235*4882a593Smuzhiyun compared byte for byte with 2048+ bit RSA keys. Unless you plan on 236*4882a593Smuzhiyun using a smartcard device that does not support ECC operations, we 237*4882a593Smuzhiyun recommend that you create an ECC signing subkey for your kernel 238*4882a593Smuzhiyun work. 239*4882a593Smuzhiyun 240*4882a593Smuzhiyun If for some reason you prefer to stay with RSA subkeys, just replace 241*4882a593Smuzhiyun "ed25519" with "rsa2048" in the above command. Additionally, if you 242*4882a593Smuzhiyun plan to use a hardware device that does not support ED25519 ECC 243*4882a593Smuzhiyun keys, like Nitrokey Pro or a Yubikey, then you should use 244*4882a593Smuzhiyun "nistp256" instead or "ed25519." 245*4882a593Smuzhiyun 246*4882a593Smuzhiyun 247*4882a593SmuzhiyunBack up your master key for disaster recovery 248*4882a593Smuzhiyun--------------------------------------------- 249*4882a593Smuzhiyun 250*4882a593SmuzhiyunThe more signatures you have on your PGP key from other developers, the 251*4882a593Smuzhiyunmore reasons you have to create a backup version that lives on something 252*4882a593Smuzhiyunother than digital media, for disaster recovery reasons. 253*4882a593Smuzhiyun 254*4882a593SmuzhiyunThe best way to create a printable hardcopy of your private key is by 255*4882a593Smuzhiyunusing the ``paperkey`` software written for this very purpose. See ``man 256*4882a593Smuzhiyunpaperkey`` for more details on the output format and its benefits over 257*4882a593Smuzhiyunother solutions. Paperkey should already be packaged for most 258*4882a593Smuzhiyundistributions. 259*4882a593Smuzhiyun 260*4882a593SmuzhiyunRun the following command to create a hardcopy backup of your private 261*4882a593Smuzhiyunkey:: 262*4882a593Smuzhiyun 263*4882a593Smuzhiyun $ gpg --export-secret-key [fpr] | paperkey -o /tmp/key-backup.txt 264*4882a593Smuzhiyun 265*4882a593SmuzhiyunPrint out that file (or pipe the output straight to lpr), then take a 266*4882a593Smuzhiyunpen and write your passphrase on the margin of the paper. **This is 267*4882a593Smuzhiyunstrongly recommended** because the key printout is still encrypted with 268*4882a593Smuzhiyunthat passphrase, and if you ever change it you will not remember what it 269*4882a593Smuzhiyunused to be when you had created the backup -- *guaranteed*. 270*4882a593Smuzhiyun 271*4882a593SmuzhiyunPut the resulting printout and the hand-written passphrase into an envelope 272*4882a593Smuzhiyunand store in a secure and well-protected place, preferably away from your 273*4882a593Smuzhiyunhome, such as your bank vault. 274*4882a593Smuzhiyun 275*4882a593Smuzhiyun.. note:: 276*4882a593Smuzhiyun 277*4882a593Smuzhiyun Your printer is probably no longer a simple dumb device connected to 278*4882a593Smuzhiyun your parallel port, but since the output is still encrypted with 279*4882a593Smuzhiyun your passphrase, printing out even to "cloud-integrated" modern 280*4882a593Smuzhiyun printers should remain a relatively safe operation. One option is to 281*4882a593Smuzhiyun change the passphrase on your master key immediately after you are 282*4882a593Smuzhiyun done with paperkey. 283*4882a593Smuzhiyun 284*4882a593SmuzhiyunBack up your whole GnuPG directory 285*4882a593Smuzhiyun---------------------------------- 286*4882a593Smuzhiyun 287*4882a593Smuzhiyun.. warning:: 288*4882a593Smuzhiyun 289*4882a593Smuzhiyun **!!!Do not skip this step!!!** 290*4882a593Smuzhiyun 291*4882a593SmuzhiyunIt is important to have a readily available backup of your PGP keys 292*4882a593Smuzhiyunshould you need to recover them. This is different from the 293*4882a593Smuzhiyundisaster-level preparedness we did with ``paperkey``. You will also rely 294*4882a593Smuzhiyunon these external copies whenever you need to use your Certify key -- 295*4882a593Smuzhiyunsuch as when making changes to your own key or signing other people's 296*4882a593Smuzhiyunkeys after conferences and summits. 297*4882a593Smuzhiyun 298*4882a593SmuzhiyunStart by getting a small USB "thumb" drive (preferably two!) that you 299*4882a593Smuzhiyunwill use for backup purposes. You will need to encrypt them using LUKS 300*4882a593Smuzhiyun-- refer to your distro's documentation on how to accomplish this. 301*4882a593Smuzhiyun 302*4882a593SmuzhiyunFor the encryption passphrase, you can use the same one as on your 303*4882a593Smuzhiyunmaster key. 304*4882a593Smuzhiyun 305*4882a593SmuzhiyunOnce the encryption process is over, re-insert the USB drive and make 306*4882a593Smuzhiyunsure it gets properly mounted. Copy your entire ``.gnupg`` directory 307*4882a593Smuzhiyunover to the encrypted storage:: 308*4882a593Smuzhiyun 309*4882a593Smuzhiyun $ cp -a ~/.gnupg /media/disk/foo/gnupg-backup 310*4882a593Smuzhiyun 311*4882a593SmuzhiyunYou should now test to make sure everything still works:: 312*4882a593Smuzhiyun 313*4882a593Smuzhiyun $ gpg --homedir=/media/disk/foo/gnupg-backup --list-key [fpr] 314*4882a593Smuzhiyun 315*4882a593SmuzhiyunIf you don't get any errors, then you should be good to go. Unmount the 316*4882a593SmuzhiyunUSB drive, distinctly label it so you don't blow it away next time you 317*4882a593Smuzhiyunneed to use a random USB drive, and put in a safe place -- but not too 318*4882a593Smuzhiyunfar away, because you'll need to use it every now and again for things 319*4882a593Smuzhiyunlike editing identities, adding or revoking subkeys, or signing other 320*4882a593Smuzhiyunpeople's keys. 321*4882a593Smuzhiyun 322*4882a593SmuzhiyunRemove the master key from your homedir 323*4882a593Smuzhiyun---------------------------------------- 324*4882a593Smuzhiyun 325*4882a593SmuzhiyunThe files in our home directory are not as well protected as we like to 326*4882a593Smuzhiyunthink. They can be leaked or stolen via many different means: 327*4882a593Smuzhiyun 328*4882a593Smuzhiyun- by accident when making quick homedir copies to set up a new workstation 329*4882a593Smuzhiyun- by systems administrator negligence or malice 330*4882a593Smuzhiyun- via poorly secured backups 331*4882a593Smuzhiyun- via malware in desktop apps (browsers, pdf viewers, etc) 332*4882a593Smuzhiyun- via coercion when crossing international borders 333*4882a593Smuzhiyun 334*4882a593SmuzhiyunProtecting your key with a good passphrase greatly helps reduce the risk 335*4882a593Smuzhiyunof any of the above, but passphrases can be discovered via keyloggers, 336*4882a593Smuzhiyunshoulder-surfing, or any number of other means. For this reason, the 337*4882a593Smuzhiyunrecommended setup is to remove your master key from your home directory 338*4882a593Smuzhiyunand store it on offline storage. 339*4882a593Smuzhiyun 340*4882a593Smuzhiyun.. warning:: 341*4882a593Smuzhiyun 342*4882a593Smuzhiyun Please see the previous section and make sure you have backed up 343*4882a593Smuzhiyun your GnuPG directory in its entirety. What we are about to do will 344*4882a593Smuzhiyun render your key useless if you do not have a usable backup! 345*4882a593Smuzhiyun 346*4882a593SmuzhiyunFirst, identify the keygrip of your master key:: 347*4882a593Smuzhiyun 348*4882a593Smuzhiyun $ gpg --with-keygrip --list-key [fpr] 349*4882a593Smuzhiyun 350*4882a593SmuzhiyunThe output will be something like this:: 351*4882a593Smuzhiyun 352*4882a593Smuzhiyun pub rsa2048 2018-01-24 [SC] [expires: 2020-01-24] 353*4882a593Smuzhiyun 000000000000000000000000AAAABBBBCCCCDDDD 354*4882a593Smuzhiyun Keygrip = 1111000000000000000000000000000000000000 355*4882a593Smuzhiyun uid [ultimate] Alice Dev <adev@kernel.org> 356*4882a593Smuzhiyun sub rsa2048 2018-01-24 [E] [expires: 2020-01-24] 357*4882a593Smuzhiyun Keygrip = 2222000000000000000000000000000000000000 358*4882a593Smuzhiyun sub ed25519 2018-01-24 [S] 359*4882a593Smuzhiyun Keygrip = 3333000000000000000000000000000000000000 360*4882a593Smuzhiyun 361*4882a593SmuzhiyunFind the keygrip entry that is beneath the ``pub`` line (right under the 362*4882a593Smuzhiyunmaster key fingerprint). This will correspond directly to a file in your 363*4882a593Smuzhiyun``~/.gnupg`` directory:: 364*4882a593Smuzhiyun 365*4882a593Smuzhiyun $ cd ~/.gnupg/private-keys-v1.d 366*4882a593Smuzhiyun $ ls 367*4882a593Smuzhiyun 1111000000000000000000000000000000000000.key 368*4882a593Smuzhiyun 2222000000000000000000000000000000000000.key 369*4882a593Smuzhiyun 3333000000000000000000000000000000000000.key 370*4882a593Smuzhiyun 371*4882a593SmuzhiyunAll you have to do is simply remove the .key file that corresponds to 372*4882a593Smuzhiyunthe master keygrip:: 373*4882a593Smuzhiyun 374*4882a593Smuzhiyun $ cd ~/.gnupg/private-keys-v1.d 375*4882a593Smuzhiyun $ rm 1111000000000000000000000000000000000000.key 376*4882a593Smuzhiyun 377*4882a593SmuzhiyunNow, if you issue the ``--list-secret-keys`` command, it will show that 378*4882a593Smuzhiyunthe master key is missing (the ``#`` indicates it is not available):: 379*4882a593Smuzhiyun 380*4882a593Smuzhiyun $ gpg --list-secret-keys 381*4882a593Smuzhiyun sec# rsa2048 2018-01-24 [SC] [expires: 2020-01-24] 382*4882a593Smuzhiyun 000000000000000000000000AAAABBBBCCCCDDDD 383*4882a593Smuzhiyun uid [ultimate] Alice Dev <adev@kernel.org> 384*4882a593Smuzhiyun ssb rsa2048 2018-01-24 [E] [expires: 2020-01-24] 385*4882a593Smuzhiyun ssb ed25519 2018-01-24 [S] 386*4882a593Smuzhiyun 387*4882a593SmuzhiyunYou should also remove any ``secring.gpg`` files in the ``~/.gnupg`` 388*4882a593Smuzhiyundirectory, which are left over from earlier versions of GnuPG. 389*4882a593Smuzhiyun 390*4882a593SmuzhiyunIf you don't have the "private-keys-v1.d" directory 391*4882a593Smuzhiyun~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 392*4882a593Smuzhiyun 393*4882a593SmuzhiyunIf you do not have a ``~/.gnupg/private-keys-v1.d`` directory, then your 394*4882a593Smuzhiyunsecret keys are still stored in the legacy ``secring.gpg`` file used by 395*4882a593SmuzhiyunGnuPG v1. Making any changes to your key, such as changing the 396*4882a593Smuzhiyunpassphrase or adding a subkey, should automatically convert the old 397*4882a593Smuzhiyun``secring.gpg`` format to use ``private-keys-v1.d`` instead. 398*4882a593Smuzhiyun 399*4882a593SmuzhiyunOnce you get that done, make sure to delete the obsolete ``secring.gpg`` 400*4882a593Smuzhiyunfile, which still contains your private keys. 401*4882a593Smuzhiyun 402*4882a593Smuzhiyun.. _smartcards: 403*4882a593Smuzhiyun 404*4882a593SmuzhiyunMove the subkeys to a dedicated crypto device 405*4882a593Smuzhiyun============================================= 406*4882a593Smuzhiyun 407*4882a593SmuzhiyunEven though the master key is now safe from being leaked or stolen, the 408*4882a593Smuzhiyunsubkeys are still in your home directory. Anyone who manages to get 409*4882a593Smuzhiyuntheir hands on those will be able to decrypt your communication or fake 410*4882a593Smuzhiyunyour signatures (if they know the passphrase). Furthermore, each time a 411*4882a593SmuzhiyunGnuPG operation is performed, the keys are loaded into system memory and 412*4882a593Smuzhiyuncan be stolen from there by sufficiently advanced malware (think 413*4882a593SmuzhiyunMeltdown and Spectre). 414*4882a593Smuzhiyun 415*4882a593SmuzhiyunThe best way to completely protect your keys is to move them to a 416*4882a593Smuzhiyunspecialized hardware device that is capable of smartcard operations. 417*4882a593Smuzhiyun 418*4882a593SmuzhiyunThe benefits of smartcards 419*4882a593Smuzhiyun-------------------------- 420*4882a593Smuzhiyun 421*4882a593SmuzhiyunA smartcard contains a cryptographic chip that is capable of storing 422*4882a593Smuzhiyunprivate keys and performing crypto operations directly on the card 423*4882a593Smuzhiyunitself. Because the key contents never leave the smartcard, the 424*4882a593Smuzhiyunoperating system of the computer into which you plug in the hardware 425*4882a593Smuzhiyundevice is not able to retrieve the private keys themselves. This is very 426*4882a593Smuzhiyundifferent from the encrypted USB storage device we used earlier for 427*4882a593Smuzhiyunbackup purposes -- while that USB device is plugged in and mounted, the 428*4882a593Smuzhiyunoperating system is able to access the private key contents. 429*4882a593Smuzhiyun 430*4882a593SmuzhiyunUsing external encrypted USB media is not a substitute to having a 431*4882a593Smuzhiyunsmartcard-capable device. 432*4882a593Smuzhiyun 433*4882a593SmuzhiyunAvailable smartcard devices 434*4882a593Smuzhiyun--------------------------- 435*4882a593Smuzhiyun 436*4882a593SmuzhiyunUnless all your laptops and workstations have smartcard readers, the 437*4882a593Smuzhiyuneasiest is to get a specialized USB device that implements smartcard 438*4882a593Smuzhiyunfunctionality. There are several options available: 439*4882a593Smuzhiyun 440*4882a593Smuzhiyun- `Nitrokey Start`_: Open hardware and Free Software, based on FSI 441*4882a593Smuzhiyun Japan's `Gnuk`_. One of the few available commercial devices that 442*4882a593Smuzhiyun support ED25519 ECC keys, but offer fewest security features (such as 443*4882a593Smuzhiyun resistance to tampering or some side-channel attacks). 444*4882a593Smuzhiyun- `Nitrokey Pro 2`_: Similar to the Nitrokey Start, but more 445*4882a593Smuzhiyun tamper-resistant and offers more security features. Pro 2 supports ECC 446*4882a593Smuzhiyun cryptography (NISTP). 447*4882a593Smuzhiyun- `Yubikey 5`_: proprietary hardware and software, but cheaper than 448*4882a593Smuzhiyun Nitrokey Pro and comes available in the USB-C form that is more useful 449*4882a593Smuzhiyun with newer laptops. Offers additional security features such as FIDO 450*4882a593Smuzhiyun U2F, among others, and now finally supports ECC keys (NISTP). 451*4882a593Smuzhiyun 452*4882a593Smuzhiyun`LWN has a good review`_ of some of the above models, as well as several 453*4882a593Smuzhiyunothers. Your choice will depend on cost, shipping availability in your 454*4882a593Smuzhiyungeographical region, and open/proprietary hardware considerations. 455*4882a593Smuzhiyun 456*4882a593Smuzhiyun.. note:: 457*4882a593Smuzhiyun 458*4882a593Smuzhiyun If you are listed in MAINTAINERS or have an account at kernel.org, 459*4882a593Smuzhiyun you `qualify for a free Nitrokey Start`_ courtesy of The Linux 460*4882a593Smuzhiyun Foundation. 461*4882a593Smuzhiyun 462*4882a593Smuzhiyun.. _`Nitrokey Start`: https://shop.nitrokey.com/shop/product/nitrokey-start-6 463*4882a593Smuzhiyun.. _`Nitrokey Pro 2`: https://shop.nitrokey.com/shop/product/nitrokey-pro-2-3 464*4882a593Smuzhiyun.. _`Yubikey 5`: https://www.yubico.com/products/yubikey-5-overview/ 465*4882a593Smuzhiyun.. _Gnuk: https://www.fsij.org/doc-gnuk/ 466*4882a593Smuzhiyun.. _`LWN has a good review`: https://lwn.net/Articles/736231/ 467*4882a593Smuzhiyun.. _`qualify for a free Nitrokey Start`: https://www.kernel.org/nitrokey-digital-tokens-for-kernel-developers.html 468*4882a593Smuzhiyun 469*4882a593SmuzhiyunConfigure your smartcard device 470*4882a593Smuzhiyun------------------------------- 471*4882a593Smuzhiyun 472*4882a593SmuzhiyunYour smartcard device should Just Work (TM) the moment you plug it into 473*4882a593Smuzhiyunany modern Linux workstation. You can verify it by running:: 474*4882a593Smuzhiyun 475*4882a593Smuzhiyun $ gpg --card-status 476*4882a593Smuzhiyun 477*4882a593SmuzhiyunIf you see full smartcard details, then you are good to go. 478*4882a593SmuzhiyunUnfortunately, troubleshooting all possible reasons why things may not 479*4882a593Smuzhiyunbe working for you is way beyond the scope of this guide. If you are 480*4882a593Smuzhiyunhaving trouble getting the card to work with GnuPG, please seek help via 481*4882a593Smuzhiyunusual support channels. 482*4882a593Smuzhiyun 483*4882a593SmuzhiyunTo configure your smartcard, you will need to use the GnuPG menu system, as 484*4882a593Smuzhiyunthere are no convenient command-line switches:: 485*4882a593Smuzhiyun 486*4882a593Smuzhiyun $ gpg --card-edit 487*4882a593Smuzhiyun [...omitted...] 488*4882a593Smuzhiyun gpg/card> admin 489*4882a593Smuzhiyun Admin commands are allowed 490*4882a593Smuzhiyun gpg/card> passwd 491*4882a593Smuzhiyun 492*4882a593SmuzhiyunYou should set the user PIN (1), Admin PIN (3), and the Reset Code (4). 493*4882a593SmuzhiyunPlease make sure to record and store these in a safe place -- especially 494*4882a593Smuzhiyunthe Admin PIN and the Reset Code (which allows you to completely wipe 495*4882a593Smuzhiyunthe smartcard). You so rarely need to use the Admin PIN, that you will 496*4882a593Smuzhiyuninevitably forget what it is if you do not record it. 497*4882a593Smuzhiyun 498*4882a593SmuzhiyunGetting back to the main card menu, you can also set other values (such 499*4882a593Smuzhiyunas name, sex, login data, etc), but it's not necessary and will 500*4882a593Smuzhiyunadditionally leak information about your smartcard should you lose it. 501*4882a593Smuzhiyun 502*4882a593Smuzhiyun.. note:: 503*4882a593Smuzhiyun 504*4882a593Smuzhiyun Despite having the name "PIN", neither the user PIN nor the admin 505*4882a593Smuzhiyun PIN on the card need to be numbers. 506*4882a593Smuzhiyun 507*4882a593Smuzhiyun.. warning:: 508*4882a593Smuzhiyun 509*4882a593Smuzhiyun Some devices may require that you move the subkeys onto the device 510*4882a593Smuzhiyun before you can change the passphrase. Please check the documentation 511*4882a593Smuzhiyun provided by the device manufacturer. 512*4882a593Smuzhiyun 513*4882a593SmuzhiyunMove the subkeys to your smartcard 514*4882a593Smuzhiyun---------------------------------- 515*4882a593Smuzhiyun 516*4882a593SmuzhiyunExit the card menu (using "q") and save all changes. Next, let's move 517*4882a593Smuzhiyunyour subkeys onto the smartcard. You will need both your PGP key 518*4882a593Smuzhiyunpassphrase and the admin PIN of the card for most operations:: 519*4882a593Smuzhiyun 520*4882a593Smuzhiyun $ gpg --edit-key [fpr] 521*4882a593Smuzhiyun 522*4882a593Smuzhiyun Secret subkeys are available. 523*4882a593Smuzhiyun 524*4882a593Smuzhiyun pub rsa2048/AAAABBBBCCCCDDDD 525*4882a593Smuzhiyun created: 2018-01-23 expires: 2020-01-23 usage: SC 526*4882a593Smuzhiyun trust: ultimate validity: ultimate 527*4882a593Smuzhiyun ssb rsa2048/1111222233334444 528*4882a593Smuzhiyun created: 2018-01-23 expires: never usage: E 529*4882a593Smuzhiyun ssb ed25519/5555666677778888 530*4882a593Smuzhiyun created: 2017-12-07 expires: never usage: S 531*4882a593Smuzhiyun [ultimate] (1). Alice Dev <adev@kernel.org> 532*4882a593Smuzhiyun 533*4882a593Smuzhiyun gpg> 534*4882a593Smuzhiyun 535*4882a593SmuzhiyunUsing ``--edit-key`` puts us into the menu mode again, and you will 536*4882a593Smuzhiyunnotice that the key listing is a little different. From here on, all 537*4882a593Smuzhiyuncommands are done from inside this menu mode, as indicated by ``gpg>``. 538*4882a593Smuzhiyun 539*4882a593SmuzhiyunFirst, let's select the key we'll be putting onto the card -- you do 540*4882a593Smuzhiyunthis by typing ``key 1`` (it's the first one in the listing, the **[E]** 541*4882a593Smuzhiyunsubkey):: 542*4882a593Smuzhiyun 543*4882a593Smuzhiyun gpg> key 1 544*4882a593Smuzhiyun 545*4882a593SmuzhiyunIn the output, you should now see ``ssb*`` on the **[E]** key. The ``*`` 546*4882a593Smuzhiyunindicates which key is currently "selected." It works as a *toggle*, 547*4882a593Smuzhiyunmeaning that if you type ``key 1`` again, the ``*`` will disappear and 548*4882a593Smuzhiyunthe key will not be selected any more. 549*4882a593Smuzhiyun 550*4882a593SmuzhiyunNow, let's move that key onto the smartcard:: 551*4882a593Smuzhiyun 552*4882a593Smuzhiyun gpg> keytocard 553*4882a593Smuzhiyun Please select where to store the key: 554*4882a593Smuzhiyun (2) Encryption key 555*4882a593Smuzhiyun Your selection? 2 556*4882a593Smuzhiyun 557*4882a593SmuzhiyunSince it's our **[E]** key, it makes sense to put it into the Encryption 558*4882a593Smuzhiyunslot. When you submit your selection, you will be prompted first for 559*4882a593Smuzhiyunyour PGP key passphrase, and then for the admin PIN. If the command 560*4882a593Smuzhiyunreturns without an error, your key has been moved. 561*4882a593Smuzhiyun 562*4882a593Smuzhiyun**Important**: Now type ``key 1`` again to unselect the first key, and 563*4882a593Smuzhiyun``key 2`` to select the **[S]** key:: 564*4882a593Smuzhiyun 565*4882a593Smuzhiyun gpg> key 1 566*4882a593Smuzhiyun gpg> key 2 567*4882a593Smuzhiyun gpg> keytocard 568*4882a593Smuzhiyun Please select where to store the key: 569*4882a593Smuzhiyun (1) Signature key 570*4882a593Smuzhiyun (3) Authentication key 571*4882a593Smuzhiyun Your selection? 1 572*4882a593Smuzhiyun 573*4882a593SmuzhiyunYou can use the **[S]** key both for Signature and Authentication, but 574*4882a593Smuzhiyunwe want to make sure it's in the Signature slot, so choose (1). Once 575*4882a593Smuzhiyunagain, if your command returns without an error, then the operation was 576*4882a593Smuzhiyunsuccessful:: 577*4882a593Smuzhiyun 578*4882a593Smuzhiyun gpg> q 579*4882a593Smuzhiyun Save changes? (y/N) y 580*4882a593Smuzhiyun 581*4882a593SmuzhiyunSaving the changes will delete the keys you moved to the card from your 582*4882a593Smuzhiyunhome directory (but it's okay, because we have them in our backups 583*4882a593Smuzhiyunshould we need to do this again for a replacement smartcard). 584*4882a593Smuzhiyun 585*4882a593SmuzhiyunVerifying that the keys were moved 586*4882a593Smuzhiyun~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 587*4882a593Smuzhiyun 588*4882a593SmuzhiyunIf you perform ``--list-secret-keys`` now, you will see a subtle 589*4882a593Smuzhiyundifference in the output:: 590*4882a593Smuzhiyun 591*4882a593Smuzhiyun $ gpg --list-secret-keys 592*4882a593Smuzhiyun sec# rsa2048 2018-01-24 [SC] [expires: 2020-01-24] 593*4882a593Smuzhiyun 000000000000000000000000AAAABBBBCCCCDDDD 594*4882a593Smuzhiyun uid [ultimate] Alice Dev <adev@kernel.org> 595*4882a593Smuzhiyun ssb> rsa2048 2018-01-24 [E] [expires: 2020-01-24] 596*4882a593Smuzhiyun ssb> ed25519 2018-01-24 [S] 597*4882a593Smuzhiyun 598*4882a593SmuzhiyunThe ``>`` in the ``ssb>`` output indicates that the subkey is only 599*4882a593Smuzhiyunavailable on the smartcard. If you go back into your secret keys 600*4882a593Smuzhiyundirectory and look at the contents there, you will notice that the 601*4882a593Smuzhiyun``.key`` files there have been replaced with stubs:: 602*4882a593Smuzhiyun 603*4882a593Smuzhiyun $ cd ~/.gnupg/private-keys-v1.d 604*4882a593Smuzhiyun $ strings *.key | grep 'private-key' 605*4882a593Smuzhiyun 606*4882a593SmuzhiyunThe output should contain ``shadowed-private-key`` to indicate that 607*4882a593Smuzhiyunthese files are only stubs and the actual content is on the smartcard. 608*4882a593Smuzhiyun 609*4882a593SmuzhiyunVerifying that the smartcard is functioning 610*4882a593Smuzhiyun~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 611*4882a593Smuzhiyun 612*4882a593SmuzhiyunTo verify that the smartcard is working as intended, you can create a 613*4882a593Smuzhiyunsignature:: 614*4882a593Smuzhiyun 615*4882a593Smuzhiyun $ echo "Hello world" | gpg --clearsign > /tmp/test.asc 616*4882a593Smuzhiyun $ gpg --verify /tmp/test.asc 617*4882a593Smuzhiyun 618*4882a593SmuzhiyunThis should ask for your smartcard PIN on your first command, and then 619*4882a593Smuzhiyunshow "Good signature" after you run ``gpg --verify``. 620*4882a593Smuzhiyun 621*4882a593SmuzhiyunCongratulations, you have successfully made it extremely difficult to 622*4882a593Smuzhiyunsteal your digital developer identity! 623*4882a593Smuzhiyun 624*4882a593SmuzhiyunOther common GnuPG operations 625*4882a593Smuzhiyun----------------------------- 626*4882a593Smuzhiyun 627*4882a593SmuzhiyunHere is a quick reference for some common operations you'll need to do 628*4882a593Smuzhiyunwith your PGP key. 629*4882a593Smuzhiyun 630*4882a593SmuzhiyunMounting your master key offline storage 631*4882a593Smuzhiyun~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 632*4882a593Smuzhiyun 633*4882a593SmuzhiyunYou will need your master key for any of the operations below, so you 634*4882a593Smuzhiyunwill first need to mount your backup offline storage and tell GnuPG to 635*4882a593Smuzhiyunuse it:: 636*4882a593Smuzhiyun 637*4882a593Smuzhiyun $ export GNUPGHOME=/media/disk/foo/gnupg-backup 638*4882a593Smuzhiyun $ gpg --list-secret-keys 639*4882a593Smuzhiyun 640*4882a593SmuzhiyunYou want to make sure that you see ``sec`` and not ``sec#`` in the 641*4882a593Smuzhiyunoutput (the ``#`` means the key is not available and you're still using 642*4882a593Smuzhiyunyour regular home directory location). 643*4882a593Smuzhiyun 644*4882a593SmuzhiyunExtending key expiration date 645*4882a593Smuzhiyun~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 646*4882a593Smuzhiyun 647*4882a593SmuzhiyunThe master key has the default expiration date of 2 years from the date 648*4882a593Smuzhiyunof creation. This is done both for security reasons and to make obsolete 649*4882a593Smuzhiyunkeys eventually disappear from keyservers. 650*4882a593Smuzhiyun 651*4882a593SmuzhiyunTo extend the expiration on your key by a year from current date, just 652*4882a593Smuzhiyunrun:: 653*4882a593Smuzhiyun 654*4882a593Smuzhiyun $ gpg --quick-set-expire [fpr] 1y 655*4882a593Smuzhiyun 656*4882a593SmuzhiyunYou can also use a specific date if that is easier to remember (e.g. 657*4882a593Smuzhiyunyour birthday, January 1st, or Canada Day):: 658*4882a593Smuzhiyun 659*4882a593Smuzhiyun $ gpg --quick-set-expire [fpr] 2020-07-01 660*4882a593Smuzhiyun 661*4882a593SmuzhiyunRemember to send the updated key back to keyservers:: 662*4882a593Smuzhiyun 663*4882a593Smuzhiyun $ gpg --send-key [fpr] 664*4882a593Smuzhiyun 665*4882a593SmuzhiyunUpdating your work directory after any changes 666*4882a593Smuzhiyun~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 667*4882a593Smuzhiyun 668*4882a593SmuzhiyunAfter you make any changes to your key using the offline storage, you will 669*4882a593Smuzhiyunwant to import these changes back into your regular working directory:: 670*4882a593Smuzhiyun 671*4882a593Smuzhiyun $ gpg --export | gpg --homedir ~/.gnupg --import 672*4882a593Smuzhiyun $ unset GNUPGHOME 673*4882a593Smuzhiyun 674*4882a593SmuzhiyunUsing gpg-agent over ssh 675*4882a593Smuzhiyun~~~~~~~~~~~~~~~~~~~~~~~~ 676*4882a593Smuzhiyun 677*4882a593SmuzhiyunYou can forward your gpg-agent over ssh if you need to sign tags or 678*4882a593Smuzhiyuncommits on a remote system. Please refer to the instructions provided 679*4882a593Smuzhiyunon the GnuPG wiki: 680*4882a593Smuzhiyun 681*4882a593Smuzhiyun- `Agent Forwarding over SSH`_ 682*4882a593Smuzhiyun 683*4882a593SmuzhiyunIt works more smoothly if you can modify the sshd server settings on the 684*4882a593Smuzhiyunremote end. 685*4882a593Smuzhiyun 686*4882a593Smuzhiyun.. _`Agent Forwarding over SSH`: https://wiki.gnupg.org/AgentForwarding 687*4882a593Smuzhiyun 688*4882a593Smuzhiyun 689*4882a593SmuzhiyunUsing PGP with Git 690*4882a593Smuzhiyun================== 691*4882a593Smuzhiyun 692*4882a593SmuzhiyunOne of the core features of Git is its decentralized nature -- once a 693*4882a593Smuzhiyunrepository is cloned to your system, you have full history of the 694*4882a593Smuzhiyunproject, including all of its tags, commits and branches. However, with 695*4882a593Smuzhiyunhundreds of cloned repositories floating around, how does anyone verify 696*4882a593Smuzhiyunthat their copy of linux.git has not been tampered with by a malicious 697*4882a593Smuzhiyunthird party? 698*4882a593Smuzhiyun 699*4882a593SmuzhiyunOr what happens if a backdoor is discovered in the code and the "Author" 700*4882a593Smuzhiyunline in the commit says it was done by you, while you're pretty sure you 701*4882a593Smuzhiyunhad `nothing to do with it`_? 702*4882a593Smuzhiyun 703*4882a593SmuzhiyunTo address both of these issues, Git introduced PGP integration. Signed 704*4882a593Smuzhiyuntags prove the repository integrity by assuring that its contents are 705*4882a593Smuzhiyunexactly the same as on the workstation of the developer who created the 706*4882a593Smuzhiyuntag, while signed commits make it nearly impossible for someone to 707*4882a593Smuzhiyunimpersonate you without having access to your PGP keys. 708*4882a593Smuzhiyun 709*4882a593Smuzhiyun.. _`nothing to do with it`: https://github.com/jayphelps/git-blame-someone-else 710*4882a593Smuzhiyun 711*4882a593SmuzhiyunConfigure git to use your PGP key 712*4882a593Smuzhiyun--------------------------------- 713*4882a593Smuzhiyun 714*4882a593SmuzhiyunIf you only have one secret key in your keyring, then you don't really 715*4882a593Smuzhiyunneed to do anything extra, as it becomes your default key. However, if 716*4882a593Smuzhiyunyou happen to have multiple secret keys, you can tell git which key 717*4882a593Smuzhiyunshould be used (``[fpr]`` is the fingerprint of your key):: 718*4882a593Smuzhiyun 719*4882a593Smuzhiyun $ git config --global user.signingKey [fpr] 720*4882a593Smuzhiyun 721*4882a593Smuzhiyun**IMPORTANT**: If you have a distinct ``gpg2`` command, then you should 722*4882a593Smuzhiyuntell git to always use it instead of the legacy ``gpg`` from version 1:: 723*4882a593Smuzhiyun 724*4882a593Smuzhiyun $ git config --global gpg.program gpg2 725*4882a593Smuzhiyun $ git config --global gpgv.program gpgv2 726*4882a593Smuzhiyun 727*4882a593SmuzhiyunHow to work with signed tags 728*4882a593Smuzhiyun---------------------------- 729*4882a593Smuzhiyun 730*4882a593SmuzhiyunTo create a signed tag, simply pass the ``-s`` switch to the tag 731*4882a593Smuzhiyuncommand:: 732*4882a593Smuzhiyun 733*4882a593Smuzhiyun $ git tag -s [tagname] 734*4882a593Smuzhiyun 735*4882a593SmuzhiyunOur recommendation is to always sign git tags, as this allows other 736*4882a593Smuzhiyundevelopers to ensure that the git repository they are pulling from has 737*4882a593Smuzhiyunnot been maliciously altered. 738*4882a593Smuzhiyun 739*4882a593SmuzhiyunHow to verify signed tags 740*4882a593Smuzhiyun~~~~~~~~~~~~~~~~~~~~~~~~~ 741*4882a593Smuzhiyun 742*4882a593SmuzhiyunTo verify a signed tag, simply use the ``verify-tag`` command:: 743*4882a593Smuzhiyun 744*4882a593Smuzhiyun $ git verify-tag [tagname] 745*4882a593Smuzhiyun 746*4882a593SmuzhiyunIf you are pulling a tag from another fork of the project repository, 747*4882a593Smuzhiyungit should automatically verify the signature at the tip you're pulling 748*4882a593Smuzhiyunand show you the results during the merge operation:: 749*4882a593Smuzhiyun 750*4882a593Smuzhiyun $ git pull [url] tags/sometag 751*4882a593Smuzhiyun 752*4882a593SmuzhiyunThe merge message will contain something like this:: 753*4882a593Smuzhiyun 754*4882a593Smuzhiyun Merge tag 'sometag' of [url] 755*4882a593Smuzhiyun 756*4882a593Smuzhiyun [Tag message] 757*4882a593Smuzhiyun 758*4882a593Smuzhiyun # gpg: Signature made [...] 759*4882a593Smuzhiyun # gpg: Good signature from [...] 760*4882a593Smuzhiyun 761*4882a593SmuzhiyunIf you are verifying someone else's git tag, then you will need to 762*4882a593Smuzhiyunimport their PGP key. Please refer to the 763*4882a593Smuzhiyun":ref:`verify_identities`" section below. 764*4882a593Smuzhiyun 765*4882a593Smuzhiyun.. note:: 766*4882a593Smuzhiyun 767*4882a593Smuzhiyun If you get "``gpg: Can't check signature: unknown pubkey 768*4882a593Smuzhiyun algorithm``" error, you need to tell git to use gpgv2 for 769*4882a593Smuzhiyun verification, so it properly processes signatures made by ECC keys. 770*4882a593Smuzhiyun See instructions at the start of this section. 771*4882a593Smuzhiyun 772*4882a593SmuzhiyunConfigure git to always sign annotated tags 773*4882a593Smuzhiyun~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 774*4882a593Smuzhiyun 775*4882a593SmuzhiyunChances are, if you're creating an annotated tag, you'll want to sign 776*4882a593Smuzhiyunit. To force git to always sign annotated tags, you can set a global 777*4882a593Smuzhiyunconfiguration option:: 778*4882a593Smuzhiyun 779*4882a593Smuzhiyun $ git config --global tag.forceSignAnnotated true 780*4882a593Smuzhiyun 781*4882a593SmuzhiyunHow to work with signed commits 782*4882a593Smuzhiyun------------------------------- 783*4882a593Smuzhiyun 784*4882a593SmuzhiyunIt is easy to create signed commits, but it is much more difficult to 785*4882a593Smuzhiyunuse them in Linux kernel development, since it relies on patches sent to 786*4882a593Smuzhiyunthe mailing list, and this workflow does not preserve PGP commit 787*4882a593Smuzhiyunsignatures. Furthermore, when rebasing your repository to match 788*4882a593Smuzhiyunupstream, even your own PGP commit signatures will end up discarded. For 789*4882a593Smuzhiyunthis reason, most kernel developers don't bother signing their commits 790*4882a593Smuzhiyunand will ignore signed commits in any external repositories that they 791*4882a593Smuzhiyunrely upon in their work. 792*4882a593Smuzhiyun 793*4882a593SmuzhiyunHowever, if you have your working git tree publicly available at some 794*4882a593Smuzhiyungit hosting service (kernel.org, infradead.org, ozlabs.org, or others), 795*4882a593Smuzhiyunthen the recommendation is that you sign all your git commits even if 796*4882a593Smuzhiyunupstream developers do not directly benefit from this practice. 797*4882a593Smuzhiyun 798*4882a593SmuzhiyunWe recommend this for the following reasons: 799*4882a593Smuzhiyun 800*4882a593Smuzhiyun1. Should there ever be a need to perform code forensics or track code 801*4882a593Smuzhiyun provenance, even externally maintained trees carrying PGP commit 802*4882a593Smuzhiyun signatures will be valuable for such purposes. 803*4882a593Smuzhiyun2. If you ever need to re-clone your local repository (for example, 804*4882a593Smuzhiyun after a disk failure), this lets you easily verify the repository 805*4882a593Smuzhiyun integrity before resuming your work. 806*4882a593Smuzhiyun3. If someone needs to cherry-pick your commits, this allows them to 807*4882a593Smuzhiyun quickly verify their integrity before applying them. 808*4882a593Smuzhiyun 809*4882a593SmuzhiyunCreating signed commits 810*4882a593Smuzhiyun~~~~~~~~~~~~~~~~~~~~~~~ 811*4882a593Smuzhiyun 812*4882a593SmuzhiyunTo create a signed commit, you just need to pass the ``-S`` flag to the 813*4882a593Smuzhiyun``git commit`` command (it's capital ``-S`` due to collision with 814*4882a593Smuzhiyunanother flag):: 815*4882a593Smuzhiyun 816*4882a593Smuzhiyun $ git commit -S 817*4882a593Smuzhiyun 818*4882a593SmuzhiyunConfigure git to always sign commits 819*4882a593Smuzhiyun~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 820*4882a593Smuzhiyun 821*4882a593SmuzhiyunYou can tell git to always sign commits:: 822*4882a593Smuzhiyun 823*4882a593Smuzhiyun git config --global commit.gpgSign true 824*4882a593Smuzhiyun 825*4882a593Smuzhiyun.. note:: 826*4882a593Smuzhiyun 827*4882a593Smuzhiyun Make sure you configure ``gpg-agent`` before you turn this on. 828*4882a593Smuzhiyun 829*4882a593Smuzhiyun.. _verify_identities: 830*4882a593Smuzhiyun 831*4882a593SmuzhiyunHow to verify kernel developer identities 832*4882a593Smuzhiyun========================================= 833*4882a593Smuzhiyun 834*4882a593SmuzhiyunSigning tags and commits is easy, but how does one go about verifying 835*4882a593Smuzhiyunthat the key used to sign something belongs to the actual kernel 836*4882a593Smuzhiyundeveloper and not to a malicious imposter? 837*4882a593Smuzhiyun 838*4882a593SmuzhiyunConfigure auto-key-retrieval using WKD and DANE 839*4882a593Smuzhiyun----------------------------------------------- 840*4882a593Smuzhiyun 841*4882a593SmuzhiyunIf you are not already someone with an extensive collection of other 842*4882a593Smuzhiyundevelopers' public keys, then you can jumpstart your keyring by relying 843*4882a593Smuzhiyunon key auto-discovery and auto-retrieval. GnuPG can piggyback on other 844*4882a593Smuzhiyundelegated trust technologies, namely DNSSEC and TLS, to get you going if 845*4882a593Smuzhiyunthe prospect of starting your own Web of Trust from scratch is too 846*4882a593Smuzhiyundaunting. 847*4882a593Smuzhiyun 848*4882a593SmuzhiyunAdd the following to your ``~/.gnupg/gpg.conf``:: 849*4882a593Smuzhiyun 850*4882a593Smuzhiyun auto-key-locate wkd,dane,local 851*4882a593Smuzhiyun auto-key-retrieve 852*4882a593Smuzhiyun 853*4882a593SmuzhiyunDNS-Based Authentication of Named Entities ("DANE") is a method for 854*4882a593Smuzhiyunpublishing public keys in DNS and securing them using DNSSEC signed 855*4882a593Smuzhiyunzones. Web Key Directory ("WKD") is the alternative method that uses 856*4882a593Smuzhiyunhttps lookups for the same purpose. When using either DANE or WKD for 857*4882a593Smuzhiyunlooking up public keys, GnuPG will validate DNSSEC or TLS certificates, 858*4882a593Smuzhiyunrespectively, before adding auto-retrieved public keys to your local 859*4882a593Smuzhiyunkeyring. 860*4882a593Smuzhiyun 861*4882a593SmuzhiyunKernel.org publishes the WKD for all developers who have kernel.org 862*4882a593Smuzhiyunaccounts. Once you have the above changes in your ``gpg.conf``, you can 863*4882a593Smuzhiyunauto-retrieve the keys for Linus Torvalds and Greg Kroah-Hartman (if you 864*4882a593Smuzhiyundon't already have them):: 865*4882a593Smuzhiyun 866*4882a593Smuzhiyun $ gpg --locate-keys torvalds@kernel.org gregkh@kernel.org 867*4882a593Smuzhiyun 868*4882a593SmuzhiyunIf you have a kernel.org account, then you should `add the kernel.org 869*4882a593SmuzhiyunUID to your key`_ to make WKD more useful to other kernel developers. 870*4882a593Smuzhiyun 871*4882a593Smuzhiyun.. _`add the kernel.org UID to your key`: https://korg.wiki.kernel.org/userdoc/mail#adding_a_kernelorg_uid_to_your_pgp_key 872*4882a593Smuzhiyun 873*4882a593SmuzhiyunWeb of Trust (WOT) vs. Trust on First Use (TOFU) 874*4882a593Smuzhiyun------------------------------------------------ 875*4882a593Smuzhiyun 876*4882a593SmuzhiyunPGP incorporates a trust delegation mechanism known as the "Web of 877*4882a593SmuzhiyunTrust." At its core, this is an attempt to replace the need for 878*4882a593Smuzhiyuncentralized Certification Authorities of the HTTPS/TLS world. Instead of 879*4882a593Smuzhiyunvarious software makers dictating who should be your trusted certifying 880*4882a593Smuzhiyunentity, PGP leaves this responsibility to each user. 881*4882a593Smuzhiyun 882*4882a593SmuzhiyunUnfortunately, very few people understand how the Web of Trust works. 883*4882a593SmuzhiyunWhile it remains an important aspect of the OpenPGP specification, 884*4882a593Smuzhiyunrecent versions of GnuPG (2.2 and above) have implemented an alternative 885*4882a593Smuzhiyunmechanism called "Trust on First Use" (TOFU). You can think of TOFU as 886*4882a593Smuzhiyun"the SSH-like approach to trust." With SSH, the first time you connect 887*4882a593Smuzhiyunto a remote system, its key fingerprint is recorded and remembered. If 888*4882a593Smuzhiyunthe key changes in the future, the SSH client will alert you and refuse 889*4882a593Smuzhiyunto connect, forcing you to make a decision on whether you choose to 890*4882a593Smuzhiyuntrust the changed key or not. Similarly, the first time you import 891*4882a593Smuzhiyunsomeone's PGP key, it is assumed to be valid. If at any point in the 892*4882a593Smuzhiyunfuture GnuPG comes across another key with the same identity, both the 893*4882a593Smuzhiyunpreviously imported key and the new key will be marked as invalid and 894*4882a593Smuzhiyunyou will need to manually figure out which one to keep. 895*4882a593Smuzhiyun 896*4882a593SmuzhiyunWe recommend that you use the combined TOFU+PGP trust model (which is 897*4882a593Smuzhiyunthe new default in GnuPG v2). To set it, add (or modify) the 898*4882a593Smuzhiyun``trust-model`` setting in ``~/.gnupg/gpg.conf``:: 899*4882a593Smuzhiyun 900*4882a593Smuzhiyun trust-model tofu+pgp 901*4882a593Smuzhiyun 902*4882a593SmuzhiyunHow to use keyservers (more) safely 903*4882a593Smuzhiyun----------------------------------- 904*4882a593Smuzhiyun 905*4882a593SmuzhiyunIf you get a "No public key" error when trying to validate someone's 906*4882a593Smuzhiyuntag, then you should attempt to lookup that key using a keyserver. It is 907*4882a593Smuzhiyunimportant to keep in mind that there is absolutely no guarantee that the 908*4882a593Smuzhiyunkey you retrieve from PGP keyservers belongs to the actual person -- 909*4882a593Smuzhiyunthat much is by design. You are supposed to use the Web of Trust to 910*4882a593Smuzhiyunestablish key validity. 911*4882a593Smuzhiyun 912*4882a593SmuzhiyunHow to properly maintain the Web of Trust is beyond the scope of this 913*4882a593Smuzhiyundocument, simply because doing it properly requires both effort and 914*4882a593Smuzhiyundedication that tends to be beyond the caring threshold of most human 915*4882a593Smuzhiyunbeings. Here are some shortcuts that will help you reduce the risk of 916*4882a593Smuzhiyunimporting a malicious key. 917*4882a593Smuzhiyun 918*4882a593SmuzhiyunFirst, let's say you've tried to run ``git verify-tag`` but it returned 919*4882a593Smuzhiyunan error saying the key is not found:: 920*4882a593Smuzhiyun 921*4882a593Smuzhiyun $ git verify-tag sunxi-fixes-for-4.15-2 922*4882a593Smuzhiyun gpg: Signature made Sun 07 Jan 2018 10:51:55 PM EST 923*4882a593Smuzhiyun gpg: using RSA key DA73759BF8619E484E5A3B47389A54219C0F2430 924*4882a593Smuzhiyun gpg: issuer "wens@...org" 925*4882a593Smuzhiyun gpg: Can't check signature: No public key 926*4882a593Smuzhiyun 927*4882a593SmuzhiyunLet's query the keyserver for more info about that key fingerprint (the 928*4882a593Smuzhiyunfingerprint probably belongs to a subkey, so we can't use it directly 929*4882a593Smuzhiyunwithout finding out the ID of the master key it is associated with):: 930*4882a593Smuzhiyun 931*4882a593Smuzhiyun $ gpg --search DA73759BF8619E484E5A3B47389A54219C0F2430 932*4882a593Smuzhiyun gpg: data source: hkp://keys.gnupg.net 933*4882a593Smuzhiyun (1) Chen-Yu Tsai <wens@...org> 934*4882a593Smuzhiyun 4096 bit RSA key C94035C21B4F2AEB, created: 2017-03-14, expires: 2019-03-15 935*4882a593Smuzhiyun Keys 1-1 of 1 for "DA73759BF8619E484E5A3B47389A54219C0F2430". Enter number(s), N)ext, or Q)uit > q 936*4882a593Smuzhiyun 937*4882a593SmuzhiyunLocate the ID of the master key in the output, in our example 938*4882a593Smuzhiyun``C94035C21B4F2AEB``. Now display the key of Linus Torvalds that you 939*4882a593Smuzhiyunhave on your keyring:: 940*4882a593Smuzhiyun 941*4882a593Smuzhiyun $ gpg --list-key torvalds@kernel.org 942*4882a593Smuzhiyun pub rsa2048 2011-09-20 [SC] 943*4882a593Smuzhiyun ABAF11C65A2970B130ABE3C479BE3E4300411886 944*4882a593Smuzhiyun uid [ unknown] Linus Torvalds <torvalds@kernel.org> 945*4882a593Smuzhiyun sub rsa2048 2011-09-20 [E] 946*4882a593Smuzhiyun 947*4882a593SmuzhiyunNext, open the `PGP pathfinder`_. In the "From" field, paste the key 948*4882a593Smuzhiyunfingerprint of Linus Torvalds from the output above. In the "To" field, 949*4882a593Smuzhiyunpaste the key-id you found via ``gpg --search`` of the unknown key, and 950*4882a593Smuzhiyuncheck the results: 951*4882a593Smuzhiyun 952*4882a593Smuzhiyun- `Finding paths to Linus`_ 953*4882a593Smuzhiyun 954*4882a593SmuzhiyunIf you get a few decent trust paths, then it's a pretty good indication 955*4882a593Smuzhiyunthat it is a valid key. You can add it to your keyring from the 956*4882a593Smuzhiyunkeyserver now:: 957*4882a593Smuzhiyun 958*4882a593Smuzhiyun $ gpg --recv-key C94035C21B4F2AEB 959*4882a593Smuzhiyun 960*4882a593SmuzhiyunThis process is not perfect, and you are obviously trusting the 961*4882a593Smuzhiyunadministrators of the PGP Pathfinder service to not be malicious (in 962*4882a593Smuzhiyunfact, this goes against :ref:`devs_not_infra`). However, if you 963*4882a593Smuzhiyundo not carefully maintain your own web of trust, then it is a marked 964*4882a593Smuzhiyunimprovement over blindly trusting keyservers. 965*4882a593Smuzhiyun 966*4882a593Smuzhiyun.. _`PGP pathfinder`: https://pgp.cs.uu.nl/ 967*4882a593Smuzhiyun.. _`Finding paths to Linus`: https://pgp.cs.uu.nl/paths/79BE3E4300411886/to/C94035C21B4F2AEB.html 968