-
Notifications
You must be signed in to change notification settings - Fork 366
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implmenet a TCTI module that will allow folks to write TCTIs in Python3. This will allow for more crazy and complex TCTI scenarios without having to re-write everyones stacks to use tpm2-pytss. Example Commandline: ```bash PYTHONPATH=$HOME tpm2_getcap --verbose --tcti=py:pytctitabrmd properties-fixed ``` Example TCTI: For the ultimate in mind-bending: C -> Python -> C and back for efficiency :-p. ```python3 from tpm2_pytss import TCTILdr class MyPyTCTI(object): def __init__(self, args: str): c = args.split(":", maxsplit=1) print(f"PYTHON: Initializing TCTI Ldr with mod: {c[0]} args: {c[1]}") self._tcti = TCTILdr(c[0], c[1]) @Property def magic(self): # Optional Method print("PYHTON magic") return 42 def receive(self, timeout: int) -> bytes: print("PYTHON receive") return self._tcti.receive(timeout=timeout) def transmit(self, data:bytes): print("PYTHON transmit") self._tcti.transmit(data) def tcti_init(args: str) -> MyPyTCTI: print(f"PYTHON tcti_init called with: {args}") return MyPyTCTI(args) ``` Signed-off-by: Bill Roberts <bill.c.roberts+gh@gmail.com>
- Loading branch information
1 parent
a7da221
commit c8feee6
Showing
16 changed files
with
1,002 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
# Python TCTI (py-tcti) | ||
|
||
The Python TCTI can be used to write TCTI modules in Python3. This allows a user to make use of the | ||
robust language features and modules that are available in Python3. | ||
|
||
## Invoking the Python TCTI | ||
|
||
Like implementing any TCTI, one can follow the friendly conventions or provide the full path of the shared | ||
object to `Tss2_TCTILdr_Initialize` or one can instantiate the TCTI directly with `TSS2_TCTI_Py_Initialize`. | ||
|
||
One needs to specify a module name (the name of a python file) and optionally arguments to pass to an init | ||
function in that module. The signature of this method is: `def tcti_init(args: str) -> Object` and the | ||
args string passed in is the args option appended on the configuration string. | ||
|
||
One possible way to use it with the command line tools is via the `--tcti=py:<modname>:<args>`. For | ||
example: | ||
```bash | ||
# Python3 file pytcti.py exists in $HOME | ||
PYTHONPATH=$HOME tpm2_getcap --tcti=py:pytcti properties-fixed | ||
``` | ||
|
||
## Example Python TCTI | ||
|
||
The below sample code TCTI just uses tpm2-pytss package to call TCTILdr with whatever | ||
argument string is provided. It just showcases full path delivery of commands. To invoke | ||
the example code below, assuming that the python file is named pytcti.py and you want | ||
to connect to tpm2-abrmd resource manager do: | ||
```bash | ||
PYTHONPATH=$HOME tpm2_getcap --tcti=py:pytcti:tabrmd properties-fixed | ||
``` | ||
|
||
```python3 | ||
# SPDX-License-Identifier: BSD-2-Clause | ||
from tpm2_pytss import TCTILdr | ||
|
||
|
||
class MyPyTCTI(object): | ||
def __init__(self, args: str): | ||
c = args.split(":", maxsplit=1) | ||
mod = c[0] | ||
args = c[1] if len(c) > 1 else "None" | ||
print(f"PYTHON: Initializing TCTI Ldr with mod: {mod} args: {args}") | ||
self._tcti = TCTILdr(mod, args) | ||
|
||
@property | ||
def magic(self): | ||
# Optional Method | ||
print("PYTHON magic") | ||
return 42 | ||
|
||
def receive(self, timeout: int) -> bytes: | ||
print("PYTHON receive") | ||
return self._tcti.receive(timeout=timeout) | ||
|
||
def transmit(self, data: bytes): | ||
print("PYTHON transmit") | ||
self._tcti.transmit(data) | ||
|
||
|
||
def tcti_init(args: str) -> MyPyTCTI: | ||
print(f"PYTHON tcti_init called with: {args}") | ||
return MyPyTCTI(args) | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/* SPDX-License-Identifier: BSD-2-Clause */ | ||
#ifndef TSS2_TCTI_CMD_H | ||
#define TSS2_TCTI_CMD_H | ||
|
||
#include "tss2_tcti.h" | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
TSS2_RC Tss2_Tcti_Py_Init ( | ||
TSS2_TCTI_CONTEXT *tctiContext, | ||
size_t *size, | ||
const char *conf); | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
||
#endif /* TSS2_TCTI_CMD_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
LIBRARY tss2-tcti-py | ||
EXPORTS | ||
Tss2_Tcti_Info | ||
Tss2_Tcti_Py_Init |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
global: | ||
Tss2_Tcti_Info; | ||
Tss2_Tcti_Py_Init; | ||
local: | ||
*; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
LIBRARY tss2-tcti-py | ||
EXPORTS | ||
Tss2_Tcti_Info | ||
Tss2_Tcti_Py_Init |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
global: | ||
Tss2_Tcti_Info; | ||
Tss2_Tcti_Py_Init; | ||
local: | ||
*; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
prefix=@prefix@ | ||
exec_prefix=@exec_prefix@ | ||
libdir=@libdir@ | ||
includedir=@includedir@ | ||
|
||
Name: tss2-tcti-py | ||
Description: TCTI library for implementing TCTIs in Python3. | ||
URL: https://github.com/tpm2-software/tpm2-tss | ||
Version: @VERSION@ | ||
Cflags: -I${includedir} -I${includedir}/tss2 | ||
Libs: -ltss2-py -L${libdir} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
.\" Process this file with | ||
.\" groff -man -Tascii foo.1 | ||
.\" | ||
.TH TCTI-PY 7 "JANUARY 2023" "TPM2 Software Stack" | ||
.SH NAME | ||
tcti-py \- Launch Python3 TPM2 TCTIs | ||
.SH SYNOPSIS | ||
Write a TCTI in Python3. | ||
.SH DESCRIPTION | ||
tcti-py is a library that allows creating TCTIs in Python3 by implementing a | ||
a TCTI interface in Python. More complete documentation can be found by | ||
visiting this URL: https://github.com/tpm2-software/tpm2-tss/tree/master/doc/tcti-py.md | ||
|
||
It is related to the TPM Command Transmission Interface Specification\*(rq specification. |
Oops, something went wrong.