Skip to main content

CI PyPI version

tpmstream

A tool to help you understand TPM commands and responses. You can either use the convert command if you want to decode TPM commands/responses or the example command to find examples.

Install

pip install .

For development, it is recommended to use a virtual environment and install with the --editable switch.

Decode TPM Commands/Responses:

The convert command reads binary (or pcapng) data from a file:

❯ tpmstream convert create_primary.bin

Example

Or you can read data from stdin. Just pass -:

❯ printf "80020000007700000131400000010000003d0200000000145536c0a5ba338e58abfe729f76ccca61ebaf821f01002082fc712f21e4c7e47bbf84dfa0fb15ddfc7013eb61ed3eb2edaf0286e88ba20c000400000000001a0023000b0004007200000010001a000b00000003001000000000000000000000"  | xxd -r -p | tpmstream convert -

Find Examples for TPM Commands/Responses:

You want to see an exemplary TPM command? Easy, try:

❯ tpmstream ex NV_Write

Don't worry, the tool helps you out if you do not know how to spell a given command:

❯ tpmstream ex NVDefine
Unknown commandCode: NVDefine.

Did you mean:

  tpmstream ex NV_DefineSpace

Python API

Marshalling

Marshalling functions convert a particular data stream (binary, pcapng, ...) into a canonical format: a sequence of MarshalEvents. These events can be converted to a python representation of the respective datatype (e.g. a TPMS_SIG_SCHEME_ECDSA object).

from tpmstream.common.event import events_to_obj
from tpmstream.io.binary import Binary
from tpmstream.spec.commands.commands import Command
from tpmstream.spec.structures.constants import TPM_SU

events = Binary.marshal(tpm_type=Command, buffer=b"\x80\x01\x00\x00\x00\x0c\x00\x00\x01\x44\x00\x00")
command = events_to_obj(Command, events)

print(command.parameters.startupType)  # prints TPM_SU.CLEAR

Likewise, these python objects can be turned into a sequence of events, again.

from tpmstream.common.event import obj_to_events

# ...

events = obj_to_events(command)

# Note that `events` is a generator. You can obtain a list by via `list(events)`

Unmarshalling

Unmarshalling functions convert a given set of MarshalEvents into a custom format (binary, pretty print, ...).

from tpmstream.io.binary import Binary
from tpmstream.io.pretty import Pretty
from tpmstream.spec.commands.commands import Command

events = Binary.marshal(tpm_type=Command, buffer=b"\x80\x01\x00\x00\x00\x0c\x00\x00\x01\x44\x00\x00")
pretty = Pretty.unmarshal(events=events)

for line in pretty:
     print(line)

Example flow

Marshalling (e.g. binary to events) and unmarshalling (e.g. events to pretty print) is decoupled. Events can be turnt into python objects (like TPMS_SIG_SCHEME_ECDSA) and vice versa.

               +---------------------+                                                         +----------------------+
---[binary]--> | binary marshalling  | ---[events]---+-------------------------+---[events]--> | binary unmarshalling | ---[pretty print]-->
               +---------------------+               |                         |               +----------------------+
                                                     |    +---------------+    |
                                                     +--> | python object | ---+
                                                          +---------------+

Metadata

Release files for tpmstream 0.1.10

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distribution (wheel)

Table of built distributions (wheels) for tpmstream 0.1.10
File Interpreter ABI Platform
tpmstream-0.1.10-py3-none-any.whl Python 3 none any Details

Release files / tpmstream-0.1.10-py3-none-any.whl

Download URL tpmstream-0.1.10-py3-none-any.whl
Size 320.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b5bef2f2a9ec4280833dc9496cf37d38eedafb6d9653fd78b44c4a858bcffe2c
BLAKE2b-256 checksum
How to use checksums
5aa7e49142f4ed51a426a6c3c316b04d04bbfe1e1523bc0d7eada10626d02612
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.12

Release history Release notifications | RSS feed

This release

0.1.10 This release

1 release file

0.1.9

1 release file

0.1.8

1 release file

0.1.7

1 release file

0.1.6

1 release file

0.1.5

1 release file

0.1.4

1 release file

0.1.2

1 release file

0.1.1

1 release file

0.1.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page