2023-05-25 12:43:44 -04:00
|
|
|
/*
|
|
|
|
Copyright (c) Edgeless Systems GmbH
|
|
|
|
|
|
|
|
SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
*/
|
2023-06-02 03:19:23 -04:00
|
|
|
|
2023-06-07 10:16:32 -04:00
|
|
|
package attestationconfigapi
|
2023-05-25 12:43:44 -04:00
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"path"
|
2023-06-09 06:48:12 -04:00
|
|
|
"sort"
|
2023-05-25 12:43:44 -04:00
|
|
|
"strings"
|
|
|
|
|
2023-06-09 09:41:02 -04:00
|
|
|
"github.com/edgelesssys/constellation/v2/internal/attestation/variant"
|
2023-05-25 12:43:44 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
// attestationURLPath is the URL path to the attestation versions.
|
|
|
|
const attestationURLPath = "constellation/v1/attestation"
|
|
|
|
|
|
|
|
// AzureSEVSNPVersionType is the type of the version to be requested.
|
|
|
|
type AzureSEVSNPVersionType string
|
|
|
|
|
|
|
|
// AzureSEVSNPVersion tracks the latest version of each component of the Azure SEVSNP.
|
|
|
|
type AzureSEVSNPVersion struct {
|
|
|
|
// Bootloader is the latest version of the Azure SEVSNP bootloader.
|
|
|
|
Bootloader uint8 `json:"bootloader"`
|
|
|
|
// TEE is the latest version of the Azure SEVSNP TEE.
|
|
|
|
TEE uint8 `json:"tee"`
|
|
|
|
// SNP is the latest version of the Azure SEVSNP SNP.
|
|
|
|
SNP uint8 `json:"snp"`
|
|
|
|
// Microcode is the latest version of the Azure SEVSNP microcode.
|
|
|
|
Microcode uint8 `json:"microcode"`
|
|
|
|
}
|
|
|
|
|
2023-06-05 06:33:22 -04:00
|
|
|
// AzureSEVSNPVersionAPI is the request to get the version information of the specific version in the config api.
|
|
|
|
type AzureSEVSNPVersionAPI struct {
|
2023-05-25 12:43:44 -04:00
|
|
|
Version string `json:"-"`
|
|
|
|
AzureSEVSNPVersion
|
|
|
|
}
|
|
|
|
|
|
|
|
// JSONPath returns the path to the JSON file for the request to the config api.
|
2023-06-05 06:33:22 -04:00
|
|
|
func (i AzureSEVSNPVersionAPI) JSONPath() string {
|
2023-05-25 12:43:44 -04:00
|
|
|
return path.Join(attestationURLPath, variant.AzureSEVSNP{}.String(), i.Version)
|
|
|
|
}
|
|
|
|
|
|
|
|
// ValidateRequest validates the request.
|
2023-06-05 06:33:22 -04:00
|
|
|
func (i AzureSEVSNPVersionAPI) ValidateRequest() error {
|
2023-05-25 12:43:44 -04:00
|
|
|
if !strings.HasSuffix(i.Version, ".json") {
|
|
|
|
return fmt.Errorf("version has no .json suffix")
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Validate is a No-Op at the moment.
|
2023-06-05 06:33:22 -04:00
|
|
|
func (i AzureSEVSNPVersionAPI) Validate() error {
|
2023-05-25 12:43:44 -04:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// AzureSEVSNPVersionList is the request to list all versions in the config api.
|
|
|
|
type AzureSEVSNPVersionList []string
|
|
|
|
|
|
|
|
// JSONPath returns the path to the JSON file for the request to the config api.
|
|
|
|
func (i AzureSEVSNPVersionList) JSONPath() string {
|
|
|
|
return path.Join(attestationURLPath, variant.AzureSEVSNP{}.String(), "list")
|
|
|
|
}
|
|
|
|
|
|
|
|
// ValidateRequest is a NoOp as there is no input.
|
|
|
|
func (i AzureSEVSNPVersionList) ValidateRequest() error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2023-06-09 06:48:12 -04:00
|
|
|
// SortAzureSEVSNPVersionList sorts the list of versions in reverse order.
|
|
|
|
func SortAzureSEVSNPVersionList(versions AzureSEVSNPVersionList) {
|
|
|
|
sort.Sort(sort.Reverse(sort.StringSlice(versions)))
|
|
|
|
}
|
|
|
|
|
2023-05-25 12:43:44 -04:00
|
|
|
// Validate validates the response.
|
|
|
|
func (i AzureSEVSNPVersionList) Validate() error {
|
|
|
|
if len(i) < 1 {
|
|
|
|
return fmt.Errorf("no versions found in /list")
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|