maintainer-pgp-guide.rst 37 KB

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