xref: /aosp_15_r20/external/tpm2-tss/README.md (revision 758e9fba6fc9adbf15340f70c73baee7b168b1c9)
1*758e9fbaSOystein Eftevaag[![Linux Build Status](https://travis-ci.org/tpm2-software/tpm2-tss.svg?branch=master)](https://travis-ci.org/tpm2-software/tpm2-tss)
2*758e9fbaSOystein Eftevaag[![Windows Build status](https://ci.appveyor.com/api/projects/status/2rdmyn1ndkiavngn?svg=true)](https://ci.appveyor.com/project/tpm2-software/tpm2-tss)
3*758e9fbaSOystein Eftevaag[![FreeBSD Build status](https://api.cirrus-ci.com/github/tpm2-software/tpm2-tss.svg?branch=master)](https://cirrus-ci.com/github/tpm2-software/tpm2-tss)
4*758e9fbaSOystein Eftevaag[![Coverity Scan](https://img.shields.io/coverity/scan/3997.svg)](https://scan.coverity.com/projects/tpm2-tss)
5*758e9fbaSOystein Eftevaag[![Coverage Status](https://codecov.io/gh/tpm2-software/tpm2-tss/branch/master/graph/badge.svg)](https://codecov.io/gh/tpm2-software/tpm2-tss)
6*758e9fbaSOystein Eftevaag[![CII Best Practices](https://bestpractices.coreinfrastructure.org/projects/2332/badge)](https://bestpractices.coreinfrastructure.org/projects/2332)
7*758e9fbaSOystein Eftevaag[![Total alerts](https://img.shields.io/lgtm/alerts/g/tpm2-software/tpm2-tss.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/tpm2-software/tpm2-tss/alerts/)
8*758e9fbaSOystein Eftevaag[![Language grade: C/C++](https://img.shields.io/lgtm/grade/cpp/g/tpm2-software/tpm2-tss.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/tpm2-software/tpm2-tss/context:cpp)
9*758e9fbaSOystein Eftevaag[![Documentation Status](https://readthedocs.org/projects/tpm2-tss/badge/?version=latest)](https://tpm2-tss.readthedocs.io/en/latest/?badge=latest)
10*758e9fbaSOystein Eftevaag[![Fuzzing Status](https://oss-fuzz-build-logs.storage.googleapis.com/badges/tpm2-tss.svg)](https://bugs.chromium.org/p/oss-fuzz/issues/list?sort=-opened&can=1&q=proj:tpm2-tss)
11*758e9fbaSOystein Eftevaag[![Gitter](https://badges.gitter.im/tpm2-software/community.svg)](https://gitter.im/tpm2-software/community?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)
12*758e9fbaSOystein Eftevaag
13*758e9fbaSOystein Eftevaag# Overview
14*758e9fbaSOystein EftevaagThis repository hosts source code implementing the Trusted Computing Group's (TCG) TPM2 Software Stack (TSS).
15*758e9fbaSOystein EftevaagThis stack consists of the following layers from top to bottom:
16*758e9fbaSOystein Eftevaag
17*758e9fbaSOystein Eftevaag* Feature API (FAPI) as described in the [TSS 2.0 Feature API Specification](https://trustedcomputinggroup.org/wp-content/uploads/TSS_FAPI_v0.94_r04_pubrev.pdf)
18*758e9fbaSOystein Eftevaagalong with [TSS 2.0 JSON Data Types and Policy Language Specification](https://trustedcomputinggroup.org/wp-content/uploads/TSS_JSON_Policy_v0.7_r04_pubrev.pdf)
19*758e9fbaSOystein EftevaagThis API is designed to be very high-level API, intended to make programming with the TPM as simple as possible.
20*758e9fbaSOystein EftevaagThe API functions are exposed through a single library: libtss2-fapi.
21*758e9fbaSOystein Eftevaag* Enhanced System API (ESAPI) as described in the [TSS 2.0 Enhanced System API (ESAPI) Specification](https://trustedcomputinggroup.org/wp-content/uploads/TSS_ESAPI_Version-0.9_Revision-04_reviewEND030918.pdf).
22*758e9fbaSOystein EftevaagThis API is a 1-to-1 mapping of the TPM2 commands documented in Part 3 of the TPM2 specification.
23*758e9fbaSOystein EftevaagAdditionally there are asynchronous versions of each command.
24*758e9fbaSOystein EftevaagIn addition to SAPI, the ESAPI performs tracking of meta data for TPM object and automatic calculation of session based authorization and encryption values.
25*758e9fbaSOystein EftevaagBoth the synchronous and asynchronous API are exposed through a single library: libtss2-esys.
26*758e9fbaSOystein Eftevaag* System API (SAPI) as described in the [system level API and TPM command transmission interface specification](http://www.trustedcomputinggroup.org/resources/tss_system_level_api_and_tpm_command_transmission_interface_specification).
27*758e9fbaSOystein EftevaagThis API is a 1-to-1 mapping of the TPM2 commands documented in Part 3 of the TPM2 specification.
28*758e9fbaSOystein EftevaagAdditionally there are asynchronous versions of each command.
29*758e9fbaSOystein EftevaagThese asynchronous variants may be useful for integration into event-driven programming environments.
30*758e9fbaSOystein EftevaagBoth the synchronous and asynchronous API are exposed through a single library: libtss2-sys.
31*758e9fbaSOystein Eftevaag* Marshaling/Unmarshaling (MU) as described in the [TCG TSS 2.0 Marshaling/Unmarshaling API Specification](https://trustedcomputinggroup.org/wp-content/uploads/TSS_Marshaling_Unmarshaling_API_Version-1.0_Revision-04_review_ENDS030918.pdf).
32*758e9fbaSOystein EftevaagThis API provides a set of marshaling and unmarshaling functions for all data types define by the TPM library specification.
33*758e9fbaSOystein EftevaagThe Marshaling/Unmarshaling API is exposed through a library called libtss2-mu.
34*758e9fbaSOystein Eftevaag* TPM Command Transmission Interface (TCTI) that is described in the same specification.
35*758e9fbaSOystein EftevaagThis API provides a standard interface to transmit / receive TPM command / response buffers.
36*758e9fbaSOystein EftevaagIt is expected that any number of libraries implementing the TCTI API will be implemented as a way to abstract various platform specific IPC mechanisms.
37*758e9fbaSOystein EftevaagCurrently this repository provides two TCTI implementations: libtss2-tcti-device and libtss2-tcti-mssim.
38*758e9fbaSOystein EftevaagThe former should be used for direct access to the TPM through the Linux kernel driver.
39*758e9fbaSOystein EftevaagThe latter implements the protocol exposed by the Microsoft software TPM2 simulator.
40*758e9fbaSOystein Eftevaag* The [TCG TSS 2.0 Overview and Common Structures Specification](https://trustedcomputinggroup.org/wp-content/uploads/TSS_Overview_Common_Structures_Version-0.9_Revision-03_Review_030918.pdf) forms the basis for all implementations in this project. NOTE: We deviate from this draft of the specification by increasing the value of TPM2_NUM_PCR_BANKS from 3 to 16 to ensure compatibility with TPM2 implementations that have enabled a larger than typical number of PCR banks. This larger value for TPM2_NUM_PCR_BANKS is expected to be included in a future revision of the specification.
41*758e9fbaSOystein Eftevaag
42*758e9fbaSOystein Eftevaag# Build and Installation Instructions:
43*758e9fbaSOystein EftevaagInstructions to build and install tpm2-tss are available in the [INSTALL](INSTALL.md) file.
44*758e9fbaSOystein Eftevaag
45*758e9fbaSOystein Eftevaag# Getting in Touch:
46*758e9fbaSOystein EftevaagIf you're looking to discuss the source code in this project or get some questions answered you should join the 01.org TPM2 mailing list: https://lists.01.org/postorius/lists/tpm2.lists.01.org/.
47*758e9fbaSOystein EftevaagWe also have an IRC channel set up on [FreeNode](https://freenode.net/) called \#tpm2.0-tss.
48*758e9fbaSOystein EftevaagYou can also try Gitter [![Gitter](https://badges.gitter.im/tpm2-software/community.svg)](https://gitter.im/tpm2-software/community?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)
49*758e9fbaSOystein Eftevaag
50*758e9fbaSOystein EftevaagIn case you want to contribute to the project, please also have a look at the [Contribution Guidelines](CONTRIBUTING.md).
51*758e9fbaSOystein Eftevaag
52*758e9fbaSOystein Eftevaag# Documentation
53*758e9fbaSOystein Eftevaag
54*758e9fbaSOystein EftevaagThe doxygen documentation can either be built by oneself (see the [INSTALL](INSTALL.md) file) or browsed directly on [tpm2-tss.readthedocs.io](https://tpm2-tss.readthedocs.io/).
55*758e9fbaSOystein Eftevaag
56*758e9fbaSOystein Eftevaag# Test Suite
57*758e9fbaSOystein EftevaagThis repository contains a test suite intended to exercise the TCTI, SAPI and ESAPI code.
58*758e9fbaSOystein EftevaagThis test suite is *not* intended to test a TPM implementation, so this test suite should only be run against a TPM simulator.
59*758e9fbaSOystein EftevaagIf this test suite is executed against a TPM other than the software simulator it may cause damage to the TPM (NV storage wear out, etc.).
60*758e9fbaSOystein EftevaagYou have been warned.
61*758e9fbaSOystein Eftevaag
62*758e9fbaSOystein Eftevaag## Simulator
63*758e9fbaSOystein EftevaagThe TPM library specification contains reference code sufficient to construct a software TPM 2.0 simulator.
64*758e9fbaSOystein EftevaagThis code was provided by Microsoft and they provide a binary download for Windows [here](https://www.microsoft.com/en-us/download/details.aspx?id=52507).
65*758e9fbaSOystein EftevaagIBM has repackaged this code with a few Makefiles so that the Microsoft code can be built and run on Linux systems.
66*758e9fbaSOystein EftevaagThe Linux version of the Microsoft TPM 2.0 simulator can be obtained [here](https://downloads.sourceforge.net/project/ibmswtpm2/ibmtpm974.tar.gz).
67*758e9fbaSOystein EftevaagOnce you've downloaded and successfully built and execute the simulator it will, by default, be accepting connections on the localhost, TCP ports 2321 and 2322.
68*758e9fbaSOystein Eftevaag
69*758e9fbaSOystein EftevaagIssues building or running the simulator should be reported to the IBM software TPM2 project.
70*758e9fbaSOystein Eftevaag
71*758e9fbaSOystein EftevaagNOTE: The Intel TCG TSS is currently tested against version 974 of the simulator.
72*758e9fbaSOystein EftevaagCompatibility with later versions has not yet been tested.
73*758e9fbaSOystein Eftevaag
74*758e9fbaSOystein Eftevaag## Testing
75*758e9fbaSOystein EftevaagTo test the various TCTI, SAPI and ESAPI api calls, unit and integration tests can
76*758e9fbaSOystein Eftevaagbe run by configuring the build to enable unit testing and running the "check"
77*758e9fbaSOystein Eftevaagbuild target. It is recommended to use a simulator for testing, and the
78*758e9fbaSOystein Eftevaagsimulator will be automatically launched by the tests. Please review the
79*758e9fbaSOystein Eftevaagdependency list in [INSTALL](INSTALL.md) for dependencies when building
80*758e9fbaSOystein Eftevaagthe test suite.
81*758e9fbaSOystein Eftevaag```
82*758e9fbaSOystein Eftevaag$ ./configure --enable-unit --enable-integration
83*758e9fbaSOystein Eftevaag$ make -j$(nproc) check
84*758e9fbaSOystein Eftevaag```
85*758e9fbaSOystein EftevaagThis will generate a file called "test-suite.log" in the root of the build
86*758e9fbaSOystein Eftevaagdirectory.
87*758e9fbaSOystein Eftevaag
88*758e9fbaSOystein EftevaagPlease report failures in a Github 'issue' with a full log of the test run.
89*758e9fbaSOystein Eftevaag
90*758e9fbaSOystein EftevaagNOTE: The unit and integration tests can be enabled independently.
91*758e9fbaSOystein EftevaagThe --enable-unit option controls unit tests, and --enable-integration
92*758e9fbaSOystein Eftevaagcontrols the integration tests.
93*758e9fbaSOystein Eftevaag
94*758e9fbaSOystein Eftevaag### Running tests on physical TPM device
95*758e9fbaSOystein EftevaagTo run integration tests on a physical TPM device, including a TPM hardware
96*758e9fbaSOystein Eftevaagor a software TPM implemented in platform firmware the configure script
97*758e9fbaSOystein Eftevaagprovides two options.
98*758e9fbaSOystein EftevaagThe first option is called --with-ptpm and it is used to point to the TPM
99*758e9fbaSOystein Eftevaagdevice interface exposed by the OS, for example:
100*758e9fbaSOystein Eftevaag
101*758e9fbaSOystein Eftevaag```
102*758e9fbaSOystein Eftevaag  $ ./configure  --with-ptpm=/dev/tpm0
103*758e9fbaSOystein Eftevaag```
104*758e9fbaSOystein EftevaagThe second option, --with-ptpmtests, enables a "class" of test.
105*758e9fbaSOystein EftevaagThere are three classes:
106*758e9fbaSOystein Eftevaag1. destructive - these tests can affect TPM capability or lifespan
107*758e9fbaSOystein Eftevaag2. mandatory   - these tests check all the functionality that is mandatory
108*758e9fbaSOystein Eftevaag                 per the TCG specification (default).
109*758e9fbaSOystein Eftevaag3. optional    - these tests are for functionality that is optional per the
110*758e9fbaSOystein Eftevaag                 TCG specification.
111*758e9fbaSOystein Eftevaag
112*758e9fbaSOystein EftevaagFor example to enable both mandatory and optional test cases during configure
113*758e9fbaSOystein Eftevaagone needs to set this flag as follows:
114*758e9fbaSOystein Eftevaag
115*758e9fbaSOystein Eftevaag```
116*758e9fbaSOystein Eftevaag  $ ./configure --with-ptpmtests="mandatory,optional"
117*758e9fbaSOystein Eftevaag```
118*758e9fbaSOystein EftevaagTht default value for the flag is "mandatory"
119*758e9fbaSOystein EftevaagAny combination of the three is valid.
120*758e9fbaSOystein EftevaagThe two flags are only valid when the integration tests are enabled with
121*758e9fbaSOystein Eftevaag--enable-integration flag.
122*758e9fbaSOystein Eftevaag
123*758e9fbaSOystein EftevaagAfter that the following command is used to run the test on the configured
124*758e9fbaSOystein EftevaagTPM device:
125*758e9fbaSOystein Eftevaag
126*758e9fbaSOystein Eftevaag```
127*758e9fbaSOystein Eftevaag  $ sudo make check-ptpm
128*758e9fbaSOystein Eftevaag```
129*758e9fbaSOystein Eftevaag  or
130*758e9fbaSOystein Eftevaag```
131*758e9fbaSOystein Eftevaag  $ sudo make check -j 1
132*758e9fbaSOystein Eftevaag```
133*758e9fbaSOystein Eftevaag
134*758e9fbaSOystein EftevaagNote: The tests can not be run in paralel.
135*758e9fbaSOystein Eftevaag
136*758e9fbaSOystein Eftevaag### Running valgrind check
137*758e9fbaSOystein EftevaagThe unit and integration tests can be run under the valgrind tool, which
138*758e9fbaSOystein Eftevaagperforms additional checks on the library and test code, such as memory
139*758e9fbaSOystein Eftevaagleak checks etc. The following command is used to run the tests under
140*758e9fbaSOystein Eftevaagvalgrind:
141*758e9fbaSOystein Eftevaag
142*758e9fbaSOystein Eftevaag  $ make check-valgrind
143*758e9fbaSOystein Eftevaag
144*758e9fbaSOystein EftevaagThis command will enable all valgrind "tools" and kick off as many test
145*758e9fbaSOystein Eftevaagas many tools it supports. It is possible to enable different valgrind
146*758e9fbaSOystein Eftevaagtools (checks) in more granularity. This can be controlled by invoking
147*758e9fbaSOystein Eftevaagdifferent tools separately using check-valgrind-<tool>, for instance:
148*758e9fbaSOystein Eftevaag
149*758e9fbaSOystein Eftevaag```
150*758e9fbaSOystein Eftevaag  $ make check-valgrind-memcheck
151*758e9fbaSOystein Eftevaag```
152*758e9fbaSOystein Eftevaag  or
153*758e9fbaSOystein Eftevaag```
154*758e9fbaSOystein Eftevaag  $ make check-valgrind-drd
155*758e9fbaSOystein Eftevaag```
156*758e9fbaSOystein Eftevaag
157*758e9fbaSOystein EftevaagCurrently the the following tools are supported:
158*758e9fbaSOystein Eftevaag
159*758e9fbaSOystein Eftevaagmemcheck - Performs memory related checks. This is the default tool.
160*758e9fbaSOystein Eftevaaghelgrind - Performs synchronization errors checks.
161*758e9fbaSOystein Eftevaagdrd      - Performs thread related checks.
162*758e9fbaSOystein Eftevaagsgcheck  - Performs stack overrun related checks.
163*758e9fbaSOystein Eftevaag
164*758e9fbaSOystein EftevaagNote that the valgring tool can also be invoked manually using the standard
165*758e9fbaSOystein Eftevaaglibtool:
166*758e9fbaSOystein Eftevaag
167*758e9fbaSOystein Eftevaag```
168*758e9fbaSOystein Eftevaag  $ libtool exec valgrind --tool=memcheck --leak-check=full \
169*758e9fbaSOystein Eftevaag    test/integration/esys-auto-session-flags.int
170*758e9fbaSOystein Eftevaag```
171*758e9fbaSOystein Eftevaag
172*758e9fbaSOystein EftevaagThis allows for more control on what checks are performed.
173*758e9fbaSOystein Eftevaag
174*758e9fbaSOystein Eftevaag### Logging
175*758e9fbaSOystein EftevaagWhile investigating issues it might be helpful to enable extra debug/trace
176*758e9fbaSOystein Eftevaagoutput. It can be enabled separately for different components.
177*758e9fbaSOystein EftevaagThe description how to do this can be found in the [logging](doc/logging.md) file.
178*758e9fbaSOystein Eftevaag
179*758e9fbaSOystein Eftevaag### Fuzzing
180*758e9fbaSOystein EftevaagAll system API function calls can be tested using a fuzzing library.
181*758e9fbaSOystein EftevaagThe description how to do this can be found in the [fuzzing](doc/fuzzing.md) file.
182*758e9fbaSOystein Eftevaag
183*758e9fbaSOystein Eftevaag# Architecture/Block Diagram
184*758e9fbaSOystein EftevaagSAPI library, TAB/RM, and Test Code Block Diagram:
185*758e9fbaSOystein Eftevaag![Architecture Block Diagram](doc/TSS_block_diagram.png)
186*758e9fbaSOystein Eftevaag
187*758e9fbaSOystein Eftevaag# Project Layout
188*758e9fbaSOystein Eftevaag```
189*758e9fbaSOystein Eftevaag├── doc     : various bits of documentation\
190*758e9fbaSOystein Eftevaag├── include : header files installed in $(includedir)\
191*758e9fbaSOystein Eftevaag│   └── tss2      : all public headers for this project\
192*758e9fbaSOystein Eftevaag├── lib     : data files used by the build or installed into $(libdir)\
193*758e9fbaSOystein Eftevaag├── m4      : autoconf support macros\
194*758e9fbaSOystein Eftevaag├── man     : man pages\
195*758e9fbaSOystein Eftevaag├── script  : scripts used by the build or CI\
196*758e9fbaSOystein Eftevaag├── src     : all source files\
197*758e9fbaSOystein Eftevaag│   ├── tss2-esys : enhanced system API (ESAPI) implementation\
198*758e9fbaSOystein Eftevaag│   │   └── api   : ESAPI TPM API implementation\
199*758e9fbaSOystein Eftevaag│   ├── tss2-mu   : TPM2 type marshaling/unmarshaling (MU) API implementation\
200*758e9fbaSOystein Eftevaag│   ├── tss2-sys  : system API (SAPI) implementation\
201*758e9fbaSOystein Eftevaag│   │   └── api   : SAPI public API implementation\
202*758e9fbaSOystein Eftevaag│   ├── tss2-tcti : TCTI implementations for device and mssim\
203*758e9fbaSOystein Eftevaag│   └── util      : Internal utility library (e.g. logging framework)\
204*758e9fbaSOystein Eftevaag└── test    : test code\
205*758e9fbaSOystein Eftevaag    ├── integration : integration test harness and test cases\
206*758e9fbaSOystein Eftevaag    ├── tpmclient   : monolithic, legacy test application\
207*758e9fbaSOystein Eftevaag    └── unit        : unit tests
208*758e9fbaSOystein Eftevaag```
209