]> git.ipfire.org Git - thirdparty/systemd.git/blame - man/systemd-measure.xml
meson: move systemd-cryptsetup to /usr/bin
[thirdparty/systemd.git] / man / systemd-measure.xml
CommitLineData
ca1092dc
LP
1<?xml version="1.0"?>
2<!--*-nxml-*-->
3<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
4 "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">
5<!-- SPDX-License-Identifier: LGPL-2.1-or-later -->
dfca5587 6<refentry id="systemd-measure" xmlns:xi="http://www.w3.org/2001/XInclude" conditional='ENABLE_BOOTLOADER'>
ca1092dc
LP
7
8 <refentryinfo>
9 <title>systemd-measure</title>
10 <productname>systemd</productname>
11 </refentryinfo>
12
13 <refmeta>
14 <refentrytitle>systemd-measure</refentrytitle>
15 <manvolnum>1</manvolnum>
16 </refmeta>
17
18 <refnamediv>
19 <refname>systemd-measure</refname>
cdaaa62c 20 <refpurpose>Pre-calculate and sign expected TPM2 PCR values for booted unified kernel images</refpurpose>
ca1092dc
LP
21 </refnamediv>
22
23 <refsynopsisdiv>
24 <cmdsynopsis>
25 <command>/usr/lib/systemd/systemd-measure <arg choice="opt" rep="repeat">OPTIONS</arg></command>
26 </cmdsynopsis>
27 </refsynopsisdiv>
28
29 <refsect1>
30 <title>Description</title>
31
32 <para>Note: this command is experimental for now. While it is likely to become a regular component of
33 systemd, it might still change in behaviour and interface.</para>
34
cdaaa62c 35 <para><command>systemd-measure</command> is a tool that may be used to pre-calculate and sign the
048bcb9d
ZJS
36 expected TPM2 PCR 11 values that should be seen when a Linux <ulink
37 url="https://uapi-group.org/specifications/specs/unified_kernel_image/">Unified Kernel Image
38 (UKI)</ulink> based on
ca1092dc 39 <citerefentry><refentrytitle>systemd-stub</refentrytitle><manvolnum>7</manvolnum></citerefentry> is
55c041b4
LP
40 booted up. It accepts paths to the ELF kernel image file, initrd image file, devicetree file, kernel
41 command line file,
2deca517
LP
42 <citerefentry><refentrytitle>os-release</refentrytitle><manvolnum>5</manvolnum></citerefentry> file, boot
43 splash file, and TPM2 PCR PEM public key file that make up the unified kernel image, and determines the
44 PCR values expected to be in place after booting the image. Calculation starts with a zero-initialized
048bcb9d
ZJS
45 PCR 11, and is executed in a fashion compatible with what <filename>systemd-stub</filename> does at boot.
46 The result may optionally be signed cryptographically, to allow TPM2 policies that can only be unlocked
47 if a certain set of kernels is booted, for which such a PCR signature can be provided.</para>
48
49 <para>It usually doesn't make sense to call this tool directly when constructing a UKI. Instead,
50 <citerefentry><refentrytitle>ukify</refentrytitle><manvolnum>1</manvolnum></citerefentry> should be used;
51 it will invoke <command>systemd-measure</command> and take care of embedding the resulting measurements
52 into the UKI.</para>
ca1092dc
LP
53 </refsect1>
54
55 <refsect1>
56 <title>Commands</title>
57
58 <para>The following commands are understood:</para>
59
60 <variablelist>
61 <varlistentry>
62 <term><command>status</command></term>
63
64 <listitem><para>This is the default command if none is specified. This queries the local system's
65 TPM2 PCR 11+12+13 values and displays them. The data is written in a similar format as the
66 <command>calculate</command> command below, and may be used to quickly compare expectation with
ec07c3c8
AK
67 reality.</para>
68
69 <xi:include href="version-info.xml" xpointer="v252"/></listitem>
ca1092dc
LP
70 </varlistentry>
71
72 <varlistentry>
73 <term><command>calculate</command></term>
74
cdaaa62c 75 <listitem><para>Pre-calculate the expected values seen in PCR register 11 after boot-up of a unified
ca1092dc
LP
76 kernel image consisting of the components specified with <option>--linux=</option>,
77 <option>--osrel=</option>, <option>--cmdline=</option>, <option>--initrd=</option>,
d5f91cf7
LB
78 <option>--splash=</option>, <option>--dtb=</option>, <option>--sbat=</option>,
79 <option>--pcrpkey=</option> see below. Only <option>--linux=</option> is mandatory. (Alternatively,
80 specify <option>--current</option> to use the current values of PCR register 11 instead.)</para>
ec07c3c8
AK
81
82 <xi:include href="version-info.xml" xpointer="v252"/>
d5f91cf7 83 </listitem>
cdaaa62c
LP
84 </varlistentry>
85
86 <varlistentry>
87 <term><command>sign</command></term>
88
89 <listitem><para>As with the <command>calculate</command> command, pre-calculate the expected value
90 seen in TPM2 PCR register 11 after boot-up of a unified kernel image. Then, cryptographically sign
91 the resulting values with the private/public key pair (RSA) configured via
92 <option>--private-key=</option> and <option>--public-key=</option>. This will write a JSON object to
8b9f0921 93 standard output that contains signatures for all specified PCR banks (see the
916db27f 94 <option>--bank=</option> option below), which may be used to unlock encrypted credentials (see
cdaaa62c
LP
95 <citerefentry><refentrytitle>systemd-creds</refentrytitle><manvolnum>1</manvolnum></citerefentry>) or
96 LUKS volumes (see
8b9f0921
ZJS
97 <citerefentry><refentrytitle>systemd-cryptsetup@.service</refentrytitle><manvolnum>8</manvolnum></citerefentry>).
98 This allows binding secrets to a set of kernels for which such PCR 11 signatures can be
99 provided.</para>
cdaaa62c
LP
100
101 <para>Note that a TPM2 device must be available for this signing to take place, even though the
ec07c3c8
AK
102 result is not tied to any TPM2 device or its state.</para>
103
104 <xi:include href="version-info.xml" xpointer="v252"/></listitem>
ca1092dc
LP
105 </varlistentry>
106 </variablelist>
107 </refsect1>
108
109 <refsect1>
110 <title>Options</title>
111
112 <para>The following options are understood:</para>
113
114 <variablelist>
115 <varlistentry>
8b9f0921
ZJS
116 <term><option>--linux=<replaceable>PATH</replaceable></option></term>
117 <term><option>--osrel=<replaceable>PATH</replaceable></option></term>
118 <term><option>--cmdline=<replaceable>PATH</replaceable></option></term>
119 <term><option>--initrd=<replaceable>PATH</replaceable></option></term>
120 <term><option>--splash=<replaceable>PATH</replaceable></option></term>
121 <term><option>--dtb=<replaceable>PATH</replaceable></option></term>
d5f91cf7 122 <term><option>--sbat=<replaceable>PATH</replaceable></option></term>
8b9f0921 123 <term><option>--pcrpkey=<replaceable>PATH</replaceable></option></term>
ca1092dc 124
cdaaa62c
LP
125 <listitem><para>When used with the <command>calculate</command> or <command>sign</command> verb,
126 configures the files to read the unified kernel image components from. Each option corresponds with
127 the equally named section in the unified kernel PE file. The <option>--linux=</option> switch expects
128 the path to the ELF kernel file that the unified PE kernel will wrap. All switches except
aefdc112
AK
129 <option>--linux=</option> are optional. Each option may be used at most once.</para>
130
131 <xi:include href="version-info.xml" xpointer="v252"/></listitem>
ca1092dc
LP
132 </varlistentry>
133
127b72da
LP
134 <varlistentry>
135 <term><option>--current</option></term>
cdaaa62c
LP
136 <listitem><para>When used with the <command>calculate</command> or <command>sign</command> verb,
137 takes the PCR 11 values currently in effect for the system (which should typically reflect the hashes
138 of the currently booted kernel). This can be used in place of <option>--linux=</option> and the other
ec07c3c8
AK
139 switches listed above.</para>
140
141 <xi:include href="version-info.xml" xpointer="v252"/></listitem>
127b72da
LP
142 </varlistentry>
143
ca1092dc 144 <varlistentry>
8b9f0921 145 <term><option>--bank=<replaceable>DIGEST</replaceable></option></term>
ca1092dc
LP
146
147 <listitem><para>Controls the PCR banks to pre-calculate the PCR values for – in case
cdaaa62c
LP
148 <command>calculate</command> or <command>sign</command> is invoked –, or the banks to show in the
149 <command>status</command> output. May be used more then once to specify multiple banks. If not
150 specified, defaults to the four banks <literal>sha1</literal>, <literal>sha256</literal>,
ec07c3c8
AK
151 <literal>sha384</literal>, <literal>sha512</literal>.</para>
152
153 <xi:include href="version-info.xml" xpointer="v252"/></listitem>
cdaaa62c
LP
154 </varlistentry>
155
156 <varlistentry>
8b9f0921
ZJS
157 <term><option>--private-key=<replaceable>PATH</replaceable></option></term>
158 <term><option>--public-key=<replaceable>PATH</replaceable></option></term>
cdaaa62c
LP
159
160 <listitem><para>These switches take paths to a pair of PEM encoded RSA key files, for use with
2deca517
LP
161 the <command>sign</command> command.</para>
162
163 <para>Note the difference between the <option>--pcrpkey=</option> and <option>--public-key=</option>
164 switches. The former selects the data to include in the <literal>.pcrpkey</literal> PE section of the
165 unified kernel image, the latter picks the public key of the key pair used to sign the resulting PCR
166 11 values. The former is the key that the booted system will likely use to lock disk and credential
167 encryption to, the latter is the key used for unlocking such resources again. Hence, typically the
a434e25f
LP
168 same PEM key should be supplied in both cases.</para>
169
170 <para>If the <option>--public-key=</option> is not specified but <option>--private-key=</option> is
ec07c3c8
AK
171 specified the public key is automatically derived from the private key.</para>
172
173 <xi:include href="version-info.xml" xpointer="v252"/></listitem>
cdaaa62c
LP
174 </varlistentry>
175
176 <varlistentry>
177 <term><option>--tpm2-device=</option><replaceable>PATH</replaceable></term>
178
179 <listitem><para>Controls which TPM2 device to use. Expects a device node path referring to the TPM2
180 chip (e.g. <filename>/dev/tpmrm0</filename>). Alternatively the special value <literal>auto</literal>
181 may be specified, in order to automatically determine the device node of a suitable TPM2 device (of
182 which there must be exactly one). The special value <literal>list</literal> may be used to enumerate
ec07c3c8
AK
183 all suitable TPM2 devices currently discovered.</para>
184
185 <xi:include href="version-info.xml" xpointer="v252"/></listitem>
ca1092dc
LP
186 </varlistentry>
187
6ca00163
LP
188 <varlistentry>
189 <term><option>--phase=</option><replaceable>PHASE</replaceable></term>
190
0923b425 191 <listitem><para>Controls which boot phases to calculate expected PCR 11 values for. This takes a
6ca00163
LP
192 series of colon-separated strings that encode boot "paths" for entering a specific phase of the boot
193 process. Each of the specified strings is measured by the
194 <filename>systemd-pcrphase-initrd.service</filename> and
195 <citerefentry><refentrytitle>systemd-pcrphase.service</refentrytitle><manvolnum>8</manvolnum></citerefentry>
196 into PCR 11 during different milestones of the boot process. This switch may be specified multiple
197 times to calculate PCR values for multiple boot phases at once. If not used defaults to
198 <literal>enter-initrd</literal>, <literal>enter-initrd:leave-initrd</literal>,
047273e6
LP
199 <literal>enter-initrd:leave-initrd:sysinit</literal>,
200 <literal>enter-initrd:leave-initrd:sysinit:ready</literal>, i.e. calculates expected PCR values for
201 the boot phase in the initrd, during early boot, during later boot, and during system runtime, but
202 excluding the phases before the initrd or when shutting down. This setting is honoured both by
203 <command>calculate</command> and <command>sign</command>. When used with the latter it's particularly
204 useful for generating PCR signatures that can only be used for unlocking resources during specific
205 parts of the boot process.</para>
6ca00163
LP
206
207 <para>For further details about PCR boot phases, see
ec07c3c8
AK
208 <citerefentry><refentrytitle>systemd-pcrphase.service</refentrytitle><manvolnum>8</manvolnum></citerefentry>.</para>
209
210 <xi:include href="version-info.xml" xpointer="v252"/></listitem>
6ca00163
LP
211 </varlistentry>
212
a5c690a8
LP
213 <varlistentry>
214 <term><option>--append=</option><replaceable>PATH</replaceable></term>
215
216 <listitem><para>When generating a PCR JSON signature (via the <command>sign</command> command),
217 combine it with a previously generated PCR JSON signature, and output it as one. The specified path
218 must refer to a regular file that contains a valid JSON PCR signature object. The specified file is
219 not modified. It will be read first, then the newly generated signature appended to it, and the
220 resulting object is written to standard output. Use this to generate a single JSON object consisting
221 from signatures made with a number of signing keys (for example, to have one key per boot phase). The
222 command will suppress duplicates: if a specific signature is already included in a JSON signature
ec07c3c8
AK
223 object it is not added a second time.</para>
224
225 <xi:include href="version-info.xml" xpointer="v253"/></listitem>
a5c690a8
LP
226 </varlistentry>
227
c06b6d46
LP
228 <xi:include href="standard-options.xml" xpointer="json" />
229 <xi:include href="standard-options.xml" xpointer="no-pager" />
ca1092dc
LP
230 <xi:include href="standard-options.xml" xpointer="help" />
231 <xi:include href="standard-options.xml" xpointer="version" />
232 </variablelist>
233 </refsect1>
234
235 <refsect1>
236 <title>Examples</title>
237
238 <example>
239 <title>Generate a unified kernel image, and calculate the expected TPM PCR 11 value</title>
240
048bcb9d
ZJS
241 <programlisting>$ ukify --output=vmlinux.efi \
242 --os-release=@os-release.txt \
243 --cmdline=@cmdline.txt \
244 --splash=splash.bmp \
245 --devicetree=devicetree.dtb \
e069c57f
JJ
246 --measure \
247 vmlinux initrd.cpio
ca1092dc
LP
24811:sha1=d775a7b4482450ac77e03ee19bda90bd792d6ec7
24911:sha256=bc6170f9ce28eb051ab465cd62be8cf63985276766cf9faf527ffefb66f45651
048bcb9d
ZJS
25011:sha384=1cf67dff4757e61e5...7f49ad720be02fd07263e1f93061243aec599d1ee4b4
25111:sha512=8e79acd3ddbbc8282...0c3e8ec0c714821032038f525f744960bcd082d937da
ca1092dc 252</programlisting>
048bcb9d
ZJS
253
254 <para><citerefentry><refentrytitle>ukify</refentrytitle><manvolnum>1</manvolnum></citerefentry>
255 internally calls <command>systemd-measure</command>. The output with hashes is from
256 <command>systemd-measure</command>.</para>
ca1092dc 257 </example>
cdaaa62c
LP
258
259 <example>
048bcb9d 260 <title>Generate a private/public key pair, a unified kernel image, and a TPM PCR 11 signature for
2deca517 261 it, and embed the signature and the public key in the image</title>
cdaaa62c 262
048bcb9d
ZJS
263 <programlisting>$ openssl genpkey -algorithm RSA -pkeyopt rsa_keygen_bits:2048 -out tpm2-pcr-private.pem
264..+.+++++++++......+.........+......+.......+....+.....+.+...+..........
265$ openssl rsa -pubout -in tpm2-pcr-private.pem -out tpm2-pcr-public.pem
cdaaa62c
LP
266# systemd-measure sign \
267 --linux=vmlinux \
268 --osrel=os-release.txt \
269 --cmdline=cmdline.txt \
270 --initrd=initrd.cpio \
271 --splash=splash.bmp \
272 --dtb=devicetree.dtb \
2deca517 273 --pcrpkey=tpm2-pcr-public.pem \
cdaaa62c
LP
274 --bank=sha1 \
275 --bank=sha256 \
276 --private-key=tpm2-pcr-private.pem \
7a17e41d 277 --public-key=tpm2-pcr-public.pem >tpm2-pcr-signature.json
048bcb9d
ZJS
278# ukify --output=vmlinuz.efi \
279 --os-release=@os-release.txt \
280 --cmdline=@cmdline.txt \
281 --splash=splash.bmp \
282 --devicetree=devicetree.dtb \
283 --pcr-private-key=tpm2-pcr-private.pem \
284 --pcr-public-key=tpm2-pcr-public.pem \
285 --pcr-banks=sha1,sha256 \
e069c57f 286 vmlinux initrd.cpio</programlisting>
cdaaa62c
LP
287
288 <para>Later on, enroll the signed PCR policy on a LUKS volume:</para>
289
048bcb9d
ZJS
290 <programlisting># systemd-cryptenroll --tpm2-device=auto \
291 --tpm2-public-key=tpm2-pcr-public.pem \
292 --tpm2-signature=tpm2-pcr-signature.json \
293 /dev/sda5</programlisting>
cdaaa62c
LP
294
295 <para>And then unlock the device with the signature:</para>
296
fb8d67cd 297 <programlisting># systemd-cryptsetup attach \
048bcb9d
ZJS
298 volume5 /dev/sda5 - \
299 tpm2-device=auto,tpm2-signature=/path/to/tpm2-pcr-signature.json</programlisting>
2deca517 300
048bcb9d 301 <para>Note that when the generated unified kernel image <filename>vmlinux.efi</filename> is booted, the
2deca517
LP
302 signature and public key files will be placed at locations <command>systemd-cryptenroll</command> and
303 <command>systemd-cryptsetup</command> will look for anyway, and thus these paths do not actually need to
304 be specified.</para>
cdaaa62c 305 </example>
7eb51b8e
LP
306
307 <example>
308 <title>Introduce a second public key, signing the same kernel PCR measurements, but only for the initrd boot phase</title>
309
310 <para>This example extends the previous one, but we now introduce a second signing key that is only
311 used to sign PCR policies restricted to the initrd boot phase. This can be used to lock down root
312 volumes in a way that they can only be unlocked before the transition to the host system. Thus we have
313 two classes of secrets or credentials: one that can be unlocked during the entire runtime, and the
314 other that can only be used in the initrd.</para>
315
048bcb9d
ZJS
316 <programlisting>$ openssl genpkey -algorithm RSA -pkeyopt rsa_keygen_bits:2048 -out tpm2-pcr-private.pem
317.+........+.+........+.......+...+...+........+....+......+..+..........
318$ openssl rsa -pubout -in tpm2-pcr-private.pem -out tpm2-pcr-public.pem
319$ openssl genpkey -algorithm RSA -pkeyopt rsa_keygen_bits:2048 -out tpm2-pcr-initrd-private.pem
320..+.......++........+........+......+........+....+.....+.+..+..........
321$ openssl rsa -pubout -in tpm2-pcr-initrd-private.pem -out tpm2-pcr-initrd-public.pem
322# ukify --output vmlinux-1.2.3.efi \
323 --os-release=@os-release.txt \
324 --cmdline=@cmdline.txt \
7eb51b8e 325 --splash=splash.bmp \
048bcb9d
ZJS
326 --devicetree=devicetree.dtb \
327 --pcr-private-key=tpm2-pcr-private.pem \
328 --pcr-public-key=tpm2-pcr-public.pem \
329 --phases=enter-initrd,enter-initrd:leave-initrd,enter-initrd:leave-initrd:sysinit,enter-initrd:leave-initrd:sysinit:ready \
330 --pcr-banks=sha1,sha256 \
331 --pcr-private-key=tpm2-pcr-initrd-private.pem \
332 --pcr-public-key=tpm2-pcr-initrd-public.pem \
333 --phases=enter-initrd \
334 vmlinux-1.2.3 initrd.cpio \
335 --uname=1.2.3
336+ /usr/lib/systemd/systemd-measure sign --linux=vmlinux-1.2.3 \
337--osrel=os-release.txt --cmdline=cmdline.txt --dtb=devicetree.dtb \
338--splash=splash.bmp --initrd=initrd.cpio --bank=sha1 --bank=sha256 \
339--private-key=tpm2-pcr-private.pem --public-key=tpm2-pcr-public.pem \
340--phase=enter-initrd --phase=enter-initrd:leave-initrd \
341--phase=enter-initrd:leave-initrd:sysinit \
342--phase=enter-initrd:leave-initrd:sysinit:ready
343+ /usr/lib/systemd/systemd-measure sign --linux=vmlinux-1.2.3 \
344--osrel=os-release.txt --cmdline=cmdline.txt --dtb=devicetree.dtb \
345--splash=splash.bmp --initrd=initrd.cpio --bank=sha1 --bank=sha256 \
346--private-key=tpm2-pcr-initrd-private.pem \
347--public-key=tpm2-pcr-initrd-public.pem \
348--phase=enter-initrd
349Wrote unsigned vmlinux-1.2.3.efi
350 </programlisting>
351
352 <para><command>ukify</command> prints out both invocations of <command>systemd-measure</command> as
353 informative output (the lines starting with <literal>+</literal>); this allows us to see how
354 <command>systemd-measure</command> is called. It then merges the output of both invocations into the
355 <literal>.pcrsig</literal> section. <command>systemd-measure</command> may also do this merge itself
356 using the <option>--append=</option> option.</para>
357
358 <para>Note that in this example the <literal>.pcrpkey</literal> PE section contains the key specified
359 by the first <option>--pcr-private-key=</option> option, covering all boot phases. The
360 <literal>.pcrpkey</literal> section is used in the default policies of
361 <command>systemd-cryptenroll</command> and <command>systemd-creds</command>. To use the stricter policy
362 bound to <filename>tpm-pcr-initrd-public.pem</filename>, specify <option>--tpm2-public-key=</option> on
363 the command line of those tools.</para>
7eb51b8e 364 </example>
ca1092dc
LP
365 </refsect1>
366
367 <refsect1>
368 <title>Exit status</title>
369
370 <para>On success, 0 is returned, a non-zero failure code otherwise.</para>
371 </refsect1>
372
373 <refsect1>
374 <title>See Also</title>
375 <para>
376 <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
377 <citerefentry><refentrytitle>systemd-stub</refentrytitle><manvolnum>7</manvolnum></citerefentry>,
e069c57f 378 <citerefentry><refentrytitle>ukify</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
cdaaa62c 379 <citerefentry><refentrytitle>systemd-creds</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
708d7524 380 <citerefentry><refentrytitle>systemd-cryptsetup@.service</refentrytitle><manvolnum>8</manvolnum></citerefentry>,
9e60dc0d 381 <citerefentry><refentrytitle>systemd-pcrphase.service</refentrytitle><manvolnum>8</manvolnum></citerefentry>
ca1092dc
LP
382 </para>
383 </refsect1>
384
385</refentry>