TCTI

class tpm2_pytss.TCTI.PyTCTI(max_size=4096, magic=b'PYTCTI\x00\x00')[source]

Subclass for implementing a TCTI in Python.

Extend this object and implement the following methods:
  • def do_transmit(self, command: bytes) -> None

    This method transmits a command buffer to the TPM. This method IS REQUIRED.

  • def do_receive(self, timeout: int) -> bytes:

    This method receives a response from the TPM and returns it. This method IS REQUIRED

  • def do_cancel(self) -> None:

    Cancels an I/O operation with the TPM. This method is OPTIONAL.

  • def do_get_poll_handles(self) -> Optional[Tuple[PollData]]:

    Retrieves PollData objects from the TCTI used for async I/O. This method is OPTIONAL.

  • def do_set_locality(self, locality: int) -> None:

    Sets the locality in which to communicate with the TPM. This method is OPTIONAL.

  • def do_make_sticky(self, handle: int, is_sticky: bool) -> None:

    Makes a handle sticky to persist across client exits with an RM. This method is OPTIONAL.

  • def do_finalize(self) -> None:

    Finalizes a TCTI, this is analogous to close on a file. This method is OPTIONAL.

Note

All methods may throw exceptions as needed.

Parameters:
  • max_size (int) – The size of the response buffer for callers to allocate. Defaults to 4096.

  • magic (bytes) – The magic value for the TCTI, may aid in debugging. Max length is 8, defaults to b”PYTCTI"

Returns:

An instance of the PyTCTI class. It’s unusable as is, users should extend it.

do_cancel()[source]

Cancels an I/O operation with the TPM. This method is OPTIONAL.

Raises:
  • Exception – Implementations are free to raise any Exception. Exceptions are retained

  • across the native boundary.

do_finalize()[source]

Finalizes a TCTI, this is analogous to close on a file. This method is OPTIONAL.

Note: Native TCTIs do not return anything and thus cannot raise any errors. Python TCTIs MAY raise exceptions across this interface.

Raises:
  • Exception – Implementations are free to raise any Exception. Exceptions are retained

  • across the native boundary.

do_get_poll_handles()[source]

Retrieves PollData objects from the TCTI used for async I/O. This method is OPTIONAL.

Returns:

The tuple of PollData handles or None.

Raises:
  • Exception – Implementations are free to raise any Exception. Exceptions are retained

  • across the native boundary.

do_make_sticky(handle, is_sticky)[source]

Makes a handle sticky to persist across client exits with a Resource Manager. This method is OPTIONAL.

Note: A sticky object is one a RM doesn’t flush when the client closes their connection.

Parameters:
  • handle (int) – The TPM handle to make sticky.

  • is_sticky (bool) – True to make sticky, False to make it not sticky.

Raises:
  • Exception – Implementations are free to raise any Exception. Exceptions are retained

  • across the native boundary.

do_receive(timeout)[source]

This method receives a response from the TPM and returns it. This method IS REQUIRED.

Parameters:

timeout (int) – The timeout in milliseconds to wait for the TPM. Negative values mean wait indefinitely.

Raises:
  • NotImplementedError – If a subclass has not implemented this.

  • Exception – Implementations are free to raise any Exception. Exceptions are retained

  • across the native boundary.

do_set_locality(locality)[source]

Sets the locality in which to communicate with the TPM. This method is OPTIONAL.

Parameters:

locality (int) – The locality of communication with the TPM.

Raises:
  • Exception – Implementations are free to raise any Exception. Exceptions are retained

  • across the native boundary.

do_transmit(command)[source]

This method transmits a command buffer to the TPM. This method IS REQUIRED.

Parameters:

command (bytes) – The bytes to send to the TPM.

Raises:
  • NotImplementedError – If a subclass has not implemented this.

  • Exception – Implementations are free to raise any Exception. Exceptions are retained

  • across the native boundary.

class tpm2_pytss.TCTI.TCTI(ctx)[source]

Initialize a TCTI object.

Initialize a TCTI from a NATIVE instantiated TCTI.

Parameters:

ctx (ffi.CData) – A TSS2_TCTI_CONTEXT * variable. This would be returned from a TCTIs initialize or TCTILdr routine.

Returns:

An instance of a TCTI.

cancel(*args, **kwargs)[source]
finalize(*args, **kwargs)[source]
get_poll_handles(*args, **kwargs)[source]
property magic

Returns the MAGIC string of the TCTI.

Returns:

The magic byte string.

make_sticky(*args, **kwargs)[source]
receive(*args, **kwargs)[source]
set_locality(*args, **kwargs)[source]
transmit(*args, **kwargs)[source]
property version

Returns the VERSION number of the TCTI.

This is the TCTI interface version NOT the release version of the TCTI. Ie if it implements version 1 or version 2 of the spec.

Returns:

The TCTI version number.

class tpm2_pytss.TCTILdr.TCTILdr(name=None, conf=None)[source]
close()[source]
property conf
static is_available(name=None)[source]

Lookup the TCTI and return its availability

Returns:

True if the interface is available

property name
property name_conf
classmethod parse(tcti_name_conf)[source]
class tpm2_pytss.TCTISPIHelper.TCTISPIHelper(with_wait_state=False)[source]

The TCTI for interacting with SPI devices.

Users should extend a TCTISPIHelper object and implement the following callbacks:

All Users:
  • on_sleep_ms

  • on_start_timeout

  • on_timeout_expired

  • on_spi_transfer

with_wait_state=true:
  • on_spi_acquire

  • on_spi_release

Optional:
  • on_finalize

Parameters:

with_wait_state (bool) – True if you intend to use wait states. Defaults to False.

on_finalize()[source]

Called when the TCTI is finalized.

This callback is OPTIONAL.

Raises:
  • Exception – Implementations are free to raise any Exception. Exceptions are retained

  • across the native boundary.

on_sleep_ms(milliseconds)[source]

Sleeps for a specified amount of time in millisecons.

This callback is REQUIRED.

Parameters:

milliseconds (int) – The time to sleep.

Raises:
  • Exception – Implementations are free to raise any Exception. Exceptions are retained

  • across the native boundary.

on_spi_acquire()[source]

Called when the SPI bus needs to be acquired for wait states.

This callback is REQUIRED for WAIT STATES. No errors may occur across this boundary.

on_spi_release()[source]

Called when the SPI bus needs to be released for wait states.

This callback is REQUIRED for WAIT STATES.

Raises:
  • Exception – Implementations are free to raise any Exception. Exceptions are retained

  • across the native boundary.

on_spi_transfer(data_in)[source]

Called to transfer data across the SPI bus.

This callback is REQUIRED.

Parameters:

data_in (bytes) – The data to send.

Returns(bytes):

The bytes to send.

Raises:
  • Exception – Implementations are free to raise any Exception. Exceptions are retained

  • across the native boundary.

on_start_timeout(milliseconds)[source]

Called when a timeout is occurring with the sleep duration in millisecons.

This callback is REQUIRED.

Parameters:

milliseconds (int) – The time to sleep.

Raises:
  • Exception – Implementations are free to raise any Exception. Exceptions are retained

  • across the native boundary.

on_timeout_expired()[source]

Called to determine if a timeout is expired.

This callback is REQUIRED. No errors may occur across this boundary.

property waitstate

Gets the wait state property.

Returns(bool):

True if this TCTI implements wait states, false otherwise.