challenger.go 1.9 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 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
package attestation // import "github.com/opencontainers/runc/libenclave/attestation"

import (
	"fmt"
)

type Challenger interface {
	Name() string
	New(map[string]string) error
	Check([]byte) error
	Verify([]byte) (*ReportStatus, error)
	GetReport([]byte, uint64) (*ReportStatus, map[string]string, error)
	ShowReportStatus(*ReportStatus)
	// TODO
	// PrepareChallenge() (*pb.AttestChallenge, error)
	// HandleChallengeResponse(*pb.AttestResponse) (*Quote, error)
}

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

/*
type Service struct {
	NonceForChallenge Nonce
	NonceForVerify    Nonce
}

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

const (
	// FIXME: allow tuning via parameter
	seedTimeout int64 = 6e10 // 60 seconds
)

func NewChallenger(aType string, cfg map[string]string) (Challenger, error) {
	for _, c := range challengerList {
		if c.Name() == aType {
			if err := c.New(cfg); err != nil {
				return nil, err
			}

			return c, nil
		}
	}

	return nil, fmt.Errorf("Unsupported attestation service %s specified", aType)
}

var challengerList []Challenger

func registerChallenger(challenger Challenger) error {
	for _, c := range challengerList {
		if c.Name() == challenger.Name() {
			return fmt.Errorf("Attestation service %s registered already", challenger.Name())
		}
	}

	challengerList = append(challengerList, challenger)

	return nil
}

/*
func PrepareChallenger() (*pb.AttestChallenge, error) {
        return &pb.AttestChallenge{
                Nonce: NonceForChallenge.Generate(),
        }, nil
}

func HandleResponse(r *pb.AttestResponse) (*attest.Quote, error) {
        quote := r.GetQuote()

        if len(quote) <= intelsgx.QuoteLength {
                return nil, fmt.Errorf("Invalid length of quote returned: %d-byte", len(quote))
        }

        return &Quote{Evidence: quote}, nil
}
*/