mirror of
https://github.com/ultravioletrs/cocos.git
synced 2026-06-23 04:10:25 +00:00
67f939fc66
* manager, cli and agent vtpm support * rebase and changed atls for vtpm * deleted unused code * changed chekproto.yaml script so it find the manager proto file correctly * fixe manager proto version * fix agent tests * fix server agent test * fix attestation test * fix attestation test gofumpt * created dummy RWC for TPM * fix comment * add default PCR values * rebase main * fix rust ci and missing header * changed embedded attestation to VMPL 2 * fix unused impot * fix pkg test * address attestation type * fix agent attestation test * add prc15 check * fix comments * fix cli tests * add doc * add mock for LeveledQuoteProvider when SEV-SNP device is not found Signed-off-by: Sammy Oina <sammyoina@gmail.com> * fix manager reading attestation policy * refactor PCR value checks and update attestation policy values Signed-off-by: Sammy Oina <sammyoina@gmail.com> * fix tests for sev and grpc --------- Signed-off-by: Sammy Oina <sammyoina@gmail.com> Co-authored-by: Sammy Oina <sammyoina@gmail.com>
70 lines
1.8 KiB
Go
70 lines
1.8 KiB
Go
// Copyright (c) Ultraviolet
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
package config
|
|
|
|
import (
|
|
"encoding/json"
|
|
"os"
|
|
|
|
"github.com/absmach/magistrala/pkg/errors"
|
|
"github.com/google/go-sev-guest/proto/check"
|
|
"google.golang.org/protobuf/encoding/protojson"
|
|
)
|
|
|
|
type AttestationType int32
|
|
|
|
const (
|
|
SNP AttestationType = iota
|
|
VTPM
|
|
SNPvTPM
|
|
)
|
|
|
|
var (
|
|
AttestationPolicy = Config{SnpCheck: &check.Config{Policy: &check.Policy{}, RootOfTrust: &check.RootOfTrust{}}, PcrConfig: &PcrConfig{}}
|
|
ErrAttestationPolicyOpen = errors.New("failed to open Attestation Policy file")
|
|
ErrAttestationPolicyDecode = errors.New("failed to decode Attestation Policy file")
|
|
ErrAttestationPolicyMissing = errors.New("failed due to missing Attestation Policy file")
|
|
)
|
|
|
|
type PcrValues struct {
|
|
Sha256 map[string]string `json:"sha256"`
|
|
Sha384 map[string]string `json:"sha384"`
|
|
}
|
|
|
|
type PcrConfig struct {
|
|
PCRValues PcrValues `json:"pcr_values"`
|
|
}
|
|
|
|
type Config struct {
|
|
SnpCheck *check.Config
|
|
PcrConfig *PcrConfig
|
|
}
|
|
|
|
func ReadAttestationPolicy(policyPath string, attestationConfiguration *Config) error {
|
|
if policyPath != "" {
|
|
policyData, err := os.ReadFile(policyPath)
|
|
if err != nil {
|
|
return errors.Wrap(ErrAttestationPolicyOpen, err)
|
|
}
|
|
|
|
return ReadAttestationPolicyFromByte(policyData, attestationConfiguration)
|
|
}
|
|
|
|
return ErrAttestationPolicyMissing
|
|
}
|
|
|
|
func ReadAttestationPolicyFromByte(policyData []byte, attestationConfiguration *Config) error {
|
|
unmarshalOptions := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
|
|
|
|
if err := unmarshalOptions.Unmarshal(policyData, attestationConfiguration.SnpCheck); err != nil {
|
|
return errors.Wrap(ErrAttestationPolicyDecode, err)
|
|
}
|
|
|
|
if err := json.Unmarshal(policyData, attestationConfiguration.PcrConfig); err != nil {
|
|
return errors.Wrap(ErrAttestationPolicyDecode, err)
|
|
}
|
|
|
|
return nil
|
|
}
|