Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename dependency cc-trusted-api to evidence-api #88

Merged
merged 1 commit into from
Jul 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions container/cima-example/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ FROM python:3.12.3-alpine3.19 AS python-builder

RUN apk update && apk add git
RUN python3 -m pip install --upgrade build
RUN git clone https://github.com/cc-api/cc-trusted-api && \
cd cc-trusted-api/common/python && \
RUN git clone https://github.com/cc-api/evidence-api && \
cd evidence-api/common/python && \
python3 -m build

COPY sdk/python3 cima-sdk
Expand Down Expand Up @@ -37,14 +37,14 @@ RUN chown $USER:$GROUP /run/cima

COPY test ./
COPY sdk/python3/example/py_sdk_example.py ./
COPY --from=python-builder cc-trusted-api/common/python/dist/cctrusted_base*.whl ./
COPY --from=python-builder evidence-api/common/python/dist/evidence_api*.whl ./
COPY --from=python-builder cima-sdk/dist/cima*.whl ./

COPY --from=golang-builder /go/cima-sdk/example/go-sdk-example ./
COPY --from=rust-builder cima-sdk/example/target/release/rust-sdk-example ./

RUN apk update && apk add bash vim tar wget libexpat=2.6.2-r0
RUN pip install ./cctrusted_base*.whl ./cima*.whl pytest && rm -f *.whl
RUN pip install ./evidence_api*.whl ./cima*.whl pytest && rm -f *.whl

USER ${USER}
ENTRYPOINT ["tail", "-f", "/dev/null"]
8 changes: 4 additions & 4 deletions container/cima-perf/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ FROM python:alpine AS python-builder

RUN apk update && apk add git
RUN python3 -m pip install --upgrade build
RUN git clone https://github.com/cc-api/cc-trusted-api && \
cd cc-trusted-api/common/python && \
RUN git clone https://github.com/cc-api/evidence-api && \
cd evidence-api/common/python && \
python3 -m build

COPY sdk/python3 cima-sdk
Expand All @@ -16,11 +16,11 @@ FROM python:alpine
WORKDIR /run/cima

COPY container/cima-perf/cima_perf.py ./
COPY --from=python-builder cc-trusted-api/common/python/dist/cctrusted_base*.whl ./
COPY --from=python-builder evidence-api/common/python/dist/evidence_api*.whl ./
COPY --from=python-builder cima-sdk/dist/cima*.whl ./

RUN apk update && apk add bash vim
RUN python3 -m pip install pytest
RUN pip install ./cctrusted_base*.whl ./cima*.whl && rm -f *.whl
RUN pip install ./evidence_api*.whl ./cima*.whl && rm -f *.whl

ENTRYPOINT ["tail", "-f", "/dev/null"]
14 changes: 7 additions & 7 deletions sdk/golang/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ import (
"fmt"
"os"

"github.com/cc-api/cc-trusted-api/common/golang/cctrusted_base"
"github.com/cc-api/evidence-api/common/golang/evidence_api"
"github.com/cc-api/container-integrity-measurement-agent/sdk/golang/cima"
)

Expand All @@ -74,7 +74,7 @@ func testGetCCReport() {
}

fmt.Println("Dump the attestation report fetched.")
report.Dump(cctrusted_base.QuoteDumpFormat(cctrusted_base.QuoteDumpFormatRaw))
report.Dump(evidence_api.QuoteDumpFormat(evidence_api.QuoteDumpFormatRaw))
}

```
Expand All @@ -96,7 +96,7 @@ import(
"os"
"fmt"

"github.com/cc-api/cc-trusted-api/common/golang/cctrusted_base"
"github.com/cc-api/evidence-api/common/golang/evidence_api"
"github.com/cc-api/container-integrity-measurement-agent/sdk/golang/cima"
)

Expand All @@ -105,7 +105,7 @@ func testGetCCMeasurement() {

// set the imr index to 0
imr_index := 0
alg := cctrusted_base.TPM_ALG_SHA384
alg := evidence_api.TPM_ALG_SHA384

measurement, err := sdk.GetCCMeasurement(imr_index, alg)
if err != nil {
Expand Down Expand Up @@ -135,7 +135,7 @@ import(
"os"
"fmt"

"github.com/cc-api/cc-trusted-api/common/golang/cctrusted_base"
"github.com/cc-api/evidence-api/common/golang/evidence_api"
"github.com/cc-api/container-integrity-measurement-agent/sdk/golang/cima"
)

Expand Down Expand Up @@ -168,7 +168,7 @@ import(
"os"
"fmt"

"github.com/cc-api/cc-trusted-api/common/golang/cctrusted_base"
"github.com/cc-api/evidence-api/common/golang/evidence_api"
"github.com/cc-api/container-integrity-measurement-agent/sdk/golang/cima"
)

Expand Down Expand Up @@ -215,4 +215,4 @@ If you encounter any bugs or have suggestions, please file an issue in the Issue
<!-- LINKS -->
[source_code]: https://github.com/cc-api/container-integrity-measurement-agent/tree/main/sdk/golang
[cima_golang]: https://pkg.go.dev/github.com/cc-api/container-integrity-measurement-agent/sdk/golang/cima
[api_doc]: https://github.com/cc-api/cc-trusted-api?tab=readme-ov-file#3-apis
[api_doc]: https://github.com/cc-api/evidence-api?tab=readme-ov-file#3-apis
4 changes: 2 additions & 2 deletions sdk/golang/cima/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import (
"strings"
"time"

"github.com/cc-api/cc-trusted-api/common/golang/cctrusted_base"
pb "github.com/cc-api/container-integrity-measurement-agent/sdk/golang/cima/proto"
"github.com/cc-api/evidence-api/common/golang/evidence_api"
"google.golang.org/grpc"
)

Expand Down Expand Up @@ -129,7 +129,7 @@ func (cc *Client) GetMeasurementCountFromServer() (pb.GetMeasurementCountRespons
return *response, nil
}

func (cc *Client) GetCCMeasurementFromServer(index int, alg cctrusted_base.TCG_ALG) (pb.GetCcMeasurementResponse, error) {
func (cc *Client) GetCCMeasurementFromServer(index int, alg evidence_api.TCG_ALG) (pb.GetCcMeasurementResponse, error) {
ctx, cancel := context.WithTimeout(context.Background(), 60*time.Second)
defer cancel()

Expand Down
62 changes: 31 additions & 31 deletions sdk/golang/cima/sdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@ import (
"errors"
"log"

"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 {
}

// GetCCReport implements CCTrustedAPI
func (s *SDK) GetCCReport(nonce string, userData string, _ any) (cctrusted_base.Report, error) {
// GetCCReport implements EvidenceAPI
func (s *SDK) GetCCReport(nonce string, userData string, _ any) (evidence_api.Report, error) {
client, err := NewClient()
if err != nil {
log.Fatalf("[GetCCReport] failed to connect to client with error %v", err)
Expand All @@ -31,8 +31,8 @@ func (s *SDK) GetCCReport(nonce string, userData string, _ any) (cctrusted_base.
return nil, err
}

switch cctrusted_base.CC_Type(result.CcType) {
case cctrusted_base.TYPE_CC_TDX:
switch evidence_api.CC_Type(result.CcType) {
case evidence_api.TYPE_CC_TDX:
report, err := tdx.NewTdxReportFromBytes(result.CcReport)
if err != nil {
return nil, err
Expand All @@ -43,27 +43,27 @@ func (s *SDK) GetCCReport(nonce string, userData string, _ any) (cctrusted_base.
return nil, errors.New("[GetCCReport] get CC report failed")
}

// DumpCCReport implements cctrusted_base.CCTrustedAPI.
// DumpCCReport implements evidence_api.EvidenceAPI.
func (s *SDK) DumpCCReport(reportBytes []byte) error {
return nil
}

// GetCCMeasurement implements cctrusted_base.CCTrustedAPI.
func (s *SDK) GetCCMeasurement(index int, alg cctrusted_base.TCG_ALG) (cctrusted_base.TcgDigest, error) {
// GetCCMeasurement implements evidence_api.EvidenceAPI.
func (s *SDK) GetCCMeasurement(index int, alg evidence_api.TCG_ALG) (evidence_api.TcgDigest, error) {
client, err := NewClient()
if err != nil {
log.Fatalf("[GetCCMeasurement] failed to connect to client with error %v", err)
return cctrusted_base.TcgDigest{}, err
return evidence_api.TcgDigest{}, err
}

result, err := client.GetCCMeasurementFromServer(index, alg)
if err != nil {
return cctrusted_base.TcgDigest{}, err
return evidence_api.TcgDigest{}, err
}
return cctrusted_base.TcgDigest{AlgID: cctrusted_base.TCG_ALG(result.Measurement.AlgoId), Hash: result.Measurement.Hash}, nil
return evidence_api.TcgDigest{AlgID: evidence_api.TCG_ALG(result.Measurement.AlgoId), Hash: result.Measurement.Hash}, nil
}

// GetMeasurementCount implements cctrusted_base.CCTrustedAPI.
// GetMeasurementCount implements evidence_api.EvidenceAPI.
func (s *SDK) GetMeasurementCount() (int, error) {
client, err := NewClient()
if err != nil {
Expand All @@ -78,28 +78,28 @@ func (s *SDK) GetMeasurementCount() (int, error) {
return int(result.Count), 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) {
client, err := NewClient()
if err != nil {
log.Fatalf("[GetDefaultAlgorithm] failed to connect to client with error %v", err)
return cctrusted_base.TPM_ALG_ERROR, err
return evidence_api.TPM_ALG_ERROR, err
}

result, err := client.GetDefaultAlgorithmFromServer()
if err != nil {
return cctrusted_base.TPM_ALG_ERROR, err
return evidence_api.TPM_ALG_ERROR, err
}
return cctrusted_base.TCG_ALG(result.AlgoId), nil
return evidence_api.TCG_ALG(result.AlgoId), nil
}

// GetCCEventlog implements CCTrustedAPI.
func (s *SDK) GetCCEventLog(params ...int32) ([]cctrusted_base.FormatedTcgEvent, error) {
// GetCCEventlog implements EvidenceAPI.
func (s *SDK) GetCCEventLog(params ...int32) ([]evidence_api.FormatedTcgEvent, error) {
if len(params) > 2 {
log.Fatalf("Invalid params specified for [GetCCEventlog].")
return nil, errors.New("Invalid params.")
Expand All @@ -116,19 +116,19 @@ func (s *SDK) GetCCEventLog(params ...int32) ([]cctrusted_base.FormatedTcgEvent,
return nil, err
}

formatted_log_list := make([]cctrusted_base.FormatedTcgEvent, len(result))
formatted_log_list := make([]evidence_api.FormatedTcgEvent, len(result))
for idx, log := range result {
digests := make([]cctrusted_base.TcgDigest, len(log.Digests))
digests := make([]evidence_api.TcgDigest, len(log.Digests))
for idx, digest := range log.Digests {
formattedData := cctrusted_base.TcgDigest{AlgID: cctrusted_base.TCG_ALG(digest.AlgoId), Hash: digest.Hash}
formattedData := evidence_api.TcgDigest{AlgID: evidence_api.TCG_ALG(digest.AlgoId), Hash: digest.Hash}
digests[idx] = formattedData
}
logParser := cctrusted_base.TcgEventLogParser{RecNum: int(log.RecNum), ImrIndex: int(log.ImrIndex), EventType: cctrusted_base.TcgEventType(log.EventType), Digests: digests, EventSize: int(log.EventSize), Event: log.Event, ExtraInfo: log.ExtraInfo}
if cctrusted_base.TcgEventType(log.EventType) != cctrusted_base.IMA_MEASUREMENT_EVENT {
formattedLog := logParser.Format(cctrusted_base.TCG_PCCLIENT_FORMAT)
logParser := evidence_api.TcgEventLogParser{RecNum: int(log.RecNum), ImrIndex: int(log.ImrIndex), EventType: evidence_api.TcgEventType(log.EventType), Digests: digests, EventSize: int(log.EventSize), Event: log.Event, ExtraInfo: log.ExtraInfo}
if evidence_api.TcgEventType(log.EventType) != evidence_api.IMA_MEASUREMENT_EVENT {
formattedLog := logParser.Format(evidence_api.TCG_PCCLIENT_FORMAT)
formatted_log_list[idx] = formattedLog
} else {
formattedLog := logParser.Format(cctrusted_base.TCG_PCCLIENT_FORMAT)
formattedLog := logParser.Format(evidence_api.TCG_PCCLIENT_FORMAT)
formatted_log_list[idx] = formattedLog
}
}
Expand Down
6 changes: 3 additions & 3 deletions sdk/golang/example/go-sdk-example.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import (
"math/rand"
"os"

"github.com/cc-api/cc-trusted-api/common/golang/cctrusted_base"
"github.com/cc-api/container-integrity-measurement-agent/sdk/golang/cima"
"github.com/cc-api/evidence-api/common/golang/evidence_api"
)

// func to test GetCCReport()
Expand All @@ -30,7 +30,7 @@ func testGetCCReport(sdk cima.SDK, logger *log.Logger) {
}

logger.Println("Dump the attestation report fetched.")
report.Dump(cctrusted_base.QuoteDumpFormat(cctrusted_base.QuoteDumpFormatRaw))
report.Dump(evidence_api.QuoteDumpFormat(evidence_api.QuoteDumpFormatRaw))
logger.Println("----------------------------------------------------------------------------------")
}

Expand All @@ -39,7 +39,7 @@ func testGetCCMeasurement(sdk cima.SDK, logger *log.Logger) {
logger.Println("Call [GetCCMeasurement] to fetch measurement for specific IMR[0]...")

imr_index := 0
alg := cctrusted_base.TPM_ALG_SHA384
alg := evidence_api.TPM_ALG_SHA384

measurement, err := sdk.GetCCMeasurement(imr_index, alg)
if err != nil {
Expand Down
17 changes: 1 addition & 16 deletions sdk/golang/example/go.mod
Original file line number Diff line number Diff line change
@@ -1,18 +1,3 @@
module example.com/sdk

go 1.22.1

require (
github.com/cc-api/cc-trusted-api/common/golang/cctrusted_base v0.0.0-20240401053915-fe5bfeadd509
github.com/cc-api/container-integrity-measurement-agent/sdk/golang/cima v0.0.0-20240401063131-998a393b583a
)

require (
github.com/golang/protobuf v1.5.3 // indirect
golang.org/x/net v0.23.0 // indirect
golang.org/x/sys v0.18.0 // indirect
golang.org/x/text v0.14.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240123012728-ef4313101c80 // indirect
google.golang.org/grpc v1.62.1 // indirect
google.golang.org/protobuf v1.33.0 // indirect
)
go 1.20
33 changes: 0 additions & 33 deletions sdk/golang/example/go.sum

This file was deleted.

2 changes: 1 addition & 1 deletion sdk/python3/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,4 +159,4 @@ If you encounter any bugs or have suggestions, please file an issue in the Issue
<!-- LINKS -->
[source_code]: https://github.com/cc-api/container-integrity-measurement-agent/tree/main/sdk/python3
[cima_pypi]: https://pypi.org/project/cima/
[api_doc]: https://github.com/cc-api/cc-trusted-api?tab=readme-ov-file#3-apis
[api_doc]: https://github.com/cc-api/evidence-api?tab=readme-ov-file#3-apis
18 changes: 9 additions & 9 deletions sdk/python3/cima/sdk.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@
from typing import Optional
import grpc

from cctrusted_base.api import CCTrustedApi
from cctrusted_base.ccreport import CcReport
from cctrusted_base.tcg import TcgAlgorithmRegistry
from cctrusted_base.tcg import TcgDigest
from cctrusted_base.tcg import TcgImrEvent
from cctrusted_base.tcg import TcgPcClientImrEvent
from cctrusted_base.tdx.quote import TdxQuote
from evidence_api.api import EvidenceApi
from evidence_api.ccreport import CcReport
from evidence_api.tcg import TcgAlgorithmRegistry
from evidence_api.tcg import TcgDigest
from evidence_api.tcg import TcgImrEvent
from evidence_api.tcg import TcgPcClientImrEvent
from evidence_api.tdx.quote import TdxQuote
# pylint: disable=E1101
from cima import cima_server_pb2
from cima import cima_server_pb2_grpc
Expand All @@ -26,7 +26,7 @@
# Default gRPC timeout
TIMEOUT = 60

class CimaSdk(CCTrustedApi):
class CimaSdk(EvidenceApi):
"""CIMA SDK class

This class is a client to connect to CIMA Server and do gRPC call getting the
Expand Down Expand Up @@ -193,7 +193,7 @@ def get_cc_report(
LOG.error("CIMA service response is not correct.")
return None

if resp.cc_type == CCTrustedApi.TYPE_CC_TDX:
if resp.cc_type == EvidenceApi.TYPE_CC_TDX:
return TdxQuote(resp.cc_report)

LOG.error("The SDK does not support %s yet", resp.cc_type)
Expand Down
2 changes: 1 addition & 1 deletion sdk/python3/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cctrusted_base
evidence_api
grpcio-tools
grpcio
protobuf
Loading
Loading