项目 / theupdateframework/go-tuf
go-tuf/v2 是 [The Update Framework (TUF)](https://theupdateframework.io/) 的 Go 实现,用来创建、读取和写入 TUF 元数据,完成签名与校验,并提供客户端及多仓库客户端 API,供软件更新和内容分发系统按规范集成。库本身不保存或管理私钥:`Metadata.Sign` 接受 sigstore 的 `signature.Signer` 接口,密钥可放在文件、云 KMS 或其他由调用方管理的位置。入门可运行仓库中的示例,例如 `make example-repository`、`make example-client`,或查看 `tuf-client` 命令行示例。本页只介绍用途与入口。说明见[TUF 网站](https://theupdateframework.com/)和[仓库 README](https://github.com/theupdateframework/go-tuf)。
本站整理,非 GitHub 官方 description。
官方快照(gh_history.db,2026-11-25):总榜 未进 Top50 · 日榜 未进 Top50 · 周榜未满 7 天基线(官方不生成) · 月榜暂无官方口径;下方四卡为站内趋势聚合(周卡按上榜次数,非官方 7 日增量窗)。
以下三段按该项目自己的 GitHub README 章节摘录(可合理截断并标明);README 没有对应章节的留空,不编造。
项目提供多个示例:手动维护仓库元数据的 basic_repository、基于 updater 包的客户端、tuf-client CLI 及多仓库客户端,各可通过对应 make 命令运行。
项目说明文档见 https://github.com/theupdateframework/specification/blob/master/tuf-spec.md。
来自 GitHub 仓库 README / 主页介绍正文,原样摘录,共 11,854 字节。

[](https://codecov.io/github/theupdateframework/go-tuf)
[](https://pkg.go.dev/github.com/theupdateframework/go-tuf)
[](https://goreportcard.com/report/github.com/theupdateframework/go-tuf)
[](https://opensource.org/licenses/Apache-2.0)
# <img src="https://cdn.rawgit.com/theupdateframework/artwork/3a649fa6/tuf-logo.svg" height="100" valign="middle" alt="TUF"/> go-tuf/v2 - Framework for Securing Software Update Systems
----------------------------
[The Update Framework (TUF)](https://theupdateframework.io/) is a framework for
secure content delivery and updates. It protects against various types of
supply chain attacks and provides resilience to compromise.
## About The Update Framework
----------------------------
The Update Framework (TUF) design helps developers maintain the security of a
software update system, even against attackers that compromise the repository
or signing keys.
TUF provides a flexible
[specification](https://github.com/theupdateframework/specification/blob/master/tuf-spec.md)
defining functionality that developers can use in any software update system or
re-implement to fit their needs.
TUF is hosted by the [Linux Foundation](https://www.linuxfoundation.org/) as
part of the [Cloud Native Computing Foundation](https://www.cncf.io/) (CNCF)
and its design is [used in production](https://theupdateframework.io/adoptions/)
by various tech companies and open-source organizations.
Please see [TUF's website](https://theupdateframework.com/) for more information about TUF!
## Overview
----------------------------
The go-tuf v2 project provides a lightweight library with the following functionality:
* creation, reading, and writing of TUF metadata
* an easy object-oriented approach for interacting with TUF metadata
* consistent snapshots
* signing and verifying TUF metadata
* ED25519, RSA, and ECDSA key types referenced by the latest TUF specification
* top-level role delegation
* target delegation via standard and hash bin delegations
* support of [succinct hash bin delegations](https://github.com/theupdateframework/taps/blob/master/tap15.md) which significantly reduce the size of the TUF metadata
* support for unrecognized fields within the metadata (i.e. preserved and accessible through `root.Signed.UnrecognizedFields["some-unknown-field"]`, also used for verifying/signing (if included in the Signed portion of the metadata))
* TUF client API
* TUF multi-repository client API (implements [TAP 4 - Multiple repository consensus on entrusted targets](https://github.com/theupdateframework/taps/blob/master/tap4.md))
## Examples
----------------------------
There are several examples that can act as a guideline on how to use the library and its features. Some of which are:
* [basic_repository.go](examples/repository/basic_repository.go) example which demonstrates how to *manually* create and
maintain repository metadata using the low-level Metadata API.
To try it - run `make example-repository` (the artifacts will be located at `examples/repository/`).
* [client_example.go](examples/client/client_example.go) which demonstrates how to implement a client using the [updater](metadata/updater/updater.go) package.
To try it - run `make example-client` (the artifacts will be located at `examples/client/`)
* [tuf-client CLI](examples/cli/tuf-client/) - a CLI tool that implements the client workflow specified by The Update Framework (TUF) specification.
To try it - run `make example-tuf-client-cli`
* [multi-repository client example (TAP4)](examples/multirepo/client/client_example.go) which demonstrates how to implement a multi-repository TUF client using the [multirepo](metadata/multirepo/multirepo.go) package.
To try it - run `make example-multirepo`
* [external signer](metadata/example_external_signer_test.go) and [key file](metadata/example_key_from_file_test.go) examples which demonstrate how to sign metadata with a key go-tuf has no access to and with keys loaded from PEM files (see [Signing and keys](#signing-and-keys)).
To try it - run `go test -v -run ExampleMetadata_Sign ./metadata/`
## Signing and keys
----------------------------
go-tuf does not store or manage private keys. `Metadata.Sign` takes a
[`signature.Signer`](https://pkg.go.dev/github.com/sigstore/sigstore/pkg/signature#Signer)
from [sigstore](https://github.com/sigstore/sigstore), which is an interface:
```go
type Signer interface {
PublicKey(opts ...PublicKeyOption) (crypto.PublicKey, error)
SignMessage(message io.Reader, opts ...SignOption) ([]byte, error)
}
```
Any implementation works, so the private key can be kept wherever it suits you:
* **In memory or in a file** - `signature.LoadSigner` turns a `crypto.PrivateKey` into a signer, see [Loading keys from files](#loading-keys-from-files).
* **In a cloud KMS or HashiCorp Vault** - the [sigstore KMS signers](https://github.com/sigstore/sigstore/tree/main/pkg/signature/kms) (AWS, Azure, GCP, HashiCorp Vault) implement the interface. They are separate Go modules which go-tuf does not depend on, so import the one you need and pass what `kms.Get` returns to `Sign`. The key has to be of a type and signing algorithm listed below.
* **In an HSM (PKCS#11), a YubiKey, a TPM or anywhere else** - implement the two methods yourself. The [external signer example](metadata/example_external_signer_test.go) does so for any `crypto.Signer`, which is what the client libraries for such devices usually provide.
What a custom signer has to comply with:
* `Sign` derives the TUF key (type, scheme and key ID) from the signer's public key through `metadata.KeyFromPublicKey`, so `PublicKey` has to return an `*rsa.PublicKey`, `*ecdsa.PublicKey`, `ed25519.PublicKey` or `*mldsa.PublicKey`. Use the same function to get the key to add to the delegating role. The key ID is always computed from the key.
* `SignMessage` gets the exact bytes to sign and has to return a signature of the kind go-tuf verifies for that key type:
| Public key | TUF key scheme | Expected signature |
| ---------- | -------------- | ------------------ |
| Ed25519 | `ed25519` | Ed25519 over the message |
| ECDSA | `ecdsa-sha2-nistp256` for a P-256 key, `ecdsa-sha2-nistp384` for a P-384 key (other curves are rejected) | ASN.1 DER encoded ECDSA over the SHA-256 digest of the message for a P-256 key, the SHA-384 digest for a P-384 key |
| RSA | `rsassa-pss-sha256` | RSASSA-PSS with SHA-256 (not PKCS #1 v1.5) |
| ML-DSA | `ml-dsa-44/1`, `ml-dsa-65/1` or `ml-dsa-87/1` | ML-DSA with an empty context over the message |
### Loading keys from files
There is no go-tuf specific key file format. Read the file and decode it with sigstore's
[`cryptoutils`](https://pkg.go.dev/github.com/sigstore/sigstore/pkg/cryptoutils) package,
as shown in the [key file example](metadata/example_key_from_file_test.go):
| From | To | Function |
| ---- | -- | -------- |
| PEM private key (PKCS #8, PKCS #1, SEC 1, optionally encrypted) | `crypto.PrivateKey` | `cryptoutils.UnmarshalPEMToPrivateKey` |
| PEM public key | `crypto.PublicKey` | `cryptoutils.UnmarshalPEMToPublicKey` |
| `crypto.PrivateKey` | `signature.Signer` | `signature.LoadSigner` (`signature.LoadRSAPSSSigner` for RSA) |
| `crypto.PublicKey` | TUF `metadata.Key` | `metadata.KeyFromPublicKey` |
| TUF `metadata.Key` | `crypto.PublicKey` | `Key.ToPublicKey` |
| `crypto.PrivateKey` / `crypto.PublicKey` | PEM | `cryptoutils.MarshalPrivateKeyToPEM` / `cryptoutils.MarshalPublicKeyToPEM` |
`signature.LoadSignerFromPEMFile` combines the first and the third step. Note that for an RSA key both it and
`signature.LoadSigner` return a PKCS #1 v1.5 signer whose signatures go-tuf does not accept, so load RSA keys with
`signature.LoadRSAPSSSigner(key, crypto.SHA256, &rsa.PSSOptions{Hash: crypto.SHA256})`.
## Package details
----------------------------
### The `metadata` package
* The `metadata` package provides access to a Metadata file abstraction that closely
follows the TUF specification’s document formats. This API handles de/serialization
to and from files and bytes. It also covers the process of creating and verifying metadata
signatures and makes it easier to access and modify metadata content. It is purely
focused on individual pieces of Metadata and provides no concepts like “repository”
or “update workflow”.
### The `trustedmetadata` package
* A `TrustedMetadata` instance ensures that the collection of metadata in it is valid
and trusted through the whole client update workflow. It provides easy ways to update
the metadata with the caller making decisions on what is updated.
### The `config` package
* The `config` package stores configuration for an ``Updater`` instance.
### The `fetcher` package
* The `fetcher` package defines an interface for abstract network download.
### The `updater` package
* The `updater` package provides an implementation of the TUF client workflow.
It provides ways to query and download target files securely while handling the
TUF update workflow behind the scenes. It is implemented on top of the Metadata API
and can be used to implement various TUF clients with relatively little effort.
### The `multirepo` package
* The `multirepo` package provides an implementation of [TAP 4 - Multiple repository consensus on entrusted targets](https://github.com/theupdateframework/taps/blob/master/tap4.md). It provides a secure search for particular targets across multiple repositories. It provides the functionality for how multiple repositories with separate roots of trust can be required to sign off on the same targets, effectively creating an AND relation and ensuring any files obtained can be trusted. It offers a way to initialize multiple repositories using a `map.json` file and also mechanisms to query and download target files securely. It is implemented on top of the Updater API and can be used to implement various multi-repository TUF clients with relatively little effort.
## Documentation
----------------------------
* [Documentation](https://pkg.go.dev/github.com/theupdateframework/go-tuf/v2)
* [Introduction to TUF's Design](https://theupdateframework.io/overview/)
* [The TUF Specification](https://theupdateframework.github.io/specification/latest/)
## History - legacy go-tuf vs go-tuf/v2
The [legacy go-tuf (v0.7.0)](https://github.com/theupdateframework/go-tuf/tree/v0.7.0) codebase was difficult to maintain and prone to errors due to its initial design decisions. Now it is considered deprecated in favour of go-tuf v2 (originally from [rdimitrov/go-tuf-metadata](https://github.com/rdimitrov/go-tuf-metadata)) which started from the idea of providing a Go implementation of TUF that is heavily influenced by the design decisions made in [python-tuf](https://github.com/theupdateframework/python-tuf).
## Contact
----------------------------
Questions, feedback, and suggestions are welcomed on the [#tuf](https://cloud-native.slack.com/archives/C8NMD3QJ3) and/or [#go-tuf](https://cloud-native.slack.com/archives/C02D577GX54) channels on
[CNCF Slack](https://slack.cncf.io/).
We strive to make the specification easy to implement, so if you come across
any inconsistencies or experience any difficulty, do let us know by sending an
email, or by reporting an issue in the GitHub [specification
repo](https://github.com/theupdateframework/specification/issues).