{"id":18320322,"url":"https://github.com/tpm2-software/tpm2-send-tbs","last_synced_at":"2025-10-30T12:31:09.794Z","repository":{"id":205983422,"uuid":"654454571","full_name":"tpm2-software/tpm2-send-tbs","owner":"tpm2-software","description":"Tool to bridge from WSL to TBS","archived":false,"fork":false,"pushed_at":"2023-11-08T08:15:18.000Z","size":12,"stargazers_count":2,"open_issues_count":1,"forks_count":2,"subscribers_count":4,"default_branch":"main","last_synced_at":"2024-12-23T08:43:38.104Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-2-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tpm2-software.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-06-16T07:01:36.000Z","updated_at":"2024-11-08T08:39:28.000Z","dependencies_parsed_at":null,"dependency_job_id":"6b9a0fb5-64d4-47a1-ac85-ab3b85182512","html_url":"https://github.com/tpm2-software/tpm2-send-tbs","commit_stats":null,"previous_names":["tpm2-software/tpm2-send-tbs"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tpm2-software%2Ftpm2-send-tbs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tpm2-software%2Ftpm2-send-tbs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tpm2-software%2Ftpm2-send-tbs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tpm2-software%2Ftpm2-send-tbs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tpm2-software","download_url":"https://codeload.github.com/tpm2-software/tpm2-send-tbs/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238963881,"owners_count":19559780,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-05T18:15:54.915Z","updated_at":"2025-10-30T12:31:09.377Z","avatar_url":"https://github.com/tpm2-software.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Build Status](https://github.com/tpm2-software/tpm2-send-tbs/workflows/CI/badge.svg)](https://github.com/tpm2-software/tpm2-send-tbs/actions)\n\n\u003e [!WARNING]\n\u003e This project is in an alpha state with [known\n\u003e limitations](#limitation-some-tpm-commands-fail). Use with caution!\n\n# tpm2-send-tbs\n\ntpm2-send-tbs is a zero-dependency utility for sending raw bytes to the TPM.\n\nWant to access the TPM 2.0 from within WSL2? Just compile `tpm2-send-tbs.exe`\nand then call it from your WSL2 shell.\n\n\n# Usage\n\ntpm2-send-tbs takes an input stream (by default `stdin`) and an output stream\n(by default `stdout`).\n\n```cmd\ntpm2-send-tbs [--debug] [--bin] [-in \u003cinput file\u003e] [-out \u003coutput file\u003e]\n```\n\n## Examples\n\nBy default, tpm2-send-tbs reads a hex stream from `stdin` and writes to\n`stdout`. Here, a TPM2_GetRandom command is sent as an example:\n\n```cmd\nREM cmd.exe:\necho 80010000000c0000017b0004 | build/tpm2-send-tbs.exe\n```\n\n```bash\n# bash:\nprintf \"80010000000c0000017b0004\" | build/tpm2-send-tbs.exe\n```\n\nYou can use `--bin` to switch to binary format.\n\n```bash\n# bash:\nprintf \"80010000000c0000017b0004\" | xxd -r -p | build/tpm2-send-tbs.exe --bin | xxd -p\n```\n\n\u003e [!NOTE]\n\u003e `xxd` buffers until its input pipe is closed. If a process wants to\n\u003e send multiple TPM commands, the commands/responses are a back and forth. E.g.\n\u003e tcti-cmd waits for a TPM response before sending the next command. Thus, `xxd`\n\u003e would block indefinitely, here.\n\u003e\n\u003e As an alternative, you can use the non-blocking `build/hex` and `build/unhex`.\n\u003e\n\u003e ```bash\n\u003e # bash:\n\u003e tpm2_getrandom -T \"cmd: build/hex | build/tpm2-send-tbs.exe | build/unhex\" --hex 4\n\u003e ```\n\nFor usage with [tpm2-tools](https://github.com/tpm2-software/tpm2-tools):\n\n```bash\ntpm2_getrandom -T \"cmd: build/hex | build/tpm2-send-tbs.exe | build/unhex\" --hex 4\n```\n\n\u003e [!NOTE]\n\u003e The WSL2 pipe is broken. It turns LF into CR+LF, even if opened in\n\u003e bytewise mode. As a result, `tpm2_getrandom -T \"cmd: build/tpm2-send-tbs.exe\n\u003e --bin\" --hex 4` will not work.\n\u003e\n\u003e To work around this, use hex format instead of binary for input and output pipes.\n\n# Build\n\nIn your WSL2 (or Linux), run make. This will use mingw if installed. Otherwise,\nmsvc will be used (requires [Build Tools for Visual Studio\n2022](https://visualstudio.microsoft.com/downloads/#build-tools-for-visual-studio-2022)).\n\n```bash\nmake\n```\n\n## Compile Manually\n\nUsing mingw:\n```bash\nx86_64-w64-mingw32-gcc -Wall -Wextra -D_WIN32_WINNT=0x0600 src/tpm2-send-tbs.c -o tpm2-send-tbs.exe -L /mnt/c/Program\\ Files\\ \\(x86\\)/Windows\\ Kits/10/Lib/*/um/x64 -l:tbs.lib\n```\n\nAlternatively, in a windows-only context:\n\n```cmd\nREM setup environment\n\"C:\\Program Files (x86)\\Microsoft Visual Studio\\2022\\BuildTools\\VC\\Auxiliary\\Build\\vcvars32.bat\"\n\nREM compile\ncd build\ncl /W4 src/tpm2-send-tbs.c /link tbs.lib\n```\n\n# Test\n\nInstall the [tpm2-tools](https://github.com/tpm2-software/tpm2-tools). In your\nWSL2, run the smoke tests:\n\n```\nmake check\n```\n\n### Limitation: Some TPM Commands Fail\n\nAt the moment, some TPM commands will fail. The root cause of this is unclear.\nIt could be a limitation of the TBS, insufficient priviledges or something\nentirely different. Hints and patches welcome!\n\nExample:\n\n```bash\ntpm2_nvread 0x01C00002 -T \"cmd: build/hex | build/tpm2-send-tbs.exe --debug | build/unhex\"\nWARN: Reading full size of the NV index\nread cmd[59]: 80 01 00 00 00 3b 00 00 01 76 40 00 00 07 40 00 00 07 00 20 4f 83 b6 b9 fa 2d d2 e2 30 c8 a5 ce 6d 62 ee 9b 94 45 5e 69 47 a4 52 7f 79 39 15 2c 2f e7 b5 7b 00 00 00 00 10 00 0b\nsend rsp[48]: 80 01 00 00 00 30 00 00 00 00 02 00 00 00 00 20 c5 db 0b a8 b1 c7 03 45 76 d2 37 1b fd dd f1 ef f9 fc 1d b8 ea 5f 57 46 90 f1 6e e6 25 16 f7 38\nread cmd[14]: 80 01 00 00 00 0e 00 00 01 69 01 c0 00 02\nFailed when attempting to submit TBS context: 80284001\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftpm2-software%2Ftpm2-send-tbs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftpm2-software%2Ftpm2-send-tbs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftpm2-software%2Ftpm2-send-tbs/lists"}