Skip to content

Commit 2327034

Browse files
clayrosenthalidesai
authored andcommitted
Update 2020-04-13-Disk-Encryption.md
adding `<br>` to the start tags Signed-off-by: Clayton Rosenthal <crosenthal@covariant.ai>
1 parent 503ddf0 commit 2327034

1 file changed

Lines changed: 25 additions & 25 deletions

File tree

_posts/2020-04-13-Disk-Encryption.md

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ Create the RSA key<br>
107107
1. `tpm2_createprimary --hierarchy=o --key-algorithm=rsa --key-context=prim.ctx`<br>
108108

109109
Save it to the TPM persistent memory<br>
110-
{:start="2"}
110+
{:start="2"}<br>
111111
2. `tpm2_evictcontrol --hierarchy=o --object-context=prim.ctx 0x81010001`<br>
112112

113113
NOTE:
@@ -140,7 +140,7 @@ first setup a disk image without encryption and see if we can extract user
140140
generated content.<br>
141141

142142
Create a disk image and write some content:<br>
143-
{:start="3"}
143+
{:start="3"}<br>
144144
3. `dd if=/dev/zero of=plain.disk bs=1M count=10`<br>
145145
4. `mkfs.ext4 plain.disk`<br>
146146
5. `mkdir -p mountpoint`<br>
@@ -177,7 +177,7 @@ provided as a password just in time (default) and or specified as key file
177177
managing LUKS volumes.<br>
178178

179179
Let's setup a new LUKS volume with a simple passphrase as key protector:<br>
180-
{:start="12"}
180+
{:start="12"}<br>
181181
12. `dd if=/dev/zero of=enc.disk bs=1M count=10`<br>
182182
13. `dd if=/dev/urandom of=disk.key bs=1 count=32`<br>
183183
14. `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>
186186
At this point you have setup the luks volume and it should pop a warning about
187187
overriding the data. Next let's open the LUKS volume by authenticating with the
188188
disk.key and complete the setting up the disk with a filesystem.<br>
189-
{:start="16"}
189+
{:start="16"}<br>
190190
16. `sudo cryptsetup luksOpen --key-file=disk.key $loopdevice enc_volume`<br>
191191
17. `sudo mkfs.ext4 -j /dev/mapper/enc_volume`<br>
192192
18. `sudo mount /dev/mapper/enc_volume mountpoint`<br>
193193

194194
Now lets create a plain text file again and add user content to it:<br>
195-
{:start="16"}
195+
{:start="19"}<br>
196196
19. `sudo touch mountpoint/plain.txt`<br>
197197
20. `sudo chmod 777 mountpoint/plain.txt`<br>
198198
21. `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

203203
You will now see that you cannot dump the information from the disk image simply
204204
: <br>
205-
{:start="25"}
205+
{:start="25"}<br>
206206
25. `strings enc.disk | grep -i plain`<br>
207207

208208
NOTE:
@@ -225,7 +225,7 @@ b. Unseal the secret in memory and pass it to cryptsetup.<br>
225225

226226
Let's start with creating and persisting a sealing object and sealing a random
227227
byte sequence as the disk key.<br>
228-
{:start="26"}
228+
{:start="26"}<br>
229229
26. `tpm2_createprimary -Q -C o -c prim.ctx`<br>
230230
27. `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>
231231
28. `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>
238238
31. `shred disk.key; rm -f disk.key`<br>
239239

240240
Now let's mount the volume with the new authentication sealed up in the tpm:<br>
241-
{:start="32"}
241+
{:start="32"}<br>
242242
32. `sudo losetup $loopdevice enc.disk`<br>
243243
33. `tpm2_unseal -Q -c 0x81010001 |sudo cryptsetup luksOpen --key-file=- $loopdevice enc_volume`<br>
244244
34. `sudo mount /dev/mapper/enc_volume mountpoint`<br>
245245

246246
You can now see that disk access is granted with the new secret:<br>
247-
{:start="35"}
247+
{:start="35"}<br>
248248
35. `ls mountpoint`
249249
<br>
250250

251251
Finally unmount the disk:<br>
252-
{:start="36"}
252+
{:start="36"}<br>
253253
36. `sudo umount mountpoint`<br>
254254
37. `sudo cryptsetup remove enc_volume`<br>
255255
38. `sudo losetup -d $loopdevice`<br>
@@ -284,15 +284,15 @@ c. After unsealing the pass-phrase; extend the sealing PCRs so that the
284284
pass-phrase cannot be unsealed gain.<br>
285285

286286
Let's begin with creating a pcr policy with current value in PCR0 sha256 bank<br>
287-
{:start="39"}
287+
{:start="39"}<br>
288288
39. `tpm2_startauthsession -S session.ctx`<br>
289289
40. `tpm2_policypcr -Q -S session.ctx -l sha256:0 -L pcr0.sha256.policy`<br>
290290
41. `tpm2_flushcontext session.ctx`<br>
291291

292292
Now replace the seal object in TPM NV memory protecting the disk encryption
293293
secret with a new one that adds the pcr policy we just created as an
294294
authentication mechanism to access the sealed secret.<br>
295-
{:start="42"}
295+
{:start="42"}<br>
296296
42. `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>
297297
43. `tpm2_evictcontrol -C o -c 0x81010001`<br>
298298
44. `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
302302
unsealed off a TPM object whose unsealing operation can only be accessed by
303303
satisfying the PCR policy; in other words authenticating by virtue of intended
304304
system software state being unchanged as reflected by the PCR value.<br>
305-
{:start="46"}
305+
{:start="46"}<br>
306306
46. `sudo losetup $loopdevice enc.disk`<br>
307307
47. `tpm2_startauthsession --policy-session -S session.ctx `<br>
308308
48. `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
313313
However for the purpose of demonstrating flexible PCR in a later section we will
314314
make a copy of the unsealed secret at this point to seal it with a new object
315315
with flexible pcr policy. This breakdown to two steps<br>
316-
{:start="49"}
316+
{:start="49"}<br>
317317
49. `tpm2_unseal -p session:session.ctx -c 0x81010001 > disk_secret.bkup`<br>
318318
50. `cat disk_secret.bkup | sudo cryptsetup luksOpen --key-file=- $loopdevice enc_volume`<br>
319319
51. `tpm2_flushcontext session.ctx `<br>
@@ -329,19 +329,19 @@ consequence of failed policy check and thus a failed unsealing attempt.<br>
329329

330330
Let's look at the PCR state prior to extending it and then again after
331331
extending: <br>
332-
{:start="54"}
332+
{:start="54"}<br>
333333
54. `tpm2_pcrlist -l sha256:0`<br>
334334
55. `tpm2_pcrextend 0:sha256=0000000000000000000000000000000000000000000000000000000000000000`<br>
335335
56. `tpm2_pcrlist -l sha256:0`<br>
336336

337337
Now let's try to unseal the sealed disk encryption secret with the dirty
338338
PCR:<br>
339-
{:start="57"}
339+
{:start="57"}<br>
340340
57. `tpm2_startauthsession --policy-session -S session.ctx `<br>
341341
58. `tpm2_policypcr -Q -S session.ctx -l sha256:0`<br>
342342
The following operation should result in policy check failure preventing the
343343
unseal operation:<br>
344-
{:start="59"}
344+
{:start="59"}<br>
345345
59. `tpm2_unseal -p session:session.ctx -c 0x81010001`<br>
346346
60. `tpm2_flushcontext session.ctx`<br>
347347

@@ -366,7 +366,7 @@ PCR signature. The PCR sets are signed by the system designer and verified by
366366
the 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>
370370
61. `tpm2_startauthsession -S session.ctx`<br>
371371
62. `tpm2_policypcr -Q -S session.ctx -l sha256:0 -L set2.pcr.policy`<br>
372372
63. `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

376376
We now need the name which is a digest of the TCG public key format of the
377377
public key to include in the policy. We can use the loadexternal tool for this:<br>
378-
{:start="66"}
378+
{:start="66"}<br>
379379
66. `tpm2_loadexternal -G rsa -C o -u signing_key_public.pem -c signing_key.ctx -n signing_key.name`<br>
380380

381381
Let's now create the signer policy:<br>
382-
{:start="66"}
382+
{:start="67"}<br>
383383
67. `tpm2_startauthsession -S session.ctx`<br>
384384
68. `tpm2_policyauthorize -S session.ctx -L authorized.policy -n signing_key.name -i set2.pcr.policy`<br>
385385
69. `tpm2_flushcontext session.ctx`<br>
@@ -388,12 +388,12 @@ Let's create a new sealing object with the authorized policy which will also
388388
require the sealing secret for which we will use the disk_secret.bkup we created
389389
at #49 earlier to avoid rebooting the platform to match the PCR we originally
390390
had prior to extending.<br>
391-
{:start="70"}
391+
{:start="70"}<br>
392392
70. `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

394394
Let's replace the old persistent sealing object with the one we created
395395
above with policy_authorize policy associated with signer public key:<br>
396-
{:start="71"}
396+
{:start="71"}<br>
397397
71. `tpm2_evictcontrol -C o -c 0x81010001`<br>
398398
72. `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>
399399
73. `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
404404
and get the tpm verification tkt:__<br>
405-
{:start="75"}
405+
{:start="75"}<br>
406406
75. `tpm2_loadexternal -G rsa -C o -u signing_key_public.pem -c signing_key.ctx -n signing_key.name`<br>
407407
76. `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>
411411
77. `tpm2_startauthsession --policy-session -S session.ctx`<br>
412412
78. `tpm2_policypcr -l sha256:0 -S session.ctx`<br>
413413
79. `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>
417417
80. `sudo losetup $loopdevice enc.disk`<br>
418418
81. `tpm2_unseal -p session:session.ctx -c 0x81010001 | sudo cryptsetup luksOpen --key-file=- $loopdevice enc_volume`<br>
419419
82. `tpm2_flushcontext session.ctx `<br>

0 commit comments

Comments
 (0)