Skip to content

Commit

Permalink
treewide: allow omitting metadata
Browse files Browse the repository at this point in the history
Allow omitting the location of metadata in the configs.
The CMC can only work as verifier in this case, not
as prover.

Signed-off-by: Simon Ott <[email protected]>
  • Loading branch information
smo4201 committed Dec 7, 2023
1 parent 080b648 commit c23402e
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 3 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

cmcd/cmcd
testtool/testtool
testtool/ca.pem
est/estserver/estserver
**/nonce
**/attestation-report
Expand Down
8 changes: 7 additions & 1 deletion attestationreport/attestationreport.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"crypto/x509"
"encoding/hex"
"encoding/json"
"errors"
"fmt"

"github.com/Fraunhofer-AISEC/cmc/internal"
Expand Down Expand Up @@ -339,14 +340,19 @@ type ArPacked struct {
// format or CBOR COSE tokens. Takes a list of measurers providing a method
// for collecting the measurements from a hardware or software interface
func Generate(nonce []byte, metadata [][]byte, measurers []Driver, s Serializer) ([]byte, error) {

if s == nil {
return nil, errors.New("serializer not specified")
}

// Create attestation report object which will be filled with the attestation
// data or sent back incomplete in case errors occur
ar := ArPacked{
Type: "Attestation Report",
}

if len(nonce) > 32 {
return nil, fmt.Errorf("Generate Attestation Report: Nonce exceeds maximum length of 32 bytes")
return nil, fmt.Errorf("nonce exceeds maximum length of 32 bytes")
}
ar.Nonce = nonce

Expand Down
6 changes: 6 additions & 0 deletions cmc/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ import (

func GetMetadata(paths []string, cache string) ([][]byte, ar.Serializer, error) {

if paths == nil {
log.Trace("No metadata specified via config. Will only work as verifier")
var s ar.Serializer
return nil, s, nil
}

metadata := make([][]byte, 0)
fails := 0

Expand Down
6 changes: 6 additions & 0 deletions cmcd/coap.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,12 @@ func Attest(w mux.ResponseWriter, r *mux.Message) {
return
}

if Cmc.Metadata == nil {
sendCoapError(w, r, codes.InternalServerError,
"Metadata not specified. Can work only as verifier")
return
}

log.Debug("Prover: Generating Attestation Report with nonce: ", hex.EncodeToString(req.Nonce))

report, err := ar.Generate(req.Nonce, Cmc.Metadata, Cmc.Drivers, Cmc.Serializer)
Expand Down
10 changes: 9 additions & 1 deletion cmcd/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,22 @@ func (wrapper GrpcServerWrapper) Serve(addr string, cmc *cmc.Cmc) error {

func (s *GrpcServer) Attest(ctx context.Context, in *api.AttestationRequest) (*api.AttestationResponse, error) {

log.Info("Prover: Generating Attestation Report with nonce: ", hex.EncodeToString(in.Nonce))
log.Debug("Prover: Received gRPC attestation request")

if len(s.cmc.Drivers) == 0 {
return &api.AttestationResponse{
Status: api.Status_FAIL,
}, errors.New("no valid signers configured")
}

if s.cmc.Metadata == nil {
return &api.AttestationResponse{
Status: api.Status_FAIL,
}, errors.New("metadata not specified. Can work only as verifier")
}

log.Info("Prover: Generating Attestation Report with nonce: ", hex.EncodeToString(in.Nonce))

report, err := ar.Generate(in.Nonce, s.cmc.Metadata, s.cmc.Drivers, s.cmc.Serializer)
if err != nil {
return &api.AttestationResponse{
Expand Down
7 changes: 6 additions & 1 deletion cmcd/socket.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,18 @@ func handleIncoming(conn net.Conn, cmc *cmc.Cmc) {

func attest(conn net.Conn, payload []byte, cmc *cmc.Cmc) {

log.Debug("Prover: Received attestation request")
log.Debug("Prover: Received socket attestation request")

if len(cmc.Drivers) == 0 {
api.SendError(conn, "no valid signers configured")
return
}

if cmc.Metadata == nil {
api.SendError(conn, "Metadata not specified. Can work only as verifier")
return
}

req := new(api.AttestationRequest)
err := cbor.Unmarshal(payload, req)
if err != nil {
Expand Down
4 changes: 4 additions & 0 deletions testtool/libapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ func (a LibApi) generate(c *config) {
a.cmc = cmc
}

if a.cmc.Metadata == nil {
log.Fatalf("Metadata not specified. Can work only as verifier")
}

// Generate random nonce
nonce := make([]byte, 8)
_, err := rand.Read(nonce)
Expand Down

0 comments on commit c23402e

Please sign in to comment.