maintainer-pgp-guide.rst 35 KB

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