@@ -107,7 +107,7 @@ Create the RSA key<br>
1071071 . ` tpm2_createprimary --hierarchy=o --key-algorithm=rsa --key-context=prim.ctx ` <br >
108108
109109Save it to the TPM persistent memory<br >
110- {: start ="2"}
110+ {: start ="2"}< br >
1111112 . ` tpm2_evictcontrol --hierarchy=o --object-context=prim.ctx 0x81010001 ` <br >
112112
113113NOTE:
@@ -140,7 +140,7 @@ first setup a disk image without encryption and see if we can extract user
140140generated content.<br >
141141
142142Create a disk image and write some content:<br >
143- {: start ="3"}
143+ {: start ="3"}< br >
1441443 . ` dd if=/dev/zero of=plain.disk bs=1M count=10 ` <br >
1451454 . ` mkfs.ext4 plain.disk ` <br >
1461465 . ` mkdir -p mountpoint ` <br >
@@ -177,7 +177,7 @@ provided as a password just in time (default) and or specified as key file
177177managing LUKS volumes.<br >
178178
179179Let's setup a new LUKS volume with a simple passphrase as key protector:<br >
180- {: start ="12"}
180+ {: start ="12"}< br >
18118112 . ` dd if=/dev/zero of=enc.disk bs=1M count=10 ` <br >
18218213 . ` dd if=/dev/urandom of=disk.key bs=1 count=32 ` <br >
18318314 . ` loopdevice=$(losetup -f) && sudo losetup $loopdevice enc.disk ` <br >
@@ -186,13 +186,13 @@ Let's setup a new LUKS volume with a simple passphrase as key protector:<br>
186186At this point you have setup the luks volume and it should pop a warning about
187187overriding the data. Next let's open the LUKS volume by authenticating with the
188188disk.key and complete the setting up the disk with a filesystem.<br >
189- {: start ="16"}
189+ {: start ="16"}< br >
19019016 . ` sudo cryptsetup luksOpen --key-file=disk.key $loopdevice enc_volume ` <br >
19119117 . ` sudo mkfs.ext4 -j /dev/mapper/enc_volume ` <br >
19219218 . ` sudo mount /dev/mapper/enc_volume mountpoint ` <br >
193193
194194Now lets create a plain text file again and add user content to it:<br >
195- {: start ="16"}
195+ {: start ="19"}< br >
19619619 . ` sudo touch mountpoint/plain.txt ` <br >
19719720 . ` sudo chmod 777 mountpoint/plain.txt ` <br >
19819821 . ` sudo echo "This is my plain text" > mountpoint/plain.txt ` <br >
@@ -202,7 +202,7 @@ Now lets create a plain text file again and add user content to it:<br>
202202
203203You will now see that you cannot dump the information from the disk image simply
204204: <br >
205- {: start ="25"}
205+ {: start ="25"}< br >
20620625 . ` strings enc.disk | grep -i plain ` <br >
207207
208208NOTE:
@@ -225,7 +225,7 @@ b. Unseal the secret in memory and pass it to cryptsetup.<br>
225225
226226Let's start with creating and persisting a sealing object and sealing a random
227227byte sequence as the disk key.<br >
228- {: start ="26"}
228+ {: start ="26"}< br >
22922926 . ` tpm2_createprimary -Q -C o -c prim.ctx ` <br >
23023027 . ` dd if=/dev/urandom bs=1 count=32 status=none | tpm2_create -Q -g sha256 -u seal.pub -r seal.priv -i- -C prim.ctx ` <br >
23123128 . ` tpm2_load -Q -C prim.ctx -u seal.pub -r seal.priv -n seal.name -c seal.ctx ` <br >
@@ -238,18 +238,18 @@ sealed secret and after that shred the disk.key since it's no longer useful:<br>
23823831 . ` shred disk.key; rm -f disk.key ` <br >
239239
240240Now let's mount the volume with the new authentication sealed up in the tpm:<br >
241- {: start ="32"}
241+ {: start ="32"}< br >
24224232 . ` sudo losetup $loopdevice enc.disk ` <br >
24324333 . ` tpm2_unseal -Q -c 0x81010001 |sudo cryptsetup luksOpen --key-file=- $loopdevice enc_volume ` <br >
24424434 . ` sudo mount /dev/mapper/enc_volume mountpoint ` <br >
245245
246246You can now see that disk access is granted with the new secret:<br >
247- {: start ="35"}
247+ {: start ="35"}< br >
24824835 . ` ls mountpoint `
249249<br >
250250
251251Finally unmount the disk:<br >
252- {: start ="36"}
252+ {: start ="36"}< br >
25325336 . ` sudo umount mountpoint ` <br >
25425437 . ` sudo cryptsetup remove enc_volume ` <br >
25525538 . ` sudo losetup -d $loopdevice ` <br >
@@ -284,15 +284,15 @@ c. After unsealing the pass-phrase; extend the sealing PCRs so that the
284284pass-phrase cannot be unsealed gain.<br >
285285
286286Let's begin with creating a pcr policy with current value in PCR0 sha256 bank<br >
287- {: start ="39"}
287+ {: start ="39"}< br >
28828839 . ` tpm2_startauthsession -S session.ctx ` <br >
28928940 . ` tpm2_policypcr -Q -S session.ctx -l sha256:0 -L pcr0.sha256.policy ` <br >
29029041 . ` tpm2_flushcontext session.ctx ` <br >
291291
292292Now replace the seal object in TPM NV memory protecting the disk encryption
293293secret with a new one that adds the pcr policy we just created as an
294294authentication mechanism to access the sealed secret.<br >
295- {: start ="42"}
295+ {: start ="42"}< br >
29629642 . ` tpm2_unseal -c 0x81010001 | tpm2_create -Q -g sha256 -u pcr_seal_key.pub -r pcr_seal_key.priv -i- -C prim.ctx -L pcr0.sha256.policy ` <br >
29729743 . ` tpm2_evictcontrol -C o -c 0x81010001 ` <br >
29829844 . ` tpm2_load -Q -C prim.ctx -u pcr_seal_key.pub -r pcr_seal_key.priv -n pcr_seal_key.name -c pcr_seal_key.ctx ` <br >
@@ -302,7 +302,7 @@ Now let's try to mount the encrypted disk again but this time the secret is
302302unsealed off a TPM object whose unsealing operation can only be accessed by
303303satisfying the PCR policy; in other words authenticating by virtue of intended
304304system software state being unchanged as reflected by the PCR value.<br >
305- {: start ="46"}
305+ {: start ="46"}< br >
30630646 . ` sudo losetup $loopdevice enc.disk ` <br >
30730747 . ` tpm2_startauthsession --policy-session -S session.ctx ` <br >
30830848 . ` tpm2_policypcr -Q -S session.ctx -l sha256:0 ` <br >
@@ -313,7 +313,7 @@ directly to the cryptsetup app like this --> "tpm2_unseal -p session:session.ctx
313313However for the purpose of demonstrating flexible PCR in a later section we will
314314make a copy of the unsealed secret at this point to seal it with a new object
315315with flexible pcr policy. This breakdown to two steps<br >
316- {: start ="49"}
316+ {: start ="49"}< br >
31731749 . ` tpm2_unseal -p session:session.ctx -c 0x81010001 > disk_secret.bkup ` <br >
31831850 . ` cat disk_secret.bkup | sudo cryptsetup luksOpen --key-file=- $loopdevice enc_volume ` <br >
31931951 . ` tpm2_flushcontext session.ctx ` <br >
@@ -329,19 +329,19 @@ consequence of failed policy check and thus a failed unsealing attempt.<br>
329329
330330Let's look at the PCR state prior to extending it and then again after
331331extending: <br >
332- {: start ="54"}
332+ {: start ="54"}< br >
33333354 . ` tpm2_pcrlist -l sha256:0 ` <br >
33433455 . ` tpm2_pcrextend 0:sha256=0000000000000000000000000000000000000000000000000000000000000000 ` <br >
33533556 . ` tpm2_pcrlist -l sha256:0 ` <br >
336336
337337Now let's try to unseal the sealed disk encryption secret with the dirty
338338PCR:<br >
339- {: start ="57"}
339+ {: start ="57"}< br >
34034057 . ` tpm2_startauthsession --policy-session -S session.ctx ` <br >
34134158 . ` tpm2_policypcr -Q -S session.ctx -l sha256:0 ` <br >
342342The following operation should result in policy check failure preventing the
343343unseal operation:<br >
344- {: start ="59"}
344+ {: start ="59"}< br >
34534559 . ` tpm2_unseal -p session:session.ctx -c 0x81010001 ` <br >
34634660 . ` tpm2_flushcontext session.ctx ` <br >
347347
@@ -366,7 +366,7 @@ PCR signature. The PCR sets are signed by the system designer and verified by
366366the TPM. This is achieved in following steps:
367367
368368__ a. Get the new set of PCR and sign the pcr policy with signer private key.__ <br >
369- {: start ="61"}
369+ {: start ="61"}< br >
37037061 . ` tpm2_startauthsession -S session.ctx ` <br >
37137162 . ` tpm2_policypcr -Q -S session.ctx -l sha256:0 -L set2.pcr.policy ` <br >
37237263 . ` tpm2_flushcontext session.ctx ` <br >
@@ -375,11 +375,11 @@ __a. Get the new set of PCR and sign the pcr policy with signer private key.__<b
375375
376376We now need the name which is a digest of the TCG public key format of the
377377public key to include in the policy. We can use the loadexternal tool for this:<br >
378- {: start ="66"}
378+ {: start ="66"}< br >
37937966 . ` tpm2_loadexternal -G rsa -C o -u signing_key_public.pem -c signing_key.ctx -n signing_key.name ` <br >
380380
381381Let's now create the signer policy:<br >
382- {: start ="66"}
382+ {: start ="67"}< br >
38338367 . ` tpm2_startauthsession -S session.ctx ` <br >
38438468 . ` tpm2_policyauthorize -S session.ctx -L authorized.policy -n signing_key.name -i set2.pcr.policy ` <br >
38538569 . ` tpm2_flushcontext session.ctx ` <br >
@@ -388,12 +388,12 @@ Let's create a new sealing object with the authorized policy which will also
388388require the sealing secret for which we will use the disk_secret.bkup we created
389389at #49 earlier to avoid rebooting the platform to match the PCR we originally
390390had prior to extending.<br >
391- {: start ="70"}
391+ {: start ="70"}< br >
39239270 . ` cat disk_secret.bkup | tpm2_create -g sha256 -u auth_pcr_seal_key.pub -r auth_pcr_seal_key.priv -i- -C prim.ctx -L authorized.policy ` <br >
393393
394394Let's replace the old persistent sealing object with the one we created
395395above with policy_authorize policy associated with signer public key:<br >
396- {: start ="71"}
396+ {: start ="71"}< br >
39739771 . ` tpm2_evictcontrol -C o -c 0x81010001 ` <br >
39839872 . ` tpm2_load -Q -C prim.ctx -u auth_pcr_seal_key.pub -r auth_pcr_seal_key.priv -n auth_pcr_seal_key.name -c auth_pcr_seal_key.ctx ` <br >
39939973 . ` tpm2_evictcontrol -c auth_pcr_seal_key.ctx 0x81010001 -C o ` <br >
@@ -402,18 +402,18 @@ Let's now sign the pcr_policy with the signer private key:<br>
402402
403403__ b. Load the signer public key to the tpm and verify the signature on the pcr
404404and get the tpm verification tkt:__ <br >
405- {: start ="75"}
405+ {: start ="75"}< br >
40640675 . ` tpm2_loadexternal -G rsa -C o -u signing_key_public.pem -c signing_key.ctx -n signing_key.name ` <br >
40740776 . ` tpm2_verifysignature -c signing_key.ctx -g sha256 -m set2.pcr.policy -s set2.pcr.signature -t verification.tkt -f rsassa ` <br >
408408
409409__ c. Satisfy the authorized policy and then run policyauthorize:__ <br >
410- {: start ="77"}
410+ {: start ="77"}< br >
41141177 . ` tpm2_startauthsession --policy-session -S session.ctx ` <br >
41241278 . ` tpm2_policypcr -l sha256:0 -S session.ctx ` <br >
41341379 . ` tpm2_policyauthorize -S session.ctx -i set2.pcr.policy -n signing_key.name -t verification.tkt ` <br >
414414
415415__ d. Pipe unseal output to the cryptsetup application:__ <br >
416- {: start ="80"}
416+ {: start ="80"}< br >
41741780 . ` sudo losetup $loopdevice enc.disk ` <br >
41841881 . ` tpm2_unseal -p session:session.ctx -c 0x81010001 | sudo cryptsetup luksOpen --key-file=- $loopdevice enc_volume ` <br >
41941982 . ` tpm2_flushcontext session.ctx ` <br >
0 commit comments