@@ -34,6 +34,7 @@ import (
3434 "github.com/google/go-tpm-tools/cel"
3535 "github.com/google/go-tpm-tools/client"
3636 "github.com/google/go-tpm-tools/internal"
37+ "github.com/google/go-tpm-tools/launcher/device"
3738 "github.com/google/go-tpm-tools/launcher/internal/logging"
3839 "github.com/google/go-tpm-tools/launcher/internal/signaturediscovery"
3940 "github.com/google/go-tpm-tools/launcher/spec"
@@ -72,28 +73,13 @@ type attestRoot interface {
7273 Attest (nonce []byte ) (any , error )
7374 // ComputeNonce hashes the challenge and extraData using the algorithm preferred by the attestation root.
7475 ComputeNonce (challenge []byte , extraData []byte ) []byte
75- // AddDeviceROTs adds detected device RoTs(root of trust).
76- AddDeviceROTs ([]DeviceROT )
77- // AttestDeviceROTs fetches a list of runtime device attestation report.
78- AttestDeviceROTs (nonce []byte ) ([]any , error )
79- }
80-
81- // DeviceROT defines an interface for all attached devices to collect attestation.
82- type DeviceROT interface {
83- // Attest fetches an attestation from the attached device detected by launcher.
84- Attest (nonce []byte ) (any , error )
8576}
8677
8778// AttestAgentOpts contains user generated options when calling the
8879// VerifyAttestation API
8980type AttestAgentOpts struct {
90- TokenOptions * models.TokenOptions
91- * DeviceReportOpts
92- }
93-
94- // DeviceReportOpts contains options for runtime device attestations.
95- type DeviceReportOpts struct {
96- EnableRuntimeGPUAttestation bool
81+ TokenOptions * models.TokenOptions
82+ DeviceReportOpts device.ReportOpts
9783}
9884
9985type agent struct {
@@ -106,6 +92,7 @@ type agent struct {
10692 launchSpec spec.LaunchSpec
10793 logger logging.Logger
10894 sigsCache * sigsCache
95+ deviceROTManager * device.ROTManager
10996}
11097
11198// CreateAttestationAgent returns an agent capable of performing remote
@@ -115,7 +102,7 @@ type agent struct {
115102// - principalFetcher is a func to fetch GCE principal tokens for a given audience.
116103// - signaturesFetcher is a func to fetch container image signatures associated with the running workload.
117104// - logger will log any partial errors returned by VerifyAttestation.
118- func CreateAttestationAgent (tpm io.ReadWriteCloser , akFetcher util.TpmKeyFetcher , verifierClient verifier.Client , principalFetcher principalIDTokenFetcher , sigsFetcher signaturediscovery.Fetcher , launchSpec spec.LaunchSpec , logger logging.Logger , deviceROTs []DeviceROT ) (AttestationAgent , error ) {
105+ func CreateAttestationAgent (tpm io.ReadWriteCloser , akFetcher util.TpmKeyFetcher , verifierClient verifier.Client , principalFetcher principalIDTokenFetcher , sigsFetcher signaturediscovery.Fetcher , launchSpec spec.LaunchSpec , logger logging.Logger , deviceROTs []device. ROT ) (AttestationAgent , error ) {
119106 // Fetched the AK and save it, so the agent doesn't need to create a new key everytime
120107 ak , err := akFetcher (tpm )
121108 if err != nil {
@@ -178,8 +165,8 @@ func CreateAttestationAgent(tpm io.ReadWriteCloser, akFetcher util.TpmKeyFetcher
178165 attestAgent .avRot = tpmAR
179166 }
180167
181- // Add deviceRoTs to the CPU attestation root .
182- attestAgent .avRot . AddDeviceROTs (deviceROTs )
168+ // Register device ROT manager to the attestAgent .
169+ attestAgent .deviceROTManager = device . NewROTManager (deviceROTs )
183170 return attestAgent , nil
184171}
185172
@@ -360,10 +347,7 @@ func (a *agent) AttestationEvidence(_ context.Context, challenge []byte, extraDa
360347}
361348
362349func (a * agent ) attestDeviceROTs (nonce []byte , opts AttestAgentOpts ) ([]* attestationpb.DeviceAttestationReport , error ) {
363- if opts .DeviceReportOpts == nil {
364- return nil , nil
365- }
366- deviceROTs , err := a .avRot .AttestDeviceROTs (nonce )
350+ deviceROTs , err := a .deviceROTManager .AttestDeviceROTs (nonce , opts .DeviceReportOpts )
367351 if err != nil {
368352 return nil , err
369353 }
@@ -411,12 +395,11 @@ func convertOCIToContainerSignature(ociSig oci.Signature) (*verifier.ContainerSi
411395}
412396
413397type tpmAttestRoot struct {
414- tpmMu sync.Mutex
415- fetchedAK * client.Key
416- tpm io.ReadWriteCloser
417- cosCel gecel.CEL
418- hashAlgos []crypto.Hash
419- deviceROTs []DeviceROT
398+ tpmMu sync.Mutex
399+ fetchedAK * client.Key
400+ tpm io.ReadWriteCloser
401+ cosCel gecel.CEL
402+ hashAlgos []crypto.Hash
420403}
421404
422405func (t * tpmAttestRoot ) GetCEL () gecel.CEL {
@@ -457,22 +440,10 @@ func (t *tpmAttestRoot) ComputeNonce(challenge []byte, extraData []byte) []byte
457440 return finalNonce [:]
458441}
459442
460- func (t * tpmAttestRoot ) AddDeviceROTs (deviceROTs []DeviceROT ) {
461- t .deviceROTs = append (t .deviceROTs , deviceROTs ... )
462- }
463-
464- func (t * tpmAttestRoot ) AttestDeviceROTs (nonce []byte ) ([]any , error ) {
465- t .tpmMu .Lock ()
466- defer t .tpmMu .Unlock ()
467-
468- return doAttestDeviceROTs (t .deviceROTs , nonce )
469- }
470-
471443type tdxAttestRoot struct {
472- tdxMu sync.Mutex
473- qp * tg.LinuxConfigFsQuoteProvider
474- cosCel gecel.CEL
475- deviceROTs []DeviceROT
444+ tdxMu sync.Mutex
445+ qp * tg.LinuxConfigFsQuoteProvider
446+ cosCel gecel.CEL
476447}
477448
478449func (t * tdxAttestRoot ) GetCEL () gecel.CEL {
@@ -513,13 +484,6 @@ func (t *tdxAttestRoot) Attest(nonce []byte) (any, error) {
513484 }, nil
514485}
515486
516- func (t * tdxAttestRoot ) AttestDeviceROTs (nonce []byte ) ([]any , error ) {
517- t .tdxMu .Lock ()
518- defer t .tdxMu .Unlock ()
519-
520- return doAttestDeviceROTs (t .deviceROTs , nonce )
521- }
522-
523487func (t * tdxAttestRoot ) ComputeNonce (challenge []byte , extraData []byte ) []byte {
524488 challengeData := challenge
525489 if extraData != nil {
@@ -531,10 +495,6 @@ func (t *tdxAttestRoot) ComputeNonce(challenge []byte, extraData []byte) []byte
531495 return finalNonce [:]
532496}
533497
534- func (t * tdxAttestRoot ) AddDeviceROTs (deviceROTs []DeviceROT ) {
535- t .deviceROTs = append (t .deviceROTs , deviceROTs ... )
536- }
537-
538498// Refresh refreshes the internal state of the attestation agent.
539499// It will reset the container image signatures for now.
540500func (a * agent ) Refresh (ctx context.Context ) error {
@@ -633,15 +593,3 @@ func convertToTPMQuote(v *pb.Attestation) *attestationpb.TpmQuote {
633593 },
634594 }
635595}
636-
637- func doAttestDeviceROTs (deviceROTs []DeviceROT , nonce []byte ) ([]any , error ) {
638- var deviceReports []any
639- for _ , deviceROT := range deviceROTs {
640- deviceReport , err := deviceROT .Attest (nonce )
641- if err != nil {
642- return nil , err
643- }
644- deviceReports = append (deviceReports , deviceReport )
645- }
646- return deviceReports , nil
647- }
0 commit comments