mirror of
https://github.com/ultravioletrs/cocos.git
synced 2026-06-23 04:10:25 +00:00
4b27b98edb
* Refactor attestation handling: rename AttestationResult to AzureAttestationToken - Updated the protobuf definition to change azureAttestationResponse to azureAttestationToken. - Refactored the Service interface and its implementation to replace AttestationResult with AzureAttestationToken. - Modified mock functions and tests to reflect the new naming and functionality. - Adjusted CLI commands to use the new AzureAttestationToken method. - Removed the AzureToken constant from the attestation package as it is no longer needed. Signed-off-by: Sammy Oina <sammyoina@gmail.com> * Remove redundant data checks and logging in SendData and sendData methods Signed-off-by: Sammy Oina <sammyoina@gmail.com> * Update agent/api/grpc/server_test.go Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update agent/api/grpc/endpoint_test.go Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Refactor attestation handling: rename AttestationToken to AzureAttestationToken in server and test files Signed-off-by: Sammy Oina <sammyoina@gmail.com> * Refactor attestation command output messages for clarity and consistency Signed-off-by: Sammy Oina <sammyoina@gmail.com> * Rename AttestationToken to AzureAttestationToken in TestAttestationToken for consistency Signed-off-by: Sammy Oina <sammyoina@gmail.com> * Refactor TestChangeAttestationConfiguration to use vtpm.ConvertPolicyToJSON for JSON conversion Signed-off-by: Sammy Oina <sammyoina@gmail.com> * Fix: reset temporary file pointer after zipping directory Signed-off-by: Sammy Oina <sammyoina@gmail.com> --------- Signed-off-by: Sammy Oina <sammyoina@gmail.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
112 lines
2.7 KiB
Go
112 lines
2.7 KiB
Go
// Copyright (c) Ultraviolet
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
package grpc
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/go-kit/kit/endpoint"
|
|
"github.com/ultravioletrs/cocos/agent"
|
|
"github.com/ultravioletrs/cocos/pkg/attestation"
|
|
)
|
|
|
|
func algoEndpoint(svc agent.Service) endpoint.Endpoint {
|
|
return func(ctx context.Context, request interface{}) (interface{}, error) {
|
|
req := request.(algoReq)
|
|
|
|
if err := req.validate(); err != nil {
|
|
return algoRes{}, err
|
|
}
|
|
|
|
algo := agent.Algorithm{Algorithm: req.Algorithm, Requirements: req.Requirements}
|
|
|
|
err := svc.Algo(ctx, algo)
|
|
if err != nil {
|
|
return algoRes{}, err
|
|
}
|
|
|
|
return algoRes{}, nil
|
|
}
|
|
}
|
|
|
|
func dataEndpoint(svc agent.Service) endpoint.Endpoint {
|
|
return func(ctx context.Context, request interface{}) (interface{}, error) {
|
|
req := request.(dataReq)
|
|
|
|
if err := req.validate(); err != nil {
|
|
return dataRes{}, err
|
|
}
|
|
|
|
dataset := agent.Dataset{Dataset: req.Dataset, Filename: req.Filename}
|
|
|
|
err := svc.Data(ctx, dataset)
|
|
if err != nil {
|
|
return dataRes{}, err
|
|
}
|
|
|
|
return dataRes{}, nil
|
|
}
|
|
}
|
|
|
|
func resultEndpoint(svc agent.Service) endpoint.Endpoint {
|
|
return func(ctx context.Context, request interface{}) (interface{}, error) {
|
|
req := request.(resultReq)
|
|
|
|
if err := req.validate(); err != nil {
|
|
return resultRes{}, err
|
|
}
|
|
file, err := svc.Result(ctx)
|
|
if err != nil {
|
|
return resultRes{}, err
|
|
}
|
|
|
|
return resultRes{File: file}, nil
|
|
}
|
|
}
|
|
|
|
func attestationEndpoint(svc agent.Service) endpoint.Endpoint {
|
|
return func(ctx context.Context, request interface{}) (interface{}, error) {
|
|
req := request.(attestationReq)
|
|
|
|
if err := req.validate(); err != nil {
|
|
return attestationRes{}, err
|
|
}
|
|
file, err := svc.Attestation(ctx, req.TeeNonce, req.VtpmNonce, attestation.PlatformType(req.AttType))
|
|
if err != nil {
|
|
return attestationRes{}, err
|
|
}
|
|
|
|
return attestationRes{File: file}, nil
|
|
}
|
|
}
|
|
|
|
func imaMeasurementsEndpoint(svc agent.Service) endpoint.Endpoint {
|
|
return func(ctx context.Context, request interface{}) (interface{}, error) {
|
|
req := request.(imaMeasurementsReq)
|
|
|
|
if err := req.validate(); err != nil {
|
|
return imaMeasurementsRes{}, err
|
|
}
|
|
file, pcr10, err := svc.IMAMeasurements(ctx)
|
|
if err != nil {
|
|
return imaMeasurementsRes{}, err
|
|
}
|
|
|
|
return imaMeasurementsRes{File: file, PCR10: pcr10}, nil
|
|
}
|
|
}
|
|
|
|
func azureAttestationTokenEndpoint(svc agent.Service) endpoint.Endpoint {
|
|
return func(ctx context.Context, request interface{}) (interface{}, error) {
|
|
req := request.(azureAttestationTokenReq)
|
|
if err := req.validate(); err != nil {
|
|
return fetchAttestationTokenRes{}, err
|
|
}
|
|
file, err := svc.AzureAttestationToken(ctx, req.tokenNonce)
|
|
if err != nil {
|
|
return fetchAttestationTokenRes{}, err
|
|
}
|
|
return fetchAttestationTokenRes{File: file}, nil
|
|
}
|
|
}
|