service.go 2.0 KB
Newer Older
1
package attestation // import "github.com/opencontainers/runc/libenclave/attestation"
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19

import (
	"fmt"
	pb "github.com/opencontainers/runc/libenclave/attestation/proto"
	"log"
)

type Service struct {
	Attester
	NonceForChallenge Nonce
	NonceForVerify    Nonce
	verbose           bool
}

type Attester interface {
	PrepareChallenge() (*pb.AttestChallenge, error)
	HandleChallengeResponse(r *pb.AttestResponse) (*Quote, error)
	Check([]byte) error
20
	GetVerifiedReport([]byte) (*Status, map[string]string, error)
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
	Verify([]byte) *Status
	ShowStatus(status *Status)
}

type Quote struct {
	// FIXME: use interface like io.Reader as callback?
	Evidence []byte
}

const (
	StatusSgxBit = 0x80000000
)

type Status struct {
	StatusCode     uint32
	ErrorMessage   string
	SpecificStatus interface{}
}

func NewService(p map[string]string, verbose bool) (*Service, error) {
	// TODO: try to probe the hardware and know which hardware security
	// technology is actually supported.

	for _, reg := range registry {
		var svc *Service
		var err error

		if svc, err = reg.Create(p); err == nil {
			if svc.Attester == nil {
				log.Println("Attestation service not set attester")
				continue
			}

			svc.verbose = verbose
			return svc, nil
		}

		if verbose {
			log.Fatal(err)
		}
	}

	return nil, fmt.Errorf("No matching attestation registry available")
}

/*
func (attest *Attestation) SetParameter(key string, val string, overwrite bool) error {
	// FIXME: use sync mutex
	if err := attest.GetParameter(key); err == nil {
		if !overwrite {
			return fmt.Errorf("Attestation parameter %s exists", key)
		}
	}

	attest.parameters[key] = val

	return nil
}

func (attest *Attestation) GetParameter(key string) (string, error) {
	if !attest.parameters[key] {
		return "", fmt.Errorf("Attestation parameter %s not exists", key)
	}

	return attest.parameters[key], nil
}
*/

func (svc *Service) VerboseOn() {
	svc.verbose = true
}

func (svc *Service) VerboseOff() {
	svc.verbose = false
}

func (svc *Service) IsVerbose() bool {
	return svc.verbose
}