Documentation
¶
Index ¶
- Constants
- Variables
- func SetLogger(logger Logger)
- func ValidateDelegatedRoleName(name string) error
- type DelegatedRole
- type Delegations
- type DiscardLogger
- type ErrBadVersionNumber
- type ErrDeserialization
- type ErrDownload
- type ErrDownloadHTTP
- type ErrDownloadLengthMismatch
- type ErrEqualVersionNumber
- type ErrExpiredMetadata
- type ErrLengthOrHashMismatch
- type ErrRepository
- type ErrRuntime
- type ErrType
- type ErrUnsignedMetadata
- type ErrValue
- type Hashes
- type HexBytes
- type Key
- type KeyVal
- type Logger
- type MetaFiles
- type Metadata
- func (meta *Metadata[T]) ClearSignatures()
- func (meta *Metadata[T]) FromBytes(data []byte) (*Metadata[T], error)
- func (meta *Metadata[T]) FromFile(name string) (*Metadata[T], error)
- func (meta Metadata[T]) MarshalJSON() ([]byte, error)
- func (meta *Metadata[T]) Sign(signer signature.Signer) (*Signature, error)
- func (meta *Metadata[T]) ToBytes(pretty bool) ([]byte, error)
- func (meta *Metadata[T]) ToFile(name string, pretty bool) error
- func (meta *Metadata[T]) UnmarshalJSON(data []byte) error
- func (meta *Metadata[T]) VerifyDelegate(delegatedRole string, delegatedMetadata any) error
- type Role
- type RoleResult
- type Roles
- type RootType
- type Signature
- type SnapshotType
- type SuccinctRoles
- func (role *SuccinctRoles) GetRoles() []string
- func (role *SuccinctRoles) GetRolesForTarget(targetFilepath string) []RoleResult
- func (role *SuccinctRoles) GetSuffixLen() (int, int)
- func (role *SuccinctRoles) IsDelegatedRole(roleName string) bool
- func (role SuccinctRoles) MarshalJSON() ([]byte, error)
- func (role *SuccinctRoles) UnmarshalJSON(data []byte) error
- type TargetFiles
- func (source *TargetFiles) Equal(expected TargetFiles) bool
- func (t *TargetFiles) FromBytes(localPath string, data []byte, hashes ...string) (*TargetFiles, error)
- func (t *TargetFiles) FromFile(localPath string, hashes ...string) (*TargetFiles, error)
- func (signed TargetFiles) MarshalJSON() ([]byte, error)
- func (signed *TargetFiles) UnmarshalJSON(data []byte) error
- func (f *TargetFiles) VerifyLengthHashes(data []byte) error
- type TargetsType
- func (signed *TargetsType) AddKey(key *Key, role string) error
- func (signed *TargetsType) IsExpired(referenceTime time.Time) bool
- func (signed TargetsType) MarshalJSON() ([]byte, error)
- func (signed *TargetsType) RevokeKey(keyID string, role string) error
- func (signed *TargetsType) UnmarshalJSON(data []byte) error
- type TimestampType
Examples ¶
Constants ¶
const ( KeyTypeEd25519 = "ed25519" KeyTypeECDSA_SHA2_P256_COMPAT = "ecdsa-sha2-nistp256" KeyTypeECDSA_SHA2_P256 = "ecdsa" KeyTypeRSASSA_PSS_SHA256 = "rsa" KeyTypeMLDSA = "ml-dsa" KeySchemeEd25519 = "ed25519" KeySchemeECDSA_SHA2_P256 = "ecdsa-sha2-nistp256" KeySchemeECDSA_SHA2_P384 = "ecdsa-sha2-nistp384" KeySchemeRSASSA_PSS_SHA256 = "rsassa-pss-sha256" KeySchemeMLDSA44 = "ml-dsa-44/1" KeySchemeMLDSA65 = "ml-dsa-65/1" KeySchemeMLDSA87 = "ml-dsa-87/1" )
const ( ROOT = "root" SNAPSHOT = "snapshot" TARGETS = "targets" TIMESTAMP = "timestamp" )
Define top level role names
const (
SPECIFICATION_VERSION = "1.0.37"
)
Define version of the TUF specification
Variables ¶
Functions ¶
func ValidateDelegatedRoleName ¶ added in v2.6.0
ValidateDelegatedRoleName rejects empty delegated role names and names that match any top-level role name, including case-folded variants that collide in "<role>.json" caches on case-insensitive filesystems.
Types ¶
type DelegatedRole ¶
type DelegatedRole struct {
Name string `json:"name"`
KeyIDs []string `json:"keyids"`
Threshold int `json:"threshold"`
Terminating bool `json:"terminating"`
PathHashPrefixes []string `json:"path_hash_prefixes,omitempty"`
Paths []string `json:"paths,omitempty"`
UnrecognizedFields map[string]any `json:"-"`
}
DelegatedRole represents a delegated role in TUF
func (*DelegatedRole) IsDelegatedPath ¶
func (role *DelegatedRole) IsDelegatedPath(targetFilepath string) (bool, error)
IsDelegatedPath determines whether the given "targetFilepath" is in one of the paths that "DelegatedRole" is trusted to provide. An invalid path pattern is reported as an error only if no other pattern matches.
func (DelegatedRole) MarshalJSON ¶
func (role DelegatedRole) MarshalJSON() ([]byte, error)
func (*DelegatedRole) UnmarshalJSON ¶
func (role *DelegatedRole) UnmarshalJSON(data []byte) error
type Delegations ¶
type Delegations struct {
Keys map[string]*Key `json:"keys"`
Roles []DelegatedRole `json:"roles,omitempty"`
SuccinctRoles *SuccinctRoles `json:"succinct_roles,omitempty"`
UnrecognizedFields map[string]any `json:"-"`
}
Delegations is an optional object which represents delegation roles and their corresponding keys
func (*Delegations) GetRolesForTarget ¶
func (role *Delegations) GetRolesForTarget(targetFilepath string) []RoleResult
GetRolesForTarget return the names and terminating status of all delegated roles who are responsible for targetFilepath Note the result should be an ordered list, ref. https://github.com/theupdateframework/go-tuf/security/advisories/GHSA-4f8r-qqr9-fq8j
func (Delegations) MarshalJSON ¶
func (d Delegations) MarshalJSON() ([]byte, error)
func (*Delegations) UnmarshalJSON ¶
func (d *Delegations) UnmarshalJSON(data []byte) error
type DiscardLogger ¶
type DiscardLogger struct{}
func (DiscardLogger) Info ¶
func (d DiscardLogger) Info(msg string, kv ...any)
type ErrBadVersionNumber ¶
type ErrBadVersionNumber struct {
Msg string
}
ErrBadVersionNumber - An error for metadata that contains an invalid version number
func (*ErrBadVersionNumber) Error ¶
func (e *ErrBadVersionNumber) Error() string
func (*ErrBadVersionNumber) Is ¶
func (e *ErrBadVersionNumber) Is(target error) bool
ErrBadVersionNumber is a subset of ErrRepository
type ErrDeserialization ¶ added in v2.5.0
type ErrDeserialization struct {
Err error
}
ErrDeserialization - An error occurred while deserializing a TUF Metadata file
func (*ErrDeserialization) Error ¶ added in v2.5.0
func (e *ErrDeserialization) Error() string
func (*ErrDeserialization) Is ¶ added in v2.5.0
func (e *ErrDeserialization) Is(target error) bool
ErrDeserialization is a subset of ErrRepository
func (*ErrDeserialization) Unwrap ¶ added in v2.5.0
func (e *ErrDeserialization) Unwrap() error
type ErrDownload ¶
type ErrDownload struct {
Msg string
}
ErrDownload - An error occurred while attempting to download a file
func (*ErrDownload) Error ¶
func (e *ErrDownload) Error() string
func (*ErrDownload) Is ¶
func (e *ErrDownload) Is(target error) bool
type ErrDownloadHTTP ¶
ErrDownloadHTTP - Returned by Fetcher interface implementations for HTTP errors
func (*ErrDownloadHTTP) Error ¶
func (e *ErrDownloadHTTP) Error() string
func (*ErrDownloadHTTP) Is ¶
func (e *ErrDownloadHTTP) Is(target error) bool
ErrDownloadHTTP is a subset of ErrDownload
type ErrDownloadLengthMismatch ¶
type ErrDownloadLengthMismatch struct {
Msg string
}
ErrDownloadLengthMismatch - Indicate that a mismatch of lengths was seen while downloading a file
func (*ErrDownloadLengthMismatch) Error ¶
func (e *ErrDownloadLengthMismatch) Error() string
func (*ErrDownloadLengthMismatch) Is ¶
func (e *ErrDownloadLengthMismatch) Is(target error) bool
ErrDownloadLengthMismatch is a subset of ErrDownload
type ErrEqualVersionNumber ¶
type ErrEqualVersionNumber struct {
Msg string
}
ErrEqualVersionNumber - An error for metadata containing a previously verified version number
func (*ErrEqualVersionNumber) Error ¶
func (e *ErrEqualVersionNumber) Error() string
func (*ErrEqualVersionNumber) Is ¶
func (e *ErrEqualVersionNumber) Is(target error) bool
ErrEqualVersionNumber is a subset of both ErrRepository and ErrBadVersionNumber
type ErrExpiredMetadata ¶
type ErrExpiredMetadata struct {
Msg string
}
ErrExpiredMetadata - Indicate that a TUF Metadata file has expired
func (*ErrExpiredMetadata) Error ¶
func (e *ErrExpiredMetadata) Error() string
func (*ErrExpiredMetadata) Is ¶
func (e *ErrExpiredMetadata) Is(target error) bool
ErrExpiredMetadata is a subset of ErrRepository
type ErrLengthOrHashMismatch ¶
type ErrLengthOrHashMismatch struct {
Msg string
}
ErrLengthOrHashMismatch - An error while checking the length and hash values of an object
func (*ErrLengthOrHashMismatch) Error ¶
func (e *ErrLengthOrHashMismatch) Error() string
func (*ErrLengthOrHashMismatch) Is ¶
func (e *ErrLengthOrHashMismatch) Is(target error) bool
ErrLengthOrHashMismatch is a subset of ErrRepository
type ErrRepository ¶
type ErrRepository struct {
Msg string
}
ErrRepository - an error with a repository's state, such as a missing file. It covers all exceptions that come from the repository side when looking from the perspective of users of metadata API or client
func (*ErrRepository) Error ¶
func (e *ErrRepository) Error() string
func (*ErrRepository) Is ¶
func (e *ErrRepository) Is(target error) bool
type ErrRuntime ¶
type ErrRuntime struct {
Msg string
}
RuntimeError
func (*ErrRuntime) Error ¶
func (e *ErrRuntime) Error() string
func (*ErrRuntime) Is ¶
func (e *ErrRuntime) Is(err error) bool
type ErrUnsignedMetadata ¶
type ErrUnsignedMetadata struct {
Msg string
}
ErrUnsignedMetadata - An error about metadata object with insufficient threshold of signatures
func (*ErrUnsignedMetadata) Error ¶
func (e *ErrUnsignedMetadata) Error() string
func (*ErrUnsignedMetadata) Is ¶
func (e *ErrUnsignedMetadata) Is(target error) bool
ErrUnsignedMetadata is a subset of ErrRepository
type Key ¶
type Key struct {
Type string `json:"keytype"`
Scheme string `json:"scheme"`
Value KeyVal `json:"keyval"`
UnrecognizedFields map[string]any `json:"-"`
// contains filtered or unexported fields
}
Key represents a key in TUF
func KeyFromPublicKey ¶
KeyFromPublicKey generate metadata type Key from crypto.PublicKey. The scheme of an ECDSA key follows its curve: P-256 keys get "ecdsa-sha2-nistp256" and P-384 keys get "ecdsa-sha2-nistp384". ECDSA keys on any other curve are rejected.
Earlier releases gave every ECDSA key the "ecdsa-sha2-nistp256" scheme. Metadata they wrote still verifies, but a key that is not on P-256 needs care when it is used again:
- The scheme is part of the key ID, so a P-384 key now has a different key ID, and Sign writes only the new one. To keep signing with the key, add the Key returned here to the delegating role and remove the old entry. Its signatures must use SHA-384.
- P-224 and P-521 keys can no longer be used with Sign. Replace them with a supported key in the delegating role.
- A new root version must also verify against the root before it, which lists the key under its old key ID and scheme. If the key is needed to reach that root's threshold, Sign cannot produce the signature: sign the canonical JSON of Signed with the key and SHA-256, and append the result to Signatures under the old key ID. Clients that trust the earlier root cannot verify the new root without it.
func (*Key) ID ¶
ID returns the keyID value for the given Key, or an error if the key cannot be canonically encoded.
func (Key) MarshalJSON ¶
func (*Key) ToPublicKey ¶
ToPublicKey generate crypto.PublicKey from metadata type Key
func (*Key) UnmarshalJSON ¶
type KeyVal ¶
type KeyVal struct {
PublicKey string `json:"public"`
UnrecognizedFields map[string]any `json:"-"`
}
func (KeyVal) MarshalJSON ¶
func (*KeyVal) UnmarshalJSON ¶
type Logger ¶
type Logger interface {
// Info logs a non-error message with key/value pairs
Info(msg string, kv ...any)
// Error logs an error with a given message and key/value pairs.
Error(err error, msg string, kv ...any)
}
Logger partially implements the go-log/logr's interface: https://github.com/go-logr/logr/blob/master/logr.go
type MetaFiles ¶
type MetaFiles struct {
Length int64 `json:"length,omitempty"`
Hashes Hashes `json:"hashes,omitempty"`
Version int64 `json:"version"`
UnrecognizedFields map[string]any `json:"-"`
}
MetaFiles represents the value portion of METAFILES in TUF (used in Snapshot and Timestamp metadata). Used to store information about a particular meta file.
func (MetaFiles) MarshalJSON ¶
func (*MetaFiles) UnmarshalJSON ¶
func (*MetaFiles) VerifyLengthHashes ¶
VerifyLengthHashes checks whether the MetaFiles data matches its corresponding length and hashes
type Metadata ¶
type Metadata[T Roles] struct { Signed T `json:"signed"` Signatures []Signature `json:"signatures"` UnrecognizedFields map[string]any `json:"-"` }
Metadata[T Roles] represents a TUF metadata. Provides methods to read and write to and from file and bytes, also to create, verify and clear metadata signatures.
func Snapshot ¶
func Snapshot(expires ...time.Time) *Metadata[SnapshotType]
Snapshot return new metadata instance of type Snapshot
func Targets ¶
func Targets(expires ...time.Time) *Metadata[TargetsType]
Targets return new metadata instance of type Targets
func Timestamp ¶
func Timestamp(expires ...time.Time) *Metadata[TimestampType]
Timestamp return new metadata instance of type Timestamp
func (*Metadata[T]) ClearSignatures ¶
func (meta *Metadata[T]) ClearSignatures()
ClearSignatures clears Signatures
func (Metadata[T]) MarshalJSON ¶
func (*Metadata[T]) Sign ¶
Sign creates a signature over Signed and stores it in Signatures. It replaces any existing signature from the same key, as a key ID must be unique in Signatures. The new signature is verified against the key derived from the signer's public key, and if it does not verify an error is returned and Signatures is left unchanged.
Any signature.Signer implementation can be used, so the private key does not have to be available to go-tuf: it can be held in memory, in a KMS, an HSM or a hardware token. The TUF key and its ID are derived from the signer's public key through KeyFromPublicKey, so the signer has to return a public key type supported by it and a signature matching the resulting key scheme.
Example (ExternalSigner) ¶
Sign metadata with a key go-tuf never gets to see, e.g. one held by an HSM, a YubiKey, a TPM or a cloud KMS. Metadata.Sign only needs a signature.Signer, so any implementation of that interface works: a hand-written one like the adapter above, or one of the ready-made sigstore KMS signers (https://github.com/sigstore/sigstore/tree/main/pkg/signature/kms).
package main
import (
"crypto"
"crypto/ecdsa"
"crypto/elliptic"
"crypto/rand"
"fmt"
"io"
"time"
"github.com/sigstore/sigstore/pkg/signature"
"github.com/theupdateframework/go-tuf/v2/metadata"
)
// cryptoSigner adapts a crypto.Signer to the signature.Signer interface that
// Metadata.Sign expects.
//
// crypto.Signer is what PKCS#11, TPM, PIV (YubiKey) and cloud KMS client
// libraries usually hand out for a key that never leaves the device or the
// service, so an adapter like this one is all it takes to sign TUF metadata
// with such a key.
type cryptoSigner struct {
key crypto.Signer
// opts selects what go-tuf verifies for the key type:
// - ECDSA: crypto.SHA256 for a P-256 key, crypto.SHA384 for a P-384 key
// - RSA: &rsa.PSSOptions{Hash: crypto.SHA256, SaltLength: rsa.PSSSaltLengthEqualsHash}
// - Ed25519: crypto.Hash(0)
// - ML-DSA: crypto.Hash(0)
opts crypto.SignerOpts
}
// PublicKey returns the public key go-tuf derives the TUF key and its ID from.
func (s *cryptoSigner) PublicKey(_ ...signature.PublicKeyOption) (crypto.PublicKey, error) {
return s.key.Public(), nil
}
// SignMessage signs the payload handed over by Metadata.Sign.
func (s *cryptoSigner) SignMessage(message io.Reader, _ ...signature.SignOption) ([]byte, error) {
payload, err := io.ReadAll(message)
if err != nil {
return nil, err
}
// crypto.Signer takes a digest, unless the scheme signs the message
// itself (Ed25519, ML-DSA)
if hash := s.opts.HashFunc(); hash != crypto.Hash(0) {
h := hash.New()
h.Write(payload)
payload = h.Sum(nil)
}
return s.key.Sign(rand.Reader, payload, s.opts)
}
// Sign metadata with a key go-tuf never gets to see, e.g. one held by an HSM,
// a YubiKey, a TPM or a cloud KMS. Metadata.Sign only needs a signature.Signer,
// so any implementation of that interface works: a hand-written one like the
// adapter above, or one of the ready-made sigstore KMS signers
// (https://github.com/sigstore/sigstore/tree/main/pkg/signature/kms).
func main() {
// Stand-in for the external key: from here on it is only reachable
// through crypto.Signer, i.e. Public() and Sign()
var externalKey crypto.Signer
externalKey, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader)
if err != nil {
panic(err)
}
signer := &cryptoSigner{key: externalKey, opts: crypto.SHA256}
// The TUF key (type, scheme, value and key ID) is derived from the
// public key, so it has to be an RSA, ECDSA, Ed25519 or ML-DSA one
key, err := metadata.KeyFromPublicKey(externalKey.Public())
if err != nil {
panic(err)
}
keyID, err := key.ID()
if err != nil {
panic(err)
}
// Let root delegate the targets role to that key
expires := time.Now().AddDate(0, 0, 7).UTC()
root := metadata.Root(expires)
if err := root.Signed.AddKey(key, metadata.TARGETS); err != nil {
panic(err)
}
// Sign targets with the external signer
targets := metadata.Targets(expires)
sig, err := targets.Sign(signer)
if err != nil {
panic(err)
}
// Sign derives the same key ID from the signer's public key, so the
// signature can be verified the usual way
fmt.Println("key type:", key.Type)
fmt.Println("key scheme:", key.Scheme)
fmt.Println("signature key ID matches:", sig.KeyID == keyID)
fmt.Println("verify error:", root.VerifyDelegate(metadata.TARGETS, targets))
}
Output: key type: ecdsa key scheme: ecdsa-sha2-nistp256 signature key ID matches: true verify error: <nil>
Example (KeyFromFile) ¶
Load PEM encoded keys from files and use them to sign and verify metadata. go-tuf has no key file format of its own: reading the file and decoding the PEM with sigstore's cryptoutils package yields a crypto.PrivateKey or a crypto.PublicKey, and from there on it is signature.LoadSigner and metadata.KeyFromPublicKey.
package main
import (
"crypto"
"crypto/ed25519"
"crypto/rand"
"fmt"
"os"
"path/filepath"
"time"
"github.com/sigstore/sigstore/pkg/cryptoutils"
"github.com/sigstore/sigstore/pkg/signature"
"github.com/theupdateframework/go-tuf/v2/metadata"
)
// writeKeyPair stores a new Ed25519 key pair as PEM files (PKCS #8 and PKIX,
// the same encodings "openssl genpkey" and "openssl pkey -pubout" produce) and
// returns their paths.
func writeKeyPair(dir string) (privatePath, publicPath string, err error) {
public, private, err := ed25519.GenerateKey(rand.Reader)
if err != nil {
return "", "", err
}
privatePEM, err := cryptoutils.MarshalPrivateKeyToPEM(private)
if err != nil {
return "", "", err
}
publicPEM, err := cryptoutils.MarshalPublicKeyToPEM(public)
if err != nil {
return "", "", err
}
privatePath = filepath.Join(dir, "targets_key")
publicPath = filepath.Join(dir, "targets_key.pub")
if err := os.WriteFile(privatePath, privatePEM, 0600); err != nil {
return "", "", err
}
if err := os.WriteFile(publicPath, publicPEM, 0644); err != nil {
return "", "", err
}
return privatePath, publicPath, nil
}
// Load PEM encoded keys from files and use them to sign and verify metadata.
// go-tuf has no key file format of its own: reading the file and decoding the
// PEM with sigstore's cryptoutils package yields a crypto.PrivateKey or a
// crypto.PublicKey, and from there on it is signature.LoadSigner and
// metadata.KeyFromPublicKey.
func main() {
dir, err := os.MkdirTemp("", "go-tuf-keys")
if err != nil {
panic(err)
}
defer os.RemoveAll(dir)
privatePath, publicPath, err := writeKeyPair(dir)
if err != nil {
panic(err)
}
// Private key: file -> crypto.PrivateKey -> signature.Signer.
// Pass a cryptoutils.PassFunc instead of SkipPassword if the key is
// encrypted.
privatePEM, err := os.ReadFile(privatePath)
if err != nil {
panic(err)
}
privateKey, err := cryptoutils.UnmarshalPEMToPrivateKey(privatePEM, cryptoutils.SkipPassword)
if err != nil {
panic(err)
}
// NOTE: for an RSA key use signature.LoadRSAPSSSigner(key, crypto.SHA256,
// &rsa.PSSOptions{Hash: crypto.SHA256}) instead, as LoadSigner would
// return a PKCS #1 v1.5 signer while TUF uses RSASSA-PSS
signer, err := signature.LoadSigner(privateKey, crypto.SHA256)
if err != nil {
panic(err)
}
// Public key: file -> crypto.PublicKey -> TUF key
publicPEM, err := os.ReadFile(publicPath)
if err != nil {
panic(err)
}
publicKey, err := cryptoutils.UnmarshalPEMToPublicKey(publicPEM)
if err != nil {
panic(err)
}
key, err := metadata.KeyFromPublicKey(publicKey)
if err != nil {
panic(err)
}
// Let root delegate the targets role to the public key and sign targets
// with the private one
expires := time.Now().AddDate(0, 0, 7).UTC()
root := metadata.Root(expires)
if err := root.Signed.AddKey(key, metadata.TARGETS); err != nil {
panic(err)
}
targets := metadata.Targets(expires)
if _, err := targets.Sign(signer); err != nil {
panic(err)
}
// ... and back again: TUF key -> crypto.PublicKey
roundTripped, err := key.ToPublicKey()
if err != nil {
panic(err)
}
fmt.Println("key type:", key.Type)
fmt.Println("key scheme:", key.Scheme)
fmt.Println("public key round trip:", cryptoutils.EqualKeys(publicKey, roundTripped) == nil)
fmt.Println("verify error:", root.VerifyDelegate(metadata.TARGETS, targets))
}
Output: key type: ed25519 key scheme: ed25519 public key round trip: true verify error: <nil>
func (*Metadata[T]) UnmarshalJSON ¶
type Role ¶
type Role struct {
KeyIDs []string `json:"keyids"`
Threshold int `json:"threshold"`
UnrecognizedFields map[string]any `json:"-"`
}
Role represents one of the top-level roles in TUF
func (Role) MarshalJSON ¶
func (*Role) UnmarshalJSON ¶
type RoleResult ¶ added in v2.0.1
RoleResult represents the name and terminating status of a delegated role that is responsible for targetFilepath
type Roles ¶
type Roles interface {
RootType | SnapshotType | TimestampType | TargetsType
}
Generic type constraint
type RootType ¶
type RootType struct {
Type string `json:"_type"`
SpecVersion string `json:"spec_version"`
ConsistentSnapshot bool `json:"consistent_snapshot"`
Version int64 `json:"version"`
Expires time.Time `json:"expires"`
Keys map[string]*Key `json:"keys"`
Roles map[string]*Role `json:"roles"`
UnrecognizedFields map[string]any `json:"-"`
}
RootType represents the Signed portion of a root metadata. When setting Expires directly rather than via a constructor, normalize to whole-second UTC (t.UTC().Truncate(time.Second)) per the TUF specification.
func (*RootType) AddKey ¶
AddKey adds new signing key for delegated role "role" keyID: Identifier of the key to be added for "role". key: Signing key to be added for "role". role: Name of the role, for which "key" is added.
func (*RootType) IsExpired ¶
IsExpired returns true if metadata is expired. It checks if referenceTime is after Signed.Expires
func (RootType) MarshalJSON ¶
func (*RootType) RevokeKey ¶
RevokeKey revoke key from “role“ and updates the Keys store. keyID: Identifier of the key to be removed for “role“. role: Name of the role, for which a signing key is removed.
func (*RootType) UnmarshalJSON ¶
type Signature ¶
type Signature struct {
KeyID string `json:"keyid"`
Signature HexBytes `json:"sig"`
UnrecognizedFields map[string]any `json:"-"`
}
Signature represents the Signature part of a TUF metadata
func (Signature) MarshalJSON ¶
func (*Signature) UnmarshalJSON ¶
type SnapshotType ¶
type SnapshotType struct {
Type string `json:"_type"`
SpecVersion string `json:"spec_version"`
Version int64 `json:"version"`
Expires time.Time `json:"expires"`
Meta map[string]*MetaFiles `json:"meta"`
UnrecognizedFields map[string]any `json:"-"`
}
SnapshotType represents the Signed portion of a snapshot metadata
func (*SnapshotType) IsExpired ¶
func (signed *SnapshotType) IsExpired(referenceTime time.Time) bool
IsExpired returns true if metadata is expired. It checks if referenceTime is after Signed.Expires
func (SnapshotType) MarshalJSON ¶
func (signed SnapshotType) MarshalJSON() ([]byte, error)
func (*SnapshotType) UnmarshalJSON ¶
func (signed *SnapshotType) UnmarshalJSON(data []byte) error
type SuccinctRoles ¶
type SuccinctRoles struct {
KeyIDs []string `json:"keyids"`
Threshold int `json:"threshold"`
BitLength int `json:"bit_length"`
NamePrefix string `json:"name_prefix"`
UnrecognizedFields map[string]any `json:"-"`
}
SuccinctRoles represents a delegation graph that covers all targets, distributing them uniformly over the delegated roles (i.e. bins) in the graph.
func (*SuccinctRoles) GetRoles ¶
func (role *SuccinctRoles) GetRoles() []string
GetRoles returns the names of all different delegated roles
func (*SuccinctRoles) GetRolesForTarget ¶
func (role *SuccinctRoles) GetRolesForTarget(targetFilepath string) []RoleResult
GetRolesForTarget calculate the name of the delegated role responsible for "targetFilepath". The target at path "targetFilepath" is assigned to a bin by casting the left-most "BitLength" of bits of the file path hash digest to int, using it as bin index between 0 and “2**BitLength-1”.
func (*SuccinctRoles) GetSuffixLen ¶
func (role *SuccinctRoles) GetSuffixLen() (int, int)
func (*SuccinctRoles) IsDelegatedRole ¶
func (role *SuccinctRoles) IsDelegatedRole(roleName string) bool
IsDelegatedRole returns whether the given roleName is in one of the delegated roles that “SuccinctRoles“ represents
func (SuccinctRoles) MarshalJSON ¶
func (role SuccinctRoles) MarshalJSON() ([]byte, error)
func (*SuccinctRoles) UnmarshalJSON ¶
func (role *SuccinctRoles) UnmarshalJSON(data []byte) error
type TargetFiles ¶
type TargetFiles struct {
Length int64 `json:"length"`
Hashes Hashes `json:"hashes"`
Custom *json.RawMessage `json:"custom,omitempty"`
Path string `json:"-"`
UnrecognizedFields map[string]any `json:"-"`
}
TargetFiles represents the value portion of TARGETS in TUF (used Targets metadata). Used to store information about a particular target file.
func TargetFile ¶
func TargetFile() *TargetFiles
TargetFile return new metadata instance of type TargetFiles
func (*TargetFiles) Equal ¶
func (source *TargetFiles) Equal(expected TargetFiles) bool
Equal checks whether the source target file matches another
func (*TargetFiles) FromBytes ¶
func (t *TargetFiles) FromBytes(localPath string, data []byte, hashes ...string) (*TargetFiles, error)
FromBytes generate TargetFiles from bytes
func (*TargetFiles) FromFile ¶
func (t *TargetFiles) FromFile(localPath string, hashes ...string) (*TargetFiles, error)
FromFile generate TargetFiles from file
func (TargetFiles) MarshalJSON ¶
func (signed TargetFiles) MarshalJSON() ([]byte, error)
func (*TargetFiles) UnmarshalJSON ¶
func (signed *TargetFiles) UnmarshalJSON(data []byte) error
func (*TargetFiles) VerifyLengthHashes ¶
func (f *TargetFiles) VerifyLengthHashes(data []byte) error
VerifyLengthHashes checks whether the TargetFiles data matches its corresponding length and hashes
type TargetsType ¶
type TargetsType struct {
Type string `json:"_type"`
SpecVersion string `json:"spec_version"`
Version int64 `json:"version"`
Expires time.Time `json:"expires"`
Targets map[string]*TargetFiles `json:"targets"`
Delegations *Delegations `json:"delegations,omitempty"`
UnrecognizedFields map[string]any `json:"-"`
}
TargetsType represents the Signed portion of a targets metadata
func (*TargetsType) AddKey ¶
func (signed *TargetsType) AddKey(key *Key, role string) error
AddKey adds new signing key for delegated role "role" key: Signing key to be added for "role". role: Name of the role, for which "key" is added. If SuccinctRoles is used then the "role" argument can be ignored.
func (*TargetsType) IsExpired ¶
func (signed *TargetsType) IsExpired(referenceTime time.Time) bool
IsExpired returns true if metadata is expired. It checks if referenceTime is after Signed.Expires
func (TargetsType) MarshalJSON ¶
func (signed TargetsType) MarshalJSON() ([]byte, error)
func (*TargetsType) RevokeKey ¶
func (signed *TargetsType) RevokeKey(keyID string, role string) error
RevokeKey revokes key from delegated role "role" and updates the delegations key store keyID: Identifier of the key to be removed for “role“. role: Name of the role, for which a signing key is removed.
func (*TargetsType) UnmarshalJSON ¶
func (signed *TargetsType) UnmarshalJSON(data []byte) error
type TimestampType ¶
type TimestampType struct {
Type string `json:"_type"`
SpecVersion string `json:"spec_version"`
Version int64 `json:"version"`
Expires time.Time `json:"expires"`
Meta map[string]*MetaFiles `json:"meta"`
UnrecognizedFields map[string]any `json:"-"`
}
TimestampType represents the Signed portion of a timestamp metadata
func (*TimestampType) IsExpired ¶
func (signed *TimestampType) IsExpired(referenceTime time.Time) bool
IsExpired returns true if metadata is expired. It checks if referenceTime is after Signed.Expires
func (TimestampType) MarshalJSON ¶
func (signed TimestampType) MarshalJSON() ([]byte, error)
func (*TimestampType) UnmarshalJSON ¶
func (signed *TimestampType) UnmarshalJSON(data []byte) error