diff options
-rw-r--r-- | Documentation/admin-guide/thunderbolt.rst | 66 | ||||
-rw-r--r-- | Documentation/mips/AU1xxx_IDE.README | 7 | ||||
-rw-r--r-- | Documentation/process/index.rst | 1 | ||||
-rw-r--r-- | Documentation/process/kernel-docs.rst | 2 | ||||
-rw-r--r-- | Documentation/process/maintainer-pgp-guide.rst | 929 |
5 files changed, 964 insertions, 41 deletions
diff --git a/Documentation/admin-guide/thunderbolt.rst b/Documentation/admin-guide/thunderbolt.rst index 9b55952039a6..9948ec36a204 100644 --- a/Documentation/admin-guide/thunderbolt.rst +++ b/Documentation/admin-guide/thunderbolt.rst | |||
@@ -3,13 +3,13 @@ | |||
3 | ============= | 3 | ============= |
4 | The interface presented here is not meant for end users. Instead there | 4 | The interface presented here is not meant for end users. Instead there |
5 | should be a userspace tool that handles all the low-level details, keeps | 5 | should be a userspace tool that handles all the low-level details, keeps |
6 | database of the authorized devices and prompts user for new connections. | 6 | a database of the authorized devices and prompts users for new connections. |
7 | 7 | ||
8 | More details about the sysfs interface for Thunderbolt devices can be | 8 | More details about the sysfs interface for Thunderbolt devices can be |
9 | found in ``Documentation/ABI/testing/sysfs-bus-thunderbolt``. | 9 | found in ``Documentation/ABI/testing/sysfs-bus-thunderbolt``. |
10 | 10 | ||
11 | Those users who just want to connect any device without any sort of | 11 | Those users who just want to connect any device without any sort of |
12 | manual work, can add following line to | 12 | manual work can add following line to |
13 | ``/etc/udev/rules.d/99-local.rules``:: | 13 | ``/etc/udev/rules.d/99-local.rules``:: |
14 | 14 | ||
15 | ACTION=="add", SUBSYSTEM=="thunderbolt", ATTR{authorized}=="0", ATTR{authorized}="1" | 15 | ACTION=="add", SUBSYSTEM=="thunderbolt", ATTR{authorized}=="0", ATTR{authorized}="1" |
@@ -20,7 +20,7 @@ vulnerable to DMA attacks. | |||
20 | 20 | ||
21 | Security levels and how to use them | 21 | Security levels and how to use them |
22 | ----------------------------------- | 22 | ----------------------------------- |
23 | Starting from Intel Falcon Ridge Thunderbolt controller there are 4 | 23 | Starting with Intel Falcon Ridge Thunderbolt controller there are 4 |
24 | security levels available. The reason for these is the fact that the | 24 | security levels available. The reason for these is the fact that the |
25 | connected devices can be DMA masters and thus read contents of the host | 25 | connected devices can be DMA masters and thus read contents of the host |
26 | memory without CPU and OS knowing about it. There are ways to prevent | 26 | memory without CPU and OS knowing about it. There are ways to prevent |
@@ -37,14 +37,14 @@ The security levels are as follows: | |||
37 | user | 37 | user |
38 | User is asked whether the device is allowed to be connected. | 38 | User is asked whether the device is allowed to be connected. |
39 | Based on the device identification information available through | 39 | Based on the device identification information available through |
40 | ``/sys/bus/thunderbolt/devices``. user then can do the decision. | 40 | ``/sys/bus/thunderbolt/devices``, the user then can make the decision. |
41 | In BIOS settings this is typically called *Unique ID*. | 41 | In BIOS settings this is typically called *Unique ID*. |
42 | 42 | ||
43 | secure | 43 | secure |
44 | User is asked whether the device is allowed to be connected. In | 44 | User is asked whether the device is allowed to be connected. In |
45 | addition to UUID the device (if it supports secure connect) is sent | 45 | addition to UUID the device (if it supports secure connect) is sent |
46 | a challenge that should match the expected one based on a random key | 46 | a challenge that should match the expected one based on a random key |
47 | written to ``key`` sysfs attribute. In BIOS settings this is | 47 | written to the ``key`` sysfs attribute. In BIOS settings this is |
48 | typically called *One time saved key*. | 48 | typically called *One time saved key*. |
49 | 49 | ||
50 | dponly | 50 | dponly |
@@ -78,7 +78,7 @@ When a device is plugged in it will appear in sysfs as follows:: | |||
78 | /sys/bus/thunderbolt/devices/0-1/unique_id - e0376f00-0300-0100-ffff-ffffffffffff | 78 | /sys/bus/thunderbolt/devices/0-1/unique_id - e0376f00-0300-0100-ffff-ffffffffffff |
79 | 79 | ||
80 | The ``authorized`` attribute reads 0 which means no PCIe tunnels are | 80 | The ``authorized`` attribute reads 0 which means no PCIe tunnels are |
81 | created yet. The user can authorize the device by simply:: | 81 | created yet. The user can authorize the device by simply entering:: |
82 | 82 | ||
83 | # echo 1 > /sys/bus/thunderbolt/devices/0-1/authorized | 83 | # echo 1 > /sys/bus/thunderbolt/devices/0-1/authorized |
84 | 84 | ||
@@ -86,7 +86,7 @@ This will create the PCIe tunnels and the device is now connected. | |||
86 | 86 | ||
87 | If the device supports secure connect, and the domain security level is | 87 | If the device supports secure connect, and the domain security level is |
88 | set to ``secure``, it has an additional attribute ``key`` which can hold | 88 | set to ``secure``, it has an additional attribute ``key`` which can hold |
89 | a random 32 byte value used for authorization and challenging the device in | 89 | a random 32-byte value used for authorization and challenging the device in |
90 | future connects:: | 90 | future connects:: |
91 | 91 | ||
92 | /sys/bus/thunderbolt/devices/0-3/authorized - 0 | 92 | /sys/bus/thunderbolt/devices/0-3/authorized - 0 |
@@ -99,12 +99,12 @@ future connects:: | |||
99 | 99 | ||
100 | Notice the key is empty by default. | 100 | Notice the key is empty by default. |
101 | 101 | ||
102 | If the user does not want to use secure connect it can just ``echo 1`` | 102 | If the user does not want to use secure connect they can just ``echo 1`` |
103 | to the ``authorized`` attribute and the PCIe tunnels will be created in | 103 | to the ``authorized`` attribute and the PCIe tunnels will be created in |
104 | the same way than in ``user`` security level. | 104 | the same way as in the ``user`` security level. |
105 | 105 | ||
106 | If the user wants to use secure connect, the first time the device is | 106 | If the user wants to use secure connect, the first time the device is |
107 | plugged a key needs to be created and send to the device:: | 107 | plugged a key needs to be created and sent to the device:: |
108 | 108 | ||
109 | # key=$(openssl rand -hex 32) | 109 | # key=$(openssl rand -hex 32) |
110 | # echo $key > /sys/bus/thunderbolt/devices/0-3/key | 110 | # echo $key > /sys/bus/thunderbolt/devices/0-3/key |
@@ -121,27 +121,27 @@ device using the same key:: | |||
121 | 121 | ||
122 | If the challenge the device returns back matches the one we expect based | 122 | If the challenge the device returns back matches the one we expect based |
123 | on the key, the device is connected and the PCIe tunnels are created. | 123 | on the key, the device is connected and the PCIe tunnels are created. |
124 | However, if the challenge failed no tunnels are created and error is | 124 | However, if the challenge fails no tunnels are created and error is |
125 | returned to the user. | 125 | returned to the user. |
126 | 126 | ||
127 | If the user still wants to connect the device it can either approve | 127 | If the user still wants to connect the device they can either approve |
128 | the device without a key or write new key and write 1 to the | 128 | the device without a key or write a new key and write 1 to the |
129 | ``authorized`` file to get the new key stored on the device NVM. | 129 | ``authorized`` file to get the new key stored on the device NVM. |
130 | 130 | ||
131 | Upgrading NVM on Thunderbolt device or host | 131 | Upgrading NVM on Thunderbolt device or host |
132 | ------------------------------------------- | 132 | ------------------------------------------- |
133 | Since most of the functionality is handled in a firmware running on a | 133 | Since most of the functionality is handled in firmware running on a |
134 | host controller or a device, it is important that the firmware can be | 134 | host controller or a device, it is important that the firmware can be |
135 | upgraded to the latest where possible bugs in it have been fixed. | 135 | upgraded to the latest where possible bugs in it have been fixed. |
136 | Typically OEMs provide this firmware from their support site. | 136 | Typically OEMs provide this firmware from their support site. |
137 | 137 | ||
138 | There is also a central site which has links where to download firmwares | 138 | There is also a central site which has links where to download firmware |
139 | for some machines: | 139 | for some machines: |
140 | 140 | ||
141 | `Thunderbolt Updates <https://thunderbolttechnology.net/updates>`_ | 141 | `Thunderbolt Updates <https://thunderbolttechnology.net/updates>`_ |
142 | 142 | ||
143 | Before you upgrade firmware on a device or host, please make sure it is | 143 | Before you upgrade firmware on a device or host, please make sure it is a |
144 | the suitable. Failing to do that may render the device (or host) in a | 144 | suitable upgrade. Failing to do that may render the device (or host) in a |
145 | state where it cannot be used properly anymore without special tools! | 145 | state where it cannot be used properly anymore without special tools! |
146 | 146 | ||
147 | Host NVM upgrade on Apple Macs is not supported. | 147 | Host NVM upgrade on Apple Macs is not supported. |
@@ -151,7 +151,7 @@ Thunderbolt device so that the host controller appears. It does not | |||
151 | matter which device is connected (unless you are upgrading NVM on a | 151 | matter which device is connected (unless you are upgrading NVM on a |
152 | device - then you need to connect that particular device). | 152 | device - then you need to connect that particular device). |
153 | 153 | ||
154 | Note OEM-specific method to power the controller up ("force power") may | 154 | Note an OEM-specific method to power the controller up ("force power") may |
155 | be available for your system in which case there is no need to plug in a | 155 | be available for your system in which case there is no need to plug in a |
156 | Thunderbolt device. | 156 | Thunderbolt device. |
157 | 157 | ||
@@ -171,7 +171,7 @@ it comes back the driver notices it and initiates a full power cycle. | |||
171 | After a while the host controller appears again and this time it should | 171 | After a while the host controller appears again and this time it should |
172 | be fully functional. | 172 | be fully functional. |
173 | 173 | ||
174 | We can verify that the new NVM firmware is active by running following | 174 | We can verify that the new NVM firmware is active by running the following |
175 | commands:: | 175 | commands:: |
176 | 176 | ||
177 | # cat /sys/bus/thunderbolt/devices/0-0/nvm_authenticate | 177 | # cat /sys/bus/thunderbolt/devices/0-0/nvm_authenticate |
@@ -179,38 +179,38 @@ commands:: | |||
179 | # cat /sys/bus/thunderbolt/devices/0-0/nvm_version | 179 | # cat /sys/bus/thunderbolt/devices/0-0/nvm_version |
180 | 18.0 | 180 | 18.0 |
181 | 181 | ||
182 | If ``nvm_authenticate`` contains anything else than 0x0 it is the error | 182 | If ``nvm_authenticate`` contains anything other than 0x0 it is the error |
183 | code from the last authentication cycle, which means the authentication | 183 | code from the last authentication cycle, which means the authentication |
184 | of the NVM image failed. | 184 | of the NVM image failed. |
185 | 185 | ||
186 | Note names of the NVMem devices ``nvm_activeN`` and ``nvm_non_activeN`` | 186 | Note names of the NVMem devices ``nvm_activeN`` and ``nvm_non_activeN`` |
187 | depends on the order they are registered in the NVMem subsystem. N in | 187 | depend on the order they are registered in the NVMem subsystem. N in |
188 | the name is the identifier added by the NVMem subsystem. | 188 | the name is the identifier added by the NVMem subsystem. |
189 | 189 | ||
190 | Upgrading NVM when host controller is in safe mode | 190 | Upgrading NVM when host controller is in safe mode |
191 | -------------------------------------------------- | 191 | -------------------------------------------------- |
192 | If the existing NVM is not properly authenticated (or is missing) the | 192 | If the existing NVM is not properly authenticated (or is missing) the |
193 | host controller goes into safe mode which means that only available | 193 | host controller goes into safe mode which means that the only available |
194 | functionality is flashing new NVM image. When in this mode the reading | 194 | functionality is flashing a new NVM image. When in this mode, reading |
195 | ``nvm_version`` fails with ``ENODATA`` and the device identification | 195 | ``nvm_version`` fails with ``ENODATA`` and the device identification |
196 | information is missing. | 196 | information is missing. |
197 | 197 | ||
198 | To recover from this mode, one needs to flash a valid NVM image to the | 198 | To recover from this mode, one needs to flash a valid NVM image to the |
199 | host host controller in the same way it is done in the previous chapter. | 199 | host controller in the same way it is done in the previous chapter. |
200 | 200 | ||
201 | Networking over Thunderbolt cable | 201 | Networking over Thunderbolt cable |
202 | --------------------------------- | 202 | --------------------------------- |
203 | Thunderbolt technology allows software communication across two hosts | 203 | Thunderbolt technology allows software communication between two hosts |
204 | connected by a Thunderbolt cable. | 204 | connected by a Thunderbolt cable. |
205 | 205 | ||
206 | It is possible to tunnel any kind of traffic over Thunderbolt link but | 206 | It is possible to tunnel any kind of traffic over a Thunderbolt link but |
207 | currently we only support Apple ThunderboltIP protocol. | 207 | currently we only support Apple ThunderboltIP protocol. |
208 | 208 | ||
209 | If the other host is running Windows or macOS only thing you need to | 209 | If the other host is running Windows or macOS, the only thing you need to |
210 | do is to connect Thunderbolt cable between the two hosts, the | 210 | do is to connect a Thunderbolt cable between the two hosts; the |
211 | ``thunderbolt-net`` is loaded automatically. If the other host is also | 211 | ``thunderbolt-net`` driver is loaded automatically. If the other host is |
212 | Linux you should load ``thunderbolt-net`` manually on one host (it does | 212 | also Linux you should load ``thunderbolt-net`` manually on one host (it |
213 | not matter which one):: | 213 | does not matter which one):: |
214 | 214 | ||
215 | # modprobe thunderbolt-net | 215 | # modprobe thunderbolt-net |
216 | 216 | ||
@@ -220,12 +220,12 @@ is built-in to the kernel image, there is no need to do anything. | |||
220 | The driver will create one virtual ethernet interface per Thunderbolt | 220 | The driver will create one virtual ethernet interface per Thunderbolt |
221 | port which are named like ``thunderbolt0`` and so on. From this point | 221 | port which are named like ``thunderbolt0`` and so on. From this point |
222 | you can either use standard userspace tools like ``ifconfig`` to | 222 | you can either use standard userspace tools like ``ifconfig`` to |
223 | configure the interface or let your GUI to handle it automatically. | 223 | configure the interface or let your GUI handle it automatically. |
224 | 224 | ||
225 | Forcing power | 225 | Forcing power |
226 | ------------- | 226 | ------------- |
227 | Many OEMs include a method that can be used to force the power of a | 227 | Many OEMs include a method that can be used to force the power of a |
228 | thunderbolt controller to an "On" state even if nothing is connected. | 228 | Thunderbolt controller to an "On" state even if nothing is connected. |
229 | If supported by your machine this will be exposed by the WMI bus with | 229 | If supported by your machine this will be exposed by the WMI bus with |
230 | a sysfs attribute called "force_power". | 230 | a sysfs attribute called "force_power". |
231 | 231 | ||
diff --git a/Documentation/mips/AU1xxx_IDE.README b/Documentation/mips/AU1xxx_IDE.README index 52844a58cc8a..ff675a1b1422 100644 --- a/Documentation/mips/AU1xxx_IDE.README +++ b/Documentation/mips/AU1xxx_IDE.README | |||
@@ -56,8 +56,6 @@ Following extra configs variables are introduced: | |||
56 | 56 | ||
57 | CONFIG_BLK_DEV_IDE_AU1XXX_PIO_DBDMA - enable the PIO+DBDMA mode | 57 | CONFIG_BLK_DEV_IDE_AU1XXX_PIO_DBDMA - enable the PIO+DBDMA mode |
58 | CONFIG_BLK_DEV_IDE_AU1XXX_MDMA2_DBDMA - enable the MWDMA mode | 58 | CONFIG_BLK_DEV_IDE_AU1XXX_MDMA2_DBDMA - enable the MWDMA mode |
59 | CONFIG_BLK_DEV_IDE_AU1XXX_BURSTABLE_ON - set Burstable FIFO in DBDMA | ||
60 | controller | ||
61 | 59 | ||
62 | 60 | ||
63 | SUPPORTED IDE MODES | 61 | SUPPORTED IDE MODES |
@@ -82,11 +80,9 @@ CONFIG_IDE_GENERIC=y | |||
82 | CONFIG_BLK_DEV_IDEPCI=y | 80 | CONFIG_BLK_DEV_IDEPCI=y |
83 | CONFIG_BLK_DEV_GENERIC=y | 81 | CONFIG_BLK_DEV_GENERIC=y |
84 | CONFIG_BLK_DEV_IDEDMA_PCI=y | 82 | CONFIG_BLK_DEV_IDEDMA_PCI=y |
85 | CONFIG_IDEDMA_PCI_AUTO=y | ||
86 | CONFIG_BLK_DEV_IDE_AU1XXX=y | 83 | CONFIG_BLK_DEV_IDE_AU1XXX=y |
87 | CONFIG_BLK_DEV_IDE_AU1XXX_MDMA2_DBDMA=y | 84 | CONFIG_BLK_DEV_IDE_AU1XXX_MDMA2_DBDMA=y |
88 | CONFIG_BLK_DEV_IDEDMA=y | 85 | CONFIG_BLK_DEV_IDEDMA=y |
89 | CONFIG_IDEDMA_AUTO=y | ||
90 | 86 | ||
91 | Also define 'IDE_AU1XXX_BURSTMODE' in 'drivers/ide/mips/au1xxx-ide.c' to enable | 87 | Also define 'IDE_AU1XXX_BURSTMODE' in 'drivers/ide/mips/au1xxx-ide.c' to enable |
92 | the burst support on DBDMA controller. | 88 | the burst support on DBDMA controller. |
@@ -94,16 +90,13 @@ the burst support on DBDMA controller. | |||
94 | If the used system need the USB support enable the following kernel configs for | 90 | If the used system need the USB support enable the following kernel configs for |
95 | high IDE to USB throughput. | 91 | high IDE to USB throughput. |
96 | 92 | ||
97 | CONFIG_BLK_DEV_IDEDISK=y | ||
98 | CONFIG_IDE_GENERIC=y | 93 | CONFIG_IDE_GENERIC=y |
99 | CONFIG_BLK_DEV_IDEPCI=y | 94 | CONFIG_BLK_DEV_IDEPCI=y |
100 | CONFIG_BLK_DEV_GENERIC=y | 95 | CONFIG_BLK_DEV_GENERIC=y |
101 | CONFIG_BLK_DEV_IDEDMA_PCI=y | 96 | CONFIG_BLK_DEV_IDEDMA_PCI=y |
102 | CONFIG_IDEDMA_PCI_AUTO=y | ||
103 | CONFIG_BLK_DEV_IDE_AU1XXX=y | 97 | CONFIG_BLK_DEV_IDE_AU1XXX=y |
104 | CONFIG_BLK_DEV_IDE_AU1XXX_MDMA2_DBDMA=y | 98 | CONFIG_BLK_DEV_IDE_AU1XXX_MDMA2_DBDMA=y |
105 | CONFIG_BLK_DEV_IDEDMA=y | 99 | CONFIG_BLK_DEV_IDEDMA=y |
106 | CONFIG_IDEDMA_AUTO=y | ||
107 | 100 | ||
108 | Also undefine 'IDE_AU1XXX_BURSTMODE' in 'drivers/ide/mips/au1xxx-ide.c' to | 101 | Also undefine 'IDE_AU1XXX_BURSTMODE' in 'drivers/ide/mips/au1xxx-ide.c' to |
109 | disable the burst support on DBDMA controller. | 102 | disable the burst support on DBDMA controller. |
diff --git a/Documentation/process/index.rst b/Documentation/process/index.rst index a430f6eee756..1c9fe657ed01 100644 --- a/Documentation/process/index.rst +++ b/Documentation/process/index.rst | |||
@@ -24,6 +24,7 @@ Below are the essential guides that every developer should read. | |||
24 | development-process | 24 | development-process |
25 | submitting-patches | 25 | submitting-patches |
26 | coding-style | 26 | coding-style |
27 | maintainer-pgp-guide | ||
27 | email-clients | 28 | email-clients |
28 | kernel-enforcement-statement | 29 | kernel-enforcement-statement |
29 | kernel-driver-statement | 30 | kernel-driver-statement |
diff --git a/Documentation/process/kernel-docs.rst b/Documentation/process/kernel-docs.rst index b8cac85a4001..3fb28de556e4 100644 --- a/Documentation/process/kernel-docs.rst +++ b/Documentation/process/kernel-docs.rst | |||
@@ -58,7 +58,7 @@ On-line docs | |||
58 | * Title: **Linux Kernel Mailing List Glossary** | 58 | * Title: **Linux Kernel Mailing List Glossary** |
59 | 59 | ||
60 | :Author: various | 60 | :Author: various |
61 | :URL: http://kernelnewbies.org/glossary/ | 61 | :URL: https://kernelnewbies.org/KernelGlossary |
62 | :Date: rolling version | 62 | :Date: rolling version |
63 | :Keywords: glossary, terms, linux-kernel. | 63 | :Keywords: glossary, terms, linux-kernel. |
64 | :Description: From the introduction: "This glossary is intended as | 64 | :Description: From the introduction: "This glossary is intended as |
diff --git a/Documentation/process/maintainer-pgp-guide.rst b/Documentation/process/maintainer-pgp-guide.rst new file mode 100644 index 000000000000..b453561a7148 --- /dev/null +++ b/Documentation/process/maintainer-pgp-guide.rst | |||
@@ -0,0 +1,929 @@ | |||
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 | Set up a refresh cronjob | ||
125 | ~~~~~~~~~~~~~~~~~~~~~~~~ | ||
126 | |||
127 | You will need to regularly refresh your keyring in order to get the | ||
128 | latest changes on other people's public keys, which is best done with a | ||
129 | daily cronjob:: | ||
130 | |||
131 | @daily /usr/bin/gpg2 --refresh >/dev/null 2>&1 | ||
132 | |||
133 | Check the full path to your ``gpg`` or ``gpg2`` command and use the | ||
134 | ``gpg2`` command if regular ``gpg`` for you is the legacy GnuPG v.1. | ||
135 | |||
136 | .. _master_key: | ||
137 | |||
138 | Protect your master PGP key | ||
139 | =========================== | ||
140 | |||
141 | This guide assumes that you already have a PGP key that you use for Linux | ||
142 | kernel development purposes. If you do not yet have one, please see the | ||
143 | "`Protecting Code Integrity`_" document mentioned earlier for guidance | ||
144 | on how to create a new one. | ||
145 | |||
146 | You should also make a new key if your current one is weaker than 2048 bits | ||
147 | (RSA). | ||
148 | |||
149 | Master key vs. Subkeys | ||
150 | ---------------------- | ||
151 | |||
152 | Subkeys are fully independent PGP keypairs that are tied to the "master" | ||
153 | key using certifying key signatures (certificates). It is important to | ||
154 | understand the following: | ||
155 | |||
156 | 1. There are no technical differences between the "master key" and "subkeys." | ||
157 | 2. At creation time, we assign functional limitations to each key by | ||
158 | giving it specific capabilities. | ||
159 | 3. A PGP key can have 4 capabilities: | ||
160 | |||
161 | - **[S]** key can be used for signing | ||
162 | - **[E]** key can be used for encryption | ||
163 | - **[A]** key can be used for authentication | ||
164 | - **[C]** key can be used for certifying other keys | ||
165 | |||
166 | 4. A single key may have multiple capabilities. | ||
167 | 5. A subkey is fully independent from the master key. A message | ||
168 | encrypted to a subkey cannot be decrypted with the master key. If you | ||
169 | lose your private subkey, it cannot be recreated from the master key | ||
170 | in any way. | ||
171 | |||
172 | The key carrying the **[C]** (certify) capability is considered the | ||
173 | "master" key because it is the only key that can be used to indicate | ||
174 | relationship with other keys. Only the **[C]** key can be used to: | ||
175 | |||
176 | - add or revoke other keys (subkeys) with S/E/A capabilities | ||
177 | - add, change or revoke identities (uids) associated with the key | ||
178 | - add or change the expiration date on itself or any subkey | ||
179 | - sign other people's keys for web of trust purposes | ||
180 | |||
181 | By default, GnuPG creates the following when generating new keys: | ||
182 | |||
183 | - A master key carrying both Certify and Sign capabilities (**[SC]**) | ||
184 | - A separate subkey with the Encryption capability (**[E]**) | ||
185 | |||
186 | If you used the default parameters when generating your key, then that | ||
187 | is what you will have. You can verify by running ``gpg --list-secret-keys``, | ||
188 | for example:: | ||
189 | |||
190 | sec rsa2048 2018-01-23 [SC] [expires: 2020-01-23] | ||
191 | 000000000000000000000000AAAABBBBCCCCDDDD | ||
192 | uid [ultimate] Alice Dev <adev@kernel.org> | ||
193 | ssb rsa2048 2018-01-23 [E] [expires: 2020-01-23] | ||
194 | |||
195 | Any key carrying the **[C]** capability is your master key, regardless | ||
196 | of any other capabilities it may have assigned to it. | ||
197 | |||
198 | The long line under the ``sec`` entry is your key fingerprint -- | ||
199 | whenever you see ``[fpr]`` in the examples below, that 40-character | ||
200 | string is what it refers to. | ||
201 | |||
202 | Ensure your passphrase is strong | ||
203 | -------------------------------- | ||
204 | |||
205 | GnuPG uses passphrases to encrypt your private keys before storing them on | ||
206 | disk. This way, even if your ``.gnupg`` directory is leaked or stolen in | ||
207 | its entirety, the attackers cannot use your private keys without first | ||
208 | obtaining the passphrase to decrypt them. | ||
209 | |||
210 | It is absolutely essential that your private keys are protected by a | ||
211 | strong passphrase. To set it or change it, use:: | ||
212 | |||
213 | $ gpg --change-passphrase [fpr] | ||
214 | |||
215 | Create a separate Signing subkey | ||
216 | -------------------------------- | ||
217 | |||
218 | Our goal is to protect your master key by moving it to offline media, so | ||
219 | if you only have a combined **[SC]** key, then you should create a separate | ||
220 | signing subkey:: | ||
221 | |||
222 | $ gpg --quick-add-key [fpr] ed25519 sign | ||
223 | |||
224 | Remember to tell the keyservers about this change, so others can pull down | ||
225 | your new subkey:: | ||
226 | |||
227 | $ gpg --send-key [fpr] | ||
228 | |||
229 | .. note:: ECC support in GnuPG | ||
230 | |||
231 | GnuPG 2.1 and later has full support for Elliptic Curve | ||
232 | Cryptography, with ability to combine ECC subkeys with traditional | ||
233 | RSA master keys. The main upside of ECC cryptography is that it is | ||
234 | much faster computationally and creates much smaller signatures when | ||
235 | compared byte for byte with 2048+ bit RSA keys. Unless you plan on | ||
236 | using a smartcard device that does not support ECC operations, we | ||
237 | recommend that you create an ECC signing subkey for your kernel | ||
238 | work. | ||
239 | |||
240 | If for some reason you prefer to stay with RSA subkeys, just replace | ||
241 | "ed25519" with "rsa2048" in the above command. | ||
242 | |||
243 | |||
244 | Back up your master key for disaster recovery | ||
245 | --------------------------------------------- | ||
246 | |||
247 | The more signatures you have on your PGP key from other developers, the | ||
248 | more reasons you have to create a backup version that lives on something | ||
249 | other than digital media, for disaster recovery reasons. | ||
250 | |||
251 | The best way to create a printable hardcopy of your private key is by | ||
252 | using the ``paperkey`` software written for this very purpose. See ``man | ||
253 | paperkey`` for more details on the output format and its benefits over | ||
254 | other solutions. Paperkey should already be packaged for most | ||
255 | distributions. | ||
256 | |||
257 | Run the following command to create a hardcopy backup of your private | ||
258 | key:: | ||
259 | |||
260 | $ gpg --export-secret-key [fpr] | paperkey -o /tmp/key-backup.txt | ||
261 | |||
262 | Print out that file (or pipe the output straight to lpr), then take a | ||
263 | pen and write your passphrase on the margin of the paper. **This is | ||
264 | strongly recommended** because the key printout is still encrypted with | ||
265 | that passphrase, and if you ever change it you will not remember what it | ||
266 | used to be when you had created the backup -- *guaranteed*. | ||
267 | |||
268 | Put the resulting printout and the hand-written passphrase into an envelope | ||
269 | and store in a secure and well-protected place, preferably away from your | ||
270 | home, such as your bank vault. | ||
271 | |||
272 | .. note:: | ||
273 | |||
274 | Your printer is probably no longer a simple dumb device connected to | ||
275 | your parallel port, but since the output is still encrypted with | ||
276 | your passphrase, printing out even to "cloud-integrated" modern | ||
277 | printers should remain a relatively safe operation. One option is to | ||
278 | change the passphrase on your master key immediately after you are | ||
279 | done with paperkey. | ||
280 | |||
281 | Back up your whole GnuPG directory | ||
282 | ---------------------------------- | ||
283 | |||
284 | .. warning:: | ||
285 | |||
286 | **!!!Do not skip this step!!!** | ||
287 | |||
288 | It is important to have a readily available backup of your PGP keys | ||
289 | should you need to recover them. This is different from the | ||
290 | disaster-level preparedness we did with ``paperkey``. You will also rely | ||
291 | on these external copies whenever you need to use your Certify key -- | ||
292 | such as when making changes to your own key or signing other people's | ||
293 | keys after conferences and summits. | ||
294 | |||
295 | Start by getting a small USB "thumb" drive (preferably two!) that you | ||
296 | will use for backup purposes. You will need to encrypt them using LUKS | ||
297 | -- refer to your distro's documentation on how to accomplish this. | ||
298 | |||
299 | For the encryption passphrase, you can use the same one as on your | ||
300 | master key. | ||
301 | |||
302 | Once the encryption process is over, re-insert the USB drive and make | ||
303 | sure it gets properly mounted. Copy your entire ``.gnupg`` directory | ||
304 | over to the encrypted storage:: | ||
305 | |||
306 | $ cp -a ~/.gnupg /media/disk/foo/gnupg-backup | ||
307 | |||
308 | You should now test to make sure everything still works:: | ||
309 | |||
310 | $ gpg --homedir=/media/disk/foo/gnupg-backup --list-key [fpr] | ||
311 | |||
312 | If you don't get any errors, then you should be good to go. Unmount the | ||
313 | USB drive, distinctly label it so you don't blow it away next time you | ||
314 | need to use a random USB drive, and put in a safe place -- but not too | ||
315 | far away, because you'll need to use it every now and again for things | ||
316 | like editing identities, adding or revoking subkeys, or signing other | ||
317 | people's keys. | ||
318 | |||
319 | Remove the master key from your homedir | ||
320 | ---------------------------------------- | ||
321 | |||
322 | The files in our home directory are not as well protected as we like to | ||
323 | think. They can be leaked or stolen via many different means: | ||
324 | |||
325 | - by accident when making quick homedir copies to set up a new workstation | ||
326 | - by systems administrator negligence or malice | ||
327 | - via poorly secured backups | ||
328 | - via malware in desktop apps (browsers, pdf viewers, etc) | ||
329 | - via coercion when crossing international borders | ||
330 | |||
331 | Protecting your key with a good passphrase greatly helps reduce the risk | ||
332 | of any of the above, but passphrases can be discovered via keyloggers, | ||
333 | shoulder-surfing, or any number of other means. For this reason, the | ||
334 | recommended setup is to remove your master key from your home directory | ||
335 | and store it on offline storage. | ||
336 | |||
337 | .. warning:: | ||
338 | |||
339 | Please see the previous section and make sure you have backed up | ||
340 | your GnuPG directory in its entirety. What we are about to do will | ||
341 | render your key useless if you do not have a usable backup! | ||
342 | |||
343 | First, identify the keygrip of your master key:: | ||
344 | |||
345 | $ gpg --with-keygrip --list-key [fpr] | ||
346 | |||
347 | The output will be something like this:: | ||
348 | |||
349 | pub rsa2048 2018-01-24 [SC] [expires: 2020-01-24] | ||
350 | 000000000000000000000000AAAABBBBCCCCDDDD | ||
351 | Keygrip = 1111000000000000000000000000000000000000 | ||
352 | uid [ultimate] Alice Dev <adev@kernel.org> | ||
353 | sub rsa2048 2018-01-24 [E] [expires: 2020-01-24] | ||
354 | Keygrip = 2222000000000000000000000000000000000000 | ||
355 | sub ed25519 2018-01-24 [S] | ||
356 | Keygrip = 3333000000000000000000000000000000000000 | ||
357 | |||
358 | Find the keygrip entry that is beneath the ``pub`` line (right under the | ||
359 | master key fingerprint). This will correspond directly to a file in your | ||
360 | ``~/.gnupg`` directory:: | ||
361 | |||
362 | $ cd ~/.gnupg/private-keys-v1.d | ||
363 | $ ls | ||
364 | 1111000000000000000000000000000000000000.key | ||
365 | 2222000000000000000000000000000000000000.key | ||
366 | 3333000000000000000000000000000000000000.key | ||
367 | |||
368 | All you have to do is simply remove the .key file that corresponds to | ||
369 | the master keygrip:: | ||
370 | |||
371 | $ cd ~/.gnupg/private-keys-v1.d | ||
372 | $ rm 1111000000000000000000000000000000000000.key | ||
373 | |||
374 | Now, if you issue the ``--list-secret-keys`` command, it will show that | ||
375 | the master key is missing (the ``#`` indicates it is not available):: | ||
376 | |||
377 | $ gpg --list-secret-keys | ||
378 | sec# rsa2048 2018-01-24 [SC] [expires: 2020-01-24] | ||
379 | 000000000000000000000000AAAABBBBCCCCDDDD | ||
380 | uid [ultimate] Alice Dev <adev@kernel.org> | ||
381 | ssb rsa2048 2018-01-24 [E] [expires: 2020-01-24] | ||
382 | ssb ed25519 2018-01-24 [S] | ||
383 | |||
384 | You should also remove any ``secring.gpg`` files in the ``~/.gnupg`` | ||
385 | directory, which are left over from earlier versions of GnuPG. | ||
386 | |||
387 | If you don't have the "private-keys-v1.d" directory | ||
388 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
389 | |||
390 | If you do not have a ``~/.gnupg/private-keys-v1.d`` directory, then your | ||
391 | secret keys are still stored in the legacy ``secring.gpg`` file used by | ||
392 | GnuPG v1. Making any changes to your key, such as changing the | ||
393 | passphrase or adding a subkey, should automatically convert the old | ||
394 | ``secring.gpg`` format to use ``private-keys-v1.d`` instead. | ||
395 | |||
396 | Once you get that done, make sure to delete the obsolete ``secring.gpg`` | ||
397 | file, which still contains your private keys. | ||
398 | |||
399 | .. _smartcards: | ||
400 | |||
401 | Move the subkeys to a dedicated crypto device | ||
402 | ============================================= | ||
403 | |||
404 | Even though the master key is now safe from being leaked or stolen, the | ||
405 | subkeys are still in your home directory. Anyone who manages to get | ||
406 | their hands on those will be able to decrypt your communication or fake | ||
407 | your signatures (if they know the passphrase). Furthermore, each time a | ||
408 | GnuPG operation is performed, the keys are loaded into system memory and | ||
409 | can be stolen from there by sufficiently advanced malware (think | ||
410 | Meltdown and Spectre). | ||
411 | |||
412 | The best way to completely protect your keys is to move them to a | ||
413 | specialized hardware device that is capable of smartcard operations. | ||
414 | |||
415 | The benefits of smartcards | ||
416 | -------------------------- | ||
417 | |||
418 | A smartcard contains a cryptographic chip that is capable of storing | ||
419 | private keys and performing crypto operations directly on the card | ||
420 | itself. Because the key contents never leave the smartcard, the | ||
421 | operating system of the computer into which you plug in the hardware | ||
422 | device is not able to retrieve the private keys themselves. This is very | ||
423 | different from the encrypted USB storage device we used earlier for | ||
424 | backup purposes -- while that USB device is plugged in and mounted, the | ||
425 | operating system is able to access the private key contents. | ||
426 | |||
427 | Using external encrypted USB media is not a substitute to having a | ||
428 | smartcard-capable device. | ||
429 | |||
430 | Available smartcard devices | ||
431 | --------------------------- | ||
432 | |||
433 | Unless all your laptops and workstations have smartcard readers, the | ||
434 | easiest is to get a specialized USB device that implements smartcard | ||
435 | functionality. There are several options available: | ||
436 | |||
437 | - `Nitrokey Start`_: Open hardware and Free Software, based on FSI | ||
438 | Japan's `Gnuk`_. Offers support for ECC keys, but fewest security | ||
439 | features (such as resistance to tampering or some side-channel | ||
440 | attacks). | ||
441 | - `Nitrokey Pro`_: Similar to the Nitrokey Start, but more | ||
442 | tamper-resistant and offers more security features, but no ECC | ||
443 | support. | ||
444 | - `Yubikey 4`_: proprietary hardware and software, but cheaper than | ||
445 | Nitrokey Pro and comes available in the USB-C form that is more useful | ||
446 | with newer laptops. Offers additional security features such as FIDO | ||
447 | U2F, but no ECC. | ||
448 | |||
449 | `LWN has a good review`_ of some of the above models, as well as several | ||
450 | others. If you want to use ECC keys, your best bet among commercially | ||
451 | available devices is the Nitrokey Start. | ||
452 | |||
453 | .. _`Nitrokey Start`: https://shop.nitrokey.com/shop/product/nitrokey-start-6 | ||
454 | .. _`Nitrokey Pro`: https://shop.nitrokey.com/shop/product/nitrokey-pro-3 | ||
455 | .. _`Yubikey 4`: https://www.yubico.com/product/yubikey-4-series/ | ||
456 | .. _Gnuk: http://www.fsij.org/doc-gnuk/ | ||
457 | .. _`LWN has a good review`: https://lwn.net/Articles/736231/ | ||
458 | |||
459 | Configure your smartcard device | ||
460 | ------------------------------- | ||
461 | |||
462 | Your smartcard device should Just Work (TM) the moment you plug it into | ||
463 | any modern Linux workstation. You can verify it by running:: | ||
464 | |||
465 | $ gpg --card-status | ||
466 | |||
467 | If you see full smartcard details, then you are good to go. | ||
468 | Unfortunately, troubleshooting all possible reasons why things may not | ||
469 | be working for you is way beyond the scope of this guide. If you are | ||
470 | having trouble getting the card to work with GnuPG, please seek help via | ||
471 | usual support channels. | ||
472 | |||
473 | To configure your smartcard, you will need to use the GnuPG menu system, as | ||
474 | there are no convenient command-line switches:: | ||
475 | |||
476 | $ gpg --card-edit | ||
477 | [...omitted...] | ||
478 | gpg/card> admin | ||
479 | Admin commands are allowed | ||
480 | gpg/card> passwd | ||
481 | |||
482 | You should set the user PIN (1), Admin PIN (3), and the Reset Code (4). | ||
483 | Please make sure to record and store these in a safe place -- especially | ||
484 | the Admin PIN and the Reset Code (which allows you to completely wipe | ||
485 | the smartcard). You so rarely need to use the Admin PIN, that you will | ||
486 | inevitably forget what it is if you do not record it. | ||
487 | |||
488 | Getting back to the main card menu, you can also set other values (such | ||
489 | as name, sex, login data, etc), but it's not necessary and will | ||
490 | additionally leak information about your smartcard should you lose it. | ||
491 | |||
492 | .. note:: | ||
493 | |||
494 | Despite having the name "PIN", neither the user PIN nor the admin | ||
495 | PIN on the card need to be numbers. | ||
496 | |||
497 | Move the subkeys to your smartcard | ||
498 | ---------------------------------- | ||
499 | |||
500 | Exit the card menu (using "q") and save all changes. Next, let's move | ||
501 | your subkeys onto the smartcard. You will need both your PGP key | ||
502 | passphrase and the admin PIN of the card for most operations:: | ||
503 | |||
504 | $ gpg --edit-key [fpr] | ||
505 | |||
506 | Secret subkeys are available. | ||
507 | |||
508 | pub rsa2048/AAAABBBBCCCCDDDD | ||
509 | created: 2018-01-23 expires: 2020-01-23 usage: SC | ||
510 | trust: ultimate validity: ultimate | ||
511 | ssb rsa2048/1111222233334444 | ||
512 | created: 2018-01-23 expires: never usage: E | ||
513 | ssb ed25519/5555666677778888 | ||
514 | created: 2017-12-07 expires: never usage: S | ||
515 | [ultimate] (1). Alice Dev <adev@kernel.org> | ||
516 | |||
517 | gpg> | ||
518 | |||
519 | Using ``--edit-key`` puts us into the menu mode again, and you will | ||
520 | notice that the key listing is a little different. From here on, all | ||
521 | commands are done from inside this menu mode, as indicated by ``gpg>``. | ||
522 | |||
523 | First, let's select the key we'll be putting onto the card -- you do | ||
524 | this by typing ``key 1`` (it's the first one in the listing, the **[E]** | ||
525 | subkey):: | ||
526 | |||
527 | gpg> key 1 | ||
528 | |||
529 | In the output, you should now see ``ssb*`` on the **[E]** key. The ``*`` | ||
530 | indicates which key is currently "selected." It works as a *toggle*, | ||
531 | meaning that if you type ``key 1`` again, the ``*`` will disappear and | ||
532 | the key will not be selected any more. | ||
533 | |||
534 | Now, let's move that key onto the smartcard:: | ||
535 | |||
536 | gpg> keytocard | ||
537 | Please select where to store the key: | ||
538 | (2) Encryption key | ||
539 | Your selection? 2 | ||
540 | |||
541 | Since it's our **[E]** key, it makes sense to put it into the Encryption | ||
542 | slot. When you submit your selection, you will be prompted first for | ||
543 | your PGP key passphrase, and then for the admin PIN. If the command | ||
544 | returns without an error, your key has been moved. | ||
545 | |||
546 | **Important**: Now type ``key 1`` again to unselect the first key, and | ||
547 | ``key 2`` to select the **[S]** key:: | ||
548 | |||
549 | gpg> key 1 | ||
550 | gpg> key 2 | ||
551 | gpg> keytocard | ||
552 | Please select where to store the key: | ||
553 | (1) Signature key | ||
554 | (3) Authentication key | ||
555 | Your selection? 1 | ||
556 | |||
557 | You can use the **[S]** key both for Signature and Authentication, but | ||
558 | we want to make sure it's in the Signature slot, so choose (1). Once | ||
559 | again, if your command returns without an error, then the operation was | ||
560 | successful:: | ||
561 | |||
562 | gpg> q | ||
563 | Save changes? (y/N) y | ||
564 | |||
565 | Saving the changes will delete the keys you moved to the card from your | ||
566 | home directory (but it's okay, because we have them in our backups | ||
567 | should we need to do this again for a replacement smartcard). | ||
568 | |||
569 | Verifying that the keys were moved | ||
570 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
571 | |||
572 | If you perform ``--list-secret-keys`` now, you will see a subtle | ||
573 | difference in the output:: | ||
574 | |||
575 | $ gpg --list-secret-keys | ||
576 | sec# rsa2048 2018-01-24 [SC] [expires: 2020-01-24] | ||
577 | 000000000000000000000000AAAABBBBCCCCDDDD | ||
578 | uid [ultimate] Alice Dev <adev@kernel.org> | ||
579 | ssb> rsa2048 2018-01-24 [E] [expires: 2020-01-24] | ||
580 | ssb> ed25519 2018-01-24 [S] | ||
581 | |||
582 | The ``>`` in the ``ssb>`` output indicates that the subkey is only | ||
583 | available on the smartcard. If you go back into your secret keys | ||
584 | directory and look at the contents there, you will notice that the | ||
585 | ``.key`` files there have been replaced with stubs:: | ||
586 | |||
587 | $ cd ~/.gnupg/private-keys-v1.d | ||
588 | $ strings *.key | grep 'private-key' | ||
589 | |||
590 | The output should contain ``shadowed-private-key`` to indicate that | ||
591 | these files are only stubs and the actual content is on the smartcard. | ||
592 | |||
593 | Verifying that the smartcard is functioning | ||
594 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
595 | |||
596 | To verify that the smartcard is working as intended, you can create a | ||
597 | signature:: | ||
598 | |||
599 | $ echo "Hello world" | gpg --clearsign > /tmp/test.asc | ||
600 | $ gpg --verify /tmp/test.asc | ||
601 | |||
602 | This should ask for your smartcard PIN on your first command, and then | ||
603 | show "Good signature" after you run ``gpg --verify``. | ||
604 | |||
605 | Congratulations, you have successfully made it extremely difficult to | ||
606 | steal your digital developer identity! | ||
607 | |||
608 | Other common GnuPG operations | ||
609 | ----------------------------- | ||
610 | |||
611 | Here is a quick reference for some common operations you'll need to do | ||
612 | with your PGP key. | ||
613 | |||
614 | Mounting your master key offline storage | ||
615 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
616 | |||
617 | You will need your master key for any of the operations below, so you | ||
618 | will first need to mount your backup offline storage and tell GnuPG to | ||
619 | use it:: | ||
620 | |||
621 | $ export GNUPGHOME=/media/disk/foo/gnupg-backup | ||
622 | $ gpg --list-secret-keys | ||
623 | |||
624 | You want to make sure that you see ``sec`` and not ``sec#`` in the | ||
625 | output (the ``#`` means the key is not available and you're still using | ||
626 | your regular home directory location). | ||
627 | |||
628 | Extending key expiration date | ||
629 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
630 | |||
631 | The master key has the default expiration date of 2 years from the date | ||
632 | of creation. This is done both for security reasons and to make obsolete | ||
633 | keys eventually disappear from keyservers. | ||
634 | |||
635 | To extend the expiration on your key by a year from current date, just | ||
636 | run:: | ||
637 | |||
638 | $ gpg --quick-set-expire [fpr] 1y | ||
639 | |||
640 | You can also use a specific date if that is easier to remember (e.g. | ||
641 | your birthday, January 1st, or Canada Day):: | ||
642 | |||
643 | $ gpg --quick-set-expire [fpr] 2020-07-01 | ||
644 | |||
645 | Remember to send the updated key back to keyservers:: | ||
646 | |||
647 | $ gpg --send-key [fpr] | ||
648 | |||
649 | Updating your work directory after any changes | ||
650 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
651 | |||
652 | After you make any changes to your key using the offline storage, you will | ||
653 | want to import these changes back into your regular working directory:: | ||
654 | |||
655 | $ gpg --export | gpg --homedir ~/.gnupg --import | ||
656 | $ unset GNUPGHOME | ||
657 | |||
658 | |||
659 | Using PGP with Git | ||
660 | ================== | ||
661 | |||
662 | One of the core features of Git is its decentralized nature -- once a | ||
663 | repository is cloned to your system, you have full history of the | ||
664 | project, including all of its tags, commits and branches. However, with | ||
665 | hundreds of cloned repositories floating around, how does anyone verify | ||
666 | that their copy of linux.git has not been tampered with by a malicious | ||
667 | third party? | ||
668 | |||
669 | Or what happens if a backdoor is discovered in the code and the "Author" | ||
670 | line in the commit says it was done by you, while you're pretty sure you | ||
671 | had `nothing to do with it`_? | ||
672 | |||
673 | To address both of these issues, Git introduced PGP integration. Signed | ||
674 | tags prove the repository integrity by assuring that its contents are | ||
675 | exactly the same as on the workstation of the developer who created the | ||
676 | tag, while signed commits make it nearly impossible for someone to | ||
677 | impersonate you without having access to your PGP keys. | ||
678 | |||
679 | .. _`nothing to do with it`: https://github.com/jayphelps/git-blame-someone-else | ||
680 | |||
681 | Configure git to use your PGP key | ||
682 | --------------------------------- | ||
683 | |||
684 | If you only have one secret key in your keyring, then you don't really | ||
685 | need to do anything extra, as it becomes your default key. However, if | ||
686 | you happen to have multiple secret keys, you can tell git which key | ||
687 | should be used (``[fpr]`` is the fingerprint of your key):: | ||
688 | |||
689 | $ git config --global user.signingKey [fpr] | ||
690 | |||
691 | **IMPORTANT**: If you have a distinct ``gpg2`` command, then you should | ||
692 | tell git to always use it instead of the legacy ``gpg`` from version 1:: | ||
693 | |||
694 | $ git config --global gpg.program gpg2 | ||
695 | |||
696 | How to work with signed tags | ||
697 | ---------------------------- | ||
698 | |||
699 | To create a signed tag, simply pass the ``-s`` switch to the tag | ||
700 | command:: | ||
701 | |||
702 | $ git tag -s [tagname] | ||
703 | |||
704 | Our recommendation is to always sign git tags, as this allows other | ||
705 | developers to ensure that the git repository they are pulling from has | ||
706 | not been maliciously altered. | ||
707 | |||
708 | How to verify signed tags | ||
709 | ~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
710 | |||
711 | To verify a signed tag, simply use the ``verify-tag`` command:: | ||
712 | |||
713 | $ git verify-tag [tagname] | ||
714 | |||
715 | If you are pulling a tag from another fork of the project repository, | ||
716 | git should automatically verify the signature at the tip you're pulling | ||
717 | and show you the results during the merge operation:: | ||
718 | |||
719 | $ git pull [url] tags/sometag | ||
720 | |||
721 | The merge message will contain something like this:: | ||
722 | |||
723 | Merge tag 'sometag' of [url] | ||
724 | |||
725 | [Tag message] | ||
726 | |||
727 | # gpg: Signature made [...] | ||
728 | # gpg: Good signature from [...] | ||
729 | |||
730 | If you are verifying someone else's git tag, then you will need to | ||
731 | import their PGP key. Please refer to the | ||
732 | ":ref:`verify_identities`" section below. | ||
733 | |||
734 | Configure git to always sign annotated tags | ||
735 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
736 | |||
737 | Chances are, if you're creating an annotated tag, you'll want to sign | ||
738 | it. To force git to always sign annotated tags, you can set a global | ||
739 | configuration option:: | ||
740 | |||
741 | $ git config --global tag.forceSignAnnotated true | ||
742 | |||
743 | How to work with signed commits | ||
744 | ------------------------------- | ||
745 | |||
746 | It is easy to create signed commits, but it is much more difficult to | ||
747 | use them in Linux kernel development, since it relies on patches sent to | ||
748 | the mailing list, and this workflow does not preserve PGP commit | ||
749 | signatures. Furthermore, when rebasing your repository to match | ||
750 | upstream, even your own PGP commit signatures will end up discarded. For | ||
751 | this reason, most kernel developers don't bother signing their commits | ||
752 | and will ignore signed commits in any external repositories that they | ||
753 | rely upon in their work. | ||
754 | |||
755 | However, if you have your working git tree publicly available at some | ||
756 | git hosting service (kernel.org, infradead.org, ozlabs.org, or others), | ||
757 | then the recommendation is that you sign all your git commits even if | ||
758 | upstream developers do not directly benefit from this practice. | ||
759 | |||
760 | We recommend this for the following reasons: | ||
761 | |||
762 | 1. Should there ever be a need to perform code forensics or track code | ||
763 | provenance, even externally maintained trees carrying PGP commit | ||
764 | signatures will be valuable for such purposes. | ||
765 | 2. If you ever need to re-clone your local repository (for example, | ||
766 | after a disk failure), this lets you easily verify the repository | ||
767 | integrity before resuming your work. | ||
768 | 3. If someone needs to cherry-pick your commits, this allows them to | ||
769 | quickly verify their integrity before applying them. | ||
770 | |||
771 | Creating signed commits | ||
772 | ~~~~~~~~~~~~~~~~~~~~~~~ | ||
773 | |||
774 | To create a signed commit, you just need to pass the ``-S`` flag to the | ||
775 | ``git commit`` command (it's capital ``-S`` due to collision with | ||
776 | another flag):: | ||
777 | |||
778 | $ git commit -S | ||
779 | |||
780 | Configure git to always sign commits | ||
781 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
782 | |||
783 | You can tell git to always sign commits:: | ||
784 | |||
785 | git config --global commit.gpgSign true | ||
786 | |||
787 | .. note:: | ||
788 | |||
789 | Make sure you configure ``gpg-agent`` before you turn this on. | ||
790 | |||
791 | .. _verify_identities: | ||
792 | |||
793 | How to verify kernel developer identities | ||
794 | ========================================= | ||
795 | |||
796 | Signing tags and commits is easy, but how does one go about verifying | ||
797 | that the key used to sign something belongs to the actual kernel | ||
798 | developer and not to a malicious imposter? | ||
799 | |||
800 | Configure auto-key-retrieval using WKD and DANE | ||
801 | ----------------------------------------------- | ||
802 | |||
803 | If you are not already someone with an extensive collection of other | ||
804 | developers' public keys, then you can jumpstart your keyring by relying | ||
805 | on key auto-discovery and auto-retrieval. GnuPG can piggyback on other | ||
806 | delegated trust technologies, namely DNSSEC and TLS, to get you going if | ||
807 | the prospect of starting your own Web of Trust from scratch is too | ||
808 | daunting. | ||
809 | |||
810 | Add the following to your ``~/.gnupg/gpg.conf``:: | ||
811 | |||
812 | auto-key-locate wkd,dane,local | ||
813 | auto-key-retrieve | ||
814 | |||
815 | DNS-Based Authentication of Named Entities ("DANE") is a method for | ||
816 | publishing public keys in DNS and securing them using DNSSEC signed | ||
817 | zones. Web Key Directory ("WKD") is the alternative method that uses | ||
818 | https lookups for the same purpose. When using either DANE or WKD for | ||
819 | looking up public keys, GnuPG will validate DNSSEC or TLS certificates, | ||
820 | respectively, before adding auto-retrieved public keys to your local | ||
821 | keyring. | ||
822 | |||
823 | Kernel.org publishes the WKD for all developers who have kernel.org | ||
824 | accounts. Once you have the above changes in your ``gpg.conf``, you can | ||
825 | auto-retrieve the keys for Linus Torvalds and Greg Kroah-Hartman (if you | ||
826 | don't already have them):: | ||
827 | |||
828 | $ gpg --locate-keys torvalds@kernel.org gregkh@kernel.org | ||
829 | |||
830 | If you have a kernel.org account, then you should `add the kernel.org | ||
831 | UID to your key`_ to make WKD more useful to other kernel developers. | ||
832 | |||
833 | .. _`add the kernel.org UID to your key`: https://korg.wiki.kernel.org/userdoc/mail#adding_a_kernelorg_uid_to_your_pgp_key | ||
834 | |||
835 | Web of Trust (WOT) vs. Trust on First Use (TOFU) | ||
836 | ------------------------------------------------ | ||
837 | |||
838 | PGP incorporates a trust delegation mechanism known as the "Web of | ||
839 | Trust." At its core, this is an attempt to replace the need for | ||
840 | centralized Certification Authorities of the HTTPS/TLS world. Instead of | ||
841 | various software makers dictating who should be your trusted certifying | ||
842 | entity, PGP leaves this responsibility to each user. | ||
843 | |||
844 | Unfortunately, very few people understand how the Web of Trust works. | ||
845 | While it remains an important aspect of the OpenPGP specification, | ||
846 | recent versions of GnuPG (2.2 and above) have implemented an alternative | ||
847 | mechanism called "Trust on First Use" (TOFU). You can think of TOFU as | ||
848 | "the SSH-like approach to trust." With SSH, the first time you connect | ||
849 | to a remote system, its key fingerprint is recorded and remembered. If | ||
850 | the key changes in the future, the SSH client will alert you and refuse | ||
851 | to connect, forcing you to make a decision on whether you choose to | ||
852 | trust the changed key or not. Similarly, the first time you import | ||
853 | someone's PGP key, it is assumed to be valid. If at any point in the | ||
854 | future GnuPG comes across another key with the same identity, both the | ||
855 | previously imported key and the new key will be marked as invalid and | ||
856 | you will need to manually figure out which one to keep. | ||
857 | |||
858 | We recommend that you use the combined TOFU+PGP trust model (which is | ||
859 | the new default in GnuPG v2). To set it, add (or modify) the | ||
860 | ``trust-model`` setting in ``~/.gnupg/gpg.conf``:: | ||
861 | |||
862 | trust-model tofu+pgp | ||
863 | |||
864 | How to use keyservers (more) safely | ||
865 | ----------------------------------- | ||
866 | |||
867 | If you get a "No public key" error when trying to validate someone's | ||
868 | tag, then you should attempt to lookup that key using a keyserver. It is | ||
869 | important to keep in mind that there is absolutely no guarantee that the | ||
870 | key you retrieve from PGP keyservers belongs to the actual person -- | ||
871 | that much is by design. You are supposed to use the Web of Trust to | ||
872 | establish key validity. | ||
873 | |||
874 | How to properly maintain the Web of Trust is beyond the scope of this | ||
875 | document, simply because doing it properly requires both effort and | ||
876 | dedication that tends to be beyond the caring threshold of most human | ||
877 | beings. Here are some shortcuts that will help you reduce the risk of | ||
878 | importing a malicious key. | ||
879 | |||
880 | First, let's say you've tried to run ``git verify-tag`` but it returned | ||
881 | an error saying the key is not found:: | ||
882 | |||
883 | $ git verify-tag sunxi-fixes-for-4.15-2 | ||
884 | gpg: Signature made Sun 07 Jan 2018 10:51:55 PM EST | ||
885 | gpg: using RSA key DA73759BF8619E484E5A3B47389A54219C0F2430 | ||
886 | gpg: issuer "wens@...org" | ||
887 | gpg: Can't check signature: No public key | ||
888 | |||
889 | Let's query the keyserver for more info about that key fingerprint (the | ||
890 | fingerprint probably belongs to a subkey, so we can't use it directly | ||
891 | without finding out the ID of the master key it is associated with):: | ||
892 | |||
893 | $ gpg --search DA73759BF8619E484E5A3B47389A54219C0F2430 | ||
894 | gpg: data source: hkp://keys.gnupg.net | ||
895 | (1) Chen-Yu Tsai <wens@...org> | ||
896 | 4096 bit RSA key C94035C21B4F2AEB, created: 2017-03-14, expires: 2019-03-15 | ||
897 | Keys 1-1 of 1 for "DA73759BF8619E484E5A3B47389A54219C0F2430". Enter number(s), N)ext, or Q)uit > q | ||
898 | |||
899 | Locate the ID of the master key in the output, in our example | ||
900 | ``C94035C21B4F2AEB``. Now display the key of Linus Torvalds that you | ||
901 | have on your keyring:: | ||
902 | |||
903 | $ gpg --list-key torvalds@kernel.org | ||
904 | pub rsa2048 2011-09-20 [SC] | ||
905 | ABAF11C65A2970B130ABE3C479BE3E4300411886 | ||
906 | uid [ unknown] Linus Torvalds <torvalds@kernel.org> | ||
907 | sub rsa2048 2011-09-20 [E] | ||
908 | |||
909 | Next, open the `PGP pathfinder`_. In the "From" field, paste the key | ||
910 | fingerprint of Linus Torvalds from the output above. In the "To" field, | ||
911 | paste they key-id you found via ``gpg --search`` of the unknown key, and | ||
912 | check the results: | ||
913 | |||
914 | - `Finding paths to Linus`_ | ||
915 | |||
916 | If you get a few decent trust paths, then it's a pretty good indication | ||
917 | that it is a valid key. You can add it to your keyring from the | ||
918 | keyserver now:: | ||
919 | |||
920 | $ gpg --recv-key C94035C21B4F2AEB | ||
921 | |||
922 | This process is not perfect, and you are obviously trusting the | ||
923 | administrators of the PGP Pathfinder service to not be malicious (in | ||
924 | fact, this goes against :ref:`devs_not_infra`). However, if you | ||
925 | do not carefully maintain your own web of trust, then it is a marked | ||
926 | improvement over blindly trusting keyservers. | ||
927 | |||
928 | .. _`PGP pathfinder`: https://pgp.cs.uu.nl/ | ||
929 | .. _`Finding paths to Linus`: https://pgp.cs.uu.nl/paths/79BE3E4300411886/to/C94035C21B4F2AEB.html | ||