Skip to content

Commit 503ddf0

Browse files
clayrosenthalidesai
authored andcommitted
updating the ordered lists
adding `{:start="x"}` before later ordered lists in the post to allow it to properly render as intended in jekyll Signed-off-by: Clayton Rosenthal <crosenthal@covariant.ai>
1 parent 2cefe30 commit 503ddf0

1 file changed

Lines changed: 26 additions & 0 deletions

File tree

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +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"}
110111
2. `tpm2_evictcontrol --hierarchy=o --object-context=prim.ctx 0x81010001`<br>
111112

112113
NOTE:
@@ -139,6 +140,7 @@ first setup a disk image without encryption and see if we can extract user
139140
generated content.<br>
140141

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

177179
Let's setup a new LUKS volume with a simple passphrase as key protector:<br>
180+
{:start="12"}
178181
12. `dd if=/dev/zero of=enc.disk bs=1M count=10`<br>
179182
13. `dd if=/dev/urandom of=disk.key bs=1 count=32`<br>
180183
14. `loopdevice=$(losetup -f) && sudo losetup $loopdevice enc.disk`<br>
@@ -183,11 +186,13 @@ Let's setup a new LUKS volume with a simple passphrase as key protector:<br>
183186
At this point you have setup the luks volume and it should pop a warning about
184187
overriding the data. Next let's open the LUKS volume by authenticating with the
185188
disk.key and complete the setting up the disk with a filesystem.<br>
189+
{:start="16"}
186190
16. `sudo cryptsetup luksOpen --key-file=disk.key $loopdevice enc_volume`<br>
187191
17. `sudo mkfs.ext4 -j /dev/mapper/enc_volume`<br>
188192
18. `sudo mount /dev/mapper/enc_volume mountpoint`<br>
189193

190194
Now lets create a plain text file again and add user content to it:<br>
195+
{:start="16"}
191196
19. `sudo touch mountpoint/plain.txt`<br>
192197
20. `sudo chmod 777 mountpoint/plain.txt`<br>
193198
21. `sudo echo "This is my plain text" > mountpoint/plain.txt`<br>
@@ -197,6 +202,7 @@ Now lets create a plain text file again and add user content to it:<br>
197202

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

202208
NOTE:
@@ -219,26 +225,31 @@ b. Unseal the secret in memory and pass it to cryptsetup.<br>
219225

220226
Let's start with creating and persisting a sealing object and sealing a random
221227
byte sequence as the disk key.<br>
228+
{:start="26"}
222229
26. `tpm2_createprimary -Q -C o -c prim.ctx`<br>
223230
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>
224231
28. `tpm2_load -Q -C prim.ctx -u seal.pub -r seal.priv -n seal.name -c seal.ctx`<br>
225232
29. `tpm2_evictcontrol -C o -c seal.ctx 0x81010001`<br>
226233

227234
Now lets change the authentication from previously created disk.key to the new
228235
sealed secret and after that shred the disk.key since it's no longer useful:<br>
236+
{:start="30"}
229237
30. `tpm2_unseal -Q -c 0x81010001 | sudo cryptsetup luksChangeKey enc.disk --key-file disk.key`<br>
230238
31. `shred disk.key; rm -f disk.key`<br>
231239

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

237246
You can now see that disk access is granted with the new secret:<br>
247+
{:start="35"}
238248
35. `ls mountpoint`
239249
<br>
240250

241251
Finally unmount the disk:<br>
252+
{:start="36"}
242253
36. `sudo umount mountpoint`<br>
243254
37. `sudo cryptsetup remove enc_volume`<br>
244255
38. `sudo losetup -d $loopdevice`<br>
@@ -273,13 +284,15 @@ c. After unsealing the pass-phrase; extend the sealing PCRs so that the
273284
pass-phrase cannot be unsealed gain.<br>
274285

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

280292
Now replace the seal object in TPM NV memory protecting the disk encryption
281293
secret with a new one that adds the pcr policy we just created as an
282294
authentication mechanism to access the sealed secret.<br>
295+
{:start="42"}
283296
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>
284297
43. `tpm2_evictcontrol -C o -c 0x81010001`<br>
285298
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>
@@ -289,6 +302,7 @@ Now let's try to mount the encrypted disk again but this time the secret is
289302
unsealed off a TPM object whose unsealing operation can only be accessed by
290303
satisfying the PCR policy; in other words authenticating by virtue of intended
291304
system software state being unchanged as reflected by the PCR value.<br>
305+
{:start="46"}
292306
46. `sudo losetup $loopdevice enc.disk`<br>
293307
47. `tpm2_startauthsession --policy-session -S session.ctx `<br>
294308
48. `tpm2_policypcr -Q -S session.ctx -l sha256:0`<br>
@@ -299,6 +313,7 @@ directly to the cryptsetup app like this --> "tpm2_unseal -p session:session.ctx
299313
However for the purpose of demonstrating flexible PCR in a later section we will
300314
make a copy of the unsealed secret at this point to seal it with a new object
301315
with flexible pcr policy. This breakdown to two steps<br>
316+
{:start="49"}
302317
49. `tpm2_unseal -p session:session.ctx -c 0x81010001 > disk_secret.bkup`<br>
303318
50. `cat disk_secret.bkup | sudo cryptsetup luksOpen --key-file=- $loopdevice enc_volume`<br>
304319
51. `tpm2_flushcontext session.ctx `<br>
@@ -314,16 +329,19 @@ consequence of failed policy check and thus a failed unsealing attempt.<br>
314329

315330
Let's look at the PCR state prior to extending it and then again after
316331
extending: <br>
332+
{:start="54"}
317333
54. `tpm2_pcrlist -l sha256:0`<br>
318334
55. `tpm2_pcrextend 0:sha256=0000000000000000000000000000000000000000000000000000000000000000`<br>
319335
56. `tpm2_pcrlist -l sha256:0`<br>
320336

321337
Now let's try to unseal the sealed disk encryption secret with the dirty
322338
PCR:<br>
339+
{:start="57"}
323340
57. `tpm2_startauthsession --policy-session -S session.ctx `<br>
324341
58. `tpm2_policypcr -Q -S session.ctx -l sha256:0`<br>
325342
The following operation should result in policy check failure preventing the
326343
unseal operation:<br>
344+
{:start="59"}
327345
59. `tpm2_unseal -p session:session.ctx -c 0x81010001`<br>
328346
60. `tpm2_flushcontext session.ctx`<br>
329347

@@ -348,6 +366,7 @@ PCR signature. The PCR sets are signed by the system designer and verified by
348366
the TPM. This is achieved in following steps:
349367

350368
__a. Get the new set of PCR and sign the pcr policy with signer private key.__<br>
369+
{:start="61"}
351370
61. `tpm2_startauthsession -S session.ctx`<br>
352371
62. `tpm2_policypcr -Q -S session.ctx -l sha256:0 -L set2.pcr.policy`<br>
353372
63. `tpm2_flushcontext session.ctx`<br>
@@ -356,9 +375,11 @@ __a. Get the new set of PCR and sign the pcr policy with signer private key.__<b
356375

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

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

372394
Let's replace the old persistent sealing object with the one we created
373395
above with policy_authorize policy associated with signer public key:<br>
396+
{:start="71"}
374397
71. `tpm2_evictcontrol -C o -c 0x81010001`<br>
375398
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>
376399
73. `tpm2_evictcontrol -c auth_pcr_seal_key.ctx 0x81010001 -C o`<br>
@@ -379,15 +402,18 @@ Let's now sign the pcr_policy with the signer private key:<br>
379402

380403
__b. Load the signer public key to the tpm and verify the signature on the pcr
381404
and get the tpm verification tkt:__<br>
405+
{:start="75"}
382406
75. `tpm2_loadexternal -G rsa -C o -u signing_key_public.pem -c signing_key.ctx -n signing_key.name`<br>
383407
76. `tpm2_verifysignature -c signing_key.ctx -g sha256 -m set2.pcr.policy -s set2.pcr.signature -t verification.tkt -f rsassa`<br>
384408

385409
__c. Satisfy the authorized policy and then run policyauthorize:__<br>
410+
{:start="77"}
386411
77. `tpm2_startauthsession --policy-session -S session.ctx`<br>
387412
78. `tpm2_policypcr -l sha256:0 -S session.ctx`<br>
388413
79. `tpm2_policyauthorize -S session.ctx -i set2.pcr.policy -n signing_key.name -t verification.tkt`<br>
389414

390415
__d. Pipe unseal output to the cryptsetup application:__<br>
416+
{:start="80"}
391417
80. `sudo losetup $loopdevice enc.disk`<br>
392418
81. `tpm2_unseal -p session:session.ctx -c 0x81010001 | sudo cryptsetup luksOpen --key-file=- $loopdevice enc_volume`<br>
393419
82. `tpm2_flushcontext session.ctx `<br>

0 commit comments

Comments
 (0)