2023-03-09 05:22:58 -05:00
|
|
|
/*
|
|
|
|
Copyright (c) Edgeless Systems GmbH
|
|
|
|
|
|
|
|
SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
*/
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2024-02-08 09:20:01 -05:00
|
|
|
"log/slog"
|
2023-03-09 05:22:58 -05:00
|
|
|
"os"
|
|
|
|
|
2023-06-09 09:41:02 -04:00
|
|
|
"github.com/edgelesssys/constellation/v2/internal/attestation/variant"
|
2023-03-09 05:22:58 -05:00
|
|
|
"github.com/edgelesssys/constellation/v2/internal/constants"
|
|
|
|
"github.com/edgelesssys/constellation/v2/internal/logger"
|
|
|
|
"github.com/edgelesssys/constellation/v2/measurement-reader/internal/sorted"
|
2023-03-09 12:11:47 -05:00
|
|
|
"github.com/edgelesssys/constellation/v2/measurement-reader/internal/tdx"
|
2023-03-09 05:22:58 -05:00
|
|
|
"github.com/edgelesssys/constellation/v2/measurement-reader/internal/tpm"
|
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
2024-02-08 09:20:01 -05:00
|
|
|
log := logger.NewJSONLogger(slog.LevelInfo)
|
2023-03-29 03:30:13 -04:00
|
|
|
variantString := os.Getenv(constants.AttestationVariant)
|
|
|
|
attestationVariant, err := variant.FromString(variantString)
|
2023-03-09 05:22:58 -05:00
|
|
|
if err != nil {
|
2024-02-08 09:20:01 -05:00
|
|
|
log.With(slog.Any("error", err)).Error("Failed to parse attestation variant")
|
|
|
|
os.Exit(1)
|
2023-03-09 05:22:58 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
var m []sorted.Measurement
|
|
|
|
switch attestationVariant {
|
2024-04-16 12:13:47 -04:00
|
|
|
case variant.AWSNitroTPM{}, variant.AWSSEVSNP{}, variant.AzureSEVSNP{}, variant.AzureTrustedLaunch{}, variant.GCPSEVES{}, variant.GCPSEVSNP{}, variant.QEMUVTPM{}:
|
2023-03-09 05:22:58 -05:00
|
|
|
m, err = tpm.Measurements()
|
|
|
|
if err != nil {
|
2024-02-08 09:20:01 -05:00
|
|
|
log.With(slog.Any("error", err)).Error("Failed to read TPM measurements")
|
|
|
|
os.Exit(1)
|
2023-03-09 05:22:58 -05:00
|
|
|
}
|
2023-03-10 05:33:06 -05:00
|
|
|
case variant.QEMUTDX{}:
|
2023-03-09 12:11:47 -05:00
|
|
|
m, err = tdx.Measurements()
|
|
|
|
if err != nil {
|
2024-02-08 09:20:01 -05:00
|
|
|
log.With(slog.Any("error", err)).Error("Failed to read Intel TDX measurements")
|
|
|
|
os.Exit(1)
|
2023-03-09 12:11:47 -05:00
|
|
|
}
|
2023-03-09 05:22:58 -05:00
|
|
|
default:
|
2024-02-08 09:20:01 -05:00
|
|
|
log.With(slog.String("attestationVariant", variantString)).Error("Unsupported attestation variant")
|
|
|
|
os.Exit(1)
|
2023-03-09 05:22:58 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Println("Measurements:")
|
|
|
|
for _, measurement := range m {
|
2023-03-09 12:11:47 -05:00
|
|
|
// -7 should ensure consistent padding across all current prefixes: PCR[xx], MRTD, RTMR[x].
|
|
|
|
// If the prefix gets longer somewhen in the future, this might need adjustment for consistent padding.
|
|
|
|
fmt.Printf("\t%-7s : 0x%0X\n", measurement.Index, measurement.Value)
|
2023-03-09 05:22:58 -05:00
|
|
|
}
|
|
|
|
}
|