Debian Codegraph @

README.md

raw
1 # Go-TPM tools [![GitHub release (latest SemVer)](https://img.shields.io/github/v/release/google/go-tpm-tools)](https://github.com/google/go-tpm-tools/releases)
2
3 [![Build Status](https://github.com/google/go-tpm-tools/workflows/CI/badge.svg)](https://github.com/google/go-tpm-tools/actions?query=workflow%3ACI)
4 [![Go Reference](https://pkg.go.dev/badge/github.com/google/go-tpm-tools.svg)](https://pkg.go.dev/github.com/google/go-tpm-tools)
5 ![GitHub go.mod Go version](https://img.shields.io/github/go-mod/go-version/google/go-tpm-tools)
6 [![Go Report Card](https://goreportcard.com/badge/github.com/google/go-tpm-tools)](https://goreportcard.com/report/github.com/google/go-tpm-tools)
7 [![License](https://img.shields.io/badge/LICENSE-Apache2.0-ff69b4.svg)](http://www.apache.org/licenses/LICENSE-2.0.html)
8
9 The `go-tpm-tools` module is a [TPM 2.0](https://trustedcomputinggroup.org/resource/trusted-platform-module-2-0-a-brief-introduction/) support library designed to complement [Go-TPM](https://github.com/google/go-tpm).
10
11 It contains the following public packages:
12 - [`client`](https://pkg.go.dev/github.com/google/go-tpm-tools/client):
13 A Go package providing simplified abstractions and utility functions for interacting with a TPM 2.0, including:
14 - Signing
15 - Attestation
16 - Reading PCRs
17 - Sealing/Unsealing data
18 - Importing Data and Keys
19 - Reading NVData
20 - Getting the TCG Event Log
21 - [`server`](https://pkg.go.dev/github.com/google/go-tpm-tools/server):
22 A Go package providing functionality for a remote server to send, receive, and interpret TPM 2.0 data. None of the commands in this package issue TPM commands, but instead handle:
23 - TCG Event Log parsing
24 - Attestation verification
25 - Creating data for Importing into a TPM
26 - [`proto`](https://pkg.go.dev/github.com/google/go-tpm-tools/proto):
27 Common [Protocol Buffer](https://developers.google.com/protocol-buffers) messages that are exchanged between the `client` and `server` libraries. This package also contains helper methods for validating these messages.
28 - [`simulator`](https://pkg.go.dev/github.com/google/go-tpm-tools/simulator):
29 Go bindings to the Microsoft's [TPM 2.0 simulator](https://github.com/Microsoft/ms-tpm-20-ref/).
30
31 This repository also contains `gotpm`, a command line tool for using the TPM.
32 Run `gotpm --help` and `gotpm <command> --help` for more documentation.
33
34 ### Use prebuilt `gotpm` binary
35
36 You can download the binary from a [release](https://github.com/google/go-tpm-tools/releases) directly.
37
38 ```bash
39 # VERSION: 0.4.4 ARCH: Linux_x86_64
40 curl -L https://github.com/google/go-tpm-tools/releases/download/[VERSION]/go-tpm-tools_[ARCH].tar.gz -o go-tpm-tools.tar.gz
41 tar xvf go-tpm-tools.tar.gz
42 # You may need to copy the binary to a directory with executable permissions.
43 # NOTE: on Container-Optimized OS, /var/lib/google/ is executable
44 ./gotpm --help
45 ```
46
47 ### Building and Installing `gotpm`
48
49 `gotpm` can be directly installed from this repo by running:
50 ```bash
51 go install github.com/google/go-tpm-tools/cmd/gotpm@latest
52 # gotpm will be installed to $GOBIN
53 gotpm --help
54 ```
55 Alternatively, to build `gotpm` from a cloned version of this repo, run:
56 ```bash
57 cd /my/path/to/cloned/go-tpm-tools/cmd/gotpm
58 go build
59 # gotpm will be in the cmd/gotpm subdirectory of the repo
60 ./gotpm --help
61 ```
62
63 ## Minimum Required Go Version
64
65 This project currently requires Go 1.20 or newer. Any update to the minimum required Go version will be released as a **minor** version update.
66
67 ## `openssl` errors when building `simulator`
68
69 Similarly, when building the `simulator` library (or tests), you may get an error that looks like:
70 ```
71 fatal error: openssl/aes.h: No such file or directory
72 47 | // #include <openssl/aes.h>
73 | ^~~~~~~~~~~~~~~~
74 compilation terminated.
75 ```
76 This is because the `simulator` library depends on having the [OpenSSL](https://www.openssl.org/) headers installed. To fix this error, install the appropriate header package:
77
78 ### Linux
79
80 ```bash
81 # Ubuntu/Debian based systems
82 sudo apt install libssl-dev
83 # Redhat/Centos based systems
84 sudo yum install openssl-devel
85 # Arch Linux (headers/library in the same package)
86 sudo pacman -S openssl
87 ```
88
89 ### macOS
90
91 First, install [Homebrew](https://brew.sh/). Then run:
92 ```bash
93 brew install openssl
94 ```
95
96 ### Windows
97
98 First, install [Chocolatey](https://chocolatey.org/). Then run:
99 ```bash
100 choco install openssl
101 ```
102
103 ### Custom install location
104
105 If you want to use a different installation of OpenSSL, or you are getting
106 linker errors like `ld: library not found for -lcrypto`, you can directly
107 point Go your installation. We will assume your installation is located at
108 `$OPENSSL_PATH` (with `lib` and `include` subdirectories).
109
110 #### Add OpenSSL to the include and library path at the command line
111 This solution does not require modifying go-tpm-tools code and is useful when
112 working on other projects that depend on go-tpm-tools/simulator.
113 ```
114 C_INCLUDE_PATH="$OPENSSL_PATH/include" LIBRARY_PATH="$OPENSSL_PATH/lib" go test ...
115 ```
116
117 #### Add OpenSSL to the include and library path in the code
118 This solution modifies your local copy of the go-tpm-tools simulator source
119 and removes the need to provide the paths on the command line.
120
121 Modify the `CFLAGS`/`LDFLAGS` options beginning with `#cgo darwin` or
122 `#cgo windows` in `simulator/internal/internal.go` to point at your
123 installation. This could look something like:
124 ```diff
125 // #cgo darwin CFLAGS: -I $OPENSSL_PATH/include
126 // #cgo darwin LDFLAGS: -L $OPENSSL_PATH/lib
127 ```
128 Remember to revert your modifications to `simulator/internal/internal.go`
129 before committing your changes.
130
131 ## No TPM 1.2 support
132
133 Unlike [Go-TPM](https://github.com/google/go-tpm) (which supports TPM 1.2 and TPM 2.0), this module explicitly only supports TPM 2.0. Users should avoid use of TPM 1.2 due to the inherent reliance on SHA1 (which is [quite broken](https://sha-mbles.github.io/)).
134
135 ## Confidential VMs with Intel TDX
136 For Ubuntu image, the `tdx_guest` module was moved to linux-modules-extra
137 package in the 1016 and newer kernels. You should be able to install the module,
138 and either manually load the module or reboot.
139
140 To install the linux-modules-extra package, run:
141
142 ```console
143 sudo apt-get install linux-modules-extra-gcp
144 ```
145
146 To manually load the module, run:
147
148 ```console
149 sudo modprobe tdx_guest
150 ```
151
152 ## Legal
153
154 Copyright 2018 Google Inc. under the
155 [Apache 2.0 License](https://www.apache.org/licenses/LICENSE-2.0). Microsoft's TPM simulator
156 code is licensed under a [3-clause BSD license](https://opensource.org/licenses/BSD-3-Clause) and the [TCG software license](https://trustedcomputinggroup.org/wp-content/uploads/TPM-Rev-2.0-Part-1-Architecture-01.38.pdf). See the [`LICENSE`](LICENSE) file for more information.
157
158 This is not an official Google product.