2024-06-11 10:25:24 -04:00
|
|
|
/*
|
|
|
|
Copyright (c) Edgeless Systems GmbH
|
|
|
|
|
|
|
|
SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
*/
|
|
|
|
|
|
|
|
package attestationconfigapi
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"fmt"
|
|
|
|
"path"
|
|
|
|
"sort"
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/edgelesssys/constellation/v2/internal/attestation/variant"
|
|
|
|
)
|
|
|
|
|
|
|
|
// AttestationURLPath is the URL path to the attestation versions.
|
|
|
|
const AttestationURLPath = "constellation/v1/attestation"
|
|
|
|
|
|
|
|
// SEVSNPVersion tracks the latest version of each component for SEV-SNP.
|
|
|
|
type SEVSNPVersion struct {
|
|
|
|
// Bootloader is the latest version of the SEV-SNP bootloader.
|
2024-06-12 04:24:16 -04:00
|
|
|
Bootloader uint8 `json:"bootloader"`
|
2024-06-11 10:25:24 -04:00
|
|
|
// TEE is the latest version of the SEV-SNP TEE.
|
2024-06-12 04:24:16 -04:00
|
|
|
TEE uint8 `json:"tee"`
|
2024-06-11 10:25:24 -04:00
|
|
|
// SNP is the latest version of the SEV-SNP SNP.
|
2024-06-12 04:24:16 -04:00
|
|
|
SNP uint8 `json:"snp"`
|
2024-06-11 10:25:24 -04:00
|
|
|
// Microcode is the latest version of the SEV-SNP microcode.
|
2024-06-12 04:24:16 -04:00
|
|
|
Microcode uint8 `json:"microcode"`
|
2024-06-11 10:25:24 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// TDXVersion tracks the latest version of each component for TDX.
|
|
|
|
type TDXVersion struct {
|
|
|
|
// QESVN is the latest QE security version number.
|
2024-06-12 04:24:16 -04:00
|
|
|
QESVN uint16 `json:"qeSVN"`
|
2024-06-11 10:25:24 -04:00
|
|
|
// PCESVN is the latest PCE security version number.
|
2024-06-12 04:24:16 -04:00
|
|
|
PCESVN uint16 `json:"pceSVN"`
|
2024-06-11 10:25:24 -04:00
|
|
|
// TEETCBSVN are the latest component-wise security version numbers for the TEE.
|
2024-06-12 04:24:16 -04:00
|
|
|
TEETCBSVN [16]byte `json:"teeTCBSVN"`
|
2024-06-11 10:25:24 -04:00
|
|
|
// QEVendorID is the latest QE vendor ID.
|
2024-06-12 04:24:16 -04:00
|
|
|
QEVendorID [16]byte `json:"qeVendorID"`
|
2024-06-11 10:25:24 -04:00
|
|
|
// XFAM is the latest XFAM field.
|
2024-06-12 04:24:16 -04:00
|
|
|
XFAM [8]byte `json:"xfam"`
|
2024-06-11 10:25:24 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// VersionAPIEntry is the request to get the version information of the specific version in the config api.
|
|
|
|
//
|
|
|
|
// TODO: Because variant is not part of the marshalled JSON, fetcher and client methods need to fill the variant property.
|
|
|
|
// In API v2 we should embed the variant in the object and remove some code from fetcher & client.
|
|
|
|
// That would remove the possibility of some fetcher/client code forgetting to set the variant.
|
|
|
|
type VersionAPIEntry struct {
|
|
|
|
Version string `json:"-"`
|
|
|
|
Variant variant.Variant `json:"-"`
|
|
|
|
SEVSNPVersion
|
|
|
|
TDXVersion
|
|
|
|
}
|
|
|
|
|
|
|
|
// JSONPath returns the path to the JSON file for the request to the config api.
|
|
|
|
func (i VersionAPIEntry) JSONPath() string {
|
|
|
|
return path.Join(AttestationURLPath, i.Variant.String(), i.Version)
|
|
|
|
}
|
|
|
|
|
|
|
|
// ValidateRequest validates the request.
|
|
|
|
func (i VersionAPIEntry) ValidateRequest() error {
|
|
|
|
if !strings.HasSuffix(i.Version, ".json") {
|
|
|
|
return fmt.Errorf("version has no .json suffix")
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Validate is a No-Op at the moment.
|
|
|
|
func (i VersionAPIEntry) Validate() error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// VersionList is the request to retrieve of all versions in the API for one attestation variant.
|
|
|
|
//
|
|
|
|
// TODO: Because variant is not part of the marshalled JSON, fetcher and client methods need to fill the variant property.
|
|
|
|
// In API v2 we should embed the variant in the object and remove some code from fetcher & client.
|
|
|
|
// That would remove the possibility of some fetcher/client code forgetting to set the variant.
|
|
|
|
type VersionList struct {
|
|
|
|
Variant variant.Variant
|
|
|
|
List []string
|
|
|
|
}
|
|
|
|
|
|
|
|
// MarshalJSON marshals the i's list property to JSON.
|
|
|
|
func (i VersionList) MarshalJSON() ([]byte, error) {
|
|
|
|
return json.Marshal(i.List)
|
|
|
|
}
|
|
|
|
|
|
|
|
// UnmarshalJSON unmarshals a list of strings into i's list property.
|
|
|
|
func (i *VersionList) UnmarshalJSON(data []byte) error {
|
|
|
|
return json.Unmarshal(data, &i.List)
|
|
|
|
}
|
|
|
|
|
|
|
|
// JSONPath returns the path to the JSON file for the request to the config api.
|
|
|
|
func (i VersionList) JSONPath() string {
|
|
|
|
return path.Join(AttestationURLPath, i.Variant.String(), "list")
|
|
|
|
}
|
|
|
|
|
|
|
|
// ValidateRequest is a NoOp as there is no input.
|
|
|
|
func (i VersionList) ValidateRequest() error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// SortReverse sorts the list of versions in reverse order.
|
|
|
|
func (i *VersionList) SortReverse() {
|
|
|
|
sort.Sort(sort.Reverse(sort.StringSlice(i.List)))
|
|
|
|
}
|
|
|
|
|
|
|
|
// AddVersion adds new to i's list and sorts the element in descending order.
|
|
|
|
func (i *VersionList) AddVersion(new string) {
|
|
|
|
i.List = append(i.List, new)
|
|
|
|
i.List = variant.RemoveDuplicate(i.List)
|
|
|
|
|
|
|
|
i.SortReverse()
|
|
|
|
}
|
|
|
|
|
|
|
|
// Validate validates the response.
|
|
|
|
func (i VersionList) Validate() error {
|
|
|
|
if len(i.List) < 1 {
|
|
|
|
return fmt.Errorf("no versions found in /list")
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|