Skip to content

Commit

Permalink
common: change cc-trusted-api deps to evidence-api
Browse files Browse the repository at this point in the history
Signed-off-by: Ruoyu Ying <[email protected]>
  • Loading branch information
Ruoyu-y committed Jul 29, 2024
1 parent f7e7c89 commit 9b9d452
Show file tree
Hide file tree
Showing 32 changed files with 172 additions and 172 deletions.
2 changes: 1 addition & 1 deletion setupenv.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ fi

python3 -m virtualenv -p python3 ${CURR_DIR}/venv
source ${CURR_DIR}/venv/bin/activate
python3 -m pip install "cctrusted_base @ git+https://github.com/cc-api/cc-trusted-api.git#subdirectory=common/python"
python3 -m pip install "evidence_api @ git+https://github.com/cc-api/evidence-api.git#subdirectory=common/python"
python3 -m pip install -r $CURR_DIR/src/python/requirements.txt
if [ ! $? -eq 0 ]; then
echo "Failed to install python PIP packages, please check your proxy (https_proxy) or setup PyPi mirror."
Expand Down
4 changes: 2 additions & 2 deletions src/golang/cctrusted_vm/cmd/app/eventlog.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"encoding/hex"
"log"

"github.com/cc-api/cc-trusted-api/common/golang/cctrusted_base"
"github.com/cc-api/evidence-api/common/golang/evidence_api"

"github.com/spf13/cobra"
)
Expand Down Expand Up @@ -65,7 +65,7 @@ var eventLogReplayCmd = &cobra.Command{
},
}

func filterEventLog() ([]cctrusted_base.FormatedTcgEvent, error) {
func filterEventLog() ([]evidence_api.FormatedTcgEvent, error) {
sdk, err := GetSDK()
if err != nil {
return nil, err
Expand Down
4 changes: 2 additions & 2 deletions src/golang/cctrusted_vm/cmd/app/imr.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"encoding/hex"
"log"

"github.com/cc-api/cc-trusted-api/common/golang/cctrusted_base"
"github.com/cc-api/evidence-api/common/golang/evidence_api"

"github.com/spf13/cobra"
)
Expand All @@ -25,7 +25,7 @@ var imrCmd = &cobra.Command{
group := report.IMRGroup()
l := log.Default()
l.Printf("Measurement Count: %d\n", group.MaxIndex+1)
alg := cctrusted_base.GetDefaultTPMAlg()
alg := evidence_api.GetDefaultTPMAlg()
for index, digest := range group.Group {
l.Printf("Index: %v\n", index)
l.Printf("Algorithms: %v\n", alg)
Expand Down
4 changes: 2 additions & 2 deletions src/golang/cctrusted_vm/cmd/app/report.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"math"
"math/rand"

"github.com/cc-api/cc-trusted-api/common/golang/cctrusted_base"
"github.com/cc-api/evidence-api/common/golang/evidence_api"

"github.com/spf13/cobra"
)
Expand All @@ -26,7 +26,7 @@ var reportCmd = &cobra.Command{
if err != nil {
return err
}
report.Dump(cctrusted_base.QuoteDumpFormat(FlagFormat))
report.Dump(evidence_api.QuoteDumpFormat(FlagFormat))
return nil
},
}
Expand Down
38 changes: 19 additions & 19 deletions src/golang/cctrusted_vm/cvm.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"path/filepath"
"strconv"

"github.com/cc-api/cc-trusted-api/common/golang/cctrusted_base"
"github.com/cc-api/evidence-api/common/golang/evidence_api"
)

const (
Expand All @@ -17,20 +17,20 @@ const (

type Device interface {
ProbeDevice() error
Report(nonce, userData string, extraArgs map[string]any) (cctrusted_base.CcReport, error)
Report(nonce, userData string, extraArgs map[string]any) (evidence_api.CcReport, error)
Name() string
CCType() cctrusted_base.CC_Type
Version() cctrusted_base.DeviceVersion
CCType() evidence_api.CC_Type
Version() evidence_api.DeviceVersion
}

type GenericDevice struct {
Device
}

func (d *GenericDevice) Report(nonce, userData string, extraArgs map[string]any) (cctrusted_base.CcReport, error) {
func (d *GenericDevice) Report(nonce, userData string, extraArgs map[string]any) (evidence_api.CcReport, error) {
var err error
if _, err = os.Stat(TSM_PREFIX); os.IsNotExist(err) {
return cctrusted_base.CcReport{}, errors.New("Configfs TSM is not supported in the current environment.")
return evidence_api.CcReport{}, errors.New("Configfs TSM is not supported in the current environment.")
}

// concatenate nonce and userData
Expand All @@ -56,22 +56,22 @@ func (d *GenericDevice) Report(nonce, userData string, extraArgs map[string]any)

tempdir, err := os.MkdirTemp(TSM_PREFIX, "report_")
if err != nil {
return cctrusted_base.CcReport{}, errors.New("Failed to init entry in Configfs TSM.")
return evidence_api.CcReport{}, errors.New("Failed to init entry in Configfs TSM.")
}
defer os.RemoveAll(tempdir)

if _, err = os.Stat(filepath.Join(tempdir, "inblob")); !os.IsNotExist(err) {
err = os.WriteFile(filepath.Join(tempdir, "inblob"), reportData, 0400)
if err != nil {
return cctrusted_base.CcReport{}, errors.New("Failed to push report data into inblob.")
return evidence_api.CcReport{}, errors.New("Failed to push report data into inblob.")
}
}

if v, ok := extraArgs["privilege"]; ok {
if val, ok := v.(int); ok {
err = os.WriteFile(filepath.Join(tempdir, "privlevel"), []byte(strconv.Itoa(val)), 0400)
if err != nil {
return cctrusted_base.CcReport{}, errors.New("Failed to push privilege data to privlevel file.")
return evidence_api.CcReport{}, errors.New("Failed to push privilege data to privlevel file.")
}
}
}
Expand All @@ -81,37 +81,37 @@ func (d *GenericDevice) Report(nonce, userData string, extraArgs map[string]any)
if _, err = os.Stat(filepath.Join(tempdir, "outblob")); !os.IsNotExist(err) {
outblob, err = os.ReadFile(filepath.Join(tempdir, "outblob"))
if err != nil {
return cctrusted_base.CcReport{}, errors.New("Failed to get outblob.")
return evidence_api.CcReport{}, errors.New("Failed to get outblob.")
}
}

if _, err = os.Stat(filepath.Join(tempdir, "generation")); !os.IsNotExist(err) {
rawGeneration, err := os.ReadFile(filepath.Join(tempdir, "generation"))
if err != nil {
return cctrusted_base.CcReport{}, errors.New("Failed to get generation info.")
return evidence_api.CcReport{}, errors.New("Failed to get generation info.")
}
generation, _ = strconv.Atoi(string(rawGeneration))
// Check if the outblob has been corrupted during file open
if generation > 1 {
return cctrusted_base.CcReport{}, errors.New("Found corrupted generation.")
return evidence_api.CcReport{}, errors.New("Found corrupted generation.")
}
}

if _, err = os.Stat(filepath.Join(tempdir, "provider")); !os.IsNotExist(err) {
provider, err = os.ReadFile(filepath.Join(tempdir, "provider"))
if err != nil {
return cctrusted_base.CcReport{}, errors.New("Failed to get provider info.")
return evidence_api.CcReport{}, errors.New("Failed to get provider info.")
}
}

if _, err = os.Stat(filepath.Join(tempdir, "auxblob")); !os.IsNotExist(err) {
auxblob, err = os.ReadFile(filepath.Join(tempdir, "auxblob"))
if err != nil {
return cctrusted_base.CcReport{}, errors.New("Failed to get auxblob info.")
return evidence_api.CcReport{}, errors.New("Failed to get auxblob info.")
}
}

return cctrusted_base.CcReport{
return evidence_api.CcReport{
Outblob: outblob,
Provider: string(provider),
Generation: generation,
Expand All @@ -125,18 +125,18 @@ type EventRecorder interface {
}

type CVMContext struct {
VMType cctrusted_base.CC_Type
Version cctrusted_base.DeviceVersion
VMType evidence_api.CC_Type
Version evidence_api.DeviceVersion
}

type ConfidentialVM interface {
Probe() error
CVMContext() CVMContext
MaxImrIndex() int
DefaultAlgorithm() cctrusted_base.TCG_ALG
DefaultAlgorithm() evidence_api.TCG_ALG
Device
EventRecorder
cctrusted_base.IMARecorder
evidence_api.IMARecorder
}

type CVMInitArgs struct {
Expand Down
2 changes: 1 addition & 1 deletion src/golang/cctrusted_vm/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ require (
)

require (
github.com/cc-api/cc-trusted-api/common/golang/cctrusted_base v0.0.0-20240418131523-3b0ab7d9578e
github.com/cc-api/evidence-api/common/golang/evidence_api
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
Expand Down
44 changes: 22 additions & 22 deletions src/golang/cctrusted_vm/sdk/sdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,34 +9,34 @@ import (
cctrusted_vm "github.com/cc-api/cc-trusted-vmsdk/src/golang/cctrusted_vm"
_ "github.com/cc-api/cc-trusted-vmsdk/src/golang/cctrusted_vm/tdx"

"github.com/cc-api/cc-trusted-api/common/golang/cctrusted_base"
"github.com/cc-api/cc-trusted-api/common/golang/cctrusted_base/tdx"
"github.com/cc-api/evidence-api/common/golang/evidence_api"
"github.com/cc-api/evidence-api/common/golang/evidence_api/tdx"
)

var _ cctrusted_base.CCTrustedAPI = (*SDK)(nil)
var _ evidence_api.EvidenceAPI = (*SDK)(nil)

type SDK struct {
cvm cctrusted_vm.ConfidentialVM
}

// DumpCCReport implements cctrusted_base.CCTrustedAPI.
// DumpCCReport implements evidence_api.EvidenceAPI.
func (s *SDK) DumpCCReport(reportBytes []byte) error {
vmCtx := s.cvm.CVMContext()
switch vmCtx.VMType {
case cctrusted_base.TYPE_CC_TDX:
case evidence_api.TYPE_CC_TDX:
report, err := tdx.NewTdxReportFromBytes(reportBytes)
if err != nil {
return err
}
report.Dump(cctrusted_base.QuoteDumpFormatHuman)
report.Dump(evidence_api.QuoteDumpFormatHuman)
default:
}
return nil
}

// GetCCMeasurement implements cctrusted_base.CCTrustedAPI.
func (s *SDK) GetCCMeasurement(index int, alg cctrusted_base.TCG_ALG) (cctrusted_base.TcgDigest, error) {
emptyRet := cctrusted_base.TcgDigest{}
// GetCCMeasurement implements evidence_api.EvidenceAPI.
func (s *SDK) GetCCMeasurement(index int, alg evidence_api.TCG_ALG) (evidence_api.TcgDigest, error) {
emptyRet := evidence_api.TcgDigest{}
report, err := s.GetCCReport("", "", nil)
if err != nil {
return emptyRet, err
Expand All @@ -52,23 +52,23 @@ func (s *SDK) GetCCMeasurement(index int, alg cctrusted_base.TCG_ALG) (cctrusted
return entry, nil
}

// GetMeasurementCount implements cctrusted_base.CCTrustedAPI.
// GetMeasurementCount implements evidence_api.EvidenceAPI.
func (s *SDK) GetMeasurementCount() (int, error) {
return s.cvm.MaxImrIndex() + 1, nil
}

// ReplayCCEventLog implements cctrusted_base.CCTrustedAPI.
func (s *SDK) ReplayCCEventLog(formatedEventLogs []cctrusted_base.FormatedTcgEvent) map[int]map[cctrusted_base.TCG_ALG][]byte {
return cctrusted_base.ReplayFormatedEventLog(formatedEventLogs)
// ReplayCCEventLog implements evidence_api.EvidenceAPI.
func (s *SDK) ReplayCCEventLog(formatedEventLogs []evidence_api.FormatedTcgEvent) map[int]map[evidence_api.TCG_ALG][]byte {
return evidence_api.ReplayFormatedEventLog(formatedEventLogs)
}

// GetDefaultAlgorithm implements cctrusted_base.CCTrustedAPI.
func (s *SDK) GetDefaultAlgorithm() (cctrusted_base.TCG_ALG, error) {
// GetDefaultAlgorithm implements evidence_api.EvidenceAPI.
func (s *SDK) GetDefaultAlgorithm() (evidence_api.TCG_ALG, error) {
return s.cvm.DefaultAlgorithm(), nil
}

// SelectEventlog implements CCTrustedAPI.
func (s *SDK) GetCCEventLog(params ...int32) ([]cctrusted_base.FormatedTcgEvent, error) {
// SelectEventlog implements EvidenceAPI.
func (s *SDK) GetCCEventLog(params ...int32) ([]evidence_api.FormatedTcgEvent, error) {
el, err := s.internelEventlog()
if err != nil {
return nil, err
Expand Down Expand Up @@ -101,7 +101,7 @@ func (s *SDK) GetCCEventLog(params ...int32) ([]cctrusted_base.FormatedTcgEvent,
return el.EventLog(), nil
}

func (s *SDK) internelEventlog() (*cctrusted_base.EventLogger, error) {
func (s *SDK) internelEventlog() (*evidence_api.EventLogger, error) {
if s.cvm == nil {
return nil, errors.New("no available cvm in sdk")
}
Expand All @@ -116,12 +116,12 @@ func (s *SDK) internelEventlog() (*cctrusted_base.EventLogger, error) {
return nil, err
}

el := cctrusted_base.NewEventLogger(eventLogBytes, imaLogBytes, cctrusted_base.TCG_PCCLIENT_FORMAT)
el := evidence_api.NewEventLogger(eventLogBytes, imaLogBytes, evidence_api.TCG_PCCLIENT_FORMAT)
return el, nil
}

// Report implements CCTrustedAPI.
func (s *SDK) GetCCReport(nonce, userData string, extraArgs map[string]any) (cctrusted_base.Report, error) {
// Report implements EvidenceAPI.
func (s *SDK) GetCCReport(nonce, userData string, extraArgs map[string]any) (evidence_api.Report, error) {
if s.cvm == nil {
return nil, errors.New("no available cvm in sdk")
}
Expand All @@ -133,7 +133,7 @@ func (s *SDK) GetCCReport(nonce, userData string, extraArgs map[string]any) (cct

vmCtx := s.cvm.CVMContext()
switch vmCtx.VMType {
case cctrusted_base.TYPE_CC_TDX:
case evidence_api.TYPE_CC_TDX:
report, err := tdx.NewTdxReportFromBytes(reportStruct.Outblob)
if err != nil {
return nil, err
Expand Down
6 changes: 3 additions & 3 deletions src/golang/cctrusted_vm/sdk/sdk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"log"
"testing"

"github.com/cc-api/cc-trusted-api/common/golang/cctrusted_base"
"github.com/cc-api/evidence-api/common/golang/evidence_api"

"github.com/stretchr/testify/assert"
)
Expand All @@ -18,7 +18,7 @@ func TestSDKReport(t *testing.T) {
assert.Nil(t, err)
report, err := sdk.GetCCReport("", "", nil)
assert.Nil(t, err)
report.Dump(cctrusted_base.QuoteDumpFormatHuman)
report.Dump(evidence_api.QuoteDumpFormatHuman)

}

Expand All @@ -31,6 +31,6 @@ func TestSDKFullEventLog(t *testing.T) {

el, err := sdk.GetCCEventLog(0, 0)
assert.Nil(t, err)
el.Dump(cctrusted_base.QuoteDumpFormatHuman)
el.Dump(evidence_api.QuoteDumpFormatHuman)

}
12 changes: 6 additions & 6 deletions src/golang/cctrusted_vm/tdx/cvm.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,22 @@ package tdx
import (
cctrusted_vm "github.com/cc-api/cc-trusted-vmsdk/src/golang/cctrusted_vm"

"github.com/cc-api/cc-trusted-api/common/golang/cctrusted_base"
"github.com/cc-api/cc-trusted-api/common/golang/cctrusted_base/tdx"
"github.com/cc-api/evidence-api/common/golang/evidence_api"
"github.com/cc-api/evidence-api/common/golang/evidence_api/tdx"
)

var _ cctrusted_vm.ConfidentialVM = (*TdxVM)(nil)

type TdxVM struct {
cctrusted_vm.Device
cctrusted_vm.EventRecorder
cctrusted_base.IMARecorder
evidence_api.IMARecorder
}

func NewTdxVM(args *cctrusted_vm.CVMInitArgs) *TdxVM {
vm := &TdxVM{
Device: &TDXDevice{},
IMARecorder: &cctrusted_base.DefaultIMARecorder{},
IMARecorder: &evidence_api.DefaultIMARecorder{},
}
r := &TDXEventLogRecorder{}
if args != nil {
Expand All @@ -34,8 +34,8 @@ func NewTdxVM(args *cctrusted_vm.CVMInitArgs) *TdxVM {
}

// DefaultAlgorithm implements cctrusted_vm.ConfidentialVM.
func (t *TdxVM) DefaultAlgorithm() cctrusted_base.TCG_ALG {
return cctrusted_base.TPM_ALG_SHA384
func (t *TdxVM) DefaultAlgorithm() evidence_api.TCG_ALG {
return evidence_api.TPM_ALG_SHA384
}

// MaxImrIndex implements cctrusted_vm.ConfidentialVM.
Expand Down
Loading

0 comments on commit 9b9d452

Please sign in to comment.