osresearch / safeboot

Scripts to slightly improve the security of the Linux boot process with UEFI Secure Boot and TPM support
https://safeboot.dev/
GNU General Public License v2.0
270 stars 28 forks source link

Consider using tss2_ tools in tpm2-tools for tpm2-attest script #40

Open williamcroberts opened 4 years ago

williamcroberts commented 4 years ago

The tss2_ tools use the Feature API, which is designed with simplicity at its core. You may consider using it in tpm2-attest:

  1. All sessions are encrypted where the can be and verified to the EK.
  2. Data structures are already web friendly in JSON.

Andreas over at our project might be able to give you more reasons and perhaps some help flipping the script over.

osresearch commented 4 years ago

One of the goals is to run in initrd with very few dependencies, which means running without any daemons. Is there a way to have the tools talk directly to the TPM2 without a resource manager? The man pages don't mention an option similar to either TPM2TSSENGINE_TCTI="device:/dev/tpmrm0"

(the man pages also refer me to the texinfo pages, which seem to be copies of the man pages including the reference to info).

williamcroberts commented 4 years ago

One of the goals is to run in initrd with very few dependencies, which means running without any daemons. Is there a way to have the tools talk directly to the TPM2 without a resource manager? The man pages don't mention an option similar to either TPM2TSSENGINE_TCTI="device:/dev/tpmrm0"

The actual installed manpages are just pandoc converted from markdown, so this tcti information is embedded in each manpage:

The -T, --tcti or TPM2TOOLS_TCTI can all embed the same tcti information string to control the connection.

You can also symlink libtss2-tcti-default.so to the device tcti libtss2-tcti-device.so.0.

man 3 Tss2_TctiLdr_Initialize describes this in part. You can at configure time in tpm2-tss use the configure option --with-tctidefaultmodule to set the default tcti.

(the man pages also refer me to the texinfo pages, which seem to be copies of the man pages including the reference to info).

tpm2_create(1) General Commands Manual  tpm2_create(1)

Is that what that header is saying? One if for man and one is for info? I've been searching for why its laid out like that but never found anything authoritative or is linked like that somewhere else?

williamcroberts commented 4 years ago

One of the goals is to run in initrd with very few dependencies, which means running without any daemons. Is there a way to have the tools talk directly to the TPM2 without a resource manager? The man pages don't mention an option similar to either TPM2TSSENGINE_TCTI="device:/dev/tpmrm0"

(the man pages also refer me to the texinfo pages, which seem to be copies of the man pages including the reference to info).

Also I think since like 4.12, kernel versions also have /dev/tpmrm0 as well, which is an in-kernel resource manager. Note you can't use sessions across command invocations

williamcroberts commented 4 years ago

FYI you mention that getting the quote is slow, you could generate an EC key. EC key generation is much faster than RSA.

osresearch commented 4 years ago

Thanks for the suggestion about ECC keys -- they are indeed much faster to create! #41 is for that enhancement, which is currently blocked on tpm2_checkquote handling ECC AK.

All of the tpm2-tools seem to support --tcti (and is included in all the manpages as you pointed out), but doesn't seem to exist in tss2. Is there a way to run the tools from that package with the kernel resource manager?

The texinfo footer shows up at the bottom of the tss2 manpages is likely some boilerplate from the tool used to :

SEE ALSO
       The full documentation for quote is maintained as a Texinfo manual.  If
       the info and quote programs are properly installed at  your  site,  the
       command

              info quote

       should give you access to the complete manual.

quote                              July 2017                          QUOTE(1)
williamcroberts commented 4 years ago

Yeah the tss2_tools use FAPI, which is configured differently. Its essentially a global state with a config file. That config file can be specified via: env variable TSS2_FAPICONF if you wish to override the default.

The default is the sysconfigdir:

#define DEFAULT_CONFIG_FILE (SYSCONFDIR "/tpm2-tss/fapi-config.json")

tpm2-tss/dist/fapi-config.json.in is the default confg file, it gets processed during make and installed to the sysconfdir.

My system has it installed at: /usr/local/etc/tpm2-tss/fapi-config.json

In that file:

{
     "profile_name": "P_RSA2048SHA256",
     "profile_dir": "/usr/local/etc/tpm2-tss/fapi-profiles/",
     "user_dir": "~/.local/share/tpm2-tss/user/keystore",
     "system_dir": "/usr/local/var/lib/tpm2-tss/system/keystore",
     "tcti": "",
     "system_pcrs" : [],
     "log_dir" : "/usr/local/var/run/tpm2-tss/eventlog/"
}

In there you can set the tcti. I think it just takes the normal TCTI specifiers.

You need to call tss2provision first, and then you can start using the tss2 tools. I think* you can always call it, worst case it just complains its been initialized already, you can just ignore that.

Ill fix that tpm2_checkqoute is hardcoded to RSA, thanks for that issue:

I noticed that the other day scrolling through stuff.

tss2_verifyquote seems to also do what you want if you can get it working with the tss2 tools.

nicowilliams commented 3 years ago

@williamcroberts Hmm, so, tpm2_startauthsession seems to know how to create encryption sessions, but how does one use those? Some commands seem to support them, like tpm2_activatecredential and tpm2_create, which is good, but others don't, like tpm2_loadexternal. I would think all commands should be able to use an encryption session... There is not a tss command in tpm2-tools for every TPM 2.0 command (e.g., there is no tss command for make/activatecredential, nor for policies).

williamcroberts commented 3 years ago

Not every command has the -S argument yet, @idesai is making progress towards it but it's not complete. ActivateCredential has support for -S and MakeCredential doesn't really need it, since it can be done without a TPM. MakeCredential exists solely as a convenience function of the TPM. You can use --tcti=none with the makecredential command to invoke the software only functionality.

williamcroberts commented 3 years ago

patches are always welcome

nicowilliams commented 3 years ago

@williamcroberts

patches are always welcome

I need to clone myself, slow the rest of the world so I can do more.

Anyways, tpm2 startauthsession -c ... to create an encryption session, then tpm2 ... -s ... to use the session. And this pattern needs to be extended to more commands (basically all the ones that have an encryptable TPM2B_* parameter).

But what about cpHash/rpHash handling? It would be really nice if all commands could provide an option to provide integrity protection -using an encryption session- for all parameters, even those not encrypted.