constellation/coordinator/core/attest.go
Leonard Cohnen 2d8fcd9bf4 monorepo
Co-authored-by: Malte Poll <mp@edgeless.systems>
Co-authored-by: katexochen <katexochen@users.noreply.github.com>
Co-authored-by: Daniel Weiße <dw@edgeless.systems>
Co-authored-by: Thomas Tendyck <tt@edgeless.systems>
Co-authored-by: Benedict Schlueter <bs@edgeless.systems>
Co-authored-by: leongross <leon.gross@rub.de>
Co-authored-by: Moritz Eckert <m1gh7ym0@gmail.com>
2022-03-22 16:09:39 +01:00

73 lines
1.6 KiB
Go

package core
import (
"bytes"
"encoding/json"
"fmt"
"github.com/edgelesssys/constellation/coordinator/oid"
)
// QuoteValidator validates quotes.
type QuoteValidator interface {
oid.Getter
// Validate validates a quote and returns the user data on success.
Validate(attDoc []byte, nonce []byte) ([]byte, error)
}
// QuoteIssuer issues quotes.
type QuoteIssuer interface {
oid.Getter
// Issue issues a quote for remote attestation for a given message
Issue(userData []byte, nonce []byte) (quote []byte, err error)
}
type mockAttDoc struct {
UserData []byte
Nonce []byte
}
func newMockAttDoc(userData []byte, nonce []byte) *mockAttDoc {
return &mockAttDoc{UserData: userData, Nonce: nonce}
}
type MockValidator struct {
oid.Dummy
}
// NewMockValidator returns a new MockValidator object.
func NewMockValidator() *MockValidator {
return &MockValidator{}
}
// Validate implements the Validator interface.
func (m *MockValidator) Validate(attDoc []byte, nonce []byte) ([]byte, error) {
var doc mockAttDoc
if err := json.Unmarshal(attDoc, &doc); err != nil {
return nil, err
}
if !bytes.Equal(doc.Nonce, nonce) {
return nil, fmt.Errorf("attDoc not valid: nonce not found")
}
return doc.UserData, nil
}
// MockIssuer is a mockup quote issuer.
type MockIssuer struct {
oid.Dummy
}
// NewMockIssuer returns a new MockIssuer object.
func NewMockIssuer() *MockIssuer {
return &MockIssuer{}
}
// Issue implements the Issuer interface.
func (m *MockIssuer) Issue(userData []byte, nonce []byte) ([]byte, error) {
return json.Marshal(newMockAttDoc(userData, nonce))
}