eat

package
v2.0.0-rc.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 30, 2026 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DebugEnabled              = 0 // Debug is enabled
	DebugDisabled             = 1 // Debug is disabled
	DebugDisabledSinceBoot    = 2 // Debug is disabled since boot
	DebugPermanentDisable     = 3 // Debug is permanently disabled
	DebugFullPermanentDisable = 4 // Debug is fully and permanently disabled
)

DebugStatus constants (RFC 9711 Section 4.2.6).

OEMID constants (Private Enterprise Numbers).

View Source
const (
	IntUseGenericFresh = 1 // General purpose, fresh token
)

IntUse constants (RFC 9711 Section 4.2.5).

View Source
const MinNonceLength = 8

MinNonceLength defines the minimum length for EAT nonce in bytes.

Variables

View Source
var (
	ErrVerificationKeyRequired = errors.New("EAT verification key is required")
	ErrSignedCBORRequired      = errors.New("signed COSE EAT is required")
)
View Source
var (
	ErrInvalidSigningKey      = errors.New("invalid EAT signing key")
	ErrInvalidVerificationKey = errors.New("invalid EAT verification key")
)

Functions

func EncodeToCBOR

func EncodeToCBOR(claims *EATClaims, signingKey *ecdsa.PrivateKey, issuer string) ([]byte, error)

EncodeToCBOR is a convenience function to encode EAT claims to CBOR.

func EncodeToJWT

func EncodeToJWT(claims *EATClaims, signingKey *ecdsa.PrivateKey, issuer string) (string, error)

EncodeToJWT is a convenience function to encode EAT claims to JWT.

func GenerateSigningKey

func GenerateSigningKey() (*ecdsa.PrivateKey, error)

GenerateSigningKey generates a new ECDSA signing key.

func LoadSigningKey

func LoadSigningKey(path string) (*ecdsa.PrivateKey, error)

LoadSigningKey loads an ES256 private key from a PEM-encoded SEC 1 or PKCS#8 file. Private key files with group or other permission bits are rejected.

func LoadVerificationKey

func LoadVerificationKey(path string) (*ecdsa.PublicKey, error)

LoadVerificationKey loads an ES256 public key from a PEM-encoded PKIX public key or X.509 certificate.

func ValidateEATClaims

func ValidateEATClaims(claims *EATClaims, policy *EATValidationPolicy) error

ValidateEATClaims validates EAT claims against policy.

func VerificationKeyFingerprint

func VerificationKeyFingerprint(key *ecdsa.PublicKey) (string, error)

VerificationKeyFingerprint returns the SHA-256 fingerprint of a public key's PKIX encoding.

Types

type CBOREncoder

type CBOREncoder struct {
	// contains filtered or unexported fields
}

CBOREncoder encodes EAT claims to CBOR format (CWT - CBOR Web Token).

func NewCBOREncoder

func NewCBOREncoder(signingKey *ecdsa.PrivateKey, issuer string) *CBOREncoder

NewCBOREncoder creates a new CBOR encoder.

func (*CBOREncoder) Encode

func (e *CBOREncoder) Encode(claims *EATClaims) ([]byte, error)

Encode encodes EAT claims to CBOR bytes with COSE_Sign1 signature.

type Decoder

type Decoder struct {
	// contains filtered or unexported fields
}

Decoder decodes EAT tokens (auto-detects JWT vs CBOR).

func NewDecoder

func NewDecoder(verifyKey *ecdsa.PublicKey) *Decoder

NewDecoder creates a new EAT decoder.

func (*Decoder) Decode

func (d *Decoder) Decode(token []byte) (*EATClaims, error)

Decode decodes an EAT token (auto-detects format).

type EATClaims

type EATClaims struct {
	// Standard JWT/CWT claims
	Issuer    string `json:"iss,omitempty" cbor:"1,keyasint,omitempty"`
	Subject   string `json:"sub,omitempty" cbor:"2,keyasint,omitempty"`
	IssuedAt  int64  `json:"iat,omitempty" cbor:"6,keyasint,omitempty"`
	ExpiresAt int64  `json:"exp,omitempty" cbor:"4,keyasint,omitempty"`

	// Core EAT claims (RFC 9711)
	Nonce        []byte `json:"eat_nonce" cbor:"10,keyasint"`                      // Freshness/replay protection
	UEID         []byte `json:"ueid" cbor:"256,keyasint"`                          // Universal Entity ID
	OEMID        int    `json:"oemid,omitempty" cbor:"258,keyasint,omitempty"`     // Hardware OEM ID
	HWModel      []byte `json:"hwmodel,omitempty" cbor:"259,keyasint,omitempty"`   // Hardware model
	HWVersion    string `json:"hwversion,omitempty" cbor:"260,keyasint,omitempty"` // Hardware version
	SWName       string `json:"swname,omitempty" cbor:"270,keyasint,omitempty"`    // Software name
	SWVersion    string `json:"swversion,omitempty" cbor:"271,keyasint,omitempty"` // Software version
	DebugStatus  int    `json:"dbgstat" cbor:"263,keyasint"`                       // Debug status
	IntUse       int    `json:"intuse,omitempty" cbor:"262,keyasint,omitempty"`    // Intended use
	Measurements []byte `json:"measurements" cbor:"265,keyasint"`                  // Software measurements

	// Platform type indicator
	PlatformType string `json:"platform_type"`

	// Submodules for vTPM and other components
	Submods map[string]interface{} `json:"submods,omitempty" cbor:"266,keyasint,omitempty"`

	// Platform-specific extensions (custom claims)
	SNPExtensions  *SNPExtensions  `json:"x-asb-sevsnp,omitempty"`
	TDXExtensions  *TDXExtensions  `json:"x-asb-tdx,omitempty"`
	VTPMExtensions *VTPMExtensions `json:"x-asb-vtpm,omitempty"`

	// Original binary report (for verification)
	RawReport []byte `json:"raw_report,omitempty"`
}

EATClaims represents the Entity Attestation Token claims following RFC 9711.

func Decode

func Decode(token []byte, verifyKey *ecdsa.PublicKey) (*EATClaims, error)

Decode is a convenience function that auto-detects format.

func DecodeCBOR

func DecodeCBOR(token []byte, verifyKey *ecdsa.PublicKey) (*EATClaims, error)

DecodeCBOR is a convenience function to decode CBOR EAT token.

func DecodeJWT

func DecodeJWT(tokenString string, verifyKey *ecdsa.PublicKey) (*EATClaims, error)

DecodeJWT is a convenience function to decode JWT EAT token.

func DecodeVerifiedCBOR

func DecodeVerifiedCBOR(token []byte, verifyKey *ecdsa.PublicKey) (*EATClaims, error)

DecodeVerifiedCBOR verifies a signed COSE EAT and decodes its claims. Unlike DecodeCBOR, it never accepts plain CBOR or an omitted verification key.

func NewEATClaims

func NewEATClaims(report []byte, nonce []byte, platformType attestation.PlatformType) (*EATClaims, error)

NewEATClaims creates EAT claims from binary attestation report.

func (*EATClaims) MarshalJSON

func (c *EATClaims) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler for pretty printing.

func (*EATClaims) Sanitize

func (c *EATClaims) Sanitize()

Sanitize enforces dependency rules for claims. HWModel requires OEMID. HWVersion requires HWModel.

type EATValidationPolicy

type EATValidationPolicy struct {
	RequireEATFormat   bool
	AllowedFormats     []string
	MaxTokenAgeSeconds int
	RequireClaims      []string
	VerifySignature    bool
}

EATValidationPolicy contains validation rules for EAT tokens.

type JWTEncoder

type JWTEncoder struct {
	// contains filtered or unexported fields
}

JWTEncoder encodes EAT claims to JWT format.

func NewJWTEncoder

func NewJWTEncoder(signingKey *ecdsa.PrivateKey, issuer string) *JWTEncoder

NewJWTEncoder creates a new JWT encoder.

func (*JWTEncoder) Encode

func (e *JWTEncoder) Encode(claims *EATClaims) (string, error)

Encode encodes EAT claims to JWT string.

type SNPExtensions

type SNPExtensions struct {
	Measurement   []byte `json:"measurement"`              // SNP MEASUREMENT field
	TCB           string `json:"tcb"`                      // TCB version info
	PlatformInfo  uint64 `json:"platform_info"`            // PLATFORM_INFO
	Policy        uint64 `json:"policy"`                   // POLICY field
	FamilyID      []byte `json:"family_id,omitempty"`      // Family ID
	ImageID       []byte `json:"image_id,omitempty"`       // Image ID
	VMPL          int    `json:"vmpl,omitempty"`           // VM Privilege Level
	SignatureAlgo int    `json:"signature_algo,omitempty"` // Signature algorithm
	CurrentTCB    uint64 `json:"current_tcb,omitempty"`    // Current TCB
	ReportedTCB   uint64 `json:"reported_tcb,omitempty"`   // Reported TCB
	ChipID        []byte `json:"chip_id,omitempty"`        // Chip ID
	CommittedTCB  uint64 `json:"committed_tcb,omitempty"`  // Committed TCB
	LaunchTCB     uint64 `json:"launch_tcb,omitempty"`     // Launch TCB
	Signature     []byte `json:"signature,omitempty"`      // Signature
}

SNPExtensions contains AMD SEV-SNP specific claims.

type TDXExtensions

type TDXExtensions struct {
	MRTD          []byte         `json:"tdx_mrtd"`                    // MRTD measurement
	RTMR0         []byte         `json:"tdx_rtmr0"`                   // Runtime measurement register 0
	RTMR1         []byte         `json:"tdx_rtmr1"`                   // Runtime measurement register 1
	RTMR2         []byte         `json:"tdx_rtmr2"`                   // Runtime measurement register 2
	RTMR3         []byte         `json:"tdx_rtmr3"`                   // Runtime measurement register 3
	XFAM          uint64         `json:"tdx_xfam"`                    // Extended features available mask
	TDAttributes  uint64         `json:"tdx_td_attributes"`           // TD attributes
	MRConfigID    []byte         `json:"tdx_mrconfigid,omitempty"`    // MR Config ID
	MROwner       []byte         `json:"tdx_mrowner,omitempty"`       // MR Owner
	MROwnerConfig []byte         `json:"tdx_mrownerconfig,omitempty"` // MR Owner Config
	MRSEAM        []byte         `json:"tdx_mrseam,omitempty"`        // MR SEAM
	TDXModule     *TDXModuleInfo `json:"tdx_module,omitempty"`        // TDX module info
	Signature     []byte         `json:"tdx_signature,omitempty"`     // Quote Signature
}

TDXExtensions contains Intel TDX specific claims.

type TDXModuleInfo

type TDXModuleInfo struct {
	Major     uint8  `json:"major"`
	Minor     uint8  `json:"minor"`
	BuildNum  uint16 `json:"build_num"`
	BuildDate uint32 `json:"build_date"`
}

TDXModuleInfo contains TDX module version information.

type VTPMExtensions

type VTPMExtensions struct {
	PCRs     map[string]string `json:"pcrs"`                // PCR values (SHA256/SHA384)
	EventLog []byte            `json:"event_log,omitempty"` // Event log
	Quote    []byte            `json:"quote,omitempty"`     // TPM quote
}

VTPMExtensions contains vTPM specific claims.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL