mirror of
https://github.com/edgelesssys/constellation.git
synced 2025-08-02 03:56:07 -04:00
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>
This commit is contained in:
commit
2d8fcd9bf4
362 changed files with 50980 additions and 0 deletions
72
coordinator/core/attest.go
Normal file
72
coordinator/core/attest.go
Normal file
|
@ -0,0 +1,72 @@
|
|||
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))
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue