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