All of lore.kernel.org
 help / color / mirror / Atom feed
* [tpm2] Re: How to initialize a used TPM2 module and thoughts on clevis
@ 2022-07-12 21:32 Roberts, William C
  0 siblings, 0 replies; 7+ messages in thread
From: Roberts, William C @ 2022-07-12 21:32 UTC (permalink / raw)
  To: tpm2

[-- Attachment #1: Type: text/plain, Size: 2715 bytes --]

On Tue, 2022-07-12 at 21:19 +0000, Roberts, William C wrote:
> On Mon, 2022-07-11 at 06:23 +0000, tpm2(a)bitzap.e4ward.com wrote:
> > Hello -
> > 
> > New to TPM2 here. I'm adding a *used* TPM2 module to a mobo that
> > has
> > a header. What are best practices to initialize the TPM2 module? 
> > Should I clear it first, possibly via the BIOS?
> 
> Yes
> 
> >  Should I set an owner password?
> 
> and YES. This is required to keep someone from wiping all the keys in
> the owner hierarchy which would include your disk encryption keys.
> You also want to set the lockoutauth as well.
> 
> > So far I found `echo 5 > /sys/class/tpm/tpm0/ppi/request` which is
> > probably a good idea to do as I don't know where the module comes
> > from and whether anyone has messed with it before.
> > 
> > I'd appreciate any pointers in the right direction and the correct
> > commands to start with a clean TPM2. Running Ubuntu 20.04 and I
> > installed tpm2-tools.
> 
> I think I'd clear it using the BIOS and use
> tpm2_changeauth -C o <newownerpass>
> tpm2_changeauth -C l <newlockoutpass>

Oh don't forget about the endorsement hiearchy:
tpm2_changeauth -c e <newendorsepass>

Also I accidentally put uppercase -C options for tpm2_changeauth when
it is lowercase -c, sorry :-p


> 
> You'd probably also want to create the "Storage Root Key" or SRK
> which
> is a key at certain fixed address without a password so you can put
> subordinate keys under:
> 
> # Specify -G ecc for an ecc key over RSA, but it really doesn't
> matter.
> tpm2_createprimary -c primary.ctx 
> tpm2_evictcontrol -c primary.ctx 0x81000001
> 
> to initialize the TPM.
> 
> The address 0x81000001 comes from a guidance document on how to
> provision the TPM:
>   - 
> https://trustedcomputinggroup.org/wp-content/uploads/TCG-TPM-v2.0-Provisioning-Guidance-Published-v1r1.pdf
> 
> 
> > Also, is `clevis encrypt tpm2` a good wrapper if I just want to a
> > simple way to encrypt/decrypt a file on disk that holds other
> > credentials?
> 
> Yeah clevis works great for those purposes. However, I don't know how
> clevis manages it's keys so you may need to do something else, but
> as far as I know its a simple way to use TPM2.
> 
> 
> > Thank you!
> > _______________________________________________
> > tpm2 mailing list -- tpm2(a)lists.01.org
> > To unsubscribe send an email to tpm2-leave(a)lists.01.org
> > %(web_page_url)slistinfo%(cgiext)s/%(_internal_name)s
> _______________________________________________
> tpm2 mailing list -- tpm2(a)lists.01.org
> To unsubscribe send an email to tpm2-leave(a)lists.01.org
> %(web_page_url)slistinfo%(cgiext)s/%(_internal_name)s

^ permalink raw reply	[flat|nested] 7+ messages in thread
* [tpm2] Re: How to initialize a used TPM2 module and thoughts on clevis
@ 2022-08-19 16:17 Roberts, William C
  0 siblings, 0 replies; 7+ messages in thread
From: Roberts, William C @ 2022-08-19 16:17 UTC (permalink / raw)
  To: tpm2

[-- Attachment #1: Type: text/plain, Size: 2324 bytes --]

Thanks Javier,

Seems to have the same bug:
  - https://github.com/fedora-iot/clevis-pin-tpm2/blob/main/src/utils.rs#L99


I filled issue:
https://github.com/fedora-iot/clevis-pin-tpm2/issues/20

Thanks,
Bill
________________________________
From: Javier Martinez Canillas <javierm(a)redhat.com>
Sent: Tuesday, August 16, 2022 12:29 PM
To: Roberts, William C <william.c.roberts(a)intel.com>; tpm2(a)bitzap.e4ward.com <tpm2(a)bitzap.e4ward.com>; tpm2(a)lists.01.org <tpm2(a)lists.01.org>
Subject: Re: [tpm2] Re: How to initialize a used TPM2 module and thoughts on clevis

Hello Bill,

On 7/13/22 16:53, Roberts, William C wrote:
> + Javier
>
> On Tue, 2022-07-12 at 22:25 +0000, Tim K wrote:
>> Very useful, thank you!
>>
>>> and YES. This is required to keep someone from wiping all the keys
>>> in
>>> the owner hierarchy which would include your disk encryption keys.
>>> You also want to set the lockoutauth as well.
>>
>> It appears clevis uses the owner hierarchy by default. If I set an
>> owner password, what are the implications, does clevis need to know
>> the owner password when it creates its own key and then
>> encrypts/decrypts its own key?
>>
>> This is how I'm trying to use it to encrypt a single file on disk
>> (not the entire disk/LUKS):
>> https://manpages.ubuntu.com/manpages/focal/man1/clevis-encrypt-tpm2.1.html
>
>
> Looking at the source[1,2], it appears they call tpm2_createprimary on
> encrypt which would require owner auth, call tpm2_create save the key
> and then on decrypt call tpm2_createprimary which requires owner auth
> and then call tpm2_load to load the key under that primary object.
>
> I don't see an option to use the SRK, this looks like an oversight or I
> am missing something. Javier, do you know?
>

I don't remember anymore why this was done that way. I haven't worked on
TPM stuff for a while and paged out of my head all the details... sorry.

But in case is useful, there's a new clevis tpm2 pin that is a rewrite and
and supports more features such as PCR Authorized Policies. Please take a
look, since it maybe be doing the correct thing and if not, you can file
an issue for that:

https://github.com/fedora-iot/clevis-pin-tpm2
 --
Best regards,

Javier Martinez Canillas
Linux Engineering
Red Hat


[-- Attachment #2: attachment.htm --]
[-- Type: text/html, Size: 4981 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread
* [tpm2] Re: How to initialize a used TPM2 module and thoughts on clevis
@ 2022-07-13 15:59 Tim K
  0 siblings, 0 replies; 7+ messages in thread
From: Tim K @ 2022-07-13 15:59 UTC (permalink / raw)
  To: tpm2

[-- Attachment #1: Type: text/plain, Size: 910 bytes --]

My goal is to automate a cron job that requires credentials by keeping the credentials in a file that is encrypted using TPM2 via clevis. I am fully aware this does not add much protection if someone gets access to the OS, it is just so credentials do not sit in plain text in a file on disk, just protected by file permissions and it somewhat protects me from accidentally sync'ing the file to cloud or to some other backup (the file would at least be encrypted).

In order to do this, I don't think I can password protect the TPM2 hierarchies, otherwise there would be no way to automate it, I'd have to put the TPM2 passwords in the script for clevis to use (assuming clevis adds the option or that I just call the tpm2_* commands myself).

Any other suggestions how to make this better? My original idea was to use systemd-creds but it is not available in systemd v249 that Ubuntu 22.04 LTS ships with.

^ permalink raw reply	[flat|nested] 7+ messages in thread
* [tpm2] Re: How to initialize a used TPM2 module and thoughts on clevis
@ 2022-07-13 14:53 Roberts, William C
  0 siblings, 0 replies; 7+ messages in thread
From: Roberts, William C @ 2022-07-13 14:53 UTC (permalink / raw)
  To: tpm2

[-- Attachment #1: Type: text/plain, Size: 1513 bytes --]

+ Javier

On Tue, 2022-07-12 at 22:25 +0000, Tim K wrote:
> Very useful, thank you!
> 
> > and YES. This is required to keep someone from wiping all the keys
> > in
> > the owner hierarchy which would include your disk encryption keys.
> > You also want to set the lockoutauth as well.
> 
> It appears clevis uses the owner hierarchy by default. If I set an
> owner password, what are the implications, does clevis need to know
> the owner password when it creates its own key and then
> encrypts/decrypts its own key?
> 
> This is how I'm trying to use it to encrypt a single file on disk
> (not the entire disk/LUKS):
> https://manpages.ubuntu.com/manpages/focal/man1/clevis-encrypt-tpm2.1.html


Looking at the source[1,2], it appears they call tpm2_createprimary on
encrypt which would require owner auth, call tpm2_create save the key
and then on decrypt call tpm2_createprimary which requires owner auth
and then call tpm2_load to load the key under that primary object.

I don't see an option to use the SRK, this looks like an oversight or I
am missing something. Javier, do you know?


[1] 
https://github.com/latchset/clevis/blob/master/src/pins/tpm2/clevis-encrypt-tpm2
[2] 
https://github.com/latchset/clevis/blob/master/src/pins/tpm2/clevis-decrypt-tpm2
> _______________________________________________
> tpm2 mailing list -- tpm2(a)lists.01.org
> To unsubscribe send an email to tpm2-leave(a)lists.01.org
> %(web_page_url)slistinfo%(cgiext)s/%(_internal_name)s

^ permalink raw reply	[flat|nested] 7+ messages in thread
* [tpm2] Re: How to initialize a used TPM2 module and thoughts on clevis
@ 2022-07-13 14:33 Roberts, William C
  0 siblings, 0 replies; 7+ messages in thread
From: Roberts, William C @ 2022-07-13 14:33 UTC (permalink / raw)
  To: tpm2

[-- Attachment #1: Type: text/plain, Size: 2799 bytes --]

On Tue, 2022-07-12 at 21:19 +0000, Roberts, William C wrote:
> On Mon, 2022-07-11 at 06:23 +0000, tpm2(a)bitzap.e4ward.com wrote:
> > Hello -
> > 
> > New to TPM2 here. I'm adding a *used* TPM2 module to a mobo that
> > has
> > a header. What are best practices to initialize the TPM2 module? 
> > Should I clear it first, possibly via the BIOS?
> 
> Yes
> 
> >  Should I set an owner password?
> 
> and YES. This is required to keep someone from wiping all the keys in
> the owner hierarchy which would include your disk encryption keys.
> You also want to set the lockoutauth as well.

FYI at KGoldman pointed out that tpm2_clear is not protected by owener
auth but rather platform or lockout auth. Also, FYI, tpm2_clearcontrol
during boot will disable tpm2_clear command all together.

> 
> > So far I found `echo 5 > /sys/class/tpm/tpm0/ppi/request` which is
> > probably a good idea to do as I don't know where the module comes
> > from and whether anyone has messed with it before.
> > 
> > I'd appreciate any pointers in the right direction and the correct
> > commands to start with a clean TPM2. Running Ubuntu 20.04 and I
> > installed tpm2-tools.
> 
> I think I'd clear it using the BIOS and use
> tpm2_changeauth -C o <newownerpass>
> tpm2_changeauth -C l <newlockoutpass>

This sets out lockout auth, your OS/FW during boot set platform auth.

> 
> You'd probably also want to create the "Storage Root Key" or SRK
> which
> is a key at certain fixed address without a password so you can put
> subordinate keys under:
> 
> # Specify -G ecc for an ecc key over RSA, but it really doesn't
> matter.
> tpm2_createprimary -c primary.ctx 
> tpm2_evictcontrol -c primary.ctx 0x81000001
> 
> to initialize the TPM.
> 
> The address 0x81000001 comes from a guidance document on how to
> provision the TPM:
>   - 
> https://trustedcomputinggroup.org/wp-content/uploads/TCG-TPM-v2.0-Provisioning-Guidance-Published-v1r1.pdf
> 
> 
> > Also, is `clevis encrypt tpm2` a good wrapper if I just want to a
> > simple way to encrypt/decrypt a file on disk that holds other
> > credentials?
> 
> Yeah clevis works great for those purposes. However, I don't know how
> clevis manages it's keys so you may need to do something else, but
> as far as I know its a simple way to use TPM2.
> 
> 
> > Thank you!
> > _______________________________________________
> > tpm2 mailing list -- tpm2(a)lists.01.org
> > To unsubscribe send an email to tpm2-leave(a)lists.01.org
> > %(web_page_url)slistinfo%(cgiext)s/%(_internal_name)s
> _______________________________________________
> tpm2 mailing list -- tpm2(a)lists.01.org
> To unsubscribe send an email to tpm2-leave(a)lists.01.org
> %(web_page_url)slistinfo%(cgiext)s/%(_internal_name)s

^ permalink raw reply	[flat|nested] 7+ messages in thread
* [tpm2] Re: How to initialize a used TPM2 module and thoughts on clevis
@ 2022-07-12 22:25 Tim K
  0 siblings, 0 replies; 7+ messages in thread
From: Tim K @ 2022-07-12 22:25 UTC (permalink / raw)
  To: tpm2

[-- Attachment #1: Type: text/plain, Size: 615 bytes --]

Very useful, thank you!

> and YES. This is required to keep someone from wiping all the keys in
> the owner hierarchy which would include your disk encryption keys.
> You also want to set the lockoutauth as well.

It appears clevis uses the owner hierarchy by default. If I set an owner password, what are the implications, does clevis need to know the owner password when it creates its own key and then encrypts/decrypts its own key?

This is how I'm trying to use it to encrypt a single file on disk (not the entire disk/LUKS):
https://manpages.ubuntu.com/manpages/focal/man1/clevis-encrypt-tpm2.1.html

^ permalink raw reply	[flat|nested] 7+ messages in thread
* [tpm2] Re: How to initialize a used TPM2 module and thoughts on clevis
@ 2022-07-12 21:19 Roberts, William C
  0 siblings, 0 replies; 7+ messages in thread
From: Roberts, William C @ 2022-07-12 21:19 UTC (permalink / raw)
  To: tpm2

[-- Attachment #1: Type: text/plain, Size: 2129 bytes --]

On Mon, 2022-07-11 at 06:23 +0000, tpm2(a)bitzap.e4ward.com wrote:
> Hello -
> 
> New to TPM2 here. I'm adding a *used* TPM2 module to a mobo that has
> a header. What are best practices to initialize the TPM2 module? 
> Should I clear it first, possibly via the BIOS?

Yes

>  Should I set an owner password?

and YES. This is required to keep someone from wiping all the keys in
the owner hierarchy which would include your disk encryption keys.
You also want to set the lockoutauth as well.

> 
> So far I found `echo 5 > /sys/class/tpm/tpm0/ppi/request` which is
> probably a good idea to do as I don't know where the module comes
> from and whether anyone has messed with it before.
> 
> I'd appreciate any pointers in the right direction and the correct
> commands to start with a clean TPM2. Running Ubuntu 20.04 and I
> installed tpm2-tools.

I think I'd clear it using the BIOS and use
tpm2_changeauth -C o <newownerpass>
tpm2_changeauth -C l <newlockoutpass>

You'd probably also want to create the "Storage Root Key" or SRK which
is a key at certain fixed address without a password so you can put
subordinate keys under:

# Specify -G ecc for an ecc key over RSA, but it really doesn't matter.
tpm2_createprimary -c primary.ctx 
tpm2_evictcontrol -c primary.ctx 0x81000001

to initialize the TPM.

The address 0x81000001 comes from a guidance document on how to
provision the TPM:
  - 
https://trustedcomputinggroup.org/wp-content/uploads/TCG-TPM-v2.0-Provisioning-Guidance-Published-v1r1.pdf


> 
> Also, is `clevis encrypt tpm2` a good wrapper if I just want to a
> simple way to encrypt/decrypt a file on disk that holds other
> credentials?

Yeah clevis works great for those purposes. However, I don't know how
clevis manages it's keys so you may need to do something else, but
as far as I know its a simple way to use TPM2.


> 
> Thank you!
> _______________________________________________
> tpm2 mailing list -- tpm2(a)lists.01.org
> To unsubscribe send an email to tpm2-leave(a)lists.01.org
> %(web_page_url)slistinfo%(cgiext)s/%(_internal_name)s

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2022-08-19 16:17 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-07-12 21:32 [tpm2] Re: How to initialize a used TPM2 module and thoughts on clevis Roberts, William C
  -- strict thread matches above, loose matches on Subject: below --
2022-08-19 16:17 Roberts, William C
2022-07-13 15:59 Tim K
2022-07-13 14:53 Roberts, William C
2022-07-13 14:33 Roberts, William C
2022-07-12 22:25 Tim K
2022-07-12 21:19 Roberts, William C

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.